Search in sources :

Example 1 with Projection

use of ol.proj.Projection in project gwt-ol3 by TDesjardins.

the class MapGuideExample method show.

/* (non-Javadoc)
     * @see de.desjardins.ol3.demo.client.example.Example#show()
     */
@Override
public void show(String exampleId) {
    // create a projection
    Projection projection = Projection.get("EPSG:4326");
    // create a MapGuide params
    ImageMapGuideParams imageMapGuideParams = new ImageMapGuideParams();
    imageMapGuideParams.setFormat("PNG");
    imageMapGuideParams.setMapDefinition("Library://Public/Samples/Sheboygan/Maps/Sheboygan.MapDefinition");
    imageMapGuideParams.setUserName("OpenLayers");
    imageMapGuideParams.setPassword("OpenLayers");
    // create a MapGuide image
    ImageMapGuideOptions imageMapGuideOptions = new ImageMapGuideOptions();
    imageMapGuideOptions.setParams(imageMapGuideParams);
    imageMapGuideOptions.setUrl("http://www.buoyshark.com/mapguide/mapagent/mapagent.fcgi?");
    imageMapGuideOptions.setUseOverlay(false);
    imageMapGuideOptions.setMetersPerUnit(111319.4908d);
    imageMapGuideOptions.setRatio(2.0f);
    ImageMapGuide imageMapGuideSource = new ImageMapGuide(imageMapGuideOptions);
    LayerOptions layerOptions = new LayerOptions();
    Extent bounds = new Extent(-87.865114442365922d, 43.665065564837931d, -87.595394059497067d, 43.823852564430069d);
    layerOptions.setExtent(bounds);
    layerOptions.setSource(imageMapGuideSource);
    Image mapGuideLayer = new Image(layerOptions);
    // create a view
    ViewOptions viewOptions = new ViewOptions();
    viewOptions.setProjection(projection);
    viewOptions.setZoom(12.0d);
    Coordinate centerCoordinate = new Coordinate(-87.7302542509315d, 43.744459064634d);
    viewOptions.setCenter(centerCoordinate);
    View view = new View(viewOptions);
    // create the map
    MapOptions mapOptions = new MapOptions();
    mapOptions.setTarget(exampleId);
    mapOptions.setView(view);
    Collection<Base> lstLayer = new Collection<Base>();
    lstLayer.push(mapGuideLayer);
    mapOptions.setLayers(lstLayer);
    Map map = new Map(mapOptions);
    // add some controls
    map.addControl(new ScaleLine());
    DemoUtils.addDefaultControls(map.getControls());
    // add some interactions
    map.addInteraction(new KeyboardPan());
    map.addInteraction(new KeyboardZoom());
    map.addControl(new Rotate());
}
Also used : ScaleLine(ol.control.ScaleLine) KeyboardPan(ol.interaction.KeyboardPan) Rotate(ol.control.Rotate) Extent(ol.Extent) MapOptions(ol.MapOptions) ViewOptions(ol.ViewOptions) Projection(ol.proj.Projection) Image(ol.layer.Image) LayerOptions(ol.layer.LayerOptions) View(ol.View) ImageMapGuideParams(ol.source.ImageMapGuideParams) Base(ol.layer.Base) ImageMapGuideOptions(ol.source.ImageMapGuideOptions) ImageMapGuide(ol.source.ImageMapGuide) Coordinate(ol.Coordinate) KeyboardZoom(ol.interaction.KeyboardZoom) Collection(ol.Collection) Map(ol.Map)

Example 2 with Projection

use of ol.proj.Projection in project gwt-ol3 by TDesjardins.

the class SelectFeaturesExample method show.

/* (non-Javadoc)
     * @see de.desjardins.ol3.demo.client.example.Example#show() */
