use of ol.Coordinate 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);
}
});
}
use of ol.Coordinate 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.Coordinate in project gwt-ol3 by TDesjardins.
the class TileWmsExample method show.
/*
* (non-Javadoc)
*
* @see de.desjardins.ol3.demo.client.example.Example#show()
*/
@Override
public void show(String exampleId) {
TileWmsParams params = new TileWmsParams();
params.setLayers("topp:states");
params.setTiled(true);
TileWmsOptions options = new TileWmsOptions();
options.setUrl("https://ahocevar.com/geoserver/wms");
options.setParams(params);
options.setServerType(WmsServerType.GEOSERVER);
TileWms source = new TileWms(options);
Extent extent = new Extent(-13884991, 2870341, -7455066, 6338219);
Tile layer = new Tile();
layer.setExtent(extent);
layer.setSource(source);
Coordinate centerCoordinate = new Coordinate(-10997148, 4569099);
View view = new View();
view.setCenter(centerCoordinate);
view.setZoom(4);
// create the map
MapOptions mapOptions = new MapOptions();
mapOptions.setTarget(exampleId);
mapOptions.setView(view);
Map map = new Map(mapOptions);
map.addLayer(layer);
// 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());
}
use of ol.Coordinate 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());
}
use of ol.Coordinate 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"));
}
Aggregations