Skip to content

Commit 55334c1

Browse files
fix leaflet-measure and layersControl to use addControl and removeControl
1 parent c6762e3 commit 55334c1

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

inst/htmlwidgets/leaflet.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,13 +1893,13 @@ methods.addLayersControl = function (baseGroups, overlayGroups, options) {
18931893
}
18941894
});
18951895

1896-
var layersControl = _leaflet2.default.control.layers(base, overlay, options).addTo(this);
1897-
this.currentLayersControl = layersControl;
1896+
this.currentLayersControl = _leaflet2.default.control.layers(base, overlay, options);
1897+
this.addControl(this.currentLayersControl);
18981898
};
18991899

19001900
methods.removeLayersControl = function () {
19011901
if (this.currentLayersControl) {
1902-
this.currentLayersControl.removeFrom(this);
1902+
this.removeControl(this.currentLayersControl);
19031903
this.currentLayersControl = null;
19041904
}
19051905
};
@@ -2255,16 +2255,16 @@ methods.clearImages = function () {
22552255
methods.addMeasure = function (options) {
22562256
// if a measureControl already exists, then remove it and
22572257
// replace with a new one
2258-
if (this.measureControl) {
2259-
this.removeControl(this.measureControl);
2260-
}
2258+
methods.removeMeasure.call(this);
22612259
this.measureControl = _leaflet2.default.control.measure(options);
2262-
this.measureControl.addTo(this);
2260+
this.addControl(this.measureControl);
22632261
};
22642262

22652263
methods.removeMeasure = function () {
2266-
this.removeControl(this.measureControl);
2267-
delete this.measureControl;
2264+
if (this.measureControl) {
2265+
this.removeControl(this.measureControl);
2266+
this.measureControl = null;
2267+
}
22682268
};
22692269

22702270
methods.addSelect = function (ctGroup) {

javascript/src/methods.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -826,13 +826,13 @@ methods.addLayersControl = function(baseGroups, overlayGroups, options) {
826826
}
827827
});
828828

829-
let layersControl = L.control.layers(base, overlay, options).addTo(this);
830-
this.currentLayersControl = layersControl;
829+
this.currentLayersControl = L.control.layers(base, overlay, options);
830+
this.addControl(this.currentLayersControl);
831831
};
832832

833833
methods.removeLayersControl = function() {
834834
if (this.currentLayersControl) {
835-
this.currentLayersControl.removeFrom(this);
835+
this.removeControl(this.currentLayersControl);
836836
this.currentLayersControl = null;
837837
}
838838
};
@@ -1190,16 +1190,16 @@ methods.clearImages = function() {
11901190
methods.addMeasure = function(options){
11911191
// if a measureControl already exists, then remove it and
11921192
// replace with a new one
1193-
if(this.measureControl) {
1194-
this.removeControl(this.measureControl);
1195-
}
1193+
methods.removeMeasure.call(this);
11961194
this.measureControl = L.control.measure(options);
1197-
this.measureControl.addTo(this);
1195+
this.addControl(this.measureControl);
11981196
};
11991197

12001198
methods.removeMeasure = function() {
1201-
this.removeControl(this.measureControl);
1202-
delete this.measureControl;
1199+
if(this.measureControl) {
1200+
this.removeControl(this.measureControl);
1201+
this.measureControl = null;
1202+
}
12031203
};
12041204

12051205
methods.addSelect = function(ctGroup) {

man/addMeasure.Rd

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)