diff --git a/spec/Layers/TiledMapLayerSpec.js b/spec/Layers/TiledMapLayerSpec.js index 19c112659..e6dc934c4 100644 --- a/spec/Layers/TiledMapLayerSpec.js +++ b/spec/Layers/TiledMapLayerSpec.js @@ -59,4 +59,30 @@ describe('L.esri.Layers.TiledMapLayer', function () { layer = L.esri.Layers.tiledMapLayer(url); expect(layer).to.be.instanceof(L.esri.Layers.TiledMapLayer); }); + + it('should use a token passed in options', function(){ + layer = L.esri.tiledMapLayer(url, { + token: 'foo' + }); + + expect(layer.tileUrl).to.equal('http://services.arcgisonline.com/ArcGIS/rest/services/USA_Topo_Maps/MapServer/tile/{z}/{y}/{x}?token=foo'); + }); + + it('should use a token passed with authenticate()', function(){ + layer = L.esri.tiledMapLayer(url); + + layer.authenticate('foo'); + + expect(layer.tileUrl).to.equal('http://services.arcgisonline.com/ArcGIS/rest/services/USA_Topo_Maps/MapServer/tile/{z}/{y}/{x}?token=foo'); + }); + + it('should reauthenticate with a token authenticate()', function(){ + layer = L.esri.tiledMapLayer(url, { + token: 'foo' + }); + + layer.authenticate('bar'); + + expect(layer.tileUrl).to.equal('http://services.arcgisonline.com/ArcGIS/rest/services/USA_Topo_Maps/MapServer/tile/{z}/{y}/{x}?token=bar'); + }); }); \ No newline at end of file diff --git a/src/Layers/RasterLayer.js b/src/Layers/RasterLayer.js index 08e90c7ac..dcc6bd1d3 100644 --- a/src/Layers/RasterLayer.js +++ b/src/Layers/RasterLayer.js @@ -18,8 +18,7 @@ EsriLeaflet.Layers.RasterLayer = L.Class.extend({ this.options.imageSR = sr; } - // @TODO remove at Leaflet 0.8 - this._map.addEventListener(this.getEvents(), this); + map.on('moveend', this._update, this); this._update(); @@ -51,9 +50,7 @@ EsriLeaflet.Layers.RasterLayer = L.Class.extend({ return this; }, - onRemove: function () { - this._map = null; - + onRemove: function (map) { if (this._currentImage) { this._map.removeLayer(this._currentImage); } @@ -63,8 +60,8 @@ EsriLeaflet.Layers.RasterLayer = L.Class.extend({ this._map.off('dblclick', this._resetPopupState, this); } - // @TODO remove at Leaflet 0.8 - this._map.removeEventListener(this.getEvents(), this); + this._map.off('moveend', this._update, this); + this._map = null; }, addTo: function(map){ diff --git a/src/Layers/TiledMapLayer.js b/src/Layers/TiledMapLayer.js index 230f5dddb..4cf99c0b8 100644 --- a/src/Layers/TiledMapLayer.js +++ b/src/Layers/TiledMapLayer.js @@ -14,6 +14,10 @@ EsriLeaflet.Layers.TiledMapLayer = L.TileLayer.extend({ options.subdomains = ['1', '2', '3', '4']; } + if(this.options.token) { + this.tileUrl += ('?token=' + this.options.token); + } + // init layer by calling TileLayers initialize method L.TileLayer.prototype.initialize.call(this, this.tileUrl, options); }, @@ -28,6 +32,9 @@ EsriLeaflet.Layers.TiledMapLayer = L.TileLayer.extend({ }, authenticate: function(token){ + var tokenQs = '?token=' + token; + this.tileUrl = (this.options.token) ? this.tileUrl.replace(/\?token=(.+)/g, tokenQs) : this.tileUrl + tokenQs; + this.options.token = token; this._service.authenticate(token); return this; },