Skip to content

Commit 5fa9b98

Browse files
committed
Add stroke and fill arguments to setStyleFast
Should pass pathOptions but can't be bothered to fix it rn Also fix devtools::document() unexporting setStyleFast.
1 parent 3dbf5bf commit 5fa9b98

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

R/methods.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ 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 = NULL, weight = NULL, label = NULL) {
56-
invokeMethod(map, NULL, "setStyleFast", group, color, weight, label)
55+
#' @export
56+
setStyleFast = function(map, group, color = NULL, weight = NULL, label = NULL, stroke = NULL, fill = NULL) {
57+
invokeMethod(map, NULL, "setStyleFast", group, color, weight, label, stroke, fill)
5758
}
5859

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

inst/htmlwidgets/leaflet.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ methods.setStyle = function (group, styles, labels) {
13031303
};
13041304

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

@@ -1324,6 +1324,18 @@ methods.setStyleFast = function (group, colors, weights, labels) {
13241324
layers[_i3].setStyle({ weight: weights[_i3] });
13251325
}
13261326
}
1327+
1328+
if (strokes) {
1329+
for (var _i4 = 0; _i4 < strokes.length; _i4++) {
1330+
layers[_i4].setStyle({ stroke: strokes[_i4] });
1331+
}
1332+
}
1333+
1334+
if (fills) {
1335+
for (var _i5 = 0; _i5 < fills.length; _i5++) {
1336+
layers[_i5].setStyle({ fill: fills[_i5] });
1337+
}
1338+
}
13271339
};
13281340

13291341
function mouseHandler(mapId, layerId, group, eventName, extraInfo) {

javascript/src/methods.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ 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, weights, labels) {
34+
methods.setStyleFast = function(group, colors, weights, labels, strokes, fills) {
3535
window.map = this;
3636
let layers = this.layerManager.getLayerGroup(group).getLayers();
3737

@@ -43,13 +43,25 @@ methods.setStyleFast = function(group, colors, weights, labels) {
4343

4444
if (colors) {
4545
for (let i = 0; i < colors.length; i++) {
46-
layers[i].setStyle({color: colors[i], fillColor: colors[i]})
46+
layers[i].setStyle({color: colors[i], fillColor: colors[i]});
4747
}
4848
}
4949

5050
if (weights) {
5151
for (let i = 0; i < weights.length; i++) {
52-
layers[i].setStyle({weight: weights[i]})
52+
layers[i].setStyle({weight: weights[i]});
53+
}
54+
}
55+
56+
if (strokes) {
57+
for (let i = 0; i < strokes.length; i++) {
58+
layers[i].setStyle({stroke: strokes[i]});
59+
}
60+
}
61+
62+
if (fills) {
63+
for (let i = 0; i < fills.length; i++) {
64+
layers[i].setStyle({fill: fills[i]});
5365
}
5466
}
5567
};

0 commit comments

Comments
 (0)