Search in sources :

Example 16 with View

use of ol.View in project gwt-ol3 by TDesjardins.

the class MapboxExample method show.

/* (non-Javadoc)
     * @see de.desjardins.ol3.demo.client.example.Example#show()
     */
@Override
public void show(String exampleId) {
    XyzOptions mapboxOptions = new XyzOptions();
    mapboxOptions.setTileSize(new Size(512, 512));
    mapboxOptions.setUrl("https://api.mapbox.com/styles/v1/mapbox/dark-v8/tiles/{z}/{x}/{y}?access_token=" + ACCESS_TOKEN);
    mapboxOptions.setAttributions("© <a href='https://www.mapbox.com/about/maps/'>Mapbox</a> © <a href='http://www.openstreetmap.org/copyright'>OpenStreetMap</a>");
    Xyz mapboxSource = new Xyz(mapboxOptions);
    LayerOptions xyzLayerOptions = OLFactory.createOptions();
    xyzLayerOptions.setSource(mapboxSource);
    Tile mapboxLayer = new Tile(xyzLayerOptions);
    // create a view
    View view = new View();
    Coordinate centerCoordinate = new Coordinate(1490463, 6894388);
    view.setCenter(centerCoordinate);
    view.setZoom(10);
    // create the map
    MapOptions mapOptions = new MapOptions();
    mapOptions.setTarget(exampleId);
    mapOptions.setView(view);
    Map map = new Map(mapOptions);
    ol.control.Attribution attributionControl = new ol.control.Attribution();
    attributionControl.setCollapsed(false);
    map.addControl(attributionControl);
    map.addControl(new MousePosition());
    map.addControl(DemoUtils.createMapboxLogo());
    map.addLayer(mapboxLayer);
}
Also used : XyzOptions(ol.source.XyzOptions) MapOptions(ol.MapOptions) Size(ol.Size) Tile(ol.layer.Tile) LayerOptions(ol.layer.LayerOptions) View(ol.View) MousePosition(ol.control.MousePosition) Coordinate(ol.Coordinate) Xyz(ol.source.Xyz) Map(ol.Map)

Example 17 with View

use of ol.View in project gwt-ol3 by TDesjardins.

the class MeasureExample method show.

/* (non-Javadoc)
     * @see de.desjardins.ol3.demo.client.example.Example#show()
     */
@Override
public void show(String exampleId) {
    // create a 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 = OLFactory.createView();
    Coordinate centerCoordinate = new Coordinate(-0.1275, 51.507222);
    Coordinate transformedCenterCoordinate = Projection.transform(centerCoordinate, "EPSG:4326", "EPSG:3857");
    view.setCenter(transformedCenterCoordinate);
    view.setZoom(10);
    // create the map
    MapOptions mapOptions = OLFactory.createOptions();
    mapOptions.setTarget(exampleId);
    mapOptions.setView(view);
    Map map = new Map(mapOptions);
    map.addLayer(osmLayer);
    // add some controls
    map.addControl(new ScaleLine());
    DemoUtils.addDefaultControls(map.getControls());
    Attribution attribution = new Attribution();
    attribution.setCollapsed(true);
    map.addControl(attribution);
    // add some interactions
    map.addInteraction(new KeyboardPan());
    map.addInteraction(new KeyboardZoom());
    // add measurement functionality to the map
    final Measure measure = new Measure(map);
    // start measuring immediately
    measure.startMeasureLength(new MeasureListener() {

        @Override
        public void onMeasure(MeasureEvent evt) {
            // log the measured length
            GWT.log("measure: " + evt.getMeasure());
        }
    }, true, true);
}
Also used : XyzOptions(ol.source.XyzOptions) ScaleLine(ol.control.ScaleLine) KeyboardPan(ol.interaction.KeyboardPan) MapOptions(ol.MapOptions) Osm(ol.source.Osm) Tile(ol.layer.Tile) LayerOptions(ol.layer.LayerOptions) View(ol.View) Attribution(ol.control.Attribution) MeasureListener(ol.event.MeasureListener) Coordinate(ol.Coordinate) KeyboardZoom(ol.interaction.KeyboardZoom) Measure(ol.gwt.Measure) MeasureEvent(ol.event.MeasureEvent) Map(ol.Map)

Example 18 with View

use of ol.View in project gwt-ol3 by TDesjardins.

the class OverlayExample method show.

/* (non-Javadoc)
     * @see de.desjardins.ol3.demo.client.example.Example#show()
     */
