use of ol.layer.VectorLayerOptions 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.layer.VectorLayerOptions in project gwt-ol3 by TDesjardins.
the class ClusterExample method show.
/* (non-Javadoc)
* @see de.desjardins.ol3.demo.client.example.Example#show() */
@Override
public void show(String exampleId) {
Collection<Feature> features = new Collection<Feature>();
int e = 450000;
for (int i = 0; i < 20000; ++i) {
// create a point
Coordinate coordinate = new Coordinate(2 * e * Math.random() - e, 2 * e * Math.random() - e);
Point point = new Point(coordinate);
// create feature
FeatureOptions featureOptions = new FeatureOptions();
featureOptions.setGeometry(point);
Feature feature = new Feature(featureOptions);
features.push(feature);
}
// create source
VectorOptions vectorSourceOptions = new VectorOptions();
vectorSourceOptions.setFeatures(features);
Vector vectorSource = new Vector(vectorSourceOptions);
// create clustering
ClusterOptions clusterOptions = new ClusterOptions();
clusterOptions.setDistance(40);
clusterOptions.setSource(vectorSource);
Cluster clusterSource = new Cluster(clusterOptions);
// create vector layer
VectorLayerOptions vectorLayerOptions = new VectorLayerOptions();
vectorLayerOptions.setSource(clusterSource);
vectorLayerOptions.setStyle(new GenericFunction<Feature, Style[]>() {
@Override
public Style[] call(Feature cluster) {
// create style
List<Style> style = new ArrayList<>();
Feature[] features = (Feature[]) cluster.get("features");
int clusterSize = features.length;
StyleOptions styleOptions = new StyleOptions();
TextOptions textOptions = new TextOptions();
textOptions.setText(String.valueOf(clusterSize));
styleOptions.setText(new Text(textOptions));
CircleOptions circleOptions = new CircleOptions();
circleOptions.setRadius(10);
Color color = Color.getColorFromString("#3399CC");
circleOptions.setFill(OLFactory.createFill(color));
styleOptions.setImage(new Circle(circleOptions));
style.add(new Style(styleOptions));
return style.toArray(new Style[0]);
}
});
ol.layer.Vector vectorLayer = new ol.layer.Vector(vectorLayerOptions);
// create a 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();
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);
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());
DemoUtils.addDefaultControls(map.getControls());
// add some interactions
map.addInteraction(new KeyboardPan());
map.addInteraction(new KeyboardZoom());
map.addControl(new Rotate());
}
use of ol.layer.VectorLayerOptions in project gwt-ol3 by TDesjardins.
the class GpxExample method show.
/* (non-Javadoc)
* @see de.desjardins.ol3.demo.client.example.Example#show()
*/
@Override
public void show(String exampleId) {
// create a OSM-layer
Osm osmSource = new Osm();
LayerOptions osmLayerOptions = OLFactory.createOptions();
osmLayerOptions.setSource(osmSource);
Tile osmLayer = new Tile(osmLayerOptions);
// create a GPX vector layer
VectorOptions vectorOptions = new VectorOptions();
vectorOptions.setUrl("https://openlayers.org/en/v4.6.4/examples/data/gpx/fells_loop.gpx");
vectorOptions.setFormat(new Gpx());
ol.source.Vector vectorSource = new ol.source.Vector(vectorOptions);
VectorLayerOptions vectorLayerOptions = new VectorLayerOptions();
vectorLayerOptions.setSource(vectorSource);
ol.layer.Vector gpxLayer = new ol.layer.Vector(vectorLayerOptions);
// create a view
View view = new View();
Coordinate center = new Coordinate(-7916041.528716288, 5228379.045749711);
view.setCenter(center);
view.setZoom(12);
// create the map
MapOptions mapOptions = OLFactory.createOptions();
mapOptions.setTarget(exampleId);
mapOptions.setView(view);
Map map = new Map(mapOptions);
map.addLayer(osmLayer);
map.addLayer(gpxLayer);
// 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());
}
Aggregations