nakarte

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

gpslib.js (842B)


      1 import urlViaCorsProxy from '~/lib/CORSProxy';
      2 import BaseService from './baseService';
      3 import parseGpx from '../parsers/gpx';
      4 
      5 class Gpslib extends BaseService {
      6     urlRe = /^https?:\/\/(?:.+\.)?gpslib\.[^.]+\/tracks\/info\/(\d+)/u;
      7 
      8     isOurUrl() {
      9         return this.urlRe.test(this.origUrl);
     10     }
     11 
     12     requestOptions() {
     13         const m = this.urlRe.exec(this.origUrl);
     14         const trackId = this.trackId = m[1];
     15         return [{
     16             url: urlViaCorsProxy(`https://www.gpslib.ru/tracks/download/${trackId}.gpx`),
     17             options: {responseType: 'binarystring'}
     18         }];
     19     }
     20 
     21     parseResponse(responses) {
     22         const response = responses[0];
     23         return parseGpx(response.responseBinaryText, `GPSLib ${this.trackId}`, true) ||
     24             [{name: name, error: 'UNSUPPORTED'}];
     25     }
     26 }
     27 
     28 export default Gpslib;