nakarte

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

commit 7866d074261890b80129ee629a9728af883abbb2
parent 7778d1a6cc236fc8ed21edef2ae1e8844db32992
Author: Sergej Orlov <wladimirych@gmail.com>
Date:   Sun, 15 Mar 2020 17:26:57 +0100

layers: use simple L.TileLayer with proxy for strava heatmap

Diffstat:
Msrc/layers.js | 99++++++++++++++-----------------------------------------------------------------
Dsrc/lib/leaflet.layer.strava-heatmap/index.js | 78------------------------------------------------------------------------------
2 files changed, 17 insertions(+), 160 deletions(-)

diff --git a/src/layers.js b/src/layers.js @@ -8,7 +8,7 @@ import '~/lib/leaflet.layer.soviet-topomaps-grid'; import '~/lib/leaflet.layer.westraPasses'; import '~/lib/leaflet.layer.wikimapia'; import {GeocachingSu} from '~/lib/leaflet.layer.geocaching-su'; -import {StravaHeatmap} from '~/lib/leaflet.layer.strava-heatmap'; +import urlViaCorsProxy from '~/lib/CORSProxy'; const layersDefs = [ { @@ -613,8 +613,10 @@ import {StravaHeatmap} from '~/lib/leaflet.layer.strava-heatmap'; { title: 'Strava heatmap (all)', isDefault: false, - layer: new StravaHeatmap( - 'https://heatmap-external-{s}.strava.com/tiles-auth/all/hot/{z}/{x}/{y}.png?px=256', + layer: L.tileLayer( + urlViaCorsProxy( + 'https://heatmap-external-{s}.strava.com/tiles-auth/all/hot/{z}/{x}/{y}.png?px=256' + ), { code: 'Sa', isOverlay: true, @@ -630,8 +632,10 @@ import {StravaHeatmap} from '~/lib/leaflet.layer.strava-heatmap'; { title: 'Strava heatmap (run)', isDefault: false, - layer: new StravaHeatmap( - 'https://heatmap-external-{s}.strava.com/tiles-auth/run/hot/{z}/{x}/{y}.png?px=256', + layer: L.tileLayer( + urlViaCorsProxy( + 'https://heatmap-external-{s}.strava.com/tiles-auth/run/hot/{z}/{x}/{y}.png?px=256' + ), { code: 'Sr', isOverlay: true, @@ -647,8 +651,10 @@ import {StravaHeatmap} from '~/lib/leaflet.layer.strava-heatmap'; { title: 'Strava heatmap (ride)', isDefault: false, - layer: new StravaHeatmap( - 'https://heatmap-external-{s}.strava.com/tiles-auth/ride/hot/{z}/{x}/{y}.png?px=256', + layer: L.tileLayer( + urlViaCorsProxy( + 'https://heatmap-external-{s}.strava.com/tiles-auth/ride/hot/{z}/{x}/{y}.png?px=256' + ), { code: 'Sb', isOverlay: true, @@ -664,8 +670,10 @@ import {StravaHeatmap} from '~/lib/leaflet.layer.strava-heatmap'; { title: 'Strava heatmap (winter)', isDefault: false, - layer: new StravaHeatmap( - 'https://heatmap-external-{s}.strava.com/tiles-auth/winter/hot/{z}/{x}/{y}.png?px=256', + layer: L.tileLayer( + urlViaCorsProxy( + 'https://heatmap-external-{s}.strava.com/tiles-auth/winter/hot/{z}/{x}/{y}.png?px=256' + ), { code: 'Sw', isOverlay: true, @@ -679,71 +687,6 @@ import {StravaHeatmap} from '~/lib/leaflet.layer.strava-heatmap'; ) }, { - title: 'Strava heatmap lowres (all)', - isDefault: false, - layer: L.tileLayer('https://heatmap-external-{s}.strava.com/tiles/all/hot/{z}/{x}/{y}.png?px=256', - { - code: 'Sal', - isOverlay: true, - scaleDependent: true, - print: false, - jnx: false, - subdomains: 'abc', - maxNativeZoom: 12, - noCors: true - } - ) - }, - { - title: 'Strava heatmap lowres (run)', - isDefault: false, - layer: L.tileLayer('https://heatmap-external-{s}.strava.com/tiles/run/hot/{z}/{x}/{y}.png?px=256', - { - code: 'Srl', - isOverlay: true, - scaleDependent: true, - print: false, - jnx: false, - subdomains: 'abc', - maxNativeZoom: 12, - noCors: true - } - ) - }, - { - title: 'Strava heatmap lowres (ride)', - isDefault: false, - layer: L.tileLayer('https://heatmap-external-{s}.strava.com/tiles/ride/hot/{z}/{x}/{y}.png?px=256', - { - code: 'Sbl', - isOverlay: true, - scaleDependent: true, - print: false, - jnx: false, - subdomains: 'abc', - maxNativeZoom: 12, - noCors: true - } - ) - }, - { - title: 'Strava heatmap lowres (winter)', - isDefault: false, - layer: L.tileLayer( - 'https://heatmap-external-{s}.strava.com/tiles/winter/hot/{z}/{x}/{y}.png?px=256', - { - code: 'Swl', - isOverlay: true, - scaleDependent: true, - print: false, - jnx: false, - subdomains: 'abc', - maxNativeZoom: 12, - noCors: true - } - ) - }, - { title: 'Norway paper map', isDefault: false, layer: new L.TileLayer( @@ -1038,10 +981,6 @@ import {StravaHeatmap} from '~/lib/leaflet.layer.strava-heatmap'; 'Strava heatmap (run)', 'Strava heatmap (ride)', 'Strava heatmap (winter)', - 'Strava heatmap lowres (all)', - 'Strava heatmap lowres (run)', - 'Strava heatmap lowres (ride)', - 'Strava heatmap lowres (winter)' ], }, @@ -1124,10 +1063,6 @@ import {StravaHeatmap} from '~/lib/leaflet.layer.strava-heatmap'; 'Strava heatmap (run)', 'Strava heatmap (ride)', 'Strava heatmap (winter)', - 'Strava heatmap lowres (all)', - 'Strava heatmap lowres (run)', - 'Strava heatmap lowres (ride)', - 'Strava heatmap lowres (winter)', 'Soviet topo maps grid', 'Wikimapia', diff --git a/src/lib/leaflet.layer.strava-heatmap/index.js b/src/lib/leaflet.layer.strava-heatmap/index.js @@ -1,78 +0,0 @@ -import L from 'leaflet'; -import {notify} from '~/lib/notifications'; -import {fetch} from '~/lib/xhr-promise'; - -const StravaHeatmap = L.TileLayer.extend({ - options: { - authRenewInterval: 24 * 3600 * 1000, - }, - - checkUserLoggedIn: async function() { - const data = { - x: 4954, - y: 2559, - z: 13, - s: this.options.subdomains[0], - }; - const url = L.Util.template(this._url, data); - const image = new Image(); - return new Promise((resolve) => { - image.onerror = () => resolve(false); - image.onload = () => resolve(true); - image.src = url; - }); - }, - - tryHeatmapLogin: async function() { - try { - await fetch('https://heatmap-external-a.strava.com/auth', { - withCredentials: true, - maxTries: 1, - }); - } catch (e) { - // skip error - } - }, - - ensureUserLoggedIn: async function(showInstructions = true) { - if (!(await this.checkUserLoggedIn())) { - await this.tryHeatmapLogin(); - this.redraw(); - if (!(await this.checkUserLoggedIn())) { - if (this._map && showInstructions) { - this.notifyUserNeedsLogin(); - } - } - } - }, - - notifyUserNeedsLogin: function() { - const message = ` - Для просмотра тепловой карты треков необходимо зарегистрироваться и залогиниться на сайте - <a title="Откроется в новом окне" target="_blank" href="https://strava.com/login"> - https://strava.com/login</a>, после чего нажать кнопку "Ok"<br> - Если вы не хотите регистририваться в сервисе Strava, вы можете выбрать в настройках слои с низким - разрешением "Strava&nbsp;heatmap&nbsp;lowres", они доступны всем пользователям.<br><br> - - To use tracks heatmap you need to register and log in at - <a title="Will open in new window" target="_blank" href="https://strava.com/login"> - https://strava.com/login</a> - and press "Ok" button afterwards. - If you do not want to register at Strava you can select low resolution maps in layers settings.`; - - notify(message, () => this.ensureUserLoggedIn(false)); - }, - - onAdd: function(map) { - L.TileLayer.prototype.onAdd.call(this, map); - this.ensureUserLoggedIn(); - this._authRenewIntervalId = setInterval(() => this.tryHeatmapLogin(), this.options.authRenewInterval); - }, - - onRemove: function(map) { - clearInterval(this._authRenewIntervalId); - L.TileLayer.prototype.onRemove.call(this, map); - }, -}); - -export {StravaHeatmap};