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; } };