Skip to content

Commit 21f6b5a

Browse files
committed
Add weights argument to setStyleFast
1 parent 95d9b68 commit 21f6b5a

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

R/methods.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ setStyle = function(map, group, styles, label = NULL, offset = 0) {
5252
invokeMethod(map, NULL, "setStyle", group, styles, label, offset)
5353
}
5454

55-
setStyleFast = function(map, group, color, label = NULL) {
56-
invokeMethod(map, NULL, "setStyleFast", group, color, label)
55+
setStyleFast = function(map, group, color = NULL, weight = NULL, label = NULL) {
56+
invokeMethod(map, NULL, "setStyleFast", group, color, weight, label)
5757
}
5858

5959
#' @describeIn map-methods Flys to a given location/zoom-level using smooth pan-zoom.

inst/htmlwidgets/leaflet.js

+17-4
Original file line numberDiff line numberDiff line change
@@ -1303,13 +1303,26 @@ methods.setStyle = function (group, styles, labels) {
13031303
};
13041304

13051305
/** Much more performant way to style loaded geometry */
1306-
methods.setStyleFast = function (group, colors, labels) {
1306+
methods.setStyleFast = function (group, colors, weights, labels) {
13071307
window.map = this;
13081308
var layers = this.layerManager.getLayerGroup(group).getLayers();
13091309

1310-
for (var i = 0; i < colors.length; i++) {
1311-
layers[i].setStyle({ color: colors[i], fillColor: colors[i] });
1312-
layers[i].bindTooltip(labels[i]);
1310+
if (labels) {
1311+
for (var i = 0; i < labels.length; i++) {
1312+
layers[i].bindTooltip(labels[i]);
1313+
}
1314+
}
1315+
1316+
if (colors) {
1317+
for (var _i2 = 0; _i2 < colors.length; _i2++) {
1318+
layers[_i2].setStyle({ color: colors[_i2], fillColor: colors[_i2] });
1319+
}
1320+
}
1321+
1322+
if (weights) {
1323+
for (var _i3 = 0; _i3 < weights.length; _i3++) {
1324+
layers[_i3].setStyle({ weight: weights[_i3] });
1325+
}
13131326
}
13141327
};
13151328

javascript/src/methods.js

+17-4
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,26 @@ methods.setStyle = function(group, styles, labels, offset = 0) {
3131
};
3232

3333
/** Much more performant way to style loaded geometry */
34-
methods.setStyleFast = function(group, colors, labels) {
34+
methods.setStyleFast = function(group, colors, weights, labels) {
3535
window.map = this;
3636
let layers = this.layerManager.getLayerGroup(group).getLayers();
3737

38-
for (let i = 0; i < colors.length; i++) {
39-
layers[i].setStyle({color: colors[i], fillColor: colors[i]})
40-
layers[i].bindTooltip(labels[i]);
38+
if (labels) {
39+
for (let i = 0; i < labels.length; i++) {
40+
layers[i].bindTooltip(labels[i]);
41+
}
42+
}
43+
44+
if (colors) {
45+
for (let i = 0; i < colors.length; i++) {
46+
layers[i].setStyle({color: colors[i], fillColor: colors[i]})
47+
}
48+
}
49+
50+
if (weights) {
51+
for (let i = 0; i < weights.length; i++) {
52+
layers[i].setStyle({weight: weights[i]})
53+
}
4154
}
4255
};
4356

0 commit comments

Comments
 (0)