nakarte

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

commit 19565371fe491e01238ab9d67b5912a370acb547
parent 0ec8770f2225754991bc0412342dfe75e2da35fa
Author: Sergej Orlov <wladimirych@gmail.com>
Date:   Mon, 26 Nov 2018 08:35:08 +0100

Merge branch 'movescount' into tracks-parsers-refactor-to-classes

Diffstat:
Msrc/lib/leaflet.control.track-list/lib/services/index.js | 3+++
Asrc/lib/leaflet.control.track-list/lib/services/movescount.js | 109+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 112 insertions(+), 0 deletions(-)

diff --git a/src/lib/leaflet.control.track-list/lib/services/index.js b/src/lib/leaflet.control.track-list/lib/services/index.js @@ -5,6 +5,7 @@ import Gpslib from './gpslib'; import Strava from './strava'; import {YandexRuler} from './yandex'; import {NakarteTrack, NakarteNktk, NakarteNktl} from './nakarte'; +import {MovescountMove, MovescountRoute} from './movescount'; export default [ YandexRuler, @@ -15,5 +16,7 @@ export default [ Gpsies, Gpslib, Strava, + MovescountMove, + MovescountRoute, SimpleService ] \ No newline at end of file diff --git a/src/lib/leaflet.control.track-list/lib/services/movescount.js b/src/lib/leaflet.control.track-list/lib/services/movescount.js @@ -0,0 +1,108 @@ +import BaseService from './baseService'; +import urlViaCorsProxy from 'lib/CORSProxy'; + +class MovescountBase extends BaseService { + // urlRe = null; + + isOurUrl() { + return this.urlRe.test(this.origUrl); + } +} + +class MovescountRoute extends MovescountBase { + urlRe = /^https?:\/\/www.movescount.com\/([a-z]{2}\/)?map.*[?&]route=(\d+)/; + + requestOptions() { + const m = this.urlRe.exec(this.origUrl); + const trackId = this.trackId = m[2]; + return [{ + url: urlViaCorsProxy(`http://www.movescount.com/Move/Route/${trackId}`), + options: { + responseType: 'binarystring', + isResponseSuccess: (xhr) => xhr.status === 200 || xhr.status === 403 + }, + }] + } + + parseResponse(responses) { + const response = responses[0]; + if (response.status === 403) { + return [{error: 'Movescount user disabled viewing this route'}]; + } + let data; + let name = `Movescount route ${this.trackId}`; + try { + data = JSON.parse(response.responseBinaryText) + } catch (e) { + return [{name, error: 'UNSUPPORTED'}]; + } + const track = data.points.latitudes.map((lat, i) => ({ + lat, + lng: data.points.longitudes[i] + }) + ); + + name = data.routeName ? data.routeName : name; + + return [{ + name, + tracks: [track] + }]; + } +} + +class MovescountMove extends MovescountBase { + urlRe = /^https?:\/\/www.movescount.com\/([a-z]{2}\/)?moves\/move(\d+)/; + + requestOptions() { + const m = this.urlRe.exec(this.origUrl); + const trackId = m[2]; + return [ + { + url: urlViaCorsProxy(`http://www.movescount.com/Move/Track2/${trackId}`), + options: { + responseType: 'binarystring', + isResponseSuccess: (xhr) => xhr.status === 200 || xhr.status === 403 + } + }, + { + url: urlViaCorsProxy(`https://www.movescount.com/moves/move${trackId}`), + options: { + responseType: 'binarystring', + isResponseSuccess: (xhr) => xhr.status === 200 || xhr.status === 403 || xhr.status === 404 + } + } + ] + } + + parseResponse(responses) { + const [trackResponse, pageResponse] = responses; + if (trackResponse.status === 403) { + return [{error: 'Movescount user disabled viewing this activity'}]; + } + let data; + let name = `Movescount move ${this.trackId}`; + try { + data = JSON.parse(trackResponse.responseBinaryText) + } catch (e) { + return [{name, error: 'UNSUPPORTED'}]; + } + const track = data.TrackPoints.map(trackPoint => ({ + lat: trackPoint.Latitude, + lng: trackPoint.Longitude + }) + ); + + const dom = (new DOMParser()).parseFromString(pageResponse.responseBinaryText, "text/html"); + const title = dom.querySelector('title').text.trim(); + name = title ? title : name; + + return [{ + name, + tracks: [track] + }]; + + } +} + +export {MovescountRoute, MovescountMove}; +\ No newline at end of file