【问题标题】:Is it possible to click on labels in Mapbox like on Google maps?是否可以像在 Google 地图上一样点击 Mapbox 中的标签?
【发布时间】:2017-06-29 22:28:17
【问题描述】:

是否可以点击 Mapbox 中的标签并像在谷歌地图上一样突出显示城市?

Example Screenshot

【问题讨论】:

    标签: mapbox mapbox-gl-js mapbox-gl


    【解决方案1】:

    可以点击 mapbox-gl 地图中所有可见的地图元素,包括标签。

    https://www.mapbox.com/mapbox-gl-js/example/queryrenderedfeatures/

    在该示例中,不是捕获 mousemove 事件,而是像这样捕获 click 事件:

    map.on('click', function (e) {
        var features = map.queryRenderedFeatures(e.point);
        document.getElementById('features').innerHTML = JSON.stringify(features, null, 2);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-15
      • 2016-07-08
      • 1970-01-01
      • 1970-01-01
      • 2019-07-20
      • 1970-01-01
      相关资源
      最近更新 更多