Changeset 13 for tools/GMap2QpegpsNV
- Timestamp:
- 07/22/07 12:31:41 (5 years ago)
- Files:
-
- tools/GMap2QpegpsNV/gmap2qpegps.js (modified) (24 diffs)
- tools/GMap2QpegpsNV/gmaptogpx.js (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
tools/GMap2QpegpsNV/gmap2qpegps.js
r12 r13 1 1 /* 2 GMapToQpeGPS - Nicolas GUILLAUME <ng@ngsoft-fr.com> 3 4 Adds qpe* tabs 5 6 Based on 7 GMapToGPX 8 Based in part on the "Improved MSN and Google GPS GPX Waypoint Extraction" 9 bookmarklet described at http://badsegue.org/archives/2005/04/21/ 10 2 GMapToGPX 5.4 3 Originally based in part on the "Improved MSN and Google GPS GPX Waypoint 4 Extraction" bookmarklet described at http://badsegue.org/archives/2005/04/21/ 5 11 6 Josh Larios <hades@elsewhere.org> 12 August 3, 2005 - July 21, 20067 August 3, 2005 - July 13, 2007 13 8 14 9 WARNING: Highly dependent on internal formats that aren't part of … … 16 11 control. 17 12 18 19 13 * 4.23 - Fix problem due to google internal change (in directive) 20 14 * 4.24 - Fix problem due to google internal change … … 26 20 * 4.31 - Support other languages again 27 21 * 4.32 - Fix problem due to google internal change 22 * 4.33 - Fix problem due to google internal change 28 23 29 24 */ 30 25 31 26 var error = 0; 32 var version = '4.3 2';27 var version = '4.33'; 33 28 var googledoc = ""; // will hold retrieved google info 34 29 var routes = new Array(); 30 var milestones = new Array(); 31 var yelp = new Array(); 35 32 var googlepage; // Will hold the page element that gets toggled. May change. 36 33 … … 47 44 } 48 45 49 /* return distance in m between 2 points */50 46 function calcDistanceLtLgRad(lt1, lg1, lt2, lg2) 51 47 { … … 107 103 } 108 104 } 109 105 110 106 if (req.readyState == 4) { 111 107 // only if "OK" … … 146 142 z.style.padding = ".3em 1.3em .3em .3em"; 147 143 z.style.zIndex = "1000"; 148 144 149 145 z.innerHTML = '<div style="position: absolute; border: 1px solid black; top: 0px; right: 0px;"><span style="padding: .3em; font-weight: bold;"><a style="text-decoration: none;" title="Close status box" href="#" onclick="javascript:hidestatusdiv();">X</a></span></div>'; 150 146 z.innerHTML += boxcontents; … … 188 184 189 185 190 function gmapto qpegpsnvdiv(dtype) {186 function gmaptogpxdiv(dtype) { 191 187 var mypoints = null; 192 188 193 189 var qtype = 0; 190 var subtype = 0; 191 194 192 var xmlformat = (dtype != "qpegpstrack" && dtype != "qpegpsroute"); 195 196 193 /* 197 194 Determine which type of data we're extracting -- a route, or points of … … 199 196 */ 200 197 201 if (googledoc.match(/ "id":"route0"/)) {198 if (googledoc.match(/id:'route0'/)) { 202 199 qtype = 2; 200 201 /* FIXME 202 errorbox('<p>2007.05.21 - GMapToGPX is currently unable to process driving directions, due to a change in the underlying Google Maps code. I\'m working on it.</p>'); 203 closebox(); 204 return(0); 205 END FIXME */ 206 203 207 // Doing this as a regexp was causing firefox to stall out. bah. 204 var encpointblob=googledoc.slice(googledoc.indexOf('polylines: ['));208 var encpointblob=googledoc.slice(googledoc.indexOf('polylines:[')); 205 209 encpointblob=encpointblob.slice(0, encpointblob.indexOf('],')); 206 var encmatch = encpointblob.match(/"id":"([^\"]+)","points":"([^\"]+)"/g);207 for (var i = 0; i < encmatch.length; i++) { 208 var id = encmatch[i].replace(/"id":"([^\"]+)".*/, "$1");209 var encpoints = encmatch[i].replace(/.*,"points":"([^\']+)"/, "$1");210 var encmatch = encpointblob.match(/id:'([^\']+)', *points:'([^\']+)'/g); 211 for (var i = 0; i < encmatch.length; i++) { 212 var id = encmatch[i].replace(/id:'([^\']+)'.*/, "$1"); 213 var encpoints = encmatch[i].replace(/.*, *points:'([^\']+)'/, "$1"); 210 214 // Stupid backslashes. *mutter* 211 215 routes[id] = decodeLine(encpoints.replace(/\\\\/g, '\\')); 212 216 } 213 214 // TO DO: Figure out a way to get the descriptions of milestones. 215 var descmatch; 216 if (descmatch = googledoc.match(/<tr class=\\042dirsegment\\042.*?<\/tr>/g)) { 217 for (var i = 0; i < descmatch.length; i++) { 218 var route = descmatch[i].replace(/.*showPolylineBlowup\(\\047(.*?)\\047, (.*?)\).*/, "$1"); 219 var index = descmatch[i].replace(/.*showPolylineBlowup\(\\047(.*?)\\047, (.*?)\).*/, "$2"); 220 var desc = deamp(descmatch[i].replace(/.*dirsegtext[^>]+>(.*?)<\/td>.*/, "$1")); 221 routes[route][index].desc = deamp(desc); 222 } 223 } 224 } else if (googledoc.match(/id: '(A|addr)'/)) { 217 218 // Get the milestone descriptions 219 var msaddrmatch; 220 if (msaddrmatch = googledoc.match(/<span id='sxaddr'>.*?<\/span>/g)) { 221 for (var i = 0; i < msaddrmatch.length; i++) { 222 milestones[parseInt(i)] = deamp(msaddrmatch[i].replace(/<span id='sxaddr'>(.*?)<\/span>/, "$1")); 223 } 224 } 225 226 // get the route segment descriptions 227 var routematch; 228 var segmatch; 229 if (routematch = googledoc.match(/<table class=.ddrsteps.*?<\/table>/g)) { 230 for (var r = 0; r < routematch.length; r++) { 231 var route = routematch[r].replace(/.*route='([0-9]+)'.*/, "$1"); 232 // <tr class='dirsegment' id='panel_0_2' polypoint='2'> 233 if (segmatch = routematch[r].match(/<tr class='dirsegment'.*?<\/tr>/g)) { 234 for (var s = 0; s < segmatch.length; s++) { 235 var index = segmatch[s].replace(/.*polypoint='([0-9]+)'.*/, "$1"); 236 var desc = deamp(segmatch[s].replace(/.*dirsegtext[^>]+>(.*?)<\/td>.*/, "$1")); 237 routes["route" + route][index].desc = deamp(desc); 238 } 239 } 240 } 241 } 242 } else if (googledoc.match(/id:'(A|addr)'/)) { 225 243 qtype = 1; 226 244 routes['poi'] = new Array(); 227 228 var markers=googledoc.slice(googledoc.indexOf('markers: ['));229 markers=markers.slice(0, markers.indexOf('polylines: ['));230 231 var pois = markers.match(/id: '([A-J]|addr)'.*?\}\}/g);245 246 var markers=googledoc.slice(googledoc.indexOf('markers:[')); 247 /* markers=markers.slice(0, markers.indexOf('polylines: [')); */ 248 249 var pois = markers.match(/id:'([A-Z]|addr|loc\d+)'.*?\}/g); 232 250 for (var i = 0; i < pois.length; i++) { 233 var lat = pois[i].replace(/.*lat: (.*?),.*/, "$1");234 var lon = pois[i].replace(/.*lng: (.*?),.*/, "$1");235 var desc = pois[i].replace(/.*laddr: '(.*?)',.*/, "$1");236 desc = desc.replace(/ @.*/, "");251 var lat = pois[i].replace(/.*lat:(.*?),.*/, "$1"); 252 var lon = pois[i].replace(/.*lng:(.*?),.*/, "$1"); 253 var desc = pois[i].replace(/.*laddr:'(.*?)',.*/, "$1"); 254 desc = desc.replace(/ @.*/, ""); 237 255 desc = desc.replace(/(.*) \((.*)\)/, "$2 ($1)"); 238 256 routes['poi'].push({"lat": lat, "lon": lon, "desc": deamp(desc)}); … … 244 262 qtype = 3; 245 263 } 246 264 247 265 /* HeyWhatsThat.com list of peaks visible from given location */ 248 266 if (qtype == 0 && location.href.match(/heywhatsthat.com/i) && peaks && peaks.length) { 267 qtype = 4; 268 subtype = 1; 269 } 270 271 /* Yelp.com search */ 272 if (qtype == 0 && location.href.match(/yelp.com/i) && document.body.innerHTML.match('result_plot_obj.map.addOverlay')) { 249 273 qtype = 4; 250 } 251 274 subtype = 2; 275 var yelpmatch = document.body.innerHTML.match(/result_plot_obj.map.addOverlay.*?\)\)/g); 276 for (var i = 0; i < yelpmatch.length; i++) { 277 yelp[i] = new Array(); 278 yelp[i].name = deamp(yelpmatch[i].replace(/.*<h3>(.*?)<\/h3>.*/, "$1")); 279 yelp[i].addr = deamp(yelpmatch[i].replace(/.*<address[^>]*>(.*?)<\/address>.*/, "$1")); 280 yelp[i].lon = yelpmatch[i].replace(/.*Yelp.TSRUrl.*?,.*?,.*?, (.*?),.*/, "$1"); 281 yelp[i].lat = yelpmatch[i].replace(/.*Yelp.TSRUrl.*?,.*?,.*?,.*?, (.*?),.*/, "$1"); 282 } 283 } 284 /* Yelp.com single location */ 285 // var json_biz = {"city":"Seattle","zip":"98102","review_count":6,"name":"Tacos Guaymas - CLOSED","neighborhoods":["Capitol Hill"],"photos":[],"address1":"213 Broadway East","avg_rating":4.000000,"longitude":-122.320999,"address2":null,"phone":"(206) 860-7345","state":"WA","latitude":47.620201,"id":"PidHplYWockrwJpijqUwsg","categories":{}}; 286 if (qtype == 0 && location.href.match(/yelp.com/i) && json_biz) { 287 qtype = 4; 288 subtype = 2; 289 yelp[0] = new Array(); 290 yelp[0].name = json_biz.name; 291 yelp[0].lat = json_biz.latitude; 292 yelp[0].lon = json_biz.longitude; 293 yelp[0].addr = json_biz.address1 + ", "; 294 if (json_biz.address2 != null) { 295 yelp[0].addr += json_biz.address2 + ", "; 296 } 297 yelp[0].addr += json_biz.city + ", " + json_biz.state + " " + json_biz.zip; 298 } 252 299 if (qtype==0) { 253 errorbox('<p>There doesn\'t seem to be any extractable data on this page.</p><p>If there is, but it\'s not detected, please visit the <a href="http://www.elsewhere.org/GMapToGPX/">project homepage</a> and leave a bug report, including a link to the page you\'re on right now.</p> ');300 errorbox('<p>There doesn\'t seem to be any extractable data on this page.</p><p>If there is, but it\'s not detected, please visit the <a href="http://www.elsewhere.org/GMapToGPX/">project homepage</a> and leave a bug report, including a link to the page you\'re on right now.</p><p><strong>Note:</strong> Google Maps mashups (that is, a page with a Google Map on it, but not at google.com) do not automatically work with this utility. If you would like to see GMapToGPX work with your Google Maps mashup site, please leave a comment on the project page.</p>'); 254 301 closebox(); 255 302 return(0); … … 301 348 } 302 349 350 303 351 t+="<div style='background-color:#D8D9F8;'>"; 304 352 t+='<ul class="menubar">'; … … 312 360 t+='<li class="menubar"><a href="javascript:reload(4)" title="All points as a tracklog (for qpeGPS >= v0.9.3.2 or qpeGPS NV >= v1.1 or GpsDrive)">qpeGPS/GpsDrive Track</a></li>'; 313 361 t+='<li class="menubar"><a href="javascript:reload(5)" title="All points as a route (for qpeGPS NV >= v1.1)">qpeGPS NV Route</a></li>'; 314 315 316 362 317 363 } 318 364 t+='<li class="menubar"><a href="javascript:loadabout()">About</a></li>'; 319 365 t+='<li class="menubar"><a href="javascript:closebox()">CLOSE [X]</a></li></ul></div>'; 320 t+='<textarea rows="28" cols="80">'; 321 322 323 324 if(xmlformat) 366 t+='<textarea rows="20" cols="80">'; 367 368 if(xmlformat) 325 369 t+= '<?xml version="1.0" encoding="UTF-8"?>\n' + 326 370 '<gpx version="1.1"\n' + … … 328 372 ' xmlns="http://www.topografix.com/GPX/1/1"\n' + 329 373 ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n' + 330 ' xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">\n'; 331 374 ' xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">\n'; 332 375 333 376 if ((qtype==2) && (dtype=="allpoints")) { … … 339 382 t+= ' <trkseg>\n'; 340 383 for(i=0;i<route.length;i++) { 341 if (i == route.length - 1) 384 if (i == route.length - 1) 342 385 route[i].desc = 'Arrive at destination'; 343 386 … … 349 392 t += '<desc>' + deamp(route[i].desc) + '</desc>'; 350 393 351 t+= '</trkpt>\n'; 352 394 t+= '</trkpt>\n'; 353 395 } 354 396 t+= ' </trkseg>\n'; … … 422 464 } 423 465 } else if (qtype == 4) { 424 /* HeyWhatsThat.com list of peaks */425 for (var i = 0; i < peaks.length; i++) {426 var p = peaks[i];427 t+= ' <wpt lat="' + p.lat + '" lon="' + p.lon + '">\n' +428 ' <ele>' + p.elev + '</ele>\n' +429 ' <name>' + p.name + '</name>\n' +430 ' <cmt>' + p.name + '</cmt>\n' +431 ' </wpt>\n';432 }466 /* HeyWhatsThat.com list of peaks */ 467 for (var i = 0; i < peaks.length; i++) { 468 var p = peaks[i]; 469 t+= ' <wpt lat="' + p.lat + '" lon="' + p.lon + '">\n' + 470 ' <ele>' + p.elev + '</ele>\n' + 471 ' <name>' + p.name + '</name>\n' + 472 ' <cmt>' + p.name + '</cmt>\n' + 473 ' </wpt>\n'; 474 } 433 475 } else if (qtype == 2) { 434 476 /* If we're on a page with driving directions, spit out a route. */ 435 477 var title = "Driving directions"; 436 if(xmlformat)478 if(xmlformat) 437 479 { 438 if (dtype == "track") { 439 t+= ' <trk>\n'; 440 } 441 442 var turn = 1; 443 var milestone = 1; 444 445 for (var key in routes) { 446 var route = routes[key]; 447 if (dtype == "track") { 448 t+= ' <trkseg>\n'; 449 } else if (dtype == "route") { 450 t+= ' <rte>\n'; 451 } 452 453 if ((dtype=="track") || (dtype=="route")) { 454 t+= ' <name>' + key + '</name>\n' + 455 ' <cmt>via Google Maps</cmt>\n'; 456 } 457 458 for(i=0;i<route.length;i++){ 459 if ((i != route.length - 1) && (route[i].desc == undefined)) { 460 continue; 461 } 462 // Only print turn points and milestones (last point is an 463 // undescribed milestone; first point should always have a 464 // description). 465 switch(dtype) { 466 case 'track': 467 t+= ' <trkpt '; 468 break; 469 case 'route': 470 t+= ' <rtept '; 471 break; 472 case 'points': 473 t+= ' <wpt '; 474 break; 475 } 476 t+= 'lat="' + route[i].lat + '" ' + 477 'lon="' + route[i].lon + '">\n' + 478 ' <name>'; 479 if (i == route.length - 1) { 480 route[i].desc = 'Arrive at destination'; 481 t += 'GMLS-' + ((milestone < 100) ? '0' : '') + 482 ((milestone < 10) ? '0' : '') + milestone; 483 milestone += 1; 484 turn -= 1; 485 } else { 486 t += 'GRTP-' + ((turn < 100) ? '0' : '') + 487 ((turn < 10) ? '0' : '') + turn; 488 } 489 t += '</name>\n' + 490 ' <cmt>' + route[i].desc + '</cmt>\n'; 491 492 switch(dtype) { 493 case 'track': 494 t+= ' </trkpt>\n'; 495 break; 496 case 'route': 497 t+= ' </rtept>\n'; 498 break; 499 case 'points': 500 t+= ' </wpt>\n'; 501 break; 502 } 503 turn++; 504 } 505 if (dtype == "track") { 506 t+= ' </trkseg>\n'; 480 481 if (dtype == "track") { 482 t+= ' <trk>\n'; 483 } 484 485 var turn = 1; 486 var milestone = 1; 487 488 for (var key in routes) { 489 var route = routes[key]; 490 if (dtype == "track") { 491 t+= ' <trkseg>\n'; 492 } else if (dtype == "route") { 493 t+= ' <rte>\n'; 494 } 495 496 if ((dtype=="track") || (dtype=="route")) { 497 t+= ' <name>' + key + '</name>\n' + 498 ' <cmt>via Google Maps</cmt>\n'; 499 } 500 501 for(i=0;i<route.length;i++){ 502 if ((i != route.length - 1) && (route[i].desc == undefined)) { 503 continue; 504 } 505 // Only print turn points and milestones (last point is an 506 // undescribed milestone; first point should always have a 507 // description). 508 switch(dtype) { 509 case 'track': 510 t+= ' <trkpt '; 511 break; 512 case 'route': 513 t+= ' <rtept '; 514 break; 515 case 'points': 516 t+= ' <wpt '; 517 break; 518 } 519 t+= 'lat="' + route[i].lat + '" ' + 520 'lon="' + route[i].lon + '">\n' + 521 ' <name>'; 522 if (i == route.length - 1) { 523 route[i].desc = 'Arrive at destination'; 524 525 t += 'GMLS-' + ((milestone < 100) ? '0' : '') + 526 ((milestone < 10) ? '0' : '') + milestone; 527 milestone += 1; 528 turn -= 1; 529 } else { 530 t += 'GRTP-' + ((turn < 100) ? '0' : '') + 531 ((turn < 10) ? '0' : '') + turn; 532 } 533 t += '</name>\n' + 534 ' <cmt>' + route[i].desc + '</cmt>\n'; 535 536 switch(dtype) { 537 case 'track': 538 t+= ' </trkpt>\n'; 539 break; 540 case 'route': 541 t+= ' </rtept>\n'; 542 break; 543 case 'points': 544 t+= ' </wpt>\n'; 545 break; 546 } 547 turn++; 548 } 549 if (dtype == "track") { 550 t+= ' </trkseg>\n'; 507 551 } else if (dtype == "route") { 508 552 t+= ' </rte>\n'; 509 553 } 510 } 511 512 if (dtype == "track") { 513 t+= ' </trk>\n'; 514 } 515 516 } 554 } 555 556 if (dtype == "track") { 557 t+= ' </trk>\n'; 558 } 559 560 561 } 517 562 else if (dtype=="qpegpstrack") /* qpegpstrack */ 518 563 { … … 578 623 } 579 624 580 581 } 582 625 } 583 626 } else if (qtype == 1) { 584 627 /* This is a page with points of interest - spit out waypoints. */ … … 588 631 ' <name>' + point.desc + '</name>\n' + 589 632 ' <cmt>' + point.desc.replace(/(.*) \((.*)\)/, "$2 ($1)") + '</cmt>\n' + 633 ' <desc>' + point.desc.replace(/(.*) \((.*)\)/, "$2 ($1)") + '</desc>\n' + 590 634 ' </wpt>\n'; 591 635 } … … 594 638 error = 1; 595 639 } 596 640 597 641 if(xmlformat) 598 t+='</gpx>\n';642 t+='</gpx>\n'; 599 643 t+='</textarea>'; 600 644 t+="<div style='background-color:#D8D9F8;'>"; … … 635 679 636 680 637 function loadabout() { alert('GMapToQpeGPS ' + version + ' by ng <ng@ngsoft-fr.com>\nBased on GMapToGPX Extractor 4.10\nA project of Communications From Elsewhere\nBased partially on code from http://badsegue.org\nFor details, visit http://www.elsewhere.org/GMapToGPX/'); } 681 682 function loadabout() { 683 var about = '<span style="font-size: x-small;"><p>GMapToQpeGPS ' + version + '<br />'; 684 about += 'by ng <ng@ngsoft-fr.com> and Paul Rascagneres <paul.rascagneres@free.fr><BR>Based on GMapToGPX Extractor 4.10<br>A project of Communications From Elsewhere<br>Based partially on code from http://badsegue.org<br>For details, visit http://www.elsewhere.org/GMapToGPX/'; 685 showstatusdiv(about); 686 } 638 687 639 688 function errorbox(a) { 640 err = "GMapToQpeGPS v" + version + " (ERROR)\n" + a;641 alert(err);689 var err = '<a href="http://www.elsewhere.org/GMapToGPX/">GMapToGPX</a> v' + version + " (ERROR)<br />" + a; 690 showstatusdiv(err); 642 691 } 643 692 … … 648 697 } 649 698 650 651 699 function reload(t) { 652 700 closebox(); 653 701 if (t==0) { 654 gmapto qpegpsnvdiv("route");702 gmaptogpxdiv("route"); 655 703 } else if (t=="1") { 656 gmapto qpegpsnvdiv("track");704 gmaptogpxdiv("track"); 657 705 } else if (t=="2") { 658 gmapto qpegpsnvdiv("points");706 gmaptogpxdiv("points"); 659 707 } else if (t=="3") { 660 gmapto qpegpsnvdiv("allpoints");708 gmaptogpxdiv("allpoints"); 661 709 } else if (t=="4") { 662 gmaptoqpegpsnvdiv("qpegpstrack");710 gmaptogpxdiv("qpegpstrack"); 663 711 } else if (t=="5") { 664 gmaptoqpegpsnvdiv("qpegpsroute");712 gmaptogpxdiv("qpegpsroute"); 665 713 } 666 714 } … … 669 717 670 718 function deamp(a) { 719 a = a.replace(/<br *\/>(.+)/g, ", $1"); 720 a = a.replace(/<br *\/>/g, ''); 671 721 a = a.replace(/'/g, '\''); 672 722 a = a.replace(/\\047/g, '\''); … … 680 730 a = a.replace(/\\x26/g, '&'); 681 731 a = a.replace(/&/g, '&'); 732 a = a.replace(/\\n/g, ''); 733 a = a.replace(/\\t/g, ''); 682 734 return a; 683 735 } … … 687 739 if (document.location.hostname.indexOf('google') >= 0) { 688 740 for (var i = 0; i < document.links.length; i++) { 689 // bar_icon_link.gif is the "link to this page" icon. If they change 690 // its name, I need to fix that here. 691 if (document.links.item(i).innerHTML && (document.links.item(i).innerHTML.indexOf('bar_icon_link.gif') >= 0)) 692 googledoc = loadXMLDoc(document.links.item(i).href); 741 if (document.links.item(i).innerHTML && (document.links.item(i).style.display != 'none') && (document.links.item(i).innerHTML.indexOf('view_as_kml.png') >= 0)) { 742 var kmlurl = document.links.item(i).href; 743 kmlurl = kmlurl.replace(/output=nl/, 'output=kml'); 744 errorbox('This is a "My Maps" page, which means that the original KML used to create it is available. Please <a href="' + kmlurl + '">download the KML file</a> (using this link, not the one provided by Google) and convert it using <a href="http://www.gpsvisualizer.com/convert" target="_new">GPSVisualizer</a>.'); 745 error = 1; 746 break; 747 } 748 749 // bar_icon_link.gif is the "link to this page" icon. If they change 750 // its name, I need to fix that here. 751 if (document.links.item(i).innerHTML && (document.links.item(i).innerHTML.indexOf('bar_icon_link.gif') >= 0)) { 752 var googleurl = document.links.item(i).href; 753 googleurl = googleurl.replace(/&view=text/, ''); 754 googledoc = loadXMLDoc(googleurl); 755 googledoc = googledoc.replace(/\\u003e/g, '>'); 756 googledoc = googledoc.replace(/\\u003c/g, '<'); 757 googledoc = googledoc.replace(/\\u0026/g, '&'); 758 googledoc = googledoc.replace(/\\042/g, '"'); 759 googledoc = googledoc.replace(/"*polylines"*:\s*/g, 'polylines:'); 760 googledoc = googledoc.replace(/"*markers"*:\s*/g, 'markers:'); 761 googledoc = googledoc.replace(/"*id"*:\s*/g, 'id:'); 762 googledoc = googledoc.replace(/"*lat"*:\s*/g, 'lat:'); 763 googledoc = googledoc.replace(/"*lng"*:\s*/g, 'lng:'); 764 googledoc = googledoc.replace(/"*laddr"*:\s*/g, 'laddr:'); 765 googledoc = googledoc.replace(/"*points"*:\s*/g, 'points:'); 766 googledoc = googledoc.replace(/\\"/g, '"'); 767 googledoc = googledoc.replace(/\"/g, '\''); 768 continue; 769 } 693 770 } 694 771 } … … 704 781 } 705 782 783 if (error != 1) { 706 784 /* Default action. If it's not a route, the argument doesn't matter. */ 707 gmaptoqpegpsnvdiv("route");708 709 /* Clumsy, but hey. */ 710 if (error == 1) { closebox(); } 785 gmaptogpxdiv("route"); 786 } else { 787 closebox(); 788 } tools/GMap2QpegpsNV/gmaptogpx.js
r11 r13 1 1 /* 2 GMapToGPX 2 GMapToGPX 5.4 3 3 Originally based in part on the "Improved MSN and Google GPS GPX Waypoint 4 4 Extraction" bookmarklet described at http://badsegue.org/archives/2005/04/21/ 5 5 6 6 Josh Larios <hades@elsewhere.org> 7 August 3, 2005 - May 1, 20077 August 3, 2005 - July 13, 2007 8 8 9 9 WARNING: Highly dependent on internal formats that aren't part of … … 13 13 Gmap-pedometer elevation code courtesy of Mathew O'Brien. 14 14 15 3/5/2007 HeyWhatsThat.com code addedmk -at- heywhatsthat.com15 3/5/2007 - HeyWhatsThat.com code by mk -at- heywhatsthat.com 16 16 17 17 TO DO: Separate out gpx writing and point/track extraction, so I can load … … 21 21 22 22 var error = 0; 23 var version = '5. 1c';23 var version = '5.4'; 24 24 var googledoc = ""; // will hold retrieved google info 25 25 var routes = new Array(); 26 var milestones = new Array(); 27 var yelp = new Array(); 26 28 var googlepage; // Will hold the page element that gets toggled. May change. 27 29 … … 63 65 } 64 66 } 65 67 66 68 if (req.readyState == 4) { 67 69 // only if "OK" … … 102 104 z.style.padding = ".3em 1.3em .3em .3em"; 103 105 z.style.zIndex = "1000"; 104 106 105 107 z.innerHTML = '<div style="position: absolute; border: 1px solid black; top: 0px; right: 0px;"><span style="padding: .3em; font-weight: bold;"><a style="text-decoration: none;" title="Close status box" href="#" onclick="javascript:hidestatusdiv();">X</a></span></div>'; 106 108 z.innerHTML += boxcontents; … … 148 150 149 151 var qtype = 0; 152 var subtype = 0; 150 153 151 154 /* … … 154 157 */ 155 158 156 if (googledoc.match(/ "id":"route0"/)) {159 if (googledoc.match(/id:'route0'/)) { 157 160 qtype = 2; 161 162 /* FIXME 163 errorbox('<p>2007.05.21 - GMapToGPX is currently unable to process driving directions, due to a change in the underlying Google Maps code. I\'m working on it.</p>'); 164 closebox(); 165 return(0); 166 END FIXME */ 167 158 168 // Doing this as a regexp was causing firefox to stall out. bah. 159 var encpointblob=googledoc.slice(googledoc.indexOf('polylines: ['));169 var encpointblob=googledoc.slice(googledoc.indexOf('polylines:[')); 160 170 encpointblob=encpointblob.slice(0, encpointblob.indexOf('],')); 161 var encmatch = encpointblob.match(/ "id":"([^\"]+)","points":"([^\"]+)"/g);171 var encmatch = encpointblob.match(/id:'([^\']+)', *points:'([^\']+)'/g); 162 172 for (var i = 0; i < encmatch.length; i++) { 163 var id = encmatch[i].replace(/ "id":"([^\"]+)".*/, "$1");164 var encpoints = encmatch[i].replace(/.*, "points":"([^\']+)"/, "$1");173 var id = encmatch[i].replace(/id:'([^\']+)'.*/, "$1"); 174 var encpoints = encmatch[i].replace(/.*, *points:'([^\']+)'/, "$1"); 165 175 // Stupid backslashes. *mutter* 166 176 routes[id] = decodeLine(encpoints.replace(/\\\\/g, '\\')); 167 177 } 168 169 // TO DO: Figure out a way to get the descriptions of milestones. 170 var descmatch; 171 if (descmatch = googledoc.match(/<tr class=\\042dirsegment\\042.*?<\/tr>/g)) { 172 for (var i = 0; i < descmatch.length; i++) { 173 var route = descmatch[i].replace(/.*showPolylineBlowup\(\\047(.*?)\\047, (.*?)\).*/, "$1"); 174 var index = descmatch[i].replace(/.*showPolylineBlowup\(\\047(.*?)\\047, (.*?)\).*/, "$2"); 175 var desc = deamp(descmatch[i].replace(/.*dirsegtext[^>]+>(.*?)<\/td>.*/, "$1")); 176 routes[route][index].desc = deamp(desc); 177 } 178 } 179 } else if (googledoc.match(/id: '(A|addr)'/)) { 178 179 // Get the milestone descriptions 180 var msaddrmatch; 181 if (msaddrmatch = googledoc.match(/<span id='sxaddr'>.*?<\/span>/g)) { 182 for (var i = 0; i < msaddrmatch.length; i++) { 183 milestones[parseInt(i)] = deamp(msaddrmatch[i].replace(/<span id='sxaddr'>(.*?)<\/span>/, "$1")); 184 } 185 } 186 187 // get the route segment descriptions 188 var routematch; 189 var segmatch; 190 if (routematch = googledoc.match(/<table class=.ddrsteps.*?<\/table>/g)) { 191 for (var r = 0; r < routematch.length; r++) { 192 var route = routematch[r].replace(/.*route='([0-9]+)'.*/, "$1"); 193 // <tr class='dirsegment' id='panel_0_2' polypoint='2'> 194 if (segmatch = routematch[r].match(/<tr class='dirsegment'.*?<\/tr>/g)) { 195 for (var s = 0; s < segmatch.length; s++) { 196 var index = segmatch[s].replace(/.*polypoint='([0-9]+)'.*/, "$1"); 197 var desc = deamp(segmatch[s].replace(/.*dirsegtext[^>]+>(.*?)<\/td>.*/, "$1")); 198 routes["route" + route][index].desc = deamp(desc); 199 } 200 } 201 } 202 } 203 } else if (googledoc.match(/id:'(A|addr)'/)) { 180 204 qtype = 1; 181 205 routes['poi'] = new Array(); 182 183 var markers=googledoc.slice(googledoc.indexOf('markers: ['));184 markers=markers.slice(0, markers.indexOf('polylines: ['));185 186 var pois = markers.match(/id: '([A-J]|addr)'.*?\}\}/g);206 207 var markers=googledoc.slice(googledoc.indexOf('markers:[')); 208 /* markers=markers.slice(0, markers.indexOf('polylines: [')); */ 209 210 var pois = markers.match(/id:'([A-Z]|addr|loc\d+)'.*?\}/g); 187 211 for (var i = 0; i < pois.length; i++) { 188 var lat = pois[i].replace(/.*lat: (.*?),.*/, "$1");189 var lon = pois[i].replace(/.*lng: (.*?),.*/, "$1");190 var desc = pois[i].replace(/.*laddr: '(.*?)',.*/, "$1");191 desc = desc.replace(/ @.*/, "");212 var lat = pois[i].replace(/.*lat:(.*?),.*/, "$1"); 213 var lon = pois[i].replace(/.*lng:(.*?),.*/, "$1"); 214 var desc = pois[i].replace(/.*laddr:'(.*?)',.*/, "$1"); 215 desc = desc.replace(/ @.*/, ""); 192 216 desc = desc.replace(/(.*) \((.*)\)/, "$2 ($1)"); 193 217 routes['poi'].push({"lat": lat, "lon": lon, "desc": deamp(desc)}); … … 199 223 qtype = 3; 200 224 } 201 225 202 226 /* HeyWhatsThat.com list of peaks visible from given location */ 203 227 if (qtype == 0 && location.href.match(/heywhatsthat.com/i) && peaks && peaks.length) { 228 qtype = 4; 229 subtype = 1; 230 } 231 232 /* Yelp.com search */ 233 if (qtype == 0 && location.href.match(/yelp.com/i) && document.body.innerHTML.match('result_plot_obj.map.addOverlay')) { 204 234 qtype = 4; 205 } 206 235 subtype = 2; 236 var yelpmatch = document.body.innerHTML.match(/result_plot_obj.map.addOverlay.*?\)\)/g); 237 for (var i = 0; i < yelpmatch.length; i++) { 238 yelp[i] = new Array(); 239 yelp[i].name = deamp(yelpmatch[i].replace(/.*<h3>(.*?)<\/h3>.*/, "$1")); 240 yelp[i].addr = deamp(yelpmatch[i].replace(/.*<address[^>]*>(.*?)<\/address>.*/, "$1")); 241 yelp[i].lon = yelpmatch[i].replace(/.*Yelp.TSRUrl.*?,.*?,.*?, (.*?),.*/, "$1"); 242 yelp[i].lat = yelpmatch[i].replace(/.*Yelp.TSRUrl.*?,.*?,.*?,.*?, (.*?),.*/, "$1"); 243 } 244 } 245 /* Yelp.com single location */ 246 // var json_biz = {"city":"Seattle","zip":"98102","review_count":6,"name":"Tacos Guaymas - CLOSED","neighborhoods":["Capitol Hill"],"photos":[],"address1":"213 Broadway East","avg_rating":4.000000,"longitude":-122.320999,"address2":null,"phone":"(206) 860-7345","state":"WA","latitude":47.620201,"id":"PidHplYWockrwJpijqUwsg","categories":{}}; 247 if (qtype == 0 && location.href.match(/yelp.com/i) && json_biz) { 248 qtype = 4; 249 subtype = 2; 250 yelp[0] = new Array(); 251 yelp[0].name = json_biz.name; 252 yelp[0].lat = json_biz.latitude; 253 yelp[0].lon = json_biz.longitude; 254 yelp[0].addr = json_biz.address1 + ", "; 255 if (json_biz.address2 != null) { 256 yelp[0].addr += json_biz.address2 + ", "; 257 } 258 yelp[0].addr += json_biz.city + ", " + json_biz.state + " " + json_biz.zip; 259 } 207 260 if (qtype==0) { 208 261 errorbox('<p>There doesn\'t seem to be any extractable data on this page.</p><p>If there is, but it\'s not detected, please visit the <a href="http://www.elsewhere.org/GMapToGPX/">project homepage</a> and leave a bug report, including a link to the page you\'re on right now.</p><p><strong>Note:</strong> Google Maps mashups (that is, a page with a Google Map on it, but not at google.com) do not automatically work with this utility. If you would like to see GMapToGPX work with your Google Maps mashup site, please leave a comment on the project page.</p>'); … … 296 349 for(i=0;i<route.length;i++) { 297 350 if (i == route.length - 1) { 298 route[i].desc = 'Arrive at destination'; 351 route[i].desc = milestones[parseInt(key.replace(/route/,''))]; 352 } else if ((route[i].lat == route[i+1].lat) && (route[i].lon == route[i+1].lon)) { 353 continue; 299 354 } 355 300 356 t+= ' <trkpt '; 301 357 t+= 'lat="' + route[i].lat + '" ' + … … 375 431 t+= ' </rte>\n'; 376 432 } 377 } else if (qtype == 4) { 378 /* HeyWhatsThat.com list of peaks */ 379 for (var i = 0; i < peaks.length; i++) { 380 var p = peaks[i]; 381 t+= ' <wpt lat="' + p.lat + '" lon="' + p.lon + '">\n' + 382 ' <ele>' + p.elev + '</ele>\n' + 383 ' <name>' + p.name + '</name>\n' + 384 ' <cmt>' + p.name + '</cmt>\n' + 385 ' </wpt>\n'; 386 } 433 } else if (qtype == 4 && subtype == 1) { 434 /* HeyWhatsThat.com list of peaks */ 435 for (var i = 0; i < peaks.length; i++) { 436 var p = peaks[i]; 437 t+= ' <wpt lat="' + p.lat + '" lon="' + p.lon + '">\n' + 438 ' <ele>' + p.elev + '</ele>\n' + 439 ' <name>' + p.name + '</name>\n' + 440 ' <cmt>' + p.name + '</cmt>\n' + 441 ' </wpt>\n'; 442 } 443 } else if (qtype == 4 && subtype == 2) { 444 for (var i = 0; i < yelp.length; i++) { 445 var p = yelp[i]; 446 t+= ' <wpt lat="' + p.lat + '" lon="' + p.lon + '">\n' + 447 ' <name>' + p.name + '</name>\n' + 448 ' <cmt>' + p.addr + '</cmt>\n' + 449 ' </wpt>\n'; 450 } 387 451 } else if (qtype == 2) { 388 452 /* If we're on a page with driving directions, spit out a route. */ … … 398 462 for (var key in routes) { 399 463 var route = routes[key]; 464 var routeno = key.replace(/route/, ''); 465 routeno = parseInt(routeno); 400 466 if (dtype == "track") { 401 467 t+= ' <trkseg>\n'; … … 405 471 406 472 if ((dtype=="track") || (dtype=="route")) { 407 t+= ' <name>' + key + '</name>\n' + 408 ' <cmt>via Google Maps</cmt>\n'; 473 t+= ' <name>' + key + '</name>\n'; 474 t+= ' <cmt>' + milestones[routeno] + " to " + milestones[routeno + 1] + '</cmt>\n'; 475 t+= ' <desc>' + milestones[routeno] + " to " + milestones[routeno + 1] + '</desc>\n'; 409 476 } 410 477 … … 431 498 ' <name>'; 432 499 if (i == route.length - 1) { 433 route[i].desc = 'Arrive at destination'; 500 route[i].desc = milestones[routeno+1]; 501 434 502 t += 'GMLS-' + ((milestone < 100) ? '0' : '') + 435 503 ((milestone < 10) ? '0' : '') + milestone; … … 441 509 } 442 510 t += '</name>\n' + 443 ' <cmt>' + route[i].desc + '</cmt>\n'; 511 ' <cmt>' + route[i].desc + '</cmt>\n' + 512 ' <desc>' + route[i].desc + '</desc>\n'; 444 513 445 514 switch(dtype) { … … 475 544 ' <name>' + point.desc + '</name>\n' + 476 545 ' <cmt>' + point.desc.replace(/(.*) \((.*)\)/, "$2 ($1)") + '</cmt>\n' + 546 ' <desc>' + point.desc.replace(/(.*) \((.*)\)/, "$2 ($1)") + '</desc>\n' + 477 547 ' </wpt>\n'; 478 548 } … … 519 589 } 520 590 } 521 522 591 523 592 … … 563 632 564 633 function deamp(a) { 634 a = a.replace(/<br *\/>(.+)/g, ", $1"); 635 a = a.replace(/<br *\/>/g, ''); 565 636 a = a.replace(/'/g, '\''); 566 637 a = a.replace(/\\047/g, '\''); … … 574 645 a = a.replace(/\\x26/g, '&'); 575 646 a = a.replace(/&/g, '&'); 647 a = a.replace(/\\n/g, ''); 648 a = a.replace(/\\t/g, ''); 576 649 return a; 577 650 } … … 581 654 if (document.location.hostname.indexOf('google') >= 0) { 582 655 for (var i = 0; i < document.links.length; i++) { 656 if (document.links.item(i).innerHTML && (document.links.item(i).style.display != 'none') && (document.links.item(i).innerHTML.indexOf('view_as_kml.png') >= 0)) { 657 var kmlurl = document.links.item(i).href; 658 kmlurl = kmlurl.replace(/output=nl/, 'output=kml'); 659 errorbox('This is a "My Maps" page, which means that the original KML used to create it is available. Please <a href="' + kmlurl + '">download the KML file</a> (using this link, not the one provided by Google) and convert it using <a href="http://www.gpsvisualizer.com/convert" target="_new">GPSVisualizer</a>.'); 660 error = 1; 661 break; 662 } 663 583 664 // bar_icon_link.gif is the "link to this page" icon. If they change 584 665 // its name, I need to fix that here. 585 666 if (document.links.item(i).innerHTML && (document.links.item(i).innerHTML.indexOf('bar_icon_link.gif') >= 0)) { 586 googledoc = loadXMLDoc(document.links.item(i).href); 667 var googleurl = document.links.item(i).href; 668 googleurl = googleurl.replace(/&view=text/, ''); 669 googledoc = loadXMLDoc(googleurl); 670 googledoc = googledoc.replace(/\\u003e/g, '>'); 671 googledoc = googledoc.replace(/\\u003c/g, '<'); 672 googledoc = googledoc.replace(/\\u0026/g, '&'); 673 googledoc = googledoc.replace(/\\042/g, '"'); 674 googledoc = googledoc.replace(/"*polylines"*:\s*/g, 'polylines:'); 675 googledoc = googledoc.replace(/"*markers"*:\s*/g, 'markers:'); 676 googledoc = googledoc.replace(/"*id"*:\s*/g, 'id:'); 677 googledoc = googledoc.replace(/"*lat"*:\s*/g, 'lat:'); 678 googledoc = googledoc.replace(/"*lng"*:\s*/g, 'lng:'); 679 googledoc = googledoc.replace(/"*laddr"*:\s*/g, 'laddr:'); 680 googledoc = googledoc.replace(/"*points"*:\s*/g, 'points:'); 681 googledoc = googledoc.replace(/\\"/g, '"'); 682 googledoc = googledoc.replace(/\"/g, '\''); 683 continue; 587 684 } 588 685 } … … 599 696 } 600 697 698 if (error != 1) { 601 699 /* Default action. If it's not a route, the argument doesn't matter. */ 602 gmaptogpxdiv("route");603 604 /* Clumsy, but hey. */ 605 if (error == 1) { closebox(); } 700 gmaptogpxdiv("route"); 701 } else { 702 closebox(); 703 }
