Skip to content

Commit

Permalink
fix Esri#384, passing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickarlt committed Oct 25, 2014
1 parent 8a8173e commit 632498d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
26 changes: 26 additions & 0 deletions spec/Layers/TiledMapLayerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
11 changes: 4 additions & 7 deletions src/Layers/RasterLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
}
Expand All @@ -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){
Expand Down
7 changes: 7 additions & 0 deletions src/Layers/TiledMapLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand All @@ -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;
},
Expand Down

0 comments on commit 632498d

Please sign in to comment.