osm.js (937B)
1 import {urlViaCorsProxy} from '~/lib/CORSProxy'; 2 import BaseService from './baseService'; 3 import parseGpx from '../parsers/gpx'; 4 5 class Osm extends BaseService { 6 urlRe = /^https?:\/\/(?:www\.)?openstreetmap\.org\/user\/(?:.*)\/traces\/(\d+)/u; 7 8 getTrackId() { 9 const m = this.urlRe.exec(this.origUrl); 10 return m[1]; 11 } 12 13 isOurUrl() { 14 return this.urlRe.test(this.origUrl); 15 } 16 17 requestOptions() { 18 const trackId = this.getTrackId(); 19 return [{ 20 url: urlViaCorsProxy(`https://www.openstreetmap.org/trace/${trackId}/data`), 21 options: {responseType: 'binarystring'} 22 }]; 23 } 24 25 parseResponse(responses) { 26 const trackId = this.getTrackId(); 27 const response = responses[0]; 28 return parseGpx(response.responseBinaryText, `OSM track ${trackId}`, true) || 29 [{name: name, error: 'UNSUPPORTED'}]; 30 } 31 } 32 33 export default Osm;