Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>That's because a polygon is not a not a Leaflet layer, rather it is <a href="http://leafletjs.com/reference.html#polygon" rel="nofollow">an extension of the Path class</a>. It never inherits the <code>.removeLayer()</code> method from the <a href="http://leafletjs.com/reference.html#layergroup" rel="nofollow">Layer Group class</a>. Instead it can be removed like so:</p> <pre><code>window.map.removeLayer(polygon); </code></pre> <p>Refactoring the code snippet to take this into account we get</p> <pre><code>map.on('zoomend', function(e){ console.log(map.getZoom()); //This is going to be a function that gets dynamically built. var polygons = L.polygon([ [43.22519, -107.69348], [42.99259, -105.48523], [42.26105, -107.7594] ]).bindPopup("Potential Geo polygon area of companies with violations."); if(map.getZoom() &gt;= 5){ map.removeLayer(geojson); }//order matters if(map.getZoom() == 5){ geojson = L.geoJson(statesData, { style: style, onEachFeature: onEachFeature }).addTo(map); } if(map.getZoom() == 7){ if(map.hasLayer(polygons)){ console.log("TEst"); } window.map.removeLayer(polygon); } if(map.getZoom() == 6){ polygons.addTo(map) } }); </code></pre> <p>An alternative approach would be to use <a href="http://geojson.io/#map=2/20.0/0.0" rel="nofollow">geojson.io</a> to create some geoJSON with your polygon latitude, longitude arrays and then add them to the map with the <code>L.geoJson</code> method if you prefer the <code>removeLayer()</code> method.</p> <p>Additionally, you can catch and debug many of these errors via your browsers JavaScript console. Here's an excellent course via <a href="http://discover-devtools.codeschool.com/" rel="nofollow">Code School</a> to help you better use Chrome's console to understand JavaScript errors.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload