У меня есть карта Mapbox с несколькими кластерами и некластерными слоями, которые работают с исключениями. Но когда я пытаюсь добавить уровень подсчета кластера, я получаю следующую ошибку в консоли: Uncaught TypeError: Невозможно использовать оператор 'in' для поиска 'point_count' в undefined.Mapbox JS - Исключение на уровне подсчета кластера
Я следовал the Mapbox cluster tutorial, но не могу понять, почему эта ошибка появляется.
Вот мой код:
function setMyApplicationLayers(map, layers) {
getMyApplicationLayers().forEach(function(layer) {
map.addLayer(layer);
})
}
function getMyApplicationLayers() {
var layers = [getMyApplicationRestaurantItemLayer()];
['#ef59a1', '#6ecff6', '#d7df21']
.forEach(function(color, index) {
layers.push(getMyApplicationRestaurantGroupLayer(index, color));
});
layers.push(getMyApplicationRestaurantCountLayer());
return layers;
}
function getMyApplicationRestaurantItemLayer() {
return {
id: 'unclustered-restaurants',
type: 'symbol',
source: 'my-application-restaurants',
layout: {
'icon-image': 'marker-15'
}
}
}
function getMyApplicationRestaurantGroupLayer(index, color) {
return {
id: 'clustered-restaurants-' + index,
type: 'circle',
source: 'my-application-restaurants',
paint: {
'circle-color': color,
'circle-radius': 18
},
filter: getMyApplicationRestaurantGroupLayerFilter(index)
}
}
function getMyApplicationRestaurantGroupLayerFilter(index) {
switch (index) {
case 0:
return ['>=', 'point_count', 25]
case 1:
return ['all',
['>=', 'point_count', 5],
['<', 'point_count', 25]]
case 2:
return ['all',
['>=', 'point_count', 0],
['<', 'point_count', 5]]
}
}
function getMyApplicationRestaurantCountLayer() {
return {
id: 'cluster-count',
type: 'symbol',
source: 'my-application-restaurants',
layout: {
'text-field': '{point_count}',
'text-font': [
'DIN Offc Pro Medium',
'Arial Unicode MS Bold'
],
'text-size': 12
}
}
}
Я не вижу никаких проблем с посланным кодом. Можете ли вы опубликовать runable-пример, демонстрирующий ошибку? –
Вот [JSFiddle] (https://jsfiddle.net/dyhhqLda/2/). Попробуйте увеличить/развернуть и посмотреть на консоль. Благодаря ! – OhmWang