@Override
public void show(String exampleId) {
    // create a 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();
    Coordinate centerCoordinate = OLFactory.createCoordinate(2.3, 51.507222);
    Coordinate transformedCenterCoordinate = Projection.transform(centerCoordinate, "EPSG:4326", "EPSG:3857");
    view.setCenter(transformedCenterCoordinate);
    view.setZoom(10);
    // create the map
    MapOptions mapOptions = OLFactory.createOptions();
    mapOptions.setTarget(exampleId);
    mapOptions.setView(view);
    Map map = new Map(mapOptions);
    map.addLayer(osmLayer);
    // add some controls
    map.addControl(OLFactory.createScaleLine());
    DemoUtils.addDefaultControls(map.getControls());
    Attribution attribution = new Attribution();
    attribution.setCollapsed(true);
    map.addControl(attribution);
    // add some interactions
    map.addInteraction(OLFactory.createKeyboardPan());
    map.addInteraction(OLFactory.createKeyboardZoom());
    DivElement overlay = Document.get().createDivElement();
    overlay.setClassName("overlay-font");
    overlay.setInnerText("Created with GWT SDK " + GWT.getVersion());
    OverlayOptions overlayOptions = OLFactory.createOptions();
    overlayOptions.setElement(overlay);
    overlayOptions.setPosition(transformedCenterCoordinate);
    overlayOptions.setOffset(OLFactory.createPixel(-300, 0));
    map.addOverlay(new Overlay(overlayOptions));
}
Also used : XyzOptions(ol.source.XyzOptions) DivElement(com.google.gwt.dom.client.DivElement) Coordinate(ol.Coordinate) MapOptions(ol.MapOptions) OverlayOptions(ol.OverlayOptions) Osm(ol.source.Osm) Tile(ol.layer.Tile) Overlay(ol.Overlay) LayerOptions(ol.layer.LayerOptions) View(ol.View) Map(ol.Map) Attribution(ol.control.Attribution)

Example 19 with View

use of ol.View in project gwt-ol3 by TDesjardins.

the class WfsExample method show.

/* (non-Javadoc)
     * @see de.desjardins.ol3.demo.client.example.Example#show()
     */
@Override
public void show(String exampleId) {
    // create a vector layer
    Vector vectorSource = new Vector();
    VectorLayerOptions vectorLayerOptions = new VectorLayerOptions();
    vectorLayerOptions.setSource(vectorSource);
    ol.layer.Vector wfsLayer = new ol.layer.Vector(vectorLayerOptions);
    // create a view
    View view = new View();
    Coordinate centerCoordinate = new Coordinate(-8908887.277395891, 5381918.072437216);
    view.setCenter(centerCoordinate);
    view.setZoom(12);
    view.setMaxZoom(19);
    // create the map
    MapOptions mapOptions = OLFactory.createOptions();
    mapOptions.setTarget(exampleId);
    mapOptions.setView(view);
    Map map = new Map(mapOptions);
    map.addLayer(DemoUtils.createOsmLayer());
    map.addLayer(wfsLayer);
    Wfs wfs = new Wfs();
    WfsWriteFeatureOptions wfsWriteFeatureOptions = new WfsWriteFeatureOptions();
    String[] featureTypes = { "water_areas" };
    wfsWriteFeatureOptions.setSrsName("EPSG:3857");
    wfsWriteFeatureOptions.setFeaturePrefix("osm");
    wfsWriteFeatureOptions.setFeatureNS("http://openstreemap.org");
    wfsWriteFeatureOptions.setFeatureTypes(featureTypes);
    // set a filter
    wfsWriteFeatureOptions.setFilter(new IsLike("name", "Mississippi*"));
    wfsWriteFeatureOptions.setOutputFormat("application/json");
    // create WFS-XML node
    Node wfsNode = wfs.writeGetFeature(wfsWriteFeatureOptions);
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST, "https://ahocevar.com/geoserver/wfs");
    requestBuilder.setRequestData(new XMLSerializer().serializeToString(wfsNode));
    requestBuilder.setCallback(new RequestCallback() {

        @Override
        public void onResponseReceived(com.google.gwt.http.client.Request request, Response response) {
            GeoJson geoJson = new GeoJson();
            Feature[] features = geoJson.readFeatures(response.getText());
            vectorSource.addFeatures(features);
            map.getView().fit(vectorSource.getExtent());
        }

        @Override
        public void onError(com.google.gwt.http.client.Request request, Throwable exception) {
            Window.alert(exception.getMessage());
        }
    });
    try {
        requestBuilder.send();
    } catch (RequestException e) {
        Window.alert(e.getMessage());
    }
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) MapOptions(ol.MapOptions) Node(elemental2.dom.Node) GeoJson(ol.format.GeoJson) IsLike(ol.format.filter.IsLike) RequestException(com.google.gwt.http.client.RequestException) Vector(ol.source.Vector) XMLSerializer(com.github.desjardins.elemental.XMLSerializer) Wfs(ol.format.Wfs) View(ol.View) VectorLayerOptions(ol.layer.VectorLayerOptions) Response(com.google.gwt.http.client.Response) WfsWriteFeatureOptions(ol.format.WfsWriteFeatureOptions) RequestCallback(com.google.gwt.http.client.RequestCallback) Coordinate(ol.Coordinate) Map(ol.Map)

Example 20 with View

use of ol.View in project gwt-ol3 by TDesjardins.

the class WmtsExample 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(DemoConstants.EPSG_3857);
    // create a OSM-layer
    XyzOptions osmSourceOptions = OLFactory.createOptions();
    Osm osmSource = new Osm(osmSourceOptions);
    LayerOptions osmLayerOptions = OLFactory.createOptions();
    osmLayerOptions.setSource(osmSource);
    Tile osmLayer = new Tile(osmLayerOptions);
    WmtsOptions wmtsOptions = OLFactory.createOptions();
    wmtsOptions.setUrl("https://services.arcgisonline.com/arcgis/rest/services/Demographics/USA_Population_Density/MapServer/WMTS/");
    wmtsOptions.setLayer("0");
    wmtsOptions.setFormat("image/png");
    wmtsOptions.setMatrixSet(DemoConstants.EPSG_3857);
    wmtsOptions.setStyle("default");
    wmtsOptions.setProjection(projection);
    wmtsOptions.setWrapX(true);
    wmtsOptions.setTileGrid(this.createWmtsTileGrid(projection));
    // create attribution
    wmtsOptions.setAttributions("Tiles &copy; <a href=\"http://services.arcgisonline.com/arcgis/rest/services/Demographics/USA_Population_Density/MapServer/\">ArcGIS</a>");
    Wmts wmtsSource = new Wmts(wmtsOptions);
    LayerOptions wmtsLayerOptions = OLFactory.createOptions();
    wmtsLayerOptions.setSource(wmtsSource);
    Tile wmtsLayer = new Tile(wmtsLayerOptions);
    wmtsLayer.setOpacity(0.7);
    // create a view
    ViewOptions viewOptions = OLFactory.createOptions();
    viewOptions.setProjection(projection);
    View view = new View(viewOptions);
    Coordinate centerCoordinate = new Coordinate(-11158582, 4813697);
    view.setCenter(centerCoordinate);
    view.setZoom(4);
    // create the map
    MapOptions mapOptions = OLFactory.createOptions();
    mapOptions.setTarget(exampleId);
    mapOptions.setView(view);
    Map map = new Map(mapOptions);
    // add layers
    map.addLayer(osmLayer);
    map.addLayer(wmtsLayer);
    // 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 : XyzOptions(ol.source.XyzOptions) ScaleLine(ol.control.ScaleLine) KeyboardPan(ol.interaction.KeyboardPan) Rotate(ol.control.Rotate) MapOptions(ol.MapOptions) ViewOptions(ol.ViewOptions) Osm(ol.source.Osm) Projection(ol.proj.Projection) Tile(ol.layer.Tile) LayerOptions(ol.layer.LayerOptions) View(ol.View) WmtsOptions(ol.source.WmtsOptions) Coordinate(ol.Coordinate) KeyboardZoom(ol.interaction.KeyboardZoom) Wmts(ol.source.Wmts) Map(ol.Map)

Aggregations

View (ol.View)28 MapOptions (ol.MapOptions)25 Coordinate (ol.Coordinate)24 Map (ol.Map)24 LayerOptions (ol.layer.LayerOptions)21 Tile (ol.layer.Tile)18 XyzOptions (ol.source.XyzOptions)15 ScaleLine (ol.control.ScaleLine)14 KeyboardPan (ol.interaction.KeyboardPan)13 KeyboardZoom (ol.interaction.KeyboardZoom)13 Osm (ol.source.Osm)13 Rotate (ol.control.Rotate)9 Collection (ol.Collection)8 Base (ol.layer.Base)8 Projection (ol.proj.Projection)8 ViewOptions (ol.ViewOptions)7 MousePosition (ol.control.MousePosition)7 Attribution (ol.control.Attribution)6 VectorLayerOptions (ol.layer.VectorLayerOptions)6 Image (ol.layer.Image)5