Skip to content

Commit ccc1559

Browse files
authored
Merge pull request #382 from rstudio/joe/bugfix/polygon-dblclick
Double-click on polygons wasn't zooming
2 parents 5ba1480 + 4218236 commit ccc1559

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

inst/htmlwidgets/leaflet.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,11 +1601,17 @@ methods.addPolygons = function (polygons, layerId, group, options, popup, popupO
16011601
var df = new _dataframe2.default().col("shapes", polygons).col("layerId", layerId).col("group", group).col("popup", popup).col("popupOptions", popupOptions).col("label", label).col("labelOptions", labelOptions).col("highlightOptions", highlightOptions).cbind(options);
16021602

16031603
addLayers(this, "shape", df, function (df, i) {
1604-
var shapes = df.get(i, "shapes");
1605-
shapes = shapes.map(function (polygon) {
1604+
// This code used to use L.multiPolygon, but that caused
1605+
// double-click on a multipolygon to fail to zoom in on the
1606+
// map. Surprisingly, putting all the rings in a single
1607+
// polygon seems to still work; complicated multipolygons
1608+
// are still rendered correctly.
1609+
var shapes = df.get(i, "shapes").map(function (polygon) {
16061610
return polygon.map(_htmlwidgets2.default.dataframeToD3);
1607-
});
1608-
return _leaflet2.default.multiPolygon(shapes, df.get(i));
1611+
}).reduce(function (acc, val) {
1612+
return acc.concat(val);
1613+
}, []);
1614+
return _leaflet2.default.polygon(shapes, df.get(i));
16091615
});
16101616
}
16111617
};
@@ -2290,6 +2296,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
22902296
// pixel of the original image has some contribution to the downscaled image)
22912297
// as opposed to a single-step downscaling which will discard a lot of data
22922298
// (and with sparse images at small scales can give very surprising results).
2299+
22932300
var Mipmapper = function () {
22942301
function Mipmapper(img) {
22952302
_classCallCheck(this, Mipmapper);

javascript/src/methods.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -535,11 +535,15 @@ methods.addPolygons = function(polygons, layerId, group, options, popup, popupOp
535535
.cbind(options);
536536

537537
addLayers(this, "shape", df, function(df, i) {
538-
let shapes = df.get(i, "shapes");
539-
shapes = shapes.map(function(polygon) {
540-
return polygon.map(HTMLWidgets.dataframeToD3);
541-
});
542-
return L.multiPolygon(shapes, df.get(i));
538+
// This code used to use L.multiPolygon, but that caused
539+
// double-click on a multipolygon to fail to zoom in on the
540+
// map. Surprisingly, putting all the rings in a single
541+
// polygon seems to still work; complicated multipolygons
542+
// are still rendered correctly.
543+
let shapes = df.get(i, "shapes")
544+
.map(polygon => polygon.map(HTMLWidgets.dataframeToD3))
545+
.reduce((acc, val) => acc.concat(val), []);
546+
return L.polygon(shapes, df.get(i));
543547
});
544548
}
545549
};

0 commit comments

Comments
 (0)