From e00bdc4fb8feeb3386f261f4b89ab644ef8bb688 Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Mon, 27 Apr 2020 17:36:55 +0200 Subject: [PATCH] automatically skip around the earth when going into the wraparound area of the projection extent_ --- html/script.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/html/script.js b/html/script.js index 9ce5b66..1b970c6 100644 --- a/html/script.js +++ b/html/script.js @@ -6,6 +6,7 @@ // Define our global letiables let OLMap = null; +let OLProj = null; let StaticFeatures = new ol.source.Vector(); let PlaneIconFeatures = new ol.source.Vector(); let trailGroup = new ol.Collection(); @@ -297,7 +298,7 @@ function processReceiverUpdate(data, init) { function fetchData() { ZoomLvl = OLMap.getView().getZoom(); - let center = ol.proj.toLonLat(OLMap.getView().getCenter(), OLMap.getView().getProjection()); + let center = ol.proj.toLonLat(OLMap.getView().getCenter()); localStorage['CenterLon'] = CenterLon = center[0]; localStorage['CenterLat'] = CenterLat = center[1]; clearTimeout(refreshId); @@ -1378,6 +1379,7 @@ function initialize_map() { loadTilesWhileInteracting: false, interactions: new ol.interaction.defaults({altShiftDragRotate:false, pinchRotate:false,}), }); + OLProj = OLMap.getView().getProjection(); OLMap.getView().setRotation(mapOrientation); // adjust orientation @@ -3468,7 +3470,9 @@ function zoomOut() { } function changeCenter(init) { - const center = ol.proj.toLonLat(OLMap.getView().getCenter(), OLMap.getView().getProjection()); + + const rawCenter = OLMap.getView().getCenter(); + const center = ol.proj.toLonLat(rawCenter); localStorage['CenterLon'] = CenterLon = center[0]; localStorage['CenterLat'] = CenterLat = center[1]; @@ -3478,11 +3482,16 @@ function changeCenter(init) { if (!init && showTrace) updateAddressBar(); + + if (rawCenter[0] < OLProj.extent_[0] || rawCenter[0] > OLProj.extent_[3]) { + OLMap.getView().setCenter(ol.proj.fromLonLat(center)); + } + } function checkMovement() { const zoom = OLMap.getView().getZoom(); - const center = ol.proj.toLonLat(OLMap.getView().getCenter(), OLMap.getView().getProjection()); + const center = ol.proj.toLonLat(OLMap.getView().getCenter()); if ( checkMoveZoom != zoom || @@ -4347,7 +4356,7 @@ function checkFollow() { toggleFollow(false); return; } - const center = ol.proj.toLonLat(OLMap.getView().getCenter(), OLMap.getView().getProjection()); + const center = ol.proj.toLonLat(OLMap.getView().getCenter()); if (Math.abs(center[0] - SelectedPlane.position[0]) > 0.001 || Math.abs(center[1] - SelectedPlane.position[1]) > 0.001) { toggleFollow(false);