How to clear leaflet map of all markers and layers before adding new ones?

前端 未结 6 1604
遇见更好的自我
遇见更好的自我 2021-02-05 00:02

I have the fallowing code:

map: function (events) {
    var arrayOfLatLngs = [];
    var _this = this;

    // setup a marker group
    var markers = L.markerClu         


        
6条回答
  •  無奈伤痛
    2021-02-05 00:50

    If you want to remove all the current layers (markers) in your group you can use the clearLayers method of L.markerClusterGroup(). Your reference is called markers so you would need to call:

    markers.clearLayers();
    

提交回复
热议问题