Я скопировал и настроил этот пример из mapbox: https://docs.mapbox.com/mapbox-gl-js/example/filter-markers/
Все работает нормально, но я хочу получить geo json в качестве внешнего файла.
Поэтому я изменяю этот код:
var places = {
'type': 'FeatureCollection',
'features': [
{
'type': 'Feature',
'properties': {
'icon': 'theatre'
},
'geometry': {
'type': 'Point',
'coordinates': [-77.038659, 38.931567]
}
},
]
};
следующим образом:
var places = '../images/destinations.geojson';
, и я получаю эту ошибку в DevTools: Uncaught TypeError: Невозможно прочитать свойство 'forEach' из undefined.
Остальная часть кода (что я получаю сообщение об ошибке) выглядит так:
map.on('load', function() {
// Add a GeoJSON source containing place coordinates and information.
map.addSource('places', {
'type': 'geojson',
'data': places
});
places.features.forEach(function(feature) {
var symbol = feature.properties['icon'];
var layerID = 'poi-' + symbol;
// Add a layer for this symbol type if it hasn't been added already.
if (!map.getLayer(layerID)) {
map.addLayer({
'id': layerID,
'type': 'symbol',
'source': 'places',
'layout': {
'icon-image': symbol + '-15',
'icon-allow-overlap': true
},
'filter': ['==', 'icon', symbol]
});