Show
Ignore:
Timestamp:
07/22/07 12:31:41 (5 years ago)
Author:
ng
Message:

gmaptogpx.js: 5.1c → 5.4
gmap2qpegps.js: 4.32 → 4.33 (fixed by Paul Rascagneres)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • tools/GMap2QpegpsNV/gmap2qpegps.js

    r12 r13  
    11/* 
    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 
    116  Josh Larios <hades@elsewhere.org> 
    12   August 3, 2005 - July 21, 2006 
     7  August 3, 2005 - July 13, 2007 
    138 
    149  WARNING: Highly dependent on internal formats that aren't part of 
     
    1611  control. 
    1712 
    18    
    1913  * 4.23 - Fix problem due to google internal change (in directive) 
    2014  * 4.24 - Fix problem due to google internal change 
     
    2620  * 4.31 - Support other languages again 
    2721  * 4.32 - Fix problem due to google internal change 
     22  * 4.33 - Fix problem due to google internal change 
    2823 
    2924*/ 
    3025 
    3126var error = 0; 
    32 var version = '4.32'; 
     27var version = '4.33'; 
    3328var googledoc = ""; // will hold retrieved google info 
    3429var routes = new Array(); 
     30var milestones = new Array(); 
     31var yelp = new Array(); 
    3532var googlepage; // Will hold the page element that gets toggled. May change. 
    3633 
     
    4744} 
    4845 
    49 /* return distance in m between 2 points */ 
    5046function calcDistanceLtLgRad(lt1, lg1, lt2, lg2) 
    5147{ 
     
    107103        } 
    108104    } 
    109  
     105     
    110106    if (req.readyState == 4) { 
    111107        // only if "OK" 
     
    146142    z.style.padding = ".3em 1.3em .3em .3em"; 
    147143    z.style.zIndex = "1000"; 
    148  
     144     
    149145    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>'; 
    150146    z.innerHTML += boxcontents; 
     
    188184 
    189185 
    190 function gmaptoqpegpsnvdiv(dtype) {  
     186function gmaptogpxdiv(dtype) {  
    191187    var mypoints = null; 
    192188     
    193189    var qtype = 0; 
     190    var subtype = 0; 
     191     
    194192    var xmlformat = (dtype != "qpegpstrack" && dtype != "qpegpsroute"); 
    195      
    196193    /*  
    197194       Determine which type of data we're extracting -- a route, or points of 
     
    199196    */ 
    200197     
    201     if (googledoc.match(/"id":"route0"/)) { 
     198    if (googledoc.match(/id:'route0'/)) { 
    202199        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         
    203207        // 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:[')); 
    205209        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"); 
    210214            // Stupid backslashes. *mutter* 
    211215            routes[id] = decodeLine(encpoints.replace(/\\\\/g, '\\')); 
    212216        } 
    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)'/)) { 
    225243        qtype = 1; 
    226244        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); 
    232250        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(/ @.*/, ""); 
    237255            desc = desc.replace(/(.*) \((.*)\)/, "$2 ($1)"); 
    238256            routes['poi'].push({"lat": lat, "lon": lon, "desc": deamp(desc)}); 
     
    244262        qtype = 3;  
    245263    } 
    246  
     264     
    247265    /* HeyWhatsThat.com list of peaks visible from given location */ 
    248266    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')) { 
    249273        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    } 
    252299    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>'); 
    254301        closebox(); 
    255302        return(0);  
     
    301348    } 
    302349         
     350     
    303351    t+="<div style='background-color:#D8D9F8;'>"; 
    304352    t+='<ul class="menubar">'; 
     
    312360        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>'; 
    313361        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          
    316362 
    317363    } 
    318364    t+='<li class="menubar"><a href="javascript:loadabout()">About</a></li>'; 
    319365    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) 
    325369    t+= '<?xml version="1.0" encoding="UTF-8"?>\n' +  
    326370        '<gpx version="1.1"\n' +  
     
    328372        '     xmlns="http://www.topografix.com/GPX/1/1"\n' +  
    329373        '     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';  
    332375     
    333376    if ((qtype==2) && (dtype=="allpoints")) { 
     
    339382            t+= '      <trkseg>\n'; 
    340383            for(i=0;i<route.length;i++) { 
    341                 if (i == route.length - 1) 
     384                if (i == route.length - 1)  
    342385                    route[i].desc = 'Arrive at destination'; 
    343386 
     
    349392                    t += '<desc>' + deamp(route[i].desc) + '</desc>'; 
    350393                 
    351                t+= '</trkpt>\n'; 
    352  
     394                t+= '</trkpt>\n'; 
    353395            } 
    354396            t+= '      </trkseg>\n'; 
     
    422464        } 
    423465    } 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       
    433475    } else if (qtype == 2) { 
    434476        /* If we're on a page with driving directions, spit out a route. */ 
    435477        var title = "Driving directions"; 
    436        if(xmlformat) 
     478        if(xmlformat) 
    437479        { 
    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'; 
    507551                } else if (dtype == "route") { 
    508552                    t+= '   </rte>\n'; 
    509553                } 
    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    }  
    517562        else if (dtype=="qpegpstrack") /* qpegpstrack */  
    518563        { 
     
    578623            } 
    579624             
    580  
    581         } 
    582          
     625       }         
    583626    } else if (qtype == 1) { 
    584627        /* This is a page with points of interest - spit out waypoints. */ 
     
    588631                '      <name>' + point.desc + '</name>\n' + 
    589632                '      <cmt>' + point.desc.replace(/(.*) \((.*)\)/, "$2 ($1)") + '</cmt>\n' + 
     633                '      <desc>' + point.desc.replace(/(.*) \((.*)\)/, "$2 ($1)") + '</desc>\n' + 
    590634                '   </wpt>\n'; 
    591635        } 
     
    594638        error = 1; 
    595639    } 
    596      
     640 
    597641    if(xmlformat) 
    598         t+='</gpx>\n'; 
     642       t+='</gpx>\n'; 
    599643    t+='</textarea>'; 
    600644    t+="<div style='background-color:#D8D9F8;'>"; 
     
    635679 
    636680 
    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 
     682function loadabout() { 
     683    var about = '<span style="font-size: x-small;"><p>GMapToQpeGPS ' + version + '<br />'; 
     684    about += 'by ng &lt;ng@ngsoft-fr.com&gt; and Paul Rascagneres &lt;paul.rascagneres@free.fr&gt;<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
    638687 
    639688function 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); 
    642691} 
    643692 
     
    648697} 
    649698 
    650  
    651699function reload(t) { 
    652700    closebox(); 
    653701    if (t==0) { 
    654         gmaptoqpegpsnvdiv("route"); 
     702        gmaptogpxdiv("route"); 
    655703    } else if (t=="1") { 
    656         gmaptoqpegpsnvdiv("track"); 
     704        gmaptogpxdiv("track"); 
    657705    } else if (t=="2") { 
    658         gmaptoqpegpsnvdiv("points"); 
     706        gmaptogpxdiv("points"); 
    659707    } else if (t=="3") { 
    660         gmaptoqpegpsnvdiv("allpoints"); 
     708        gmaptogpxdiv("allpoints"); 
    661709    } else if (t=="4") { 
    662        gmaptoqpegpsnvdiv("qpegpstrack"); 
     710        gmaptogpxdiv("qpegpstrack"); 
    663711    } else if (t=="5") { 
    664        gmaptoqpegpsnvdiv("qpegpsroute"); 
     712        gmaptogpxdiv("qpegpsroute"); 
    665713    } 
    666714} 
     
    669717 
    670718function deamp(a) { 
     719    a = a.replace(/<br *\/>(.+)/g, ", $1"); 
     720    a = a.replace(/<br *\/>/g, ''); 
    671721    a = a.replace(/&#39;/g, '\''); 
    672722    a = a.replace(/\\047/g, '\''); 
     
    680730    a = a.replace(/\\x26/g, '&'); 
    681731    a = a.replace(/&/g, '&amp;');   
     732    a = a.replace(/\\n/g, ''); 
     733    a = a.replace(/\\t/g, ''); 
    682734    return a; 
    683735} 
     
    687739if (document.location.hostname.indexOf('google') >= 0) { 
    688740    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        } 
    693770    } 
    694771} 
     
    704781} 
    705782 
     783if (error != 1) { 
    706784/* 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  
    11/* 
    2   GMapToGPX  
     2  GMapToGPX 5.4 
    33  Originally based in part on the "Improved MSN and Google GPS GPX Waypoint  
    44  Extraction" bookmarklet described at http://badsegue.org/archives/2005/04/21/ 
    5    
     5 
    66  Josh Larios <hades@elsewhere.org> 
    7   August 3, 2005 - May 1, 2007 
     7  August 3, 2005 - July 13, 2007 
    88 
    99  WARNING: Highly dependent on internal formats that aren't part of 
     
    1313  Gmap-pedometer elevation code courtesy of Mathew O'Brien. 
    1414 
    15   3/5/2007 HeyWhatsThat.com code added mk -at- heywhatsthat.com 
     15  3/5/2007 - HeyWhatsThat.com code by mk -at- heywhatsthat.com 
    1616 
    1717  TO DO: Separate out gpx writing and point/track extraction, so I can load 
     
    2121 
    2222var error = 0; 
    23 var version = '5.1c'; 
     23var version = '5.4'; 
    2424var googledoc = ""; // will hold retrieved google info 
    2525var routes = new Array(); 
     26var milestones = new Array(); 
     27var yelp = new Array(); 
    2628var googlepage; // Will hold the page element that gets toggled. May change. 
    2729 
     
    6365        } 
    6466    } 
    65  
     67     
    6668    if (req.readyState == 4) { 
    6769        // only if "OK" 
     
    102104    z.style.padding = ".3em 1.3em .3em .3em"; 
    103105    z.style.zIndex = "1000"; 
    104  
     106     
    105107    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>'; 
    106108    z.innerHTML += boxcontents; 
     
    148150     
    149151    var qtype = 0; 
     152    var subtype = 0; 
    150153     
    151154    /*  
     
    154157    */ 
    155158     
    156     if (googledoc.match(/"id":"route0"/)) { 
     159    if (googledoc.match(/id:'route0'/)) { 
    157160        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         
    158168        // 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:[')); 
    160170        encpointblob=encpointblob.slice(0, encpointblob.indexOf('],')); 
    161         var encmatch = encpointblob.match(/"id":"([^\"]+)","points":"([^\"]+)"/g); 
     171        var encmatch = encpointblob.match(/id:'([^\']+)', *points:'([^\']+)'/g); 
    162172        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"); 
    165175            // Stupid backslashes. *mutter* 
    166176            routes[id] = decodeLine(encpoints.replace(/\\\\/g, '\\')); 
    167177        } 
    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)'/)) { 
    180204        qtype = 1; 
    181205        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); 
    187211        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(/ @.*/, ""); 
    192216            desc = desc.replace(/(.*) \((.*)\)/, "$2 ($1)"); 
    193217            routes['poi'].push({"lat": lat, "lon": lon, "desc": deamp(desc)}); 
     
    199223        qtype = 3;  
    200224    } 
    201  
     225     
    202226    /* HeyWhatsThat.com list of peaks visible from given location */ 
    203227    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')) { 
    204234        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    } 
    207260    if (qtype==0) { 
    208261        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>'); 
     
    296349            for(i=0;i<route.length;i++) { 
    297350                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; 
    299354                } 
     355 
    300356                t+= '      <trkpt '; 
    301357                t+= 'lat="' + route[i].lat + '" ' + 
     
    375431            t+= '   </rte>\n'; 
    376432        } 
    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        } 
    387451    } else if (qtype == 2) { 
    388452        /* If we're on a page with driving directions, spit out a route. */ 
     
    398462        for (var key in routes) { 
    399463            var route = routes[key]; 
     464            var routeno = key.replace(/route/, ''); 
     465            routeno = parseInt(routeno); 
    400466            if (dtype == "track") { 
    401467                t+= '   <trkseg>\n'; 
     
    405471             
    406472            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';  
    409476            } 
    410477 
     
    431498                    '         <name>'; 
    432499                if (i == route.length - 1) { 
    433                     route[i].desc = 'Arrive at destination'; 
     500                    route[i].desc = milestones[routeno+1]; 
     501 
    434502                    t += 'GMLS-' + ((milestone < 100) ? '0' : '') +  
    435503                        ((milestone < 10) ? '0' : '') + milestone; 
     
    441509                } 
    442510                t += '</name>\n' + 
    443                     '         <cmt>' + route[i].desc + '</cmt>\n'; 
     511                    '         <cmt>' + route[i].desc + '</cmt>\n' + 
     512                    '         <desc>' + route[i].desc + '</desc>\n'; 
    444513 
    445514                switch(dtype) { 
     
    475544                '      <name>' + point.desc + '</name>\n' + 
    476545                '      <cmt>' + point.desc.replace(/(.*) \((.*)\)/, "$2 ($1)") + '</cmt>\n' + 
     546                '      <desc>' + point.desc.replace(/(.*) \((.*)\)/, "$2 ($1)") + '</desc>\n' + 
    477547                '   </wpt>\n'; 
    478548        } 
     
    519589    } 
    520590} 
    521  
    522591 
    523592 
     
    563632 
    564633function deamp(a) { 
     634    a = a.replace(/<br *\/>(.+)/g, ", $1"); 
     635    a = a.replace(/<br *\/>/g, ''); 
    565636    a = a.replace(/&#39;/g, '\''); 
    566637    a = a.replace(/\\047/g, '\''); 
     
    574645    a = a.replace(/\\x26/g, '&'); 
    575646    a = a.replace(/&/g, '&amp;');   
     647    a = a.replace(/\\n/g, ''); 
     648    a = a.replace(/\\t/g, ''); 
    576649    return a; 
    577650} 
     
    581654if (document.location.hostname.indexOf('google') >= 0) { 
    582655    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 
    583664        // bar_icon_link.gif is the "link to this page" icon. If they change  
    584665        // its name, I need to fix that here. 
    585666        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; 
    587684        } 
    588685    } 
     
    599696} 
    600697 
     698if (error != 1) { 
    601699/* 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