Skip to content

Complete Example of VectorLayer and TopoJson #101

@sirilicious

Description

@sirilicious

#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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions