I have 5 geojson layers - each layer have one line. I want to get the coordinates of the line with map.getSource or map.getLayer, but I don't see any geometry properites. I can get the coordinates with this:
var features = map.queryRenderedFeatures({layers:[layerName]});
console.log(features[0].geometry);
My geojson is:
var layer = map.addLayer({
"id": layerName,
"type": "line",
"source": {
"type": "geojson",
"data": {
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": line
}
}
},
"layout": {
"line-join": "round",
"line-cap": "round"
},
"paint": {
"line-color": "red",
"line-width": 13
}
});
getSource and getLayer are not meant to be used to retrieve the source data; the only way to access source data is to use queryRenderedFeatures or querySourceFeatures
The documentation is obscure regarding this but I found a way:
var feature = map.getSource('yoursourceid')._options.data;
The _options.data property of the datasource holds the equivalent data of a feature.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With