Skip to content

Commit

Permalink
smithmicro#73 Use conditional map.removeLayer() and map.removeSource(…
Browse files Browse the repository at this point in the history
…) calls when removing a circle (thanks @ryanbaumann!)
  • Loading branch information
vtepliuk committed Feb 25, 2018
1 parent db33129 commit 7afb03c
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1246,21 +1246,36 @@ class MapboxCircle {
this.off('radiuschanged', this._onRadiusChanged).off('centerchanged', this._onCenterChanged);

this._unbindRadiusHandlesListeners();
this.map.removeLayer(this._circleRadiusHandlesId);
if (this.map.getLayer(this._circleRadiusHandlesId)) {
this.map.removeLayer(this._circleRadiusHandlesId);
}

this._unbindCenterHandleListeners();
this.map.removeLayer(this._circleCenterHandleId);
if (this.map.getLayer(this._circleCenterHandleId)) {
this.map.removeLayer(this._circleCenterHandleId);
}

if (this.map.getSource(this._circleRadiusHandlesSourceId)) {
this.map.removeSource(this._circleRadiusHandlesSourceId);
}

this.map.removeSource(this._circleRadiusHandlesSourceId);
this.map.removeSource(this._circleCenterHandleSourceId);
if (this.map.getSource(this._circleCenterHandleSourceId)) {
this.map.removeSource(this._circleCenterHandleSourceId);
}
}

this.map.off('zoomend', this._onZoomEnd);
this._unbindCircleFillListeners();
this.map.removeLayer(this._circleFillId);
this.map.removeLayer(this._circleStrokeId);
if (this.map.getLayer(this._circleFillId)) {
this.map.removeLayer(this._circleFillId);
}
if (this.map.getLayer(this._circleStrokeId)) {
this.map.removeLayer(this._circleStrokeId);
}

this.map.removeSource(this._circleSourceId);
if (this.map.getSource(this._circleSourceId)) {
this.map.removeSource(this._circleSourceId);
}

this.map = null;

Expand Down

0 comments on commit 7afb03c

Please sign in to comment.