Search in sources :

Example 6 with XyzOptions

use of ol.source.XyzOptions in project gwt-ol3 by TDesjardins.

the class MapEventsExample 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 = new Coordinate(-0.1275, 51.507222);
    Coordinate transformedCenterCoordinate = Projection.transform(centerCoordinate, DemoConstants.EPSG_4326, DemoConstants.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);
    // clear default interactions
    map.getInteractions().clear();
    // add some interactions
    map.addInteraction(new DragPan());
    map.addInteraction(new KeyboardPan());
    map.addInteraction(new KeyboardZoom());
    map.addInteraction(new MouseWheelZoom());
    // add event handlers
    map.addDoubleClickListener(evt -> Window.alert("double click at " + evt.getCoordinate().getX() + ", " + evt.getCoordinate().getX()));
    map.addMapZoomListener(evt -> GWT.log("onZoom"));
    map.addMapZoomEndListener(evt -> GWT.log("onMapZoomEnd"));
}
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) Coordinate(ol.Coordinate) KeyboardZoom(ol.interaction.KeyboardZoom) MouseWheelZoom(ol.interaction.MouseWheelZoom) Map(ol.Map) DragPan(ol.interaction.DragPan)

Example 7 with XyzOptions

use of ol.source.XyzOptions 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 8 with XyzOptions

use of ol.source.XyzOptions 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 9 with XyzOptions

use of ol.source.XyzOptions 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 10 with XyzOptions

use of ol.source.XyzOptions 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)

Aggregations

LayerOptions (ol.layer.LayerOptions)16 Tile (ol.layer.Tile)16 XyzOptions (ol.source.XyzOptions)16 Coordinate (ol.Coordinate)15 Map (ol.Map)15 MapOptions (ol.MapOptions)15 View (ol.View)15 Osm (ol.source.Osm)13 ScaleLine (ol.control.ScaleLine)8 KeyboardPan (ol.interaction.KeyboardPan)7 KeyboardZoom (ol.interaction.KeyboardZoom)7 Collection (ol.Collection)6 MousePosition (ol.control.MousePosition)6 Base (ol.layer.Base)6 Feature (ol.Feature)4 FeatureOptions (ol.FeatureOptions)4 Attribution (ol.control.Attribution)4 Rotate (ol.control.Rotate)4 VectorLayerOptions (ol.layer.VectorLayerOptions)4 Vector (ol.source.Vector)4