Changeset 32607

Show
Ignore:
Timestamp:
16.11.2018 13:21:39 (4 weeks ago)
Author:
kjdon
Message:

fixed a bug where the paris photos in gps tutorial wouldn't show up in document view. I think its something to do with the size of the bounds that we are trying to fit the map to. using a single point as bounds. works for hamilton gardens locations, but not paris. to do with availability of photos?? not sure. anyway, if we only have a single point on the map, center on that point and set zoom rather than fit bounds to that point. also tidied up a bit of code - can use bounds.extend with lat/long rather than trying to calculate sw/ne ourselves.

Files:
1 modified

Legend:

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

    r32604 r32607  
    8282{ 
    8383    var myOptions =  
    84     { 
     84        { 
    8585        zoom: 2, 
    8686        center: new google.maps.LatLng(0, 0), 
     
    110110    var lngDistance = neLng - swLng; 
    111111     
    112     console.log("neLat = " + neLat + " neLng = " + neLng + " swLat = " + swLat + " swLng = " + swLng + " latDistance = " + latDistance + " lngDistance = " + lngDistance); 
    113      
    114112    //Check which increment to use for latitude (i.e. 0.001, 0.01, 0.1 or 1 degree increments) 
    115113    var latDelta; 
     
    136134        } 
    137135    } 
    138      
    139     if(latDelta == 0.1){latDelta = 1; latPrecision = 0;} 
    140     if(lngDelta == 0.1){lngDelta = 1; lngPrecision = 0;} 
     136 
     137    if(latDelta == 0.1){latDelta = 1; latPrecision = 0; } 
     138    if(lngDelta == 0.1){lngDelta = 1; lngPrecision = 0; } 
    141139     
    142140    var query = ""; 
     
    182180    var url = gs.xsltParams.library_name; 
    183181    var data = "a=q&s=RawQuery&rt=rd&c=" + gs.cgiParams.c + "&s1.rawquery=" + query + "&excerptid=jsonNodes"; 
    184      
    185182    $.ajax({type:"POST", url:url, data:data}) 
    186183    .success(function(responseText) 
     
    258255function updateMap() 
    259256{ 
    260     var north = -180; 
    261     var east = -180; 
    262     var south = 180; 
    263     var west = 180; 
    264  
    265     var markersOnMap = 0; 
     257    var markersOnMap = 0; 
     258    var bounds =  new google.maps.LatLngBounds(); 
    266259    for(var i = 0; i < _docList.ids.length; i++) 
    267260    { 
    268261        var doc = _docList.getDocByIndex(i); 
    269  
    270262        if(doc.parentCL && doc.parentCL.style.display == "none") 
    271263        { 
     
    278270            markersOnMap++; 
    279271        } 
    280          
    281         if(doc.lat > north) 
    282         { 
    283             north = doc.lat; 
    284         } 
    285         if(doc.lat < south) 
    286         { 
    287             south = doc.lat; 
    288         } 
    289         if(doc.lng > east) 
    290         { 
    291             east = doc.lng; 
    292         } 
    293         if(doc.lng < west) 
    294         { 
    295             west = doc.lng; 
    296         } 
    297     } 
    298      
    299     //As there is always 2 possible bounding boxes we want the smaller of the two 
    300     if(east - west > 180) 
    301     { 
    302         var temp = east; 
    303         east = west; 
    304         west = temp; 
    305     } 
    306      
    307     var bounds; 
    308     if(markersOnMap > 0) 
    309     { 
    310         bounds = new google.maps.LatLngBounds(new google.maps.LatLng(south, west), new google.maps.LatLng(north, east)); 
    311         _map.fitBounds(bounds); 
    312     } 
     272 
     273            bounds.extend(new google.maps.LatLng(doc.lat, doc.lng)); 
     274    } 
     275     
     276    if(markersOnMap > 1) 
     277    { 
     278    _map.fitBounds(bounds); 
     279    } else if (markersOnMap == 1) { 
     280    // sometimes a single point bounds are too small for the map to display, so use center and zoom instead of fitbounds. 
     281    _map.setCenter(bounds.getCenter()); 
     282    _map.setZoom(18); // arbitrary value that looked nice for my example 
     283    } 
    313284} 
    314285 
     
    438409    marker.markerInfo = info; 
    439410    doc.marker = marker; 
    440  
    441411    attachClickHandler(marker, doc.nodeID); 
    442412}