nakarte

Source code of https://map.sikmir.ru (fork)
git clone git://git.sikmir.ru/nakarte
Log | Files | Refs | LICENSE

commit b06ccb121a5a0086f3d88f0c2bcf6b5abea83a01
parent 021009a3591d4d9c5a48675270573ef0646e1d33
Author: Sergej Orlov <wladimirych@gmail.com>
Date:   Sat, 27 Aug 2022 16:17:15 +0200

search: add support for Google links to panorama views

Diffstat:
Msrc/lib/leaflet.control.search/providers/links.js | 19+++++++++++++------
Mtest/test_search_links.js | 4++++
2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/src/lib/leaflet.control.search/providers/links.js b/src/lib/leaflet.control.search/providers/links.js @@ -80,9 +80,10 @@ const YandexMapsUrl = { }; const GoogleMapsSimpleMapUrl = { - viewRe: /\/@([-\d.]+),([-\d.]+),([\d.]+)([mz])(?:\/|$)/u, + viewRe: /\/@([-\d.]+),([-\d.]+),(?:([\d.]+)([mz]))?/u, placeRe: /\/place\/([^/]+)/u, placeZoom: 14, + panoramaZoom: 16, isOurUrl: function (url) { return Boolean(url.pathname.match(this.viewRe)) || Boolean(url.pathname.match(this.placeRe)); @@ -107,12 +108,18 @@ const GoogleMapsSimpleMapUrl = { const viewMatch = path.match(this.viewRe); const lat = parseFloat(viewMatch[1]); const lon = parseFloat(viewMatch[2]); - let zoom = parseFloat(viewMatch[3]); - // zoom for satellite images is expressed in meters - if (viewMatch[4] === 'm') { - zoom = Math.log2((149175296 / zoom) * Math.cos((lat / 180) * Math.PI)); + let zoom; + // no need to check viewMatch[4] as they are together in same group + if (viewMatch[3] === undefined) { + zoom = this.panoramaZoom; + } else { + zoom = parseFloat(viewMatch[3]); + // zoom for satellite images is expressed in meters + if (viewMatch[4] === 'm') { + zoom = Math.log2((149175296 / zoom) * Math.cos((lat / 180) * Math.PI)); + } + zoom = Math.round(zoom); } - zoom = Math.round(zoom); results.push(makeSearchResult(lat, lon, zoom, 'Google map view')); } catch (e) { // pass diff --git a/test/test_search_links.js b/test/test_search_links.js @@ -117,6 +117,10 @@ suite('LinksProvider - parsing valid links'); [{title: 'Google map view', latlng: {lat: 56.0836099, lng: 37.3849634}, zoom: 16}], ], [ + 'https://www.google.com/maps/@48.6514614,16.9945421,3a,75y,253.17h,90t/data=!3m7!1e1!3m5!1s4MYpvu63gL3ZArPiSohExg!2e0!6shttps:%2F%2Fstreetviewpixels-pa.googleapis.com%2Fv1%2Fthumbnail%3Fpanoid%3D4MYpvu63gL3ZArPiSohExg%26cb_client%3Dmaps_sv.tactile.gps%26w%3D203%26h%3D100%26yaw%3D253.16992%26pitch%3D0%26thumbfov%3D100!7i13312!8i6656', // eslint-disable-line max-len + [{title: 'Google map view', latlng: {lat: 48.6514614, lng: 16.9945421}, zoom: 16}], + ], + [ 'https://nakarte.me/#m=11/49.44893/16.59897&l=O', [{title: 'Nakarte view', latlng: {lat: 49.44893, lng: 16.59897}, zoom: 11}], ],