Merge lp:~cibersheep/unav/dispatchshare into lp:unav
- dispatchshare
- Merge into trunk
Proposed by
Joan CiberSheep
Status: | Merged |
---|---|
Merged at revision: | 241 |
Proposed branch: | lp:~cibersheep/unav/dispatchshare |
Merge into: | lp:unav |
Diff against target: |
713 lines (+336/-197) 6 files modified
app-contenthub.json (+5/-0) app-dispatcher.json (+12/-0) manifest.json (+3/-2) qml/Main.qml (+39/-24) qml/components/ContentHubModel.qml (+101/-0) qml/js/utils.js (+176/-171) |
To merge this branch: | bzr merge lp:~cibersheep/unav/dispatchshare |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
costales | Approve | ||
Review via email: mp+374515@code.launchpad.net |
Commit message
Updated urldispatcher and target url shares
Description of the change
- Updated urldispatcher info to support http and https urls
- Added being the target for shared url
- Updated render received Google maps urls
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added file 'app-contenthub.json' |
2 | --- app-contenthub.json 1970-01-01 00:00:00 +0000 |
3 | +++ app-contenthub.json 2019-10-22 11:48:06 +0000 |
4 | @@ -0,0 +1,5 @@ |
5 | +{ |
6 | + "share": [ |
7 | + "links" |
8 | + ] |
9 | +} |
10 | |
11 | === modified file 'app-dispatcher.json' |
12 | --- app-dispatcher.json 2016-08-27 11:38:42 +0000 |
13 | +++ app-dispatcher.json 2019-10-22 11:48:06 +0000 |
14 | @@ -4,6 +4,10 @@ |
15 | "domain-suffix": "map.unav.me" |
16 | }, |
17 | { |
18 | + "protocol": "https", |
19 | + "domain-suffix": "map.unav.me" |
20 | + }, |
21 | + { |
22 | "protocol": "http", |
23 | "domain-suffix": "unav-go.github.io" |
24 | }, |
25 | @@ -15,11 +19,19 @@ |
26 | "domain-suffix": "www.openstreetmap.org" |
27 | }, |
28 | { |
29 | + "protocol": "https", |
30 | + "domain-suffix": "www.openstreetmap.org" |
31 | + }, |
32 | + { |
33 | "protocol": "http", |
34 | "domain-suffix": "www.opencyclemap.org" |
35 | }, |
36 | { |
37 | "protocol": "https", |
38 | + "domain-suffix": "www.opencyclemap.org" |
39 | + }, |
40 | + { |
41 | + "protocol": "https", |
42 | "domain-suffix": "maps.google.com" |
43 | } |
44 | ] |
45 | |
46 | === modified file 'manifest.json' |
47 | --- manifest.json 2019-01-05 15:42:10 +0000 |
48 | +++ manifest.json 2019-10-22 11:48:06 +0000 |
49 | @@ -6,11 +6,12 @@ |
50 | "navigator": { |
51 | "apparmor": "app-armor.json", |
52 | "desktop": "app.desktop", |
53 | - "urls": "app-dispatcher.json" |
54 | + "urls": "app-dispatcher.json", |
55 | + "content-hub": "app-contenthub.json" |
56 | } |
57 | }, |
58 | "maintainer": "Marcos Costales <costales.marcos@gmail.com>", |
59 | "name": "navigator.costales", |
60 | "title": "uNav", |
61 | - "version": "2.3" |
62 | + "version": "2.4" |
63 | } |
64 | |
65 | === modified file 'qml/Main.qml' |
66 | --- qml/Main.qml 2019-07-14 23:33:08 +0000 |
67 | +++ qml/Main.qml 2019-10-22 11:48:06 +0000 |
68 | @@ -476,18 +476,7 @@ |
69 | |
70 | // Catching urls |
71 | var url_dispatcher = Qt.application.arguments[1]; |
72 | - if (QmlJs.is_url_dispatcher(url_dispatcher)['is_dispatcher']) { |
73 | - var coord = QmlJs.get_url_coord(url_dispatcher); |
74 | - if (coord['lat'] !== null && coord['lng'] !== null) { |
75 | - mainPageStack.clickedLat = coord['lat']; |
76 | - mainPageStack.clickedLng = coord['lng']; |
77 | - if (mainPageStack.center_onpos === 2) |
78 | - mainPageStack.center_onpos = 1; |
79 | - mainPageStack.executeJavaScript("ui.markers_POI_set([{title: \"" + i18n.tr("Shared Position") + "\", lat: " + mainPageStack.clickedLat + ", lng: " + mainPageStack.clickedLng + "}])"); |
80 | - mainPageStack.favPopup = false; |
81 | - goThereActionPopover.show(); |
82 | - } |
83 | - } |
84 | + navApp.checkReceivedCoordinates(url_dispatcher); |
85 | } |
86 | } |
87 | |
88 | @@ -502,18 +491,7 @@ |
89 | } |
90 | // Catching urls |
91 | var url_dispatcher = uris[0]; |
92 | - if (QmlJs.is_url_dispatcher(url_dispatcher)['is_dispatcher']) { |
93 | - var coord = QmlJs.get_url_coord(url_dispatcher); |
94 | - if (coord['lat'] !== null && coord['lng'] !== null) { |
95 | - mainPageStack.clickedLat = coord['lat']; |
96 | - mainPageStack.clickedLng = coord['lng']; |
97 | - if (mainPageStack.center_onpos === 2) |
98 | - mainPageStack.center_onpos = 1; |
99 | - mainPageStack.executeJavaScript("ui.markers_POI_set([{title: \"" + i18n.tr("Shared Position") + "\", lat: " + mainPageStack.clickedLat + ", lng: " + mainPageStack.clickedLng + "}])"); |
100 | - mainPageStack.favPopup = false; |
101 | - goThereActionPopover.show(); |
102 | - } |
103 | - } |
104 | + navApp.checkReceivedCoordinates(url_dispatcher); |
105 | } |
106 | } |
107 | |
108 | @@ -1043,5 +1021,42 @@ |
109 | } |
110 | } |
111 | |
112 | + //Item to receive shared urls |
113 | + ContentHubModel { |
114 | + id: contentHub |
115 | + onShareRequested: navApp.startImport(transfer) |
116 | + } |
117 | + |
118 | + function startImport(transfer) { |
119 | + console.log("Start import") |
120 | + if (transfer.contentType === ContentType.Links) { |
121 | + |
122 | + // Extract the pure text |
123 | + for (var i = 0; i < transfer.items.length; i++) { |
124 | + if (transfer.items[i].url) { |
125 | + var importedUrl = String(transfer.items[i].url); |
126 | + |
127 | + checkReceivedCoordinates(importedUrl); |
128 | + } |
129 | + } |
130 | + |
131 | + console.log("Import: ", importedUrl) |
132 | + } |
133 | + } |
134 | + |
135 | + function checkReceivedCoordinates(urlToCheck){ |
136 | + if (QmlJs.is_url_dispatcher(urlToCheck)['is_dispatcher']) { |
137 | + var coord = QmlJs.get_url_coord(urlToCheck); |
138 | + if (coord['lat'] !== null && coord['lng'] !== null) { |
139 | + mainPageStack.clickedLat = coord['lat']; |
140 | + mainPageStack.clickedLng = coord['lng']; |
141 | + if (mainPageStack.center_onpos === 2) |
142 | + mainPageStack.center_onpos = 1; |
143 | + mainPageStack.executeJavaScript("ui.markers_POI_set([{title: \"" + i18n.tr("Shared Position") + "\", lat: " + mainPageStack.clickedLat + ", lng: " + mainPageStack.clickedLng + "}])"); |
144 | + mainPageStack.favPopup = false; |
145 | + goThereActionPopover.show(); |
146 | + } |
147 | + } |
148 | + } |
149 | } |
150 | } |
151 | |
152 | === added file 'qml/components/ContentHubModel.qml' |
153 | --- qml/components/ContentHubModel.qml 1970-01-01 00:00:00 +0000 |
154 | +++ qml/components/ContentHubModel.qml 2019-10-22 11:48:06 +0000 |
155 | @@ -0,0 +1,101 @@ |
156 | +import QtQuick 2.9 |
157 | +import Ubuntu.Components 1.3 |
158 | +import Ubuntu.Content 1.3 |
159 | +import Ubuntu.Components.Popups 1.3 |
160 | +import "../components" |
161 | + |
162 | +Item { |
163 | + |
164 | + id: shareController |
165 | + property url uri: "" |
166 | + property alias clipboardText: mimeData.text |
167 | + |
168 | + signal done () |
169 | + signal shareRequested ( var transfer ) |
170 | + |
171 | + function toClipboard ( text ) { |
172 | + mimeData.text = text |
173 | + Clipboard.push( mimeData ) |
174 | + } |
175 | + |
176 | + function share(url, text, contentType) { |
177 | + uri = url |
178 | + var sharePopup = PopupUtils.open(shareDialog, shareController, {"contentType" : contentType}) |
179 | + sharePopup.items.push(contentItemComponent.createObject(shareController, {"url" : uri, "text": text})) |
180 | + } |
181 | + |
182 | + function shareLink( url ) { |
183 | + share( url, url, ContentType.Links) |
184 | + } |
185 | + |
186 | + function shareText( text ) { |
187 | + share( "", text, ContentType.Text) |
188 | + } |
189 | + |
190 | + function sharePicture( url, title ) { |
191 | + share( url, title, ContentType.Pictures) |
192 | + } |
193 | + |
194 | + function shareAudio( url, title ) { |
195 | + share( url, title, ContentType.Music) |
196 | + } |
197 | + |
198 | + function shareVideo( url, title ) { |
199 | + share( url, title, ContentType.Videos) |
200 | + } |
201 | + |
202 | + function shareFile( url, title ) { |
203 | + share( url, title, ContentType.Documents) |
204 | + } |
205 | + |
206 | + function shareAll( url, title ) { |
207 | + share( url, title, ContentType.All) |
208 | + } |
209 | + |
210 | + Connections { |
211 | + target: ContentHub |
212 | + onShareRequested: shareRequested(transfer) |
213 | + } |
214 | + |
215 | + Component { |
216 | + id: shareDialog |
217 | + PopupBase { |
218 | + id: sharePopUp |
219 | + anchors.fill: parent |
220 | + property var activeTransfer |
221 | + property var items: [] |
222 | + property alias contentType: peerPicker.contentType |
223 | + |
224 | + Rectangle { |
225 | + anchors.fill: parent |
226 | + ContentPeerPicker { |
227 | + id: peerPicker |
228 | + handler: ContentHandler.Share |
229 | + visible: parent.visible |
230 | + |
231 | + onPeerSelected: { |
232 | + activeTransfer = peer.request() |
233 | + activeTransfer.items = sharePopUp.items |
234 | + activeTransfer.state = ContentTransfer.Charged |
235 | + PopupUtils.close(sharePopUp) |
236 | + } |
237 | + |
238 | + onCancelPressed: { |
239 | + PopupUtils.close(sharePopUp) |
240 | + } |
241 | + } |
242 | + } |
243 | + } |
244 | + } |
245 | + |
246 | + Component { |
247 | + id: contentItemComponent |
248 | + ContentItem { } |
249 | + } |
250 | + |
251 | + MimeData { |
252 | + id: mimeData |
253 | + text: "" |
254 | + } |
255 | + |
256 | +} |
257 | |
258 | === modified file 'qml/js/utils.js' |
259 | --- qml/js/utils.js 2018-10-27 09:19:48 +0000 |
260 | +++ qml/js/utils.js 2019-10-22 11:48:06 +0000 |
261 | @@ -2,62 +2,62 @@ |
262 | * Calculates the distance between two spots. |
263 | * This method is more simple but also far more inaccurate |
264 | * |
265 | -* @param object Start position {latitude: 123, longitude: 123} |
266 | -* @param object End position {latitude: 123, longitude: 123} |
267 | -* @param integer Accuracy (in meters) |
268 | +* @param object Start position {latitude: 123, longitude: 123} |
269 | +* @param object End position {latitude: 123, longitude: 123} |
270 | +* @param integer Accuracy (in meters) |
271 | * @return integer Distance (in meters) |
272 | */ |
273 | function calcPoiDistance(cur_lat, cur_lng, poi_lat, poi_lng, accuracy) { |
274 | if (cur_lat === null || cur_lng === null || cur_lat === 'null' || cur_lng === 'null') |
275 | - return null; |
276 | - |
277 | - accuracy = Math.floor(accuracy) || 1; |
278 | - var distance = |
279 | - Math.round( |
280 | - Math.acos( |
281 | - Math.sin( |
282 | - poi_lat * Math.PI / 180 |
283 | - ) * |
284 | - Math.sin( |
285 | - cur_lat * Math.PI / 180 |
286 | - ) + |
287 | - Math.cos( |
288 | - poi_lat * Math.PI / 180 |
289 | - ) * |
290 | - Math.cos( |
291 | - cur_lat * Math.PI / 180 |
292 | - ) * |
293 | - Math.cos( |
294 | - (cur_lng - poi_lng) * Math.PI / 180 |
295 | - ) |
296 | - ) * 6378137 // Earth radius |
297 | - ); |
298 | - return Math.floor(Math.round(distance/accuracy)*accuracy); |
299 | + return null; |
300 | + |
301 | + accuracy = Math.floor(accuracy) || 1; |
302 | + var distance = |
303 | + Math.round( |
304 | + Math.acos( |
305 | + Math.sin( |
306 | + poi_lat * Math.PI / 180 |
307 | + ) * |
308 | + Math.sin( |
309 | + cur_lat * Math.PI / 180 |
310 | + ) + |
311 | + Math.cos( |
312 | + poi_lat * Math.PI / 180 |
313 | + ) * |
314 | + Math.cos( |
315 | + cur_lat * Math.PI / 180 |
316 | + ) * |
317 | + Math.cos( |
318 | + (cur_lng - poi_lng) * Math.PI / 180 |
319 | + ) |
320 | + ) * 6378137 // Earth radius |
321 | + ); |
322 | + return Math.floor(Math.round(distance/accuracy)*accuracy); |
323 | } |
324 | |
325 | /** |
326 | * Function formatDistance(..): formats distance string |
327 | * dist: distance in m |
328 | * unit: 0...km |
329 | -* 1...mi |
330 | +* 1...mi |
331 | **/ |
332 | function formatDistance(dist, unit) { |
333 | - if (dist === null) |
334 | - return ''; |
335 | - |
336 | - var m2km = 0.001 |
337 | - var m2mi = 0.000621371192 |
338 | - var m2yd = 1.0936133 |
339 | - |
340 | - if ( unit === 1 ) // mi |
341 | - var distance = dist * m2yd < 1000 ? parseInt(dist * m2yd) + " yd" : parseInt(dist * m2mi) + "+ mi"; |
342 | - else |
343 | - var distance = dist < 1000 ? parseInt(dist) + " m" : parseInt(dist * m2km) + "+ km" ; |
344 | - |
345 | - if (distance === '0 m' || distance === '0 yd') |
346 | + if (dist === null) |
347 | + return ''; |
348 | + |
349 | + var m2km = 0.001 |
350 | + var m2mi = 0.000621371192 |
351 | + var m2yd = 1.0936133 |
352 | + |
353 | + if ( unit === 1 ) // mi |
354 | + var distance = dist * m2yd < 1000 ? parseInt(dist * m2yd) + " yd" : parseInt(dist * m2mi) + "+ mi"; |
355 | + else |
356 | + var distance = dist < 1000 ? parseInt(dist) + " m" : parseInt(dist * m2km) + "+ km" ; |
357 | + |
358 | + if (distance === '0 m' || distance === '0 yd') |
359 | return i18n.tr("Current Location"); |
360 | - else |
361 | - return distance; |
362 | + else |
363 | + return distance; |
364 | } |
365 | |
366 | /** |
367 | @@ -65,29 +65,29 @@ |
368 | * translators: string with all translators |
369 | **/ |
370 | function getTranslators(translators_string) { |
371 | - var all_translators = []; |
372 | - |
373 | - if (translators_string === '' || translators_string === 'translator-credits') { |
374 | - all_translators.push({ |
375 | - name: "Ubuntu Translators Community", |
376 | - link: "https://translations.launchpad.net/+groups/ubuntu-translators" |
377 | - }); |
378 | - return all_translators; |
379 | - } |
380 | - |
381 | - var translators = translators_string.split('\n'); |
382 | - translators.forEach(function(translator) { |
383 | - if (translator.indexOf("https://launchpad.net") > -1 && translator.indexOf("costales https://launchpad.net/~costales") < 0) { // First string will be the header and don't include myself |
384 | - var translator_name = translator.split(' https://launchpad.net/~')[0].trim(); |
385 | - var translator_link = 'https://launchpad.net/~' + translator.split('https://launchpad.net/~')[1]; |
386 | - all_translators.push({ |
387 | - name: translator_name, |
388 | - link: translator_link |
389 | - }); |
390 | - } |
391 | - }); |
392 | - |
393 | - return all_translators; |
394 | + var all_translators = []; |
395 | + |
396 | + if (translators_string === '' || translators_string === 'translator-credits') { |
397 | + all_translators.push({ |
398 | + name: "Ubuntu Translators Community", |
399 | + link: "https://translations.launchpad.net/+groups/ubuntu-translators" |
400 | + }); |
401 | + return all_translators; |
402 | + } |
403 | + |
404 | + var translators = translators_string.split('\n'); |
405 | + translators.forEach(function(translator) { |
406 | + if (translator.indexOf("https://launchpad.net") > -1 && translator.indexOf("costales https://launchpad.net/~costales") < 0) { // First string will be the header and don't include myself |
407 | + var translator_name = translator.split(' https://launchpad.net/~')[0].trim(); |
408 | + var translator_link = 'https://launchpad.net/~' + translator.split('https://launchpad.net/~')[1]; |
409 | + all_translators.push({ |
410 | + name: translator_name, |
411 | + link: translator_link |
412 | + }); |
413 | + } |
414 | + }); |
415 | + |
416 | + return all_translators; |
417 | } |
418 | |
419 | /** |
420 | @@ -95,13 +95,13 @@ |
421 | * url: POI's URL |
422 | **/ |
423 | function parse_poi_url(poi_website) { |
424 | - if (poi_website.trim() == '') // No website |
425 | - return ''; |
426 | - |
427 | - if (poi_website.substring(0, 8) === "https://" || poi_website.substring(0, 7) === "http://") |
428 | - return poi_website; |
429 | - else |
430 | - return "http://" + poi_website; |
431 | + if (poi_website.trim() == '') // No website |
432 | + return ''; |
433 | + |
434 | + if (poi_website.substring(0, 8) === "https://" || poi_website.substring(0, 7) === "http://") |
435 | + return poi_website; |
436 | + else |
437 | + return "http://" + poi_website; |
438 | } |
439 | |
440 | /** |
441 | @@ -109,10 +109,10 @@ |
442 | * url: POI's phone |
443 | **/ |
444 | function parse_poi_phone(poi_phone) { |
445 | - if (poi_phone.trim() == '') // No phone |
446 | - return ''; |
447 | - |
448 | - return poi_phone.replace(/ /g,''); // Removes all spaces |
449 | + if (poi_phone.trim() == '') // No phone |
450 | + return ''; |
451 | + |
452 | + return poi_phone.replace(/ /g,''); // Removes all spaces |
453 | } |
454 | |
455 | /** |
456 | @@ -120,45 +120,45 @@ |
457 | * url: URL calling uNav |
458 | **/ |
459 | function is_url_dispatcher(url) { |
460 | - if (url.toString().indexOf('http://map.unav.me') > -1) |
461 | - return {is_dispatcher: true, url_is: 'unav'}; |
462 | - if (url.toString().indexOf('geo:') > -1) |
463 | - return {is_dispatcher: true, url_is: 'geo'}; |
464 | - if (url.toString().indexOf('http://unav-go.github.io') > -1) |
465 | - return {is_dispatcher: true, url_is: 'unavold'}; |
466 | - if (url.toString().indexOf('http://www.openstreetmap.org') > -1) |
467 | - return {is_dispatcher: true, url_is: 'osm'}; |
468 | - if (url.toString().indexOf('http://www.opencyclemap.org') > -1) |
469 | - return {is_dispatcher: true, url_is: 'ocm'}; |
470 | - if (url.toString().indexOf('https://maps.google.com') > -1) |
471 | - return {is_dispatcher: true, url_is: 'googlemaps'}; |
472 | - |
473 | - return {is_dispatcher: false, url_is: 'none'}; |
474 | + if (url.toString().indexOf('http://map.unav.me') > -1 || url.toString().indexOf('https://map.unav.me') > -1) |
475 | + return {is_dispatcher: true, url_is: 'unav'}; |
476 | + if (url.toString().indexOf('geo:') > -1) |
477 | + return {is_dispatcher: true, url_is: 'geo'}; |
478 | + if (url.toString().indexOf('http://unav-go.github.io') > -1) |
479 | + return {is_dispatcher: true, url_is: 'unavold'}; |
480 | + if (url.toString().indexOf('http://www.openstreetmap.org') > -1 || url.toString().indexOf('https://www.openstreetmap.org') > -1) |
481 | + return {is_dispatcher: true, url_is: 'osm'}; |
482 | + if (url.toString().indexOf('http://www.opencyclemap.org') > -1 || url.toString().indexOf('https://www.opencyclemap.org') > -1) |
483 | + return {is_dispatcher: true, url_is: 'ocm'}; |
484 | + if (url.toString().indexOf('https://maps.google.com') > -1 || url.toString().indexOf('https://www.google.com/maps') > -1) |
485 | + return {is_dispatcher: true, url_is: 'googlemaps'}; |
486 | + |
487 | + return {is_dispatcher: false, url_is: 'none'}; |
488 | } |
489 | |
490 | /** |
491 | * Function validate_lat(url): Return coordinate or null |
492 | **/ |
493 | function validate_lat(lat) { |
494 | - try { |
495 | - if (!isNaN(lat) && lat.toString().indexOf('.') != -1 && lat >= -90 && lat <= 90) // It's a float |
496 | - return parseFloat(lat); |
497 | - } |
498 | - catch(e){ |
499 | - return null; |
500 | - } |
501 | + try { |
502 | + if (!isNaN(lat) && lat.toString().indexOf('.') != -1 && lat >= -90 && lat <= 90) // It's a float |
503 | + return parseFloat(lat); |
504 | + } |
505 | + catch(e){ |
506 | + return null; |
507 | + } |
508 | } |
509 | /** |
510 | * Function validate_lng(url): Return coordinate or null |
511 | **/ |
512 | function validate_lng(lng) { |
513 | - try { |
514 | - if (!isNaN(lng) && lng.toString().indexOf('.') != -1 && lng >= -180 && lng <= 180) // It's a float |
515 | - return parseFloat(lng); |
516 | - } |
517 | - catch(e){ |
518 | - return null; |
519 | - } |
520 | + try { |
521 | + if (!isNaN(lng) && lng.toString().indexOf('.') != -1 && lng >= -180 && lng <= 180) // It's a float |
522 | + return parseFloat(lng); |
523 | + } |
524 | + catch(e){ |
525 | + return null; |
526 | + } |
527 | } |
528 | |
529 | /** |
530 | @@ -166,10 +166,10 @@ |
531 | * url: URL calling uNav. ex: geo:37.786971,-122.399677 geo:51.5361,0.0084?z=16 geo:37.786971,-122.399677;u=35 geo:37.786971,-122.399677;crs=Moon-2011;u=35 |
532 | **/ |
533 | function split_geo_url(url) { |
534 | - var aux_url = url.replace('geo:', '').replace('?', ' ').replace(';', ' ').replace(',', ' '); |
535 | - |
536 | - var params = aux_url.split(' '); |
537 | - return {lat: validate_lat(params[0]), lng: validate_lng(params[1])}; |
538 | + var aux_url = url.replace('geo:', '').replace('?', ' ').replace(';', ' ').replace(',', ' '); |
539 | + |
540 | + var params = aux_url.split(' '); |
541 | + return {lat: validate_lat(params[0]), lng: validate_lng(params[1])}; |
542 | } |
543 | |
544 | /** |
545 | @@ -177,10 +177,10 @@ |
546 | * url: URL calling uNav. ex: http://unav.me/?map=51.4589,7.0072 |
547 | **/ |
548 | function split_unav_url(url) { |
549 | - var aux_url = url.replace('http://map.unav.me/?', '').replace('http://map.unav.me?', '').replace('%2C', ','); |
550 | - |
551 | - var params = aux_url.split(','); |
552 | - return {lat: validate_lat(params[0]), lng: validate_lng(params[1])}; |
553 | + var aux_url = url.replace('http://map.unav.me/?', '').replace('https://map.unav.me/?', '').replace('http://map.unav.me?', '').replace('https://map.unav.me?', '').replace('%2C', ','); |
554 | + |
555 | + var params = aux_url.split(','); |
556 | + return {lat: validate_lat(params[0]), lng: validate_lng(params[1])}; |
557 | } |
558 | |
559 | /** |
560 | @@ -188,10 +188,10 @@ |
561 | * url: URL calling uNav. ex: http://unav-go.github.io/?p=51.4589,7.0072 |
562 | **/ |
563 | function split_unavold_url(url) { |
564 | - var aux_url = url.replace('http://unav-go.github.io/?p=', '').replace('http://unav-go.github.io?p=', '').replace('%2C', ','); |
565 | - |
566 | - var params = aux_url.split(','); |
567 | - return {lat: validate_lat(params[0]), lng: validate_lng(params[1])}; |
568 | + var aux_url = url.replace('http://unav-go.github.io/?p=', '').replace('http://unav-go.github.io?p=', '').replace('%2C', ','); |
569 | + |
570 | + var params = aux_url.split(','); |
571 | + return {lat: validate_lat(params[0]), lng: validate_lng(params[1])}; |
572 | } |
573 | |
574 | /** |
575 | @@ -200,19 +200,19 @@ |
576 | * http://www.openstreetmap.org/?mlat=43.54217&mlon=-5.67633&zoom=12 |
577 | **/ |
578 | function split_osm_url(url) { |
579 | - var aux_url = url.replace('http://www.openstreetmap.org/#map=', ''); |
580 | - |
581 | - var params = aux_url.split('/'); |
582 | - |
583 | - if (params.length == 3) |
584 | - return {lat: validate_lat(params[1]), lng: validate_lng(params[2])}; |
585 | - |
586 | - var aux_url = url.replace('http://www.openstreetmap.org/?', ''); |
587 | - var params = aux_url.split('&'); |
588 | - if (params.length >= 2 && params[0].indexOf('mlat') != 1 && params[1].indexOf('mlon') != 1) |
589 | - return {lat: validate_lat(params[0].replace('mlat=', '')), lng: validate_lng(params[1].replace('mlon=', ''))}; |
590 | - |
591 | - return {lat: null, lng: null}; |
592 | + var aux_url = url.replace('http://www.openstreetmap.org/#map=', '').replace('https://www.openstreetmap.org/#map=', ''); |
593 | + |
594 | + var params = aux_url.split('/'); |
595 | + |
596 | + if (params.length == 3) |
597 | + return {lat: validate_lat(params[1]), lng: validate_lng(params[2])}; |
598 | + |
599 | + var aux_url = url.replace('http://www.openstreetmap.org/?', '').replace('https://www.openstreetmap.org/?', ''); |
600 | + var params = aux_url.split('&'); |
601 | + if (params.length >= 2 && params[0].indexOf('mlat') != 1 && params[1].indexOf('mlon') != 1) |
602 | + return {lat: validate_lat(params[0].replace('mlat=', '')), lng: validate_lng(params[1].replace('mlon=', ''))}; |
603 | + |
604 | + return {lat: null, lng: null}; |
605 | } |
606 | |
607 | /** |
608 | @@ -220,27 +220,32 @@ |
609 | * url: URL calling OpenCycleMap. ex: http://www.opencyclemap.org/?zoom=18&lat=43.5414&lon=-5.67165&layers=B0000 |
610 | **/ |
611 | function split_ocm_url(url) { |
612 | - var aux_url = url.replace('http://www.opencyclemap.org/?', ''); |
613 | - |
614 | - var params = aux_url.split('&'); |
615 | - if (params.length >= 3 && params[1].indexOf('lat') != 1 && params[2].indexOf('lon') != 1) |
616 | - return {lat: validate_lat(params[1].replace('lat=', '')), lng: validate_lng(params[2].replace('lon=', ''))}; |
617 | - |
618 | - return {lat: null, lng: null}; |
619 | + var aux_url = url.replace('http://www.opencyclemap.org/?', '').replace('https://www.opencyclemap.org/?', ''); |
620 | + |
621 | + var params = aux_url.split('&'); |
622 | + if (params.length >= 3 && params[1].indexOf('lat') != 1 && params[2].indexOf('lon') != 1) |
623 | + return {lat: validate_lat(params[1].replace('lat=', '')), lng: validate_lng(params[2].replace('lon=', ''))}; |
624 | + |
625 | + return {lat: null, lng: null}; |
626 | } |
627 | |
628 | /** |
629 | * Function split_googlemaps_url(url): Return coordenates |
630 | * url: URL calling Google Maps. ex: https://maps.google.com/?q=43.53291443249287,-5.664369592670359 |
631 | +* url: New URL format can be https://www.google.com/maps/place/[Terms of search]/@43.53291443249287,-5.664369592670359,17z/data=[more data] |
632 | **/ |
633 | function split_googlemaps_url(url) { |
634 | - var aux_url = url.replace('https://maps.google.com/?q=', '').replace('%2C', ','); |
635 | - |
636 | - var params = aux_url.split(','); |
637 | - if (params.length == 2) |
638 | - return {lat: validate_lat(params[0]), lng: validate_lng(params[1])}; |
639 | - |
640 | - return {lat: null, lng: null}; |
641 | + var aux_url = url.replace('https://maps.google.com/?q=', '').replace('%2C', ','); |
642 | + |
643 | + var params = aux_url.split(','); |
644 | + if (params.length == 2) |
645 | + return {lat: validate_lat(params[0]), lng: validate_lng(params[1])}; |
646 | + |
647 | + var params = aux_url.slice(aux_url.indexOf("@") +1).split(","); |
648 | + if (params.length > 2) |
649 | + return {lat: validate_lat(params[0]), lng: validate_lng(params[1])}; |
650 | + |
651 | + return {lat: null, lng: null}; |
652 | } |
653 | |
654 | /** |
655 | @@ -248,31 +253,31 @@ |
656 | * url: URL calling uNav |
657 | **/ |
658 | function get_url_coord(url) { |
659 | - var coord = {lat: null, lng: null}; |
660 | - var dispatcher = is_url_dispatcher(url); |
661 | - |
662 | - if (!dispatcher['is_dispatcher']) // Validate |
663 | - return coord; |
664 | - |
665 | - switch (dispatcher['url_is']) { |
666 | - case 'unav': |
667 | - coord = split_unav_url(url); |
668 | - break; |
669 | - case 'geo': |
670 | - coord = split_geo_url(url); |
671 | - break; |
672 | - case 'unavold': |
673 | - coord = split_unavold_url(url); |
674 | - break; |
675 | - case 'osm': |
676 | - coord = split_osm_url(url); |
677 | - break; |
678 | - case 'ocm': |
679 | - coord = split_ocm_url(url); |
680 | - break; |
681 | - case 'googlemaps': |
682 | - coord = split_googlemaps_url(url); |
683 | - break; |
684 | - } |
685 | - return coord; |
686 | + var coord = {lat: null, lng: null}; |
687 | + var dispatcher = is_url_dispatcher(url); |
688 | + |
689 | + if (!dispatcher['is_dispatcher']) // Validate |
690 | + return coord; |
691 | + |
692 | + switch (dispatcher['url_is']) { |
693 | + case 'unav': |
694 | + coord = split_unav_url(url); |
695 | + break; |
696 | + case 'geo': |
697 | + coord = split_geo_url(url); |
698 | + break; |
699 | + case 'unavold': |
700 | + coord = split_unavold_url(url); |
701 | + break; |
702 | + case 'osm': |
703 | + coord = split_osm_url(url); |
704 | + break; |
705 | + case 'ocm': |
706 | + coord = split_ocm_url(url); |
707 | + break; |
708 | + case 'googlemaps': |
709 | + coord = split_googlemaps_url(url); |
710 | + break; |
711 | + } |
712 | + return coord; |
713 | } |
Thanks a lot!