Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
86
rated 0 times [  90] [ 4]  / answers: 1 / hits: 21472  / 9 Years ago, mon, july 13, 2015, 12:00:00

I am adding multiple layers with various opacities to my leaflet map object like this:



 var TopoLayer = L.esri.dynamicMapLayer(https://gis.in.gov/arcgis/rest/services/Imagery_Basemap/MapServer, {
opacity: 0.8,
// Tell the map to use a loading control

useCors: false
}).addTo(map);
var EPSLayer = L.esri.dynamicMapLayer(https://gis.in.gov/arcgis/rest/services/DOT/EPS_Map_2015/MapServer, {
opacity: 1,
// Tell the map to use a loading control

useCors: false
}).addTo(map);


Now when a user clicks on a checkbox, I would like remove the layer or add it back. I have tried



                    map.removeLayer(EPSLayer);
map.removeLayer(tiles);


However, that didnt fix the issue. Any ideas or pointers that could help would be greatly appreciated.



*** Update I have created a fiddle to show the issue:



https://jsfiddle.net/31gmr4ss/3/



The idea is to click on the tree icon to show the areial view and then switch to the map view when its clicked again.



It appears to work when the tree icon is clicked however the arial view is present when the map is zoomed.



As @Fabrizio has suggested, the remove should not be passed string values, however passing just variable names causes the map to not work at all.



enter



Thanks


More From » leaflet

 Answers
6

Don't use strings in the function:



map.removeLayer(EPSLayer);
map.removeLayer(TopoLayer);


Depending on the layer you want to remove.


[#65826] Friday, July 10, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ellisc

Total Points: 533
Total Questions: 82
Total Answers: 90

Location: Bangladesh
Member since Thu, Aug 5, 2021
3 Years ago
ellisc questions
Mon, Nov 15, 21, 00:00, 3 Years ago
Sat, Jun 26, 21, 00:00, 3 Years ago
Mon, Nov 16, 20, 00:00, 4 Years ago
Sun, Apr 26, 20, 00:00, 4 Years ago
;