@Override
public void show(String exampleId) {
    Coordinate centerCoordinate = new Coordinate(13.37, 52.52);
    Coordinate transformedMidPoint = Projection.transform(centerCoordinate, DemoConstants.EPSG_4326, DemoConstants.EPSG_3857);
    // create a polygon
    Polygon polygon = DemoUtils.createTestPolygon();
    // create a feature
    FeatureOptions featureOptions = OLFactory.createOptions();
    // TODO Setter for ID seems to doesn't have an effect in feature options.
    // featureOptions.setId("g1");
    featureOptions.setGeometry(polygon);
    Feature feature = new Feature(featureOptions);
    feature.setId("g1");
    feature.set("name", "triangle");
    // create another feature via cloning
    Feature feature2 = feature.clone();
    feature2.setId("g2");
    feature2.getGeometry().rotate(180, transformedMidPoint);
    Collection<Feature> lstFeatures = new Collection<Feature>();
    lstFeatures.push(feature);
    lstFeatures.push(feature2);
    VectorOptions vectorSourceOptions = OLFactory.createOptions();
    vectorSourceOptions.setFeatures(lstFeatures);
    Vector vectorSource = new Vector(vectorSourceOptions);
    VectorLayerOptions vectorLayerOptions = OLFactory.createOptions();
    vectorLayerOptions.setSource(vectorSource);
    ol.layer.Vector vectorLayer = new ol.layer.Vector(vectorLayerOptions);
    // create an OSM-layer
    XyzOptions osmSourceOptions = OLFactory.createOptions();
    Osm osmSource = new Osm(osmSourceOptions);
    LayerOptions osmLayerOptions = OLFactory.createOptions();
    osmLayerOptions.setSource(osmSource);
    Tile osmLayer = new Tile(osmLayerOptions);
    // create a view
    View view = new View();
    view.setCenter(transformedMidPoint);
    view.setZoom(14);
    // create the map
    MapOptions mapOptions = OLFactory.createOptions();
    mapOptions.setTarget(exampleId);
    mapOptions.setView(view);
    Collection<Base> lstLayer = new Collection<Base>();
    lstLayer.push(osmLayer);
    lstLayer.push(vectorLayer);
    mapOptions.setLayers(lstLayer);
    Map map = new Map(mapOptions);
    // add some controls
    map.addControl(new ScaleLine());
    MousePositionOptions mousePositionOptions = OLFactory.createOptions();
    ProjectionOptions projectionOptions = OLFactory.createOptions();
    projectionOptions.setCode(DemoConstants.EPSG_4326);
    mousePositionOptions.setProjection(new Projection(projectionOptions));
    MousePosition mousePosition = new MousePosition(mousePositionOptions);
    mousePosition.setCoordinateFormat(Coordinate.createStringXY(5));
    map.addControl(mousePosition);
    SelectOptions selectOptions = new SelectOptions();
    selectOptions.setCondition(Condition.getClick());
    // create a select interaction
    final Select selectFeature = new Select(selectOptions);
    map.addInteraction(selectFeature);
    selectFeature.on("select", (event) -> {
        Collection<Feature> selectedFeatures = selectFeature.getFeatures();
        if (selectedFeatures.getLength() > 0) {
            Feature selectedFeature = selectedFeatures.item(0);
            String output = "You selected feature with id '" + selectedFeature.getId() + "'" + " and name '" + selectedFeature.get("name") + "'" + " and geometry name '" + selectedFeature.getGeometryName() + "'" + ".";
            Window.alert(output);
        }
    });
}
Also used : XyzOptions(ol.source.XyzOptions) ScaleLine(ol.control.ScaleLine) MapOptions(ol.MapOptions) MousePositionOptions(ol.control.MousePositionOptions) Projection(ol.proj.Projection) Feature(ol.Feature) LayerOptions(ol.layer.LayerOptions) VectorLayerOptions(ol.layer.VectorLayerOptions) FeatureOptions(ol.FeatureOptions) MousePosition(ol.control.MousePosition) Polygon(ol.geom.Polygon) Vector(ol.source.Vector) SelectOptions(ol.interaction.SelectOptions) Osm(ol.source.Osm) Tile(ol.layer.Tile) View(ol.View) Base(ol.layer.Base) VectorLayerOptions(ol.layer.VectorLayerOptions) Coordinate(ol.Coordinate) Select(ol.interaction.Select) Collection(ol.Collection) ProjectionOptions(ol.proj.ProjectionOptions) Map(ol.Map) VectorOptions(ol.source.VectorOptions)

Example 3 with Projection

use of ol.proj.Projection in project gwt-ol3 by TDesjardins.

the class WmsExample method show.

/* (non-Javadoc)
     * @see de.desjardins.ol3.demo.client.example.Example#show()
     */
@Override
public void show(String exampleId) {
    ImageWmsParams imageWMSParams = OLFactory.createOptions();
    imageWMSParams.setLayers("ch.swisstopo.geologie-geotechnik-gk500-gesteinsklassierung,ch.bafu.schutzgebiete-paerke_nationaler_bedeutung");
    ImageWmsOptions imageWMSOptions = OLFactory.createOptions();
    imageWMSOptions.setUrl("http://wms.geo.admin.ch/");
    imageWMSOptions.setParams(imageWMSParams);
    imageWMSOptions.setRatio(1.5f);
    ImageWms imageWMSSource = new ImageWms(imageWMSOptions);
    LayerOptions layerOptions = OLFactory.createOptions();
    layerOptions.setSource(imageWMSSource);
    Image wmsLayer = new Image(layerOptions);
    // create a projection
    ProjectionOptions projectionOptions = OLFactory.createOptions();
    projectionOptions.setCode("EPSG:21781");
    projectionOptions.setUnits("m");
    Projection projection = new Projection(projectionOptions);
    // create a view
    ViewOptions viewOptions = OLFactory.createOptions();
    viewOptions.setProjection(projection);
    View view = new View(viewOptions);
    Coordinate centerCoordinate = new Coordinate(660000, 190000);
    view.setCenter(centerCoordinate);
    view.setZoom(9);
    // create the map
    MapOptions mapOptions = OLFactory.createOptions();
    mapOptions.setTarget(exampleId);
    mapOptions.setView(view);
    Map map = new Map(mapOptions);
    map.addLayer(wmsLayer);
    // add some controls
    map.addControl(new ScaleLine());
    DemoUtils.addDefaultControls(map.getControls());
    // add some interactions
    map.addInteraction(new KeyboardPan());
    map.addInteraction(new KeyboardZoom());
    map.addControl(new Rotate());
}
Also used : ScaleLine(ol.control.ScaleLine) KeyboardPan(ol.interaction.KeyboardPan) ImageWmsOptions(ol.source.ImageWmsOptions) Rotate(ol.control.Rotate) MapOptions(ol.MapOptions) ViewOptions(ol.ViewOptions) Projection(ol.proj.Projection) Image(ol.layer.Image) LayerOptions(ol.layer.LayerOptions) View(ol.View) Coordinate(ol.Coordinate) KeyboardZoom(ol.interaction.KeyboardZoom) ImageWmsParams(ol.source.ImageWmsParams) ProjectionOptions(ol.proj.ProjectionOptions) Map(ol.Map) ImageWms(ol.source.ImageWms)

Example 4 with Projection

use of ol.proj.Projection in project gwt-ol3 by TDesjardins.

the class AnimationExample method show.

/* (non-Javadoc)
     * @see de.desjardins.ol3.demo.client.example.Example#show() */
