use of ol.MapOptions 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());
}
}
use of ol.MapOptions 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 © <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());
}
use of ol.MapOptions in project gwt-ol3 by TDesjardins.
the class ArcGISExample method show.
/* (non-Javadoc)
* @see de.desjardins.ol3.demo.client.example.Example#show() */
@Override
public void show(String exampleId) {
ImageArcGisRestParams params = new ImageArcGisRestParams();
params.showLayers("2");
ImageArcGisRestOptions options = new ImageArcGisRestOptions();
options.setUrl("https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer");
options.setParams(params);
options.setRatio(1f);
ImageArcGisRest source = new ImageArcGisRest(options);
LayerOptions layerOptions = OLFactory.createOptions();
layerOptions.setSource(source);
Image layer = new Image(layerOptions);
// create a view
View view = new View();
Coordinate center = OLFactory.createCoordinate(-10997148, 4569099);
view.setCenter(center);
view.setZoom(4);
// create the map
MapOptions mapOptions = OLFactory.createOptions();
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.MapOptions in project gwt-ol3 by TDesjardins.
the class ConstrainedViewExample method show.
/* (non-Javadoc)
* @see de.desjardins.ol3.demo.client.example.Example#show()
*/
@Override
public void show(String exampleId) {
XyzOptions xyzOptions = OLFactory.createOptions();
xyzOptions.setUrl("http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/{z}/{y}/{x}");
xyzOptions.setAttributions("Tiles © <a href=\"http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer\">ArcGIS</a>");
Xyz xyzSource = new Xyz(xyzOptions);
LayerOptions xyzLayerOptions = OLFactory.createOptions();
xyzLayerOptions.setSource(xyzSource);
Tile xyzLayer = new Tile(xyzLayerOptions);
// create a view
View view = new View();
Coordinate centerCoordinate = new Coordinate(-121.1, 47.5);
Coordinate transformedCenterCoordinate = Projection.transform(centerCoordinate, "EPSG:4326", "EPSG:3857");
view.setCenter(transformedCenterCoordinate);
view.setZoom(12);
// restrict zoom
view.setMinZoom(11);
view.setMaxZoom(14);
// create the map
MapOptions mapOptions = OLFactory.createOptions();
mapOptions.setTarget(exampleId);
mapOptions.setView(view);
Map map = new Map(mapOptions);
// restrict extent
ViewOptions viewOptions = new ViewOptions();
viewOptions.setCenter(map.getView().getCenter());
viewOptions.setExtent(map.getView().calculateExtent(map.getSize()));
viewOptions.setZoom(map.getView().getZoom());
viewOptions.setMinZoom(map.getView().getMinZoom());
viewOptions.setMaxZoom(map.getView().getMaxZoom());
View restrictedView = new View(viewOptions);
map.setView(restrictedView);
ol.control.Attribution attributionControl = new ol.control.Attribution();
attributionControl.setCollapsed(false);
map.addControl(attributionControl);
MousePosition mousePosition = new MousePosition();
mousePosition.setCoordinateFormat(Coordinate.createStringXY(2));
map.addControl(mousePosition);
map.addLayer(xyzLayer);
}
use of ol.MapOptions in project gwt-ol3 by TDesjardins.
the class MvtExample method show.
/* (non-Javadoc)
* @see de.desjardins.ol3.demo.client.example.Example#show()
*/
@Override
public void show(String exampleId) {
VectorTileOptions vectorTileOptions = new VectorTileOptions();
vectorTileOptions.setFormat(new Mvt());
vectorTileOptions.setUrl("https://{a-d}.tiles.mapbox.com/v4/mapbox.mapbox-streets-v6/{z}/{x}/{y}.vector.pbf?access_token=" + ACCESS_TOKEN);
vectorTileOptions.setAttributions("© <a href=\"https://www.mapbox.com/map-feedback/\">Mapbox</a> © <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap contributors</a>'");
VectorTile vectorTile = new VectorTile(vectorTileOptions);
VectorTileLayerOptions tileLayerOptions = new VectorTileLayerOptions();
tileLayerOptions.setSource(vectorTile);
ol.layer.VectorTile mvtLayer = new ol.layer.VectorTile(tileLayerOptions);
// create a view
View view = new View();
Coordinate centerCoordinate = new Coordinate(0, 0);
view.setCenter(centerCoordinate);
view.setZoom(2);
// 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(mvtLayer);
}
Aggregations