nakarte

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

commit 4135e5d1ad4db1e506198333e629a70e835a4d88
parent 6cc7509a8a9ab19c6fd2c361cd869f45d8f19986
Author: Sergey Orlov <wladimirych@gmail.com>
Date:   Thu, 30 Jul 2020 18:30:54 +0200

search, links: add support for links to Google Maps satellite, fix #474

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

diff --git a/src/lib/leaflet.control.search/providers/links.js b/src/lib/leaflet.control.search/providers/links.js @@ -53,8 +53,8 @@ const YandexMapsUrl = { }, }; -const GoogleMapsSimpleUrl = { - viewRe: /\/@([-\d.]+),([-\d.]+),([\d.]+)z(?:\/|$)/u, +const GoogleMapsSimpleMapUrl = { + viewRe: /\/@([-\d.]+),([-\d.]+),([\d.]+)([mz])(?:\/|$)/u, isOurUrl: function url(url) { return Boolean(url.pathname.match(this.viewRe)); @@ -73,7 +73,12 @@ const GoogleMapsSimpleUrl = { try { const lat = parseFloat(viewMatch[1]); const lon = parseFloat(viewMatch[2]); - const zoom = Math.round(parseFloat(viewMatch[3])); + 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)); + } + zoom = Math.round(zoom); return makeSearchResults(lat, lon, zoom, title); } catch (_) { return {error: L.Util.template(MESSAGE_LINK_MALFORMED, {name: 'Google'})}; @@ -103,7 +108,7 @@ const GoogleMapsQueryUrl = { }; const GoogleMapsUrl = { - subprocessors: [GoogleMapsSimpleUrl, GoogleMapsQueryUrl], + subprocessors: [GoogleMapsSimpleMapUrl, GoogleMapsQueryUrl], isOurUrl: function(url) { return Boolean(url.hostname.match(/\bgoogle\..+$/u) && url.pathname.match(/^\/maps(\/|$)/u)); diff --git a/test/test_search_links.js b/test/test_search_links.js @@ -11,6 +11,12 @@ suite('LinksProvider - parsing valid links'); 14, ], [ + 'https://www.google.com.ua/maps/@49.1809973,61.6591562,5952m/data=!3m1!1e3?hl=ru', + 'Google map view', + {lat: 49.1809973, lng: 61.6591562}, + 14, + ], + [ 'https://yandex.ru/maps/10509/brno/?ll=16.548629%2C49.219896&z=14', 'Yandex map view', {lat: 49.219896, lng: 16.548629},