@Override
public void show(String exampleId) {
    Coordinate centerCoordinate = new Coordinate(13.37, 52.52);
    Coordinate transformedMidPoint = Projection.transform(centerCoordinate, DemoConstants.EPSG_4326, DemoConstants.EPSG_3857);
    // create an OSM-layer
    XyzOptions osmSourceOptions = new XyzOptions();
    Osm osmSource = new Osm(osmSourceOptions);
    LayerOptions osmLayerOptions = new LayerOptions();
    osmLayerOptions.setSource(osmSource);
    Tile osmLayer = new Tile(osmLayerOptions);
    // create a view
    View view = new View();
    view.setCenter(transformedMidPoint);
    view.setZoom(16);
    // create the map
    MapOptions mapOptions = new MapOptions();
    mapOptions.setLoadTilesWhileAnimating(true);
    mapOptions.setTarget(exampleId);
    mapOptions.setView(view);
    Collection<Base> lstLayer = new Collection<Base>();
    lstLayer.push(osmLayer);
    mapOptions.setLayers(lstLayer);
    Map map = new Map(mapOptions);
    // add some controls
    map.addControl(new ScaleLine());
    MousePositionOptions mousePositionOptions = new MousePositionOptions();
    ProjectionOptions projectionOptions = new ProjectionOptions();
    projectionOptions.setCode(DemoConstants.EPSG_4326);
    mousePositionOptions.setProjection(new Projection(projectionOptions));
    MousePosition mousePosition = new MousePosition(mousePositionOptions);
    mousePosition.setCoordinateFormat(Coordinate.createStringXY(5));
    map.addControl(mousePosition);
    Coordinate tvTowerCoordinate = Projection.transform(new Coordinate(13.409, 52.52), DemoConstants.EPSG_4326, DemoConstants.EPSG_3857);
    Coordinate pplaceCoordinate = Projection.transform(new Coordinate(13.377, 52.509), DemoConstants.EPSG_4326, DemoConstants.EPSG_3857);
    Coordinate zooCoordinate = Projection.transform(new Coordinate(13.338, 52.508), DemoConstants.EPSG_4326, DemoConstants.EPSG_3857);
    final List<Coordinate> coordinates = Arrays.asList(transformedMidPoint, tvTowerCoordinate, pplaceCoordinate, zooCoordinate);
    Scheduler.get().scheduleFixedPeriod(() -> {
        int index = getNextIndex(coordinates.size());
        AnimationOptions panAnimationOptions = new AnimationOptions();
        panAnimationOptions.setDuration(2000);
        // Switch this to rotate the animation while animating.
        // panAnimationOptions.setRotation(view.getRotation() + 2 * Math.PI);
        panAnimationOptions.setCenter(coordinates.get(index));
        view.animate(panAnimationOptions);
        AnimationOptions zoomOutAnimationOptions = new AnimationOptions();
        zoomOutAnimationOptions.setDuration(1000);
        zoomOutAnimationOptions.setResolution(view.getResolution() + 4);
        AnimationOptions zoomInAnimationOptions = new AnimationOptions();
        zoomInAnimationOptions.setDuration(1000);
        zoomInAnimationOptions.setResolution(view.getResolution());
        view.animate(zoomOutAnimationOptions, zoomInAnimationOptions);
        return true;
    }, 6000);
}
Also used : XyzOptions(ol.source.XyzOptions) ScaleLine(ol.control.ScaleLine) MapOptions(ol.MapOptions) MousePositionOptions(ol.control.MousePositionOptions) Osm(ol.source.Osm) Tile(ol.layer.Tile) Projection(ol.proj.Projection) LayerOptions(ol.layer.LayerOptions) View(ol.View) Base(ol.layer.Base) MousePosition(ol.control.MousePosition) Coordinate(ol.Coordinate) AnimationOptions(ol.animation.AnimationOptions) Collection(ol.Collection) ProjectionOptions(ol.proj.ProjectionOptions) Map(ol.Map)

Example 5 with Projection

use of ol.proj.Projection in project gwt-ol3 by TDesjardins.

the class ViewTest method getTestView.

private View getTestView() {
    ProjectionOptions projectionOptions = new ProjectionOptions();
    projectionOptions.setCode("EPSG:21781");
    projectionOptions.setUnits("m");
    assertNotNull(projectionOptions);
    Projection projection = new Projection(projectionOptions);
    assertNotNull(projection);
    ViewOptions viewOptions = new ViewOptions();
    viewOptions.setProjection(projection);
    View view = new View(viewOptions);
    Coordinate centerCoordinate = new Coordinate(660000, 190000);
    view.setCenter(centerCoordinate);
    view.setZoom(9);
    return view;
}
Also used : ViewOptions(ol.ViewOptions) Projection(ol.proj.Projection) ProjectionOptions(ol.proj.ProjectionOptions) View(ol.View)

Aggregations

Projection (ol.proj.Projection)9 View (ol.View)8 MapOptions (ol.MapOptions)7 Coordinate (ol.Coordinate)6 Map (ol.Map)6 ViewOptions (ol.ViewOptions)6 LayerOptions (ol.layer.LayerOptions)6 ProjectionOptions (ol.proj.ProjectionOptions)6 ScaleLine (ol.control.ScaleLine)5 Collection (ol.Collection)4 Base (ol.layer.Base)4 Rotate (ol.control.Rotate)3 KeyboardPan (ol.interaction.KeyboardPan)3 KeyboardZoom (ol.interaction.KeyboardZoom)3 Image (ol.layer.Image)3 Tile (ol.layer.Tile)3 Osm (ol.source.Osm)3 XyzOptions (ol.source.XyzOptions)3 Extent (ol.Extent)2 MousePosition (ol.control.MousePosition)2