question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`hasLayer(layer)` showing unexpected behavior

See original GitHub issue

LL 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:open
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
prasanjitdashcommented, May 18, 2019

Any further thoughts from the LL community? Thanks

0reactions
nicholasrolstadcommented, Mar 20, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found