Skip to content

Commit

Permalink
add "Powered by Esri" attribution for [vectorBasemapLayer -> item ID]…
Browse files Browse the repository at this point in the history
… cases

In #135 we added `Util.setEsriAttribution` to add the "Powered by Esri" attribution, but after Esri Leaflet v3.0.10, calling `Util.setEsriAttribution` does not add "Powered by Esri" anymore. Esri Leaflet only adds "Powered by Esri" for dynamic attribution situations. So now for non-dynamic situations, we must add the string ourself.
  • Loading branch information
gavinr-maps committed Dec 3, 2024
1 parent 3c98a59 commit 39bc1ba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion spec/VectorBasemapLayerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ describe('VectorBasemapLayer', function () {
};

layer._setupAttribution();
const expectedAttributionValue = '<span class="esri-dynamic-attribution">@ my attribution, @ my copyright text</span>';
const expectedAttributionValue = '<span class="esri-dynamic-attribution">Powered by <a href="https://www.esri.com">Esri</a> | @ my attribution, @ my copyright text</span>';
expect(attributionValue).to.be.equal(expectedAttributionValue);
});
});
Expand Down
10 changes: 6 additions & 4 deletions src/VectorBasemapLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Util } from 'esri-leaflet';
import { getBasemapStyleUrl, getAttributionData, getBasemapStyleV2Url } from './Util';
import { VectorTileLayer } from './VectorTileLayer';

const POWERED_BY_ESRI_ATTRIBUTION_STRING = 'Powered by <a href="https://www.esri.com">Esri</a>';

export var VectorBasemapLayer = VectorTileLayer.extend({
/**
* Populates "this.options" to be used in the rest of the module.
Expand Down Expand Up @@ -69,9 +71,6 @@ export var VectorBasemapLayer = VectorTileLayer.extend({
},

_setupAttribution: function () {
// Set attribution
Util.setEsriAttribution(this._map);

if (this.options.key.length === 32) {
// this is an itemId
const sources = this._maplibreGL.getMaplibreMap().style.stylesheet.sources;
Expand All @@ -83,7 +82,10 @@ export var VectorBasemapLayer = VectorTileLayer.extend({
}
});

this._map.attributionControl.addAttribution(`<span class="esri-dynamic-attribution">${allAttributions.join(', ')}</span>`);
// In the case of an enum, since the attribution is dynamic, Esri Leaflet
// will add the "Powered by Esri" string. But in this case we are not
// dynamic so we must add it ourselves.
this._map.attributionControl.addAttribution(`<span class="esri-dynamic-attribution">${POWERED_BY_ESRI_ATTRIBUTION_STRING} | ${allAttributions.join(', ')}</span>`);
} else {
// this is an enum
if (!this.options.attributionUrls) {
Expand Down

0 comments on commit 39bc1ba

Please sign in to comment.