Skip to content

Commit

Permalink
remove injected script and style tags when map is destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
jfolds committed Nov 22, 2017
1 parent d454103 commit 2bd4f65
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Request.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export function jsonp (url, params, callback, context) {
script.type = 'text/javascript';
script.src = url + '?' + serialize(params);
script.id = callbackId;
script.classList.add('esri-leaflet-jsonp-script');

callbacks++;

Expand Down
13 changes: 13 additions & 0 deletions src/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,19 @@ export function setEsriAttribution (map) {
map.on('resize', function (e) {
map.attributionControl._container.style.maxWidth = calcAttributionWidth(e.target);
});
// remove injected scripts and style tags
map.on('unload', function () {
if (hoverAttributionStyle && hoverAttributionStyle.remove) {
hoverAttributionStyle.remove();
}
if (attributionStyle && attributionStyle.remove) {
attributionStyle.remove();
}
var nodeList = document.getElementsByClassName('esri-leaflet-jsonp-script');
for (var i = 0; i < nodeList.length; i++) {
nodeList.item(i).remove();
}
});

map.attributionControl._esriAttributionAdded = true;
}
Expand Down

0 comments on commit 2bd4f65

Please sign in to comment.