diff --git a/spec/Layers/BasemapLayerSpec.js b/spec/Layers/BasemapLayerSpec.js
index 86beef8ec..b735087c5 100644
--- a/spec/Layers/BasemapLayerSpec.js
+++ b/spec/Layers/BasemapLayerSpec.js
@@ -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');
diff --git a/src/Layers/BasemapLayer.js b/src/Layers/BasemapLayer.js
index 64e6f7425..e0a72bdb7 100644
--- a/src/Layers/BasemapLayer.js
+++ b/src/Layers/BasemapLayer.js
@@ -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('© Esri');
+ if (map.attributionControl) {
+ map.attributionControl.addAttribution('© Esri');
+ }
if (this.options.pane === 'esri-labels') {
this._initPane();
@@ -204,8 +210,10 @@ export var BasemapLayer = L.TileLayer.extend({
},
onRemove: function (map) {
- map.attributionControl.removeAttribution('© Esri');
- map.off('moveend', Util._updateMapAttribution, this);
+ if (map.attributionControl) {
+ map.attributionControl.removeAttribution('© Esri');
+ }
+ map.off('moveend', this._updateMapAttribution, this);
L.TileLayer.prototype.onRemove.call(this, map);
},