【发布时间】:2018-09-19 15:29:47
【问题描述】:
我在 mapbox 中添加了图层,然后添加点击它以触发弹出窗口。效果很好,看起来像这样:
map.addLayer({
"id": "circle",
"type": "circle",
"source": "companies",
"paint": {
"circle-radius": 20,
"circle-color": "#C6DB3E",
"circle-opacity": {
"stops": [[3, 0.1], [22, 0.8]]
}
}
});
在这里我选择那个层来触发弹出窗口:
map.on('click', function (e) {
var features = map.queryRenderedFeatures(e.point, {
layers: ["circle"]
});
if (!features.length) {
return;
}
var feature = features[0];
console.log(feature);
// Populate the popup and set its coordinates and content
var popup = new mapboxgl.Popup()
.setLngLat(feature.geometry.coordinates)
.setHTML('...')
.addTo(map);
});
但是当我将图层更改为使用动态圆半径时出现问题,图层现在看起来像这样:
map.addLayer({
"id": "circle",
"type": "circle",
"source": "companies",
"paint": {
"circle-radius": {
property: 'Size',
type: 'identity'
},
"circle-color": "#C6DB3E",
"circle-opacity": {
"stops": [[3, 0.1], [22, 0.8]]
}
}
});
此图层也可以正确打印到地图上。但是我不能点击它来弹出一个窗口。所以改变圆半径后,ID是不可点击的。 有趣的是,如果我使用 map.getStyle().layers 控制台记录 ID,则 ID 会出现在控制台中,以及所有其他图层。 没有错误。
【问题讨论】:
标签: mapbox mapbox-gl-js