From c3e5a6db1cabfa4006b85c8dfe6a587da26799e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Vigh?= Date: Sun, 2 May 2021 16:57:47 +0200 Subject: [PATCH] radius calculation for new panorama search based on latitude and mercator projection for google maps --- public/static/js/map_editor.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/public/static/js/map_editor.js b/public/static/js/map_editor.js index 2831aa5..b614f8e 100644 --- a/public/static/js/map_editor.js +++ b/public/static/js/map_editor.js @@ -86,7 +86,7 @@ sv.getPanorama({ location: location, preference: google.maps.StreetViewPreference.NEAREST, - radius: 100, + radius: MapEditor.map.getSearchRadius(location), source: canBeIndoor ? google.maps.StreetViewSource.DEFAULT : google.maps.StreetViewSource.OUTDOOR }, function (data, status) { var panoLocationData = status === google.maps.StreetViewStatus.OK ? data.location : null; @@ -473,7 +473,11 @@ LMapWrapper.markers.removeLayer(marker); }, - toggleStreetViewCover: function () { } + toggleStreetViewCover: function () { }, + + getSearchRadius: function (location) { + return 100; + } }; var GMapWrapper = { @@ -626,6 +630,20 @@ GMapWrapper.streetViewCover.setMap(GMapWrapper.map); GMapWrapper.streetViewCoverOn = true; } + }, + + getSearchRadius: function (location) { + // source: https://www.yorku.ca/mack/CHI01.htm + var movementOffset = 4; + + // source: https://groups.google.com/g/google-maps-js-api-v3/c/hDRO4oHVSeM/m/osOYQYXg2oUJ?pli=1 + var metersPerPixel = 156543.03392 * Math.cos(location.lat * Math.PI / 180) / Math.pow(2, GMapWrapper.map.getZoom()); + + var minSearchRadius = 5; + + var searchRadius = Math.max(minSearchRadius, Math.round(movementOffset * metersPerPixel)); + + return searchRadius; } }; -- 2.45.2