Skip to content

Commit

Permalink
Only attempt to set/remove attribution if control exists
Browse files Browse the repository at this point in the history
There were multiple places were the existence of the attribution control was checked, but for some code paths, it wasn't checked causing exceptions to be thrown.

Use a single check for the existence of the attribution control at the beginning of setting/removing attribution.
  • Loading branch information
avinmathew committed Jan 5, 2021
1 parent f8e8ea2 commit fa7bc3b
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 fa7bc3b

Please sign in to comment.