Reputation: 1
When pulling in data from a geojson file that is stored online. The forEach function can not read the features I have set in the geojson file. Below is part of the code.
map.on('load', function() {
// Add a GeoJSON source containing place coordinates and information.
map.addSource('orders', {
type: 'geojson',
data: ordersjson,
});
map.addLayer({
id: "layerID",
type: "symbol",
source: 'orders',
layout: {
"icon-image": "circle" + "-15",
"icon-allow-overlap": true,
},
});
map.getLayer('layerID').features.forEach(function(feature) {
var earthquakeID = feature.properties['primary ID']
});
Upvotes: 0
Views: 1535
Reputation: 2312
The layer itself does not have any data at all. What you need is to get the source that holds the data. The layer is just for style definitions.
What you want is something like this:
map.getSource('orders')._data.features.forEach(function(feature) {
// do something
});
Upvotes: 2