heigeo / leaflet.wms

A Leaflet plugin for working with Web Map services, providing: single-tile/untiled/nontiled layers, shared WMS sources, and GetFeatureInfo-powered identify.
http://heigeo.github.io/leaflet.wms/
MIT License
244 stars 135 forks source link

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

Open matbeard opened 8 years ago

matbeard commented 8 years ago

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 commented 8 years ago

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.

nadnerb33 commented 7 years ago

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 commented 6 years ago

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 commented 6 years ago

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

KrisSodroski commented 2 years ago

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

https://github.com/heigeo/leaflet.wms/pull/66

Can this get merged please?