`hasLayer(layer)` showing unexpected behavior
See original GitHub issueLL team, many thanks for the mapping API.
I’ve some issues with hasLayer; the issue perhaps is a duplication (others have raised this issue before) but looking through all the discussions, I did not find a proper closing answer.
My display and other parts are working correctly. The issue is only in checking whether a layer exists and removing it.
Description of Issue and code parts: ‘hasLayer shows always false’ Layer definition:
nasagibslayer01 = L.tileLayer(nasagibs_epsg4326_template + 'png', {
layer: 'GHRSST_L4_MUR_Sea_Surface_Temperature',
tileMatrixSet: '1km',
time: _this_YYYY_MM_DD_stamp,
tileSize: 512,
subdomains: 'abc',
noWrap: true,
bounds: [
[-90, -180],
[90, 180]
],
opacity: layer01_opacity_value,
zIndex: 10
});
layer01 = nasagibslayer01;
if (!map.hasLayer(layer01)) {
console.log('has not');
map.addLayer(layer01);
} else {
console.log('has');
map.removeLayer(layer01);
}
From external TimeDimension, the var _this_YYYY_MM_DD_stamp
is updated and the snippet is called with every change of date, i.e., time: _this_YYYY_MM_DD_stamp
is refreshed.
The console.log always shows ‘has not’, meaning either the Layer is not removed or hasLayer is not working.
Any suggestion?
Thanks
Environment
- Leaflet version: 1.4.0.
- Browser: Chrome, FireFox
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
hasLayer and removeLayer methods not working on leaflet ...
If I add the layer to the map before, the "if" condition is working ... previous ajax call) has that layer may cause...
Read more >Spring unexpected behavior in service layer - Stack Overflow
I have a problem when calling a method to delete from the data repository. In my service layers I have this two methods:...
Read more >Unexpected Behavior with arcpy.addDataFromPath
Solved: Working on a work-around for another conundrum and tried the following: import arcpy x = some X y = some Y point...
Read more >Junos OS Release 14.1X53-D140 for QFabric Systems
On a QFabric system, unexpected behavior or crash might be observed if make-before-break ... configured and has a port which has Layer 2...
Read more >Nexus 7k installs static routes to route table even if connected ...
The Nexus has layer 3 SVI's for both vlan223 and vlan224. ... And now the route table shows the static route is installed...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Any further thoughts from the LL community? Thanks
I have a similar issue. If I call map.hasLayer() on a layer that exists, it returns false when it should return true. When I call it on a layer that doesn’t exist, instead of returning false I get an Uncaught ReferenceError.
It’s strange, I’ve never had this issue before.