JasonSanford / leaflet-vector-layers

A little help to viewing ArcGIS Server, Geocommons, Arc2Earth, CartoDB, GIS Cloud, etc. vector data in a Leaflet map
http://jasonsanford.github.io/leaflet-vector-layers
BSD 2-Clause "Simplified" License
216 stars 61 forks source link

Using onAdd and onRemove to support layer control #64

Open asneuvon opened 8 years ago

asneuvon commented 8 years ago

First of all, thanks for a great package, solved a real problem for me!

But: The ArcGIS Server layer (lvector.AGS) didn't seem to support adding it into a layer control i.e. letting the user check it visible and invisible in a list of contents. I experimented a bit and ti would seem to me that this functionality can easily be included by adding following methods the Layer.js:

onAdd: function(o){
    this._show();
},

onRemove: function(o){
    this._hide();
},

Worked for me at least. However, I couldn't figure out how to set the layer invisible by code (this would be the default state when adding the layer)...

devinpatterson commented 7 years ago

i just did the same for GISCloud, for me i just added these to the bottom of lvector.js

lvector.GISCloud.prototype.onAdd = function() { this.setMap(window.map); }; lvector.GISCloud.prototype.onRemove = function() { this._hide(); this.setMap(null); };

and changed this piece:

_hide: function() { this._idleListener && this.options.map.off("moveend", this._idleListener); this._zoomChangeListener && this.options.map.off("zoomend", this._zoomChangeListener); this._autoUpdateInterval && clearInterval(this._autoUpdateInterval); this._clearFeatures(); this._lastQueriedBounds = null; if (this._gotAll) this._gotAll = !1 },

to this:

_hide: function() { this._idleListener && this.options.map.off("moveend", this._idleListener, this); this._zoomChangeListener && this.options.map.off("zoomend", this._zoomChangeListener, this); this._autoUpdateInterval && clearInterval(this._autoUpdateInterval); this._clearFeatures(); this._lastQueriedBounds = null; if (this._gotAll) this._gotAll = !1 },

should work for all the other sources.