{"action":"created","issue":{"url":"https://api.github.com/repos/Leaflet/Leaflet/issues/1724","repository_url":"https://api.github.com/repos/Leaflet/Leaflet","labels_url":"https://api.github.com/repos/Leaflet/Leaflet/issues/1724/labels{/name}","comments_url":"https://api.github.com/repos/Leaflet/Leaflet/issues/1724/comments","events_url":"https://api.github.com/repos/Leaflet/Leaflet/issues/1724/events","html_url":"https://github.com/Leaflet/Leaflet/issues/1724","id":14967983,"number":1724,"title":"hasLayer not working when supposed to be false","user":{"login":"florentj46","id":3081456,"avatar_url":"https://avatars.githubusercontent.com/u/3081456?v=3","gravatar_id":"","url":"https://api.github.com/users/florentj46","html_url":"https://github.com/florentj46","followers_url":"https://api.github.com/users/florentj46/followers","following_url":"https://api.github.com/users/florentj46/following{/other_user}","gists_url":"https://api.github.com/users/florentj46/gists{/gist_id}","starred_url":"https://api.github.com/users/florentj46/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/florentj46/subscriptions","organizations_url":"https://api.github.com/users/florentj46/orgs","repos_url":"https://api.github.com/users/florentj46/repos","events_url":"https://api.github.com/users/florentj46/events{/privacy}","received_events_url":"https://api.github.com/users/florentj46/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Leaflet/Leaflet/labels/bug","name":"bug","color":"EBC3C3"}],"state":"closed","locked":false,"assignee":{"login":"mourner","id":25395,"avatar_url":"https://avatars.githubusercontent.com/u/25395?v=3","gravatar_id":"","url":"https://api.github.com/users/mourner","html_url":"https://github.com/mourner","followers_url":"https://api.github.com/users/mourner/followers","following_url":"https://api.github.com/users/mourner/following{/other_user}","gists_url":"https://api.github.com/users/mourner/gists{/gist_id}","starred_url":"https://api.github.com/users/mourner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mourner/subscriptions","organizations_url":"https://api.github.com/users/mourner/orgs","repos_url":"https://api.github.com/users/mourner/repos","events_url":"https://api.github.com/users/mourner/events{/privacy}","received_events_url":"https://api.github.com/users/mourner/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/Leaflet/Leaflet/milestones/13","html_url":"https://github.com/Leaflet/Leaflet/milestones/0.6","labels_url":"https://api.github.com/repos/Leaflet/Leaflet/milestones/13/labels","id":215561,"number":13,"title":"0.6","description":"\r\n\r\n<!---\r\n@huboard:{\"order\":0.0}\n-->\r\n","creator":{"login":"mourner","id":25395,"avatar_url":"https://avatars.githubusercontent.com/u/25395?v=3","gravatar_id":"","url":"https://api.github.com/users/mourner","html_url":"https://github.com/mourner","followers_url":"https://api.github.com/users/mourner/followers","following_url":"https://api.github.com/users/mourner/following{/other_user}","gists_url":"https://api.github.com/users/mourner/gists{/gist_id}","starred_url":"https://api.github.com/users/mourner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mourner/subscriptions","organizations_url":"https://api.github.com/users/mourner/orgs","repos_url":"https://api.github.com/users/mourner/repos","events_url":"https://api.github.com/users/mourner/events{/privacy}","received_events_url":"https://api.github.com/users/mourner/received_events","type":"User","site_admin":false},"open_issues":0,"closed_issues":107,"state":"closed","created_at":"2012-11-19T19:46:12Z","updated_at":"2014-01-12T21:30:33Z","due_on":null,"closed_at":"2013-06-26T18:50:19Z"},"comments":13,"created_at":"2013-05-30T23:52:42Z","updated_at":"2016-03-07T10:37:34Z","closed_at":"2013-06-24T16:08:54Z","body":"Hi,\r\n\r\nI have a map displaying a building that I retrieve from a Geoserver. It's composed of 3 base layers, each base layer corresponding to a floor. I also have 2 overlays, a heatmap and a set of markers representing the locations of some sensors.\r\n\r\nWhen I switch the base layer, I'd like to update the overlay if it's displayed. To check wether an overlay is displayed or not, I use the method map.hasLayer(overlay). This method works when the overlay parameter is displayed on the map. However, if it isn't, the method bugs and the code after the call of the method is not read.\r\n\r\nHere is my code : \r\n\r\n\r\n            map.on('baselayerchange', onBaseLayerChanged);\r\n            \r\n            // Called when the base layer (meaning the floor) is changed\r\n            function onBaseLayerChanged(event) {\r\n                // Update the current floor\r\n                if (event.layer == ground_floor)\r\n                    current_floor = ground_floor;\r\n                else if (event.layer == first_floor)\r\n                    current_floor = first_floor;\r\n                else if (event.layer == second_floor)\r\n                    current_floor = second_floor;\r\n                \r\n                // Update the heatmap and sensors' location\r\n                // if they are displayed\r\n                if (map.hasLayer(heatmapLayer)) {\r\n                    removeHeatmap();\r\n                    addHeatmap();\r\n                }\r\n                \r\n                if (map.hasLayer(sensorsLayer)) {\r\n                    removeSensors();\r\n                    addSensors();\r\n                }\r\n\r\n            }\r\n\r\nSo if the heatmapLayer is displayed, it works. If it isn't, it doesn't and the second if condition is not checked.\r\n\r\nI must have done a silly mistake but I don't see it, although I'v been seeking for a long time...\r\n\r\nI hope I've been clear enough to let you understand my problem.\r\n\r\nThanking you in advance.\r\n\r\n<!---\r\n@huboard:{\"order\":30.453125}\n-->\r\n"},"comment":{"url":"https://api.github.com/repos/Leaflet/Leaflet/issues/comments/193198935","html_url":"https://github.com/Leaflet/Leaflet/issues/1724#issuecomment-193198935","issue_url":"https://api.github.com/repos/Leaflet/Leaflet/issues/1724","id":193198935,"user":{"login":"IvanSanchez","id":1125786,"avatar_url":"https://avatars.githubusercontent.com/u/1125786?v=3","gravatar_id":"","url":"https://api.github.com/users/IvanSanchez","html_url":"https://github.com/IvanSanchez","followers_url":"https://api.github.com/users/IvanSanchez/followers","following_url":"https://api.github.com/users/IvanSanchez/following{/other_user}","gists_url":"https://api.github.com/users/IvanSanchez/gists{/gist_id}","starred_url":"https://api.github.com/users/IvanSanchez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IvanSanchez/subscriptions","organizations_url":"https://api.github.com/users/IvanSanchez/orgs","repos_url":"https://api.github.com/users/IvanSanchez/repos","events_url":"https://api.github.com/users/IvanSanchez/events{/privacy}","received_events_url":"https://api.github.com/users/IvanSanchez/received_events","type":"User","site_admin":false},"created_at":"2016-03-07T10:37:34Z","updated_at":"2016-03-07T10:37:34Z","body":"@caglardursun The `baselayerchange` event fires when a base layer is *added* to the map. In your case, you're initializing the map with both base layers, so the first change doesn't add any layer, so no event is fired. This is *not* a bug in Leaflet but rather a PEBCAK.\r\n\r\nChange this:\r\n```js\r\n    mapOptions.layers.push(baseMap);\r\n```\r\nwith this:\r\n```js\r\n    if (i===0) mapOptions.layers.push(baseMap);\r\n```"}}