Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling remove() on a map with wms layers #34

Open
matbeard opened this issue Aug 25, 2016 · 5 comments
Open

Calling remove() on a map with wms layers #34

matbeard opened this issue Aug 25, 2016 · 5 comments

Comments

@matbeard
Copy link

This is with Leaflet 1.0.0-rc3 (not tried any other versions):

If you create an instance of Leaflet map and add one or more wms layers, then try to remove the map instance with map.remove() an error is generated: Uncaught TypeError: layer.onRemove is not a function

@sheppard
Copy link
Member

Thanks for the report, we'll take a look when we can. Testing with 1.0.0-rc3 is sufficient as we are primarily targeting 1.0 compatibility.

@sheppard sheppard modified the milestone: 0.3.0 Nov 7, 2016
@nadnerb33
Copy link

Any update on this?
Still happening with Leaflet 1.0.3.

Is there a work around on how to manually remove the layer from the map?

@mgurjanov
Copy link

mgurjanov commented Feb 4, 2018

Under
wms.Source = L.Layer.extend({
below

        onAdd: function() {
            this.refreshOverlay()
        },

just add this code which is implementation for onRemove() so that the final code looks like:

        onAdd: function() {
            this.refreshOverlay()
        },
        onRemove: function() {
            var subLayers = Object.keys(this._subLayers).join(",");
            if (!this._map) {
                return
            }
            if (subLayers) {
                this._overlay.remove();
            }
        },       
        getEvents: function() {
            if (this.options.identify) {
                return {
                    click: this.identify
                }
            } else {
                return {}
            }
        },

That enables when using TILED version of WMS service to remove current layer and then you can add another WMS layer to a map.

@nadnerb33
Copy link

Good timing, just came across this problem again today but your solution works. Thanks @mgurjanov

@KrisSodroski
Copy link

What's going on with this? There's been a pull request to fix this issue for like 2 years.

#66

Can this get merged please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants