VOL3 / v-ol3

Vaadin OpenLayers 3 wrapper
Apache License 2.0
15 stars 18 forks source link

Complete Example of VectorLayer and TopoJson #101

Open sirilicious opened 6 years ago

sirilicious commented 6 years ago

Hi! I'm not able to render a VectorLayer from mapzen, which is provided as TopoJson.

I noticed that the URL is not getting resolved with z,x and y, as my browser is complaining: [Error] Failed to load resource: the server responded with a status of 404 (Not Found) https://tile.mapzen.com/mapzen/vector/v1/512/all/%7Bz%7D/%7Bx%7D/%7By%7D.topojson?api_key=***

How can I specify an OLVectorSource with XYZ?

OLVectorSourceOptions optionsMapzen = new OLVectorSourceOptions();
optionsMapzen.setUrl("https://tile.mapzen.com/mapzen/vector/v1/512/all/{z}/{x}/{y}.topojson?api_key=" + apiKey);
optionsMapzen.setInputProjection(Projections.EPSG4326);
OLFeatureFormat format = OLFeatureFormat.TOPOJSON;
optionsMapzen.setFormat(format);
OLTopoJSONFormatOptions formatOptions = new OLTopoJSONFormatOptions();
formatOptions.setDefaultDataProjection(Projections.EPSG4326);
try {
   optionsMapzen.setFormatOptions(formatOptions);
} catch (JsonProcessingException e) {
...
}

OLVectorSource sourceMapZen = new OLVectorSource(optionsMapzen);
OLVectorLayer layerMapzen = new OLVectorLayer(sourceMapZen);

OLStyle style = StyleUtils.createDefaultStyle();
layerMapzen.setStyle(style);

map.addLayer(layerMapzen);

Furthermore, according to this tutorial I am missing the part where to specify the layers:

"{layerName:'layer',layers:['water','roads','buildings']}"

Thanks!