MapBox清除所有当前标记 [英] MapBox clear all current markers

查看:2446
本文介绍了MapBox清除所有当前标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用以下方法创建了一个MapBox实例:

I've created a MapBox instance with:

var map = new mapboxgl.Map({
    container : 'map',
    style : 'mapbox://styles/mapbox/streets-v9'
});

我需要清除所有标记,并尝试对每个标记进行map.remove(marker)之类的操作,以及其他一些操作,但似乎没有任何效果.

I need to clear all markers, and have tried things like map.remove(marker) on each one, and a few other things, but nothing seems to work.

是否有一个简单的函数调用来仅清除地图中的所有标记?

Is there a simple function call to just clear all markers from the map?

不同于如何删除所有图层和功能是从地图上获得的?,因为我在控制台中收到"eachLayer不是公认的函数"(或类似的结果).

Different from How to remove all layers and features from map? because I get "eachLayer is not a recognised function" (or similar) in console.

推荐答案

您看到了吗? https://www.mapbox.com/mapbox-gl-js/api/#marker#remove

可以尝试使用marker.remove代替map.remove:

Instead of map.remove maybe try marker.remove:

var marker = new mapboxgl.Marker().addTo(map);
marker.remove();

这篇关于MapBox清除所有当前标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