From af9b709a2da4ee88caa9fab21223327c9bd1208f Mon Sep 17 00:00:00 2001 From: Christoph Krey Date: Mon, 25 Feb 2019 10:23:00 +0000 Subject: [PATCH] =?UTF-8?q?[FIX]=20Leaflet=20map=20and=20view=20wrap=20aro?= =?UTF-8?q?und=20antimeridian=20(=C2=B1180=C2=B0)=20#293?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docroot/map/map_leaflet.js | 18 ++++++++++++++++++ docroot/views/leafletmap.html | 31 ++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/docroot/map/map_leaflet.js b/docroot/map/map_leaflet.js index 4c97c71..5cc7ced 100644 --- a/docroot/map/map_leaflet.js +++ b/docroot/map/map_leaflet.js @@ -30,6 +30,7 @@ function initialize_leaflet() { type: "FeatureCollection", features: [] }; + var lastLatLng = L.latLng(0.0, 0.0); var geojsonLayer = new L.GeoJSON(empty_geojson, { pointToLayer: function (feature, latlng) { @@ -63,6 +64,23 @@ function initialize_leaflet() { weight : 4, } } + }, + coordsToLatLng: function(coords) { + var lat = coords[1]; + var lon = coords[0]; + var dist0 = Math.abs(lon - lastLatLng.lng); + var dist1 = Math.abs(lon + 360.0 - lastLatLng.lng); + var dist2 = Math.abs(lon - 360.0 - lastLatLng.lng); + if (dist0 > dist1 || dist0 > dist2) { + if (dist0 > dist1) { + lon = lon + 360.0; + } else { + lon = lon - 360.0; + } + } + var latLng = L.GeoJSON.coordsToLatLng([lon, lat]); + lastLatLng = latLng; + return latLng } }); diff --git a/docroot/views/leafletmap.html b/docroot/views/leafletmap.html index 622271c..9040186 100644 --- a/docroot/views/leafletmap.html +++ b/docroot/views/leafletmap.html @@ -30,9 +30,11 @@