openstreetmapRu.js (1189B)
1 import urlViaCorsProxy from '~/lib/CORSProxy'; 2 import BaseService from './baseService'; 3 import parseGpx from '../parsers/gpx'; 4 5 class OpenStreetMapRu extends BaseService { 6 urlRe = /^https?:\/\/(?:www\.)?openstreetmap\.ru\/\?mapid=(\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://openstreetmap.ru/mymap.php?id=${trackId}&format=gpx`), 21 options: {responseType: 'binarystring'} 22 }]; 23 } 24 25 parseResponse(responses) { 26 const trackId = this.getTrackId(); 27 const response = responses[0]; 28 const geodata = parseGpx(response.responseBinaryText, `PersonalMap ${trackId}`, true); 29 if (!geodata) { 30 return [{name: name, error: 'UNSUPPORTED'}]; 31 } 32 if (geodata[0].tracks.length === 0 && geodata[0].points.length === 0) { 33 return [{error: 'Personal map is empty or does not exist'}]; 34 } 35 return geodata; 36 } 37 } 38 39 export default OpenStreetMapRu;