【问题标题】:How to add multiple ids in mapbox on?如何在mapbox上添加多个ID?
【发布时间】:2021-07-11 07:34:47
【问题描述】:

我有 3 个不同 id 的 mapbox 层

map.addLayer({
             'id': '1',
             ...
            });

map.addLayer({
             'id': '2',
             ...
            });

map.addLayer({
             'id': '3',
             ...
            });

我必须在 mouseentermouseleave 的 mapbox 上添加所有这些 id 像这样 map.on('mouseenter','1', function(e){

    });

但我必须对这 3 个不同的 id 进行单独的功能, 我想一次在 mouseentermouseleave 中添加所有 id,这样我就不必为 3 个不同的 id 分开。

我该怎么做?

【问题讨论】:

    标签: mapbox mapbox-gl-js


    【解决方案1】:

    你的理解是正确的。没有捷径可走。你当然可以定义一次函数并传递三次:

    const enterHandler = e => { ... }
    map.on('mouseenter', '1', enterHandler);
    map.on('mouseenter', '2', enterHandler);
    map.on('mouseenter', '3', enterHandler);
    

    您可能想查看map-gl-utils,它有一些方便的方法,例如hoverPointer,可能会对您有所帮助。

    【讨论】:

    • 没有捷径,不过还是谢谢:)
    猜你喜欢
    • 2021-05-18
    • 2020-06-29
    • 2021-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-25
    • 2021-10-06
    相关资源
    最近更新 更多