Changeset 32624

Show
Ignore:
Timestamp:
23.11.2018 13:40:42 (3 weeks ago)
Author:
kjdon
Message:

a few changes to nearby documents list. 1. Show distance in metres if its less than 1 km. 2. Don't put in a line in the table for the current document. 3. Modified the hover actions - show a tooltip, delays the recentring of the map so you need to deliberately hover to get the map recentred, and when you leave the table, recentres it on the current document marker.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/web/interfaces/default/js/map-scripts.js

    r32607 r32624  
    479479        <table id="nearbyDocs">\ 
    480480            <tr>\ 
    481                 <th><a href="javascript:sortByDistance();">Distance (km)</a></th><th><a href="javascript:sortAlphabetically();">Document</a></th>\ 
     481                <th><a href="javascript:sortByDistance();">Distance</a></th><th><a href="javascript:sortAlphabetically();">Document</a></th>\ 
    482482            </tr>\ 
    483483            <xsl:apply-templates select="//documentNode"/>\ 
     
    486486    \ 
    487487    <xsl:template match="documentNode" priority="5">\ 
     488             <xsl:if test="@nodeID !=\''+id+'\'">\ 
    488489        <tr>\ 
    489490            <td>___<gsf:metadata name="Latitude"/>______<gsf:metadata name="Longitude"/>___</td>\ 
    490             <td><gsf:link type="document"><gsf:metadata name="Title"/></gsf:link></td>\ 
     491            <td><gsf:link title="'+gs.text.doc.nearby_doc_tooltip+'" type="document"><gsf:metadata name="Title"/></gsf:link></td>\ 
    491492        </tr>\ 
     493             </xsl:if>\ 
    492494    </xsl:template>'; 
    493      
    494     var url = gs.xsltParams.library_name + "?a=q&s=RawQuery&rt=rd&c=" + gs.cgiParams.c + "&s1.rawquery=" + query + "&excerptid=nearbyDocs&ilt=" + inlineTemplate.replace(/ /, "%20"); 
     495 
     496        var url = gs.xsltParams.library_name + "?a=q&s=RawQuery&rt=rd&c=" + gs.cgiParams.c + "&s1.rawquery=" + query + "&excerptid=nearbyDocs&ilt=" + inlineTemplate.replace(/ /, "%20"); 
    495497    $.ajax(url) 
    496498    .success(function(response) 
     
    502504        var lats = new Array(); 
    503505        var lngs = new Array(); 
    504  
    505506        var matches = response.match(/___(-?[0-9\.]*)___/g); 
    506507        for(var i = 0; i < matches.length; i += 2) 
     
    511512            lats.push(matchLatFloat); 
    512513            lngs.push(matchLngFloat); 
    513              
    514514            var distance = Math.sqrt(Math.pow(matchLatFloat - parseFloat(lat), 2) + Math.pow(matchLngFloat - parseFloat(lng), 2)) * (40000.0/360.0); 
    515             var distanceString = "" + distance; 
    516             distanceString = distanceString.substring(0, 6); 
    517  
     515                var distanceString = "" + distance; 
     516                distanceString = distanceString.substring(0, 6); 
    518517            response = response.replace(matches[i] + matches[i+1], distanceString); 
    519518        } 
     
    533532            var docLinkEnd = response.indexOf("</td>", docLinkStart); 
    534533             
    535             var dist = response.substring(distanceStart + 4, distanceEnd); 
     534                var dist = response.substring(distanceStart + 4, distanceEnd); 
    536535            var docLink = response.substring(docLinkStart + 4, docLinkEnd); 
    537536 
    538             _nearbyDocs.push({title:docLink, distance:dist, lat:lats[i], lng:lngs[i++]}); 
     537            _nearbyDocs.push({title:docLink, distance:dist, lat:lats[i], lng:lngs[i++]});  
    539538             
    540539            index = docLinkEnd; 
    541540        } 
    542541         
    543         sortByDistance(); 
     542        sortByDistance(lat,lng); 
    544543         
    545544        var toggle = $("#nearbyDocumentsToggle"); 
     
    549548} 
    550549 
    551 function sortByDistance() 
    552 { 
    553     var sortedTable = '<table id="nearbyDocs"><tr><th><a href="javascript:;">Distance (km)</a></th><th><a href="javascript:sortAlphabetically();">Document</a></th></tr>'; 
     550var map_centering_timeout = null; 
     551function recenterMapF(lat, lng) 
     552{ 
     553    return function() { 
     554    _map.setCenter(new google.maps.LatLng(lat, lng)); 
     555    } 
     556} 
     557function recenterMap(lat, lng) 
     558{ 
     559 
     560    _map.setCenter(new google.maps.LatLng(lat, lng)); 
     561 
     562} 
     563function sortByDistance(base_lat,base_lng) 
     564{ 
     565    var sortedTable = '<table id="nearbyDocs" onmouseleave="clearTimeout(map_centering_timeout); recenterMap('+base_lat+','+base_lng+');"><tr><th><a href="javascript:;">Distance</a></th><th><a href="javascript:sortAlphabetically('+base_lat+', '+base_lng+');">Document</a></th></tr>'; 
    554566    _nearbyDocs.sort(function(a, b){return (a.distance - b.distance);}); 
    555567    for(var i = 0; i < _nearbyDocs.length; i++) 
    556     { 
    557         sortedTable += "<tr><td>" + _nearbyDocs[i].distance + '</td><td onmouseover="_map.setCenter(new google.maps.LatLng(' + _nearbyDocs[i].lat + ',' + _nearbyDocs[i].lng + '))">' + _nearbyDocs[i].title + "</td></tr>"; 
     568    { 
     569     
     570        sortedTable += "<tr><td>" + prettifyDistance(_nearbyDocs[i].distance) + '</td><td onmouseover="clearTimeout(map_centering_timeout); map_centering_timeout = setTimeout(recenterMapF(' + _nearbyDocs[i].lat + ',' + _nearbyDocs[i].lng + '), 900)" >' + _nearbyDocs[i].title + "</td></tr>"; 
    558571    } 
    559572    sortedTable += "</table>"; 
     
    561574    $("#nearbyDocuments").html(sortedTable); 
    562575} 
    563  
    564 function sortAlphabetically() 
    565 { 
    566     var sortedTable = '<table id="nearbyDocs"><tr><th><a href="javascript:sortByDistance();">Distance (km)</a></th><th><a href="javascript:;">Document</a></th></tr>'; 
     576function prettifyDistance(distance) { 
     577 
     578    var new_distance; 
     579    if (distance < 1) { 
     580    new_distance = (distance * 1000); 
     581    // Round to nearest whole number - don't need to show points of metres.. 
     582    new_distance = Math.round(new_distance); 
     583    new_distance += " m"; 
     584    } 
     585    else { 
     586    new_distance = distance +" km"; 
     587     
     588    } 
     589    return new_distance; 
     590} 
     591 
     592     
     593 
     594function sortAlphabetically(base_lat, base_lng) 
     595{ 
     596    var sortedTable = '<table id="nearbyDocs" onmouseleave="clearTimeout(map_centering_timeout); recenterMap('+base_lat+','+base_lng+');"><tr><th><a href="javascript:sortByDistance('+base_lat+', '+base_lng+');">Distance</a></th><th><a href="javascript:;">Document</a></th></tr>'; 
    567597    _nearbyDocs.sort(function(a, b) 
    568598    { 
     
    577607    for(var i = 0; i < _nearbyDocs.length; i++) 
    578608    { 
    579         sortedTable += "<tr><td>" + _nearbyDocs[i].distance + '</td><td onmouseover="_map.setCenter(new google.maps.LatLng(' + _nearbyDocs[i].lat + ',' + _nearbyDocs[i].lng + '))">' + _nearbyDocs[i].title + "</td></tr>"; 
     609        sortedTable += "<tr><td>" + _nearbyDocs[i].distance + '</td><td onmouseover="clearTimeout(map_centering_timeout); map_centering_timeout = setTimeout(recenterMapF(' + _nearbyDocs[i].lat + ',' + _nearbyDocs[i].lng + '), 900)">' + _nearbyDocs[i].title + "</td></tr>"; 
    580610    } 
    581611    sortedTable += "</table>";