Skip to content

Commit

Permalink
Merge pull request #1252 from avinmathew/master
Browse files Browse the repository at this point in the history
Only attempt to set/remove attribution if control exists
  • Loading branch information
gavinr authored Jan 6, 2021
2 parents f8e8ea2 + fa7bc3b commit a763137
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,17 @@ export function calcAttributionWidth (map) {
}

export function setEsriAttribution (map) {
if (!map.attributionControl) {
return;
}

if (!map.attributionControl._esriAttributionLayerCount) {
map.attributionControl._esriAttributionLayerCount = 0;
}

if (map.attributionControl && map.attributionControl._esriAttributionLayerCount === 0) {
if (map.attributionControl._esriAttributionLayerCount === 0) {
// Dynamically creating the CSS rules, only run this once per page load:
if (map.attributionControl && !map.attributionControl._esriAttributionAddedOnce) {
if (!map.attributionControl._esriAttributionAddedOnce) {
var hoverAttributionStyle = document.createElement('style');
hoverAttributionStyle.type = 'text/css';
hoverAttributionStyle.innerHTML = '.esri-truncated-attribution:hover {' +
Expand Down Expand Up @@ -223,8 +227,12 @@ export function setEsriAttribution (map) {
}

export function removeEsriAttribution (map) {
if (!map.attributionControl) {
return;
}

// Only remove the attribution if we're about to remove the LAST esri-leaflet layer (_esriAttributionLayerCount)
if (map.attributionControl && map.attributionControl._esriAttributionLayerCount && map.attributionControl._esriAttributionLayerCount === 1) {
if (map.attributionControl._esriAttributionLayerCount && map.attributionControl._esriAttributionLayerCount === 1) {
map.attributionControl.setPrefix(BASE_LEAFLET_ATTRIBUTION_STRING);
DomUtil.removeClass(map.attributionControl._container, 'esri-truncated-attribution:hover');
DomUtil.removeClass(map.attributionControl._container, 'esri-truncated-attribution');
Expand Down

0 comments on commit a763137

Please sign in to comment.