Skip to content

Commit ea646ea

Browse files
authored
Fix flyTo and flyToBounds crash on leaflet initialization (#552)
* use non compressed leaflet for easier debugging for everyone * fit the world before flying if no bounds have been set * undo leaflet-src change * add news * do not reset bounds if the map has already rendered
1 parent 0eddf7e commit ea646ea

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ BUG FIXES
1111
* Default marker icon locations will now use unpkg.com instead of the leaflet cdn when using https or file protocols. (#544)
1212
* `.leaflet-map-pane` `z-index` switched to 'auto'. Allows for map panes to appear above the map if they appear later in the dom. (#537)
1313
* Use correct Leaflet.js scale control remove method. (#547)
14+
* Start from world view if using flyTo or flyToBounds. (#552)
1415

1516

1617
leaflet 2.0.0

inst/htmlwidgets/leaflet.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,10 +720,18 @@ _htmlwidgets2.default.widget({
720720
methods.fitBounds.apply(map, data.fitBounds);
721721
}
722722
if (data.flyTo) {
723+
if (!explicitView && !map.leafletr.hasRendered) {
724+
// must be done to give a initial starting point
725+
map.fitWorld();
726+
}
723727
explicitView = true;
724728
map.flyTo.apply(map, data.flyTo);
725729
}
726730
if (data.flyToBounds) {
731+
if (!explicitView && !map.leafletr.hasRendered) {
732+
// must be done to give a initial starting point
733+
map.fitWorld();
734+
}
727735
explicitView = true;
728736
methods.flyToBounds.apply(map, data.flyToBounds);
729737
}

javascript/src/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,18 @@ HTMLWidgets.widget({
205205
methods.fitBounds.apply(map, data.fitBounds);
206206
}
207207
if (data.flyTo) {
208+
if (!explicitView && !map.leafletr.hasRendered) {
209+
// must be done to give a initial starting point
210+
map.fitWorld();
211+
}
208212
explicitView = true;
209213
map.flyTo.apply(map, data.flyTo);
210214
}
211215
if (data.flyToBounds) {
216+
if (!explicitView && !map.leafletr.hasRendered) {
217+
// must be done to give a initial starting point
218+
map.fitWorld();
219+
}
212220
explicitView = true;
213221
methods.flyToBounds.apply(map, data.flyToBounds);
214222
}

0 commit comments

Comments
 (0)