Browse Source

bugix centerAndZoom : éviter de générer une erreur quand les bounds du centre sont invalides

par exemple quand le json ne contient pas de point et qu'on utilise les options centrer_auto + cluster = oui
pull/16/head
b_b 2 years ago
parent
commit
0565dc7d27
  1. 33
      javascript/leaflet.gis.js

33
javascript/leaflet.gis.js

@ -208,22 +208,25 @@ L.Map.Gis = L.Map.extend({
var bounds = new L.LatLngBounds();
bounds.extend(centerOrBounds);
panonly = panonly === undefined ? false : panonly;
// avoid infinite zoom if bounds focus on a point
if (bounds._northEast.lat == bounds._southWest.lat && bounds._northEast.lng == bounds._southWest.lng) {
var singlePoint = true;
options.maxZoom = options.zoom;
if (panonly) {
options.maxZoom = map._zoom;
// pas la peine d'aller plus loin si les bounds sont invalides (json vide par exemple)
if (bounds.isValid()) {
// avoid infinite zoom if bounds focus on a point
if (bounds._northEast.lat == bounds._southWest.lat && bounds._northEast.lng == bounds._southWest.lng) {
var singlePoint = true;
options.maxZoom = options.zoom;
if (panonly) {
options.maxZoom = map._zoom;
}
bounds._northEast.lat += 0.1;
bounds._northEast.lng += 0.1;
bounds._southWest.lat -= 0.1;
bounds._southWest.lng -= 0.1;
}
map.fitBounds(bounds, options);
map.options.maxZoom = maxZoomOriginal;
if (options.zoom && singlePoint) {
map.setZoom(options.zoom);
}
bounds._northEast.lat += 0.1;
bounds._northEast.lng += 0.1;
bounds._southWest.lat -= 0.1;
bounds._southWest.lng -= 0.1;
}
map.fitBounds(bounds, options);
map.options.maxZoom = maxZoomOriginal;
if (options.zoom && singlePoint) {
map.setZoom(options.zoom);
}
},

Loading…
Cancel
Save