Mapbox JS -集群计数层异常
Mapbox JS - Exception on cluster count layer
我得到了一个Mapbox地图与多个集群和一个非集群层的工作没有例外。但是当我尝试添加集群计数层时,我在控制台中获得以下错误:Uncaught TypeError:不能使用'in'操作符在未定义的中搜索'point_count'。
我遵循了Mapbox集群教程,但不明白为什么会出现这个错误。
下面是我的代码: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
}
}
}
此异常源于不正确的GeoJSON结构。
在提供的JSFiddle中,您包含了许多结构类似于以下的GeoJSON特性:
{
type: 'Feature',
geometry: {
type: 'Point',
properties: {
description: 'kuk'
},
coordinates: [2.7, 46.95]
}
}
GeoJSON规范说:
一个特性对象必须有一个名为"properties"的成员。properties成员的值是一个对象(任何JSON对象或JSON空值)。
properties
成员应该在Feature
对象上,而不是Point
对象上。正确格式化的特性应该像
{
type: 'Feature',
properties: {
description: 'kuk'
},
geometry: {
type: 'Point',
coordinates: [2.7, 46.95]
}
}
下面是一个没有错误的修改后的演示:https://jsfiddle.net/dyhhqLda/2/
相关文章:
- node.js和express中的异常处理
- JS异常:animate不是一个函数
- 在js中捕获自定义异常
- 当我在同一页上有两个图D3.js时,宽度异常
- 节点.js未捕获的异常类型错误:无法设置未定义的预处理 ''
- 使用datetimepicker敲除js绑定会出现异常
- 抛出异常:Node.js与Gevent
- 处理 Node.js 和 Express 中的 404、500 和异常
- 在 JS 中捕获异常
- 有没有办法在node.js中的异常或测试失败时启动调试器
- 在属性名称中搜索带有冒号的 xpath 表达式会引发异常(节点.js元素树模块)
- THREE.js 使用 sceneLoader 加载由 THREE.js 编辑器创建的场景时出现异常
- 从 C# 执行 JS 代码的异常:预期函数
- 主干.js - n捕获异常:语法错误:函数构造函数:无法编译函数
- JavaScriptCore:尝试将JS函数作为块传递给Objective-C,得到“TypeError”异常
- 使用 Express 4 在 Node.js 中全局处理异常的最佳方法
- d3.js:异常错误
- 发生未捕获的异常时重新启动 Node.js 应用程序
- 使用 iewebgl 运行三个.js示例时出现异常
- 未捕获的异常:每个数据元素都必须实现一个唯一的“id”属性slick.dataview.js