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);
}
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"));
}
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()));
});
}
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);
});
}
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);
}
Aggregations