counties是mapboxgl官网提供示例图层(矢量瓦片示例)
第一种:
通过监听对应图层的鼠标事件,获取e.features,可以获取该图层上说要的feature
// counties为图层id
map.on('mousemove','counties', function(e) {
console.log(e.features) // 可以获取图层counties上面的所有feature
});
// 获取的数据
// [
// {
// "geometry": {
// "type": "Polygon",
// "coordinates": [
// [
// [
// -100.08544921875,
// 37.00255267215955
// ],
// [
// -99.5361328125,
// 37.00255267215955
// ],
// [
// -99.55810546875,
// 37.46613860234406
// ],
// [
// -100.107421875,
// 37.47485808497102
// ],
// [
// -100.08544921875,
// 37.00255267215955
// ]
// ]

本文介绍了两种方法在MapboxGL中获取矢量瓦片上的元素。第一种方法是通过监听图层的鼠标事件获取`e.features`。第二种方法利用地图的`querySourceFeatures`和`queryRenderedFeatures`方法来查询图层上的feature。这两种方式对于分析和操作MapboxGL中的vector tile数据非常有用。
最低0.47元/天 解锁文章
1421

被折叠的 条评论
为什么被折叠?



