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