Skip to content

Commit

Permalink
allow users to pass tokens through to basemaps (#800)
Browse files Browse the repository at this point in the history
* allow users to pass tokens through to basemaps

* sometimes people make maps with no attribution control
  • Loading branch information
jgravois authored Jul 14, 2016
1 parent 54dfb28 commit 640ed96
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions spec/Layers/BasemapLayerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ describe('L.esri.BasemapLayer', function () {
expect(map.hasLayer(baseLayer)).to.equal(true);
});

it('will append tokens when fetching tiles if necessary', function () {
var baseLayer = L.esri.basemapLayer('Streets', {token: 'bogus'} );
map.addLayer(baseLayer);
expect(baseLayer._url).to.contain('token=bogus');
});

it('will throw an error given invalid basemap name', function () {
expect(function () {
L.esri.basemapLayer('junk');
Expand Down
14 changes: 11 additions & 3 deletions src/Layers/BasemapLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,18 @@ export var BasemapLayer = L.TileLayer.extend({

L.Util.setOptions(this, tileOptions);

if (this.options.token) {
config.urlTemplate += ('?token=' + this.options.token);
}

// call the initialize method on L.TileLayer to set everything up
L.TileLayer.prototype.initialize.call(this, config.urlTemplate, tileOptions);
},

onAdd: function (map) {
map.attributionControl.addAttribution('<a href="https://www.esri.com">&copy; Esri</a>');
if (map.attributionControl) {
map.attributionControl.addAttribution('<a href="https://www.esri.com">&copy; Esri</a>');
}

if (this.options.pane === 'esri-labels') {
this._initPane();
Expand All @@ -204,8 +210,10 @@ export var BasemapLayer = L.TileLayer.extend({
},

onRemove: function (map) {
map.attributionControl.removeAttribution('<a href="https://www.esri.com">&copy; Esri</a>');
map.off('moveend', Util._updateMapAttribution, this);
if (map.attributionControl) {
map.attributionControl.removeAttribution('<a href="https://www.esri.com">&copy; Esri</a>');
}
map.off('moveend', this._updateMapAttribution, this);
L.TileLayer.prototype.onRemove.call(this, map);
},

Expand Down

0 comments on commit 640ed96

Please sign in to comment.