Skip to content

Commit 9143317

Browse files
committed
【fix】避免重复引用引发的循环问题 review by xiongjj
1 parent 7ae940f commit 9143317

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/mapboxgl/core/MapExtend.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,25 @@ import '../core/Base';
1212
export var MapExtend = function () {
1313

1414
mapboxgl.Map.prototype.overlayLayersManager = {};
15-
mapboxgl.Map.prototype.addLayerBak = mapboxgl.Map.prototype.addLayer;
16-
mapboxgl.Map.prototype.addLayer = function (layer, before) {
17-
if (layer.source || layer.type === 'custom' || layer.type === "background") {
18-
this.addLayerBak(layer, before);
15+
if (mapboxgl.Map.prototype.addLayerBak === undefined) {
16+
mapboxgl.Map.prototype.addLayerBak = mapboxgl.Map.prototype.addLayer;
17+
mapboxgl.Map.prototype.addLayer = function (layer, before) {
18+
if (layer.source || layer.type === 'custom' || layer.type === 'background') {
19+
this.addLayerBak(layer, before);
20+
return this;
21+
}
22+
if (this.overlayLayersManager[layer.id] || this.style._layers[layer.id]) {
23+
this.fire('error', {
24+
error: new Error('A layer with this id already exists.')
25+
});
26+
return;
27+
}
28+
addLayer(layer, this);
29+
this.overlayLayersManager[layer.id] = layer;
1930
return this;
20-
}
21-
if (this.overlayLayersManager[layer.id] || this.style._layers[layer.id]) {
22-
this.fire('error', {
23-
error: new Error('A layer with this id already exists.')
24-
});
25-
return;
26-
}
27-
addLayer(layer, this);
28-
this.overlayLayersManager[layer.id] = layer;
29-
return this;
30-
};
31+
};
32+
}
33+
3134
mapboxgl.Map.prototype.getLayer = function (id) {
3235
if (this.overlayLayersManager[id]) {
3336
return this.overlayLayersManager[id];

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy