Search in sources :

Example 1 with Attribution

use of ol.control.Attribution in project gwt-ol3 by TDesjardins.

the class TileExample method show.

/* (non-Javadoc)
     * @see de.desjardins.ol3.demo.client.example.Example#show()
     */
@Override
public void show(String exampleId) {
    LayerOptions stamenLayerOptions = OLFactory.createOptions();
    // create a Stamen-layer
    StamenOptions stamenOptions = OLFactory.createOptions();
    stamenOptions.setLayer("watercolor");
    Stamen stamenSource = new Stamen(stamenOptions);
    stamenLayerOptions.setSource(stamenSource);
    Tile stamenLayer = new Tile(stamenLayerOptions);
    // create a view
    View view = new View();
    Coordinate centerCoordinate = OLFactory.createCoordinate(1490463, 6894388);
    view.setCenter(centerCoordinate);
    view.setZoom(10);
    // create the map
    MapOptions mapOptions = OLFactory.createOptions();
    mapOptions.setTarget(exampleId);
    mapOptions.setView(view);
    Map map = new Map(mapOptions);
    stamenLayer.setOpacity(0.5f);
    // 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());
    DragAndDrop dragAndDrop = new DragAndDrop();
    map.addInteraction(dragAndDrop);
    EventListener<DragAndDrop.Event> eventListener = new EventListener<DragAndDrop.Event>() {

        @Override
        public void onEvent(DragAndDrop.Event event) {
            Window.alert(String.valueOf(event.getFeatures().length));
            Window.alert(event.getProjection().getUnits());
            Window.alert(String.valueOf(event.getProjection().getMetersPerUnit()));
        }
    };
    dragAndDrop.on("addfeatures", eventListener);
    map.addControl(new Rotate());
    map.getLayers().push(stamenLayer);
}
Also used : ScaleLine(ol.control.ScaleLine) KeyboardPan(ol.interaction.KeyboardPan) Stamen(ol.source.Stamen) Rotate(ol.control.Rotate) MapOptions(ol.MapOptions) Tile(ol.layer.Tile) LayerOptions(ol.layer.LayerOptions) View(ol.View) Attribution(ol.control.Attribution) StamenOptions(ol.source.StamenOptions) DragAndDrop(ol.interaction.DragAndDrop) Coordinate(ol.Coordinate) KeyboardZoom(ol.interaction.KeyboardZoom) EventListener(ol.event.EventListener) Map(ol.Map)

Example 2 with Attribution

use of ol.control.Attribution 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 3 with Attribution

use of ol.control.Attribution in project gwt-ol3 by TDesjardins.

the class CollectionTest method testCollection.

public void testCollection() {
    this.injectUrlAndTest(() -> {
        Collection<Control> controls = new Collection<Control>();
        assertNotNull(controls);
        assertTrue(controls.getLength() == 0);
        assertTrue(controls.isEmpty());
        assertNotNull(controls.getArray());
        // Does not work before ol v3.20. because bug in ol3.
        int length = controls.push(new Attribution());
        assertTrue(length == 1);
        assertTrue(controls.getLength() == 1);
        assertFalse(controls.isEmpty());
        assertNotNull(controls.getArray());
        assertTrue(controls.getArray().length == 1);
        Control control = controls.pop();
        assertTrue(control instanceof Attribution);
        assertTrue(controls.getLength() == 0);
        assertTrue(controls.isEmpty());
        Attribution attribution = new Attribution();
        controls.push(attribution);
        assertTrue(controls.contains(attribution));
        assertFalse(controls.contains(new Attribution()));
    });
}
Also used : Control(ol.control.Control) Attribution(ol.control.Attribution)

Example 4 with Attribution

use of ol.control.Attribution in project gwt-ol3 by TDesjardins.

the class CollectionTest method testCollectionEvents.

public void testCollectionEvents() {
    this.injectUrlAndTest(() -> {
        Collection<Control> controls = new Collection<Control>();
        assertFalse(this.elementAddedEventFired);
        assertFalse(this.elementRemovedEventFired);
        controls.addElementAddedListener(new EventListener<Collection.Event<Control>>() {

            @Override
            public void onEvent(Event<Control> event) {
                elementAddedEventFired = true;
            }
        });
        controls.addElementRemovedListener(new EventListener<Collection.Event<Control>>() {

            @Override
            public void onEvent(Event<Control> event) {
                elementRemovedEventFired = true;
            }
        });
        controls.push(new Attribution());
        assertTrue(this.elementAddedEventFired);
        assertFalse(this.elementRemovedEventFired);
        controls.removeAt(0);
        assertTrue(this.elementAddedEventFired);
        assertTrue(this.elementRemovedEventFired);
    });
}
Also used : Control(ol.control.Control) Event(ol.Collection.Event) Attribution(ol.control.Attribution)

Example 5 with Attribution

use of ol.control.Attribution 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)

Aggregations

Attribution (ol.control.Attribution)8 Coordinate (ol.Coordinate)6 Map (ol.Map)6 MapOptions (ol.MapOptions)6 View (ol.View)6 LayerOptions (ol.layer.LayerOptions)6 Tile (ol.layer.Tile)6 KeyboardPan (ol.interaction.KeyboardPan)5 KeyboardZoom (ol.interaction.KeyboardZoom)5 Osm (ol.source.Osm)5 ScaleLine (ol.control.ScaleLine)4 XyzOptions (ol.source.XyzOptions)4 Control (ol.control.Control)2 DivElement (com.google.gwt.dom.client.DivElement)1 Event (ol.Collection.Event)1 Overlay (ol.Overlay)1 OverlayOptions (ol.OverlayOptions)1 Rotate (ol.control.Rotate)1 EventListener (ol.event.EventListener)1 MeasureEvent (ol.event.MeasureEvent)1