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
}
});
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.