javascript - 重置 Mapbox 中的所有标记层

标签 javascript jquery mapbox

我使用 Mapbox 作为 map 来显示公司 geoLoc,我的代码是

var markerLayer = L.mapbox.markerLayer({
    type: 'Feature',
    geometry: {
    type: 'Point',
        coordinates: [value.GeoLng, value.GeoLat]
    },
    properties: {
        title: 'A Single Marker',
        description: 'Just one of me',
    }
}).addTo( $.mapbox.mapObj );

我的问题是,当我收到新的 json 调用及其返回的新位置时,我不知道如何重置/删除所有旧的标记层,并将所有新的标记层添加到 map 中。

我已经创建了一个 map 对象。 width jQuery as $.mapbox.mapObj 所以我希望它可以从我的对象中重置/删除所有标记层,并且我可以在其上添加所有新标记层。

最佳答案

您可以使用以下命令重置标记层

markerLayer.clearLayers()

关于javascript - 重置 Mapbox 中的所有标记层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18204797/

相关文章:

javascript - Mapbox JS SDK 地理编码客户端未定义

javascript - 我可以使用 momentjs 获取两个日期之间以年和月为单位的差异吗?

javascript - Google Page Speed Insights 不喜欢我的延迟加载英雄横幅

javascript - 向 json 数组中的元素添加不同的背景图像

javascript - 如何通过html链接将特定对象传递给函数?

jquery - Stylus 中的 CSS3 转换 - 如何针对 IE9 降级

ios - MapBox iOS SDK - 第一步

javascript - 如何在纯 CSS 中做到这一点?

javascript - 如何通过使用 javascript 单击按钮在另一个 DIV 中显示所选图像?

ios - map 框 : Image is black if its size is greater than 2048 * 2048