How do I toggle (add/remove) shapefile layers in Leaflet.js?

المشرف العام

Administrator
طاقم الإدارة
If I create a shapefile layer

var ac_shpfile = new L.Shapefile("data/AC.zip", {onEachFeature: function (feature, layer) { /* Add some colors based on shapefile features */ }}); and then add it to the map I've created

ac_shpfile.addTo(map); How do I later remove that shapefile layer from the map? I plan to create another shapefile layer (same shapefile but with different colorings) and based on some user action switch between these two shapefile layers being shown. How do I add/remove shapefile layers like this? I've looked for the "opposite" of addTo() in the documentation but this doesn't seem tot be easy to find?



أكثر...
 
أعلى