Changeset 33289

Show
Ignore:
Timestamp:
02.07.2019 21:04:34 (2 weeks ago)
Author:
wy59
Message:

1. References to new Array() changed to [] and _docList now no longer initalised with new Array but with {} because it was being used as a map. 2. Added toggleMapSection and modified httpMapBrowseRequest() to do as Dr Bainbridge had suggested: httpMapBrowseRequest would add the JSON info for the docs returned for the expanded classifier into a data attribute for the expanded classifier ID. Then on expanding during toggling a classifier, the map would add the doc info for each of the docs stored in the data attribute for the toggled section into the _docList map, and on closing the bookshelf when toggling a classifier the affected docs (those referenced in the toggled section's data attribute) would be removed from the _docList. 3. This did not solve the original problem that performSearchForMarkers() was always being called when the map bounds were extended since _docList maintained not just the expanded visible docs but also the nearbyDocs from the proximity search for what else could be displayed on the map. Dr Bainbridge solved all this by cleaning up the existing code (e.g. renaming functions like performSearchForMarkers changed to performProximitySearch and renaming variables like _nearbyDocs to _nearbyDocsByDistance) and introducing new variables like the new array nearbyDocListByProximity. The array nearbyDocListByProximity is emptied and repopulated by the performProximitySearch() function. These docs only need to be displayed on the map, so the list can be recreated on every expanded bookshelf. performProximitySearch() will first empty the _nearbyDocListByProximity array after removing its markers from the current map, then it will perform the search and add each document found that's not already in _docList (i.e. not already visible in one of the expanded classifiers) to _nearbyDocListByProximity. These docs' shapes are then drawn on the map at lower opacity but on updateMap)() these docs won't trigger a bounds_changed, as the bounds are only calculated based on the main docs, the ones in the now reduced _docList, and not based on the nearby docs in _nearbyDocListByProximity. 4. Dr Bainbridge fixed an issue whereby expanding the first node would not get nearby docs for it with performProximitySearch() as the map bounds were invalid due to incomplete map initialisation. The culprit was with setting the map display to hidden, turning it on thereafter with display block never changed the map bounds from 0 back to something valid when the map bounds were printed before the fitBounds() call. Also, setting the map's visibility to hidden with 0px height and then to visible with a positive height would result in the map bounds calculated longitude to be 0. The solution Dr Bainbridge came up with was to only use visibility rather than display, but not set the height, instead on hidden map setting the position to absolute would allow the visible elements to continue to flow on the page and when the map was set to visible, its position property should be returned to relative. 5. Added debugging and info logging functions.

Location:
main/trunk/greenstone3/web/interfaces/default/js
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/web/interfaces/default/js/classifier_scripts.js

    r33286 r33289  
    2929    if(section.length !== 0) 
    3030    { 
     31        var expanding = false; 
    3132        if(isExpanded(sectionID)) 
    3233        { 
     34            expanding = false; 
    3335            section.css("display", "none"); 
    3436            sectionToggle.attr("src", gs.imageURLs.expand); 
     
    4143        else 
    4244        { 
     45            expanding = true; 
    4346            section.css("display", "block"); 
    4447            sectionToggle.attr("src", gs.imageURLs.collapse); 
     
    4649        } 
    4750        updateOpenClassifiers(); 
    48         if(typeof mapEnabled !== 'undefined' && mapEnabled){ 
     51        if(typeof mapEnabled !== 'undefined' /*&& mapEnabled*/){ 
    4952            //console.log("Classifier scripts -> updateMap()"); 
     53            toggleMapSection({"expand": expanding, "nodeID": sectionID}); 
    5054            updateMap(); 
    5155        } 
  • main/trunk/greenstone3/web/interfaces/default/js/map-scripts.js

    r33218 r33289  
    44 
    55//var newLat, newLng = 0; 
    6 var _docList = new Array(); 
    7 _docList.ids = new Array(); 
     6var _docList = {}; 
     7_docList.ids = []; 
     8 
    89_docList.getDocByIndex = function(index) 
    910{ 
    1011    return _docList[_docList.ids[index]]; 
    1112}; 
     13 
     14var _nearbyDocListByProximity = []; 
    1215 
    1316var _map; 
    1417var _intervalHandle; 
    1518var _baseURL = document.URL.substring(0, document.URL.indexOf("?") + 1); 
    16 var _retrievedClassifiers = new Array(); 
     19var _retrievedClassifiers = []; 
    1720var _preventLoopingSingleMarker = false; 
    1821var _searchRunning = false; 
    19 var _nearbyDocs = new Array(); 
    20 var _scrollThroughDefault = true; // TODO: default starts at true 
     22var _nearbyDocsByDistance = []; 
     23var _scrollThroughDefault = true; 
    2124 
    2225var LOW_OPACITY = 0.1; // make surrounding docs' opacity 10% 
     26var _DEBUGGING_ = false; 
    2327 
    2428function initializeMapScripts()  
     
    3640        { 
    3741            mapEnabled = true; 
     42            showMap("initializeMapScripts"); 
     43             
    3844            var resultsArea = $('#resultsArea'); 
    3945            if (resultsArea.length > 0){ 
     
    4955                console.log("#### " + jsonNodes[i].nodeID + " is a main doc: "); 
    5056                console.log(jsonNodes[i]); 
    51                 createMarkers(jsonNodes[i], options); 
     57                createOverlayItems(jsonNodes[i], options); 
    5258            } 
    5359             
     
    5864            //hiding the map 
    5965            mapEnabled = false; 
    60             $("#map_canvas").css({display:"none"}); 
     66            hideMap("initializeMapScripts");             
    6167            //return; 
    62         }    
     68        } 
    6369    }    
    6470    _docList.loopIndex = 0; 
     
    116122        //console.log("@@@ created Google _map"); 
    117123         
    118         google.maps.event.addListener(_map, 'bounds_changed', performSearchForMarkers); 
    119     } 
    120 } 
    121  
    122 function performSearchForMarkers() 
    123 { 
     124        google.maps.event.addListener(_map, 'bounds_changed', performProximitySearch); 
     125    } 
     126} 
     127 
     128function performProximitySearch() 
     129{ 
     130    _gsDebug("*** START OF performProximitySearch()"); 
     131     
     132 
    124133    if(typeof mapEnabled === 'undefined') return; 
    125134    if(!mapEnabled){ return; } 
    126135     
    127     //console.log("@@@ performSearchForMarkers()"); 
    128      
    129     var bounds = _map.getBounds(); 
    130     var ne = bounds.getNorthEast(); 
    131     var sw = bounds.getSouthWest(); 
    132                    
    133     //console.log("bounds: ne = " + ne + ", sw = " + sw); 
     136    _gsDebug("*** Got past mapEnabled test"); 
     137     
     138     
     139    for(var i = 0 ; i < _nearbyDocListByProximity.length; i++) { 
     140        removeMarkersFromMap(_nearbyDocListByProximity[i]); 
     141    } 
     142    _nearbyDocListByProximity = []; 
     143     
     144     
     145    _debugPrintBounds(_map.getBounds(), "@@@ performProximitySearch():");    
    134146     
    135147     
    136148    if(_searchRunning) 
    137149    { 
    138         //console.log("*** performSearchForMarkers(): already running search => not initiating an additional search"); 
     150        _gsInfo("*** performProximitySearch(): already running search => not initiating an additional search"); 
    139151        return; 
    140152    } 
    141      
    142153     
    143154    _searchRunning = true; 
     
    152163    var latDistance = neLat - swLat; 
    153164    var lngDistance = neLng - swLng; 
     165     
     166    _gsDebug("****************START*****************"); 
     167    _gsDebug("latDistance = " + latDistance); 
     168    _gsDebug("lngDistance = " + lngDistance); 
    154169     
    155170    //Check which increment to use for latitude (i.e. 0.001, 0.01, 0.1 or 1 degree increments) 
     
    185200    if(lngDelta == 0.1){lngDelta = 1; lngPrecision = 0; } 
    186201     
     202     
     203     
     204    _gsDebug("Proximity search: lat precision BEFORE = " + latPrecision); 
     205    _gsDebug("Proximity search: lng precision BEFORE = " + lngPrecision); 
    187206     
    188207    // Want consistent precision for both lat and lng. 
     
    194213    } 
    195214     
    196     /* 
     215    _gsDebug("Proximity search: lat precision AFTER = " + latPrecision); 
     216    _gsDebug("Proximity search: lng precision AFTER = " + lngPrecision); 
     217    _gsDebug("Proximity search with: latDelta = " + latDelta); 
     218    _gsDebug("Proximity search with: lngDelta = " + lngDelta); 
     219     
    197220    var query = ""; 
    198     for(var i = 0; i <= Math.floor(latDistance / latDelta) + 1; i++) 
    199     { 
    200         for(var j = 0; j <= Math.floor(lngDistance / lngDelta) + 1; j++) 
     221    var iMax = Math.floor(latDistance / latDelta) + 1; 
     222    var jMax = Math.floor(lngDistance / lngDelta) + 1; 
     223     
     224    _gsDebug("Proximity search with: iMax = " + iMax); 
     225    _gsDebug("Proximity search with: jMax = " + jMax); 
     226     
     227    _gsDebug("****************END*****************"); 
     228     
     229    for(var i = 0; i <= iMax; i++) //for(var i = 0; i <= Math.floor(latDistance / latDelta) + 1; i++) 
     230    { 
     231        for(var j = 0; j <= jMax; j++) //for(var j = 0; j <= Math.floor(lngDistance / lngDelta) + 1; j++) 
    201232        { 
    202233            //Some necessary variables 
     
    215246            //Construct query 
    216247            query += "("; 
    217             query += "LA:" + coordToAbsDirected(newLatTrunc, "lat"); 
    218             if(latDelta != 1) 
    219             {  
    220                 query += "+AND+"; 
    221                 query += "LA:" + newLatString.substring(newLatString.indexOf(".") + 1, newLatString.indexOf(".") + latPrecision + 1); 
    222             } 
    223             query += "+AND+"; 
    224             query += "LN:" + coordToAbsDirected(newLngTrunc, "lng"); 
    225             if(lngDelta != 1) 
    226             {  
    227                 query += "+AND+"; 
    228                 query += "LN:" + newLngString.substring(newLngString.indexOf(".") + 1, newLngString.indexOf(".") + lngPrecision + 1); 
    229             } 
    230             query += ")"; 
    231  
    232             if(i != (Math.floor(latDistance / latDelta) + 1) || j != (Math.floor(lngDistance / lngDelta) + 1)){ query += "+OR+"; } 
    233         } 
    234     } 
    235     */ 
    236     var query = ""; 
    237     var iMax = Math.floor(latDistance / latDelta) + 1; 
    238     var jMax = Math.floor(lngDistance / lngDelta) + 1; 
    239     for(var i = 0; i <= iMax; i++) //for(var i = 0; i <= Math.floor(latDistance / latDelta) + 1; i++) 
    240     { 
    241         for(var j = 0; j <= jMax; j++) //for(var j = 0; j <= Math.floor(lngDistance / lngDelta) + 1; j++) 
    242         { 
    243             //Some necessary variables 
    244             var newLat = neLat - (latDelta * i); 
    245             var newLatString = "" + newLat; 
    246             var newLatTrunc; 
    247             if(newLat < 0){newLatTrunc = Math.ceil(newLat);} 
    248             else{newLatTrunc = Math.floor(newLat);} 
    249              
    250             var newLng = neLng - (lngDelta * j); 
    251             var newLngString = "" + newLng; 
    252             var newLngTrunc; 
    253             if(newLng < 0){newLngTrunc = Math.ceil(newLng);} 
    254             else{newLngTrunc = Math.floor(newLng);} 
    255  
    256             //Construct query 
    257             query += "("; 
    258248            query += "CS:\"" + coordToAbsDirected(newLatTrunc, "lat"); 
    259             //query += "CS:\"" + coordToAbsDirected(newLatTrunc, "lat") + "\" \"" + coordToAbsDirected(newLngTrunc, "lng") + "\""; //query += "LA:" + coordToAbsDirected(newLatTrunc, "lat"); 
     249             
    260250            if(latDelta != 1) 
    261251            {  
    262252                query += newLatString.substring(newLatString.indexOf(".") + 1, newLatString.indexOf(".") + latPrecision + 1); 
    263253            } 
    264             query += " "; 
    265             //query += "+AND+"; 
    266              
    267             //query += "LN:" + coordToAbsDirected(newLngTrunc, "lng"); 
     254            query += " ";            
    268255            query += coordToAbsDirected(newLngTrunc, "lng"); 
    269256            if(lngDelta != 1) 
     
    274261            query += ")"; 
    275262 
    276             //if(i != (Math.floor(latDistance / latDelta) + 1) || j != (Math.floor(lngDistance / lngDelta) + 1)){ query += "+OR+"; } 
    277             if(i != iMax || j != jMax){ query += "+OR+"; } 
     263            if(i != iMax || j != jMax){ query += "+OR+"; } //if(i != (Math.floor(latDistance / latDelta) + 1) || j != (Math.floor(lngDistance / lngDelta) + 1)){ query += "+OR+"; } 
    278264        } 
    279265    } 
     
    281267    // This works, why not from the double loop above? 
    282268    //query = "(CS:\"" + coordToAbsDirected(newLatTrunc, "lat") + " " + coordToAbsDirected(newLngTrunc, "lng") + "\")";  
    283     //alert("@@@@in map-scripts::performSearchForMarkers() - query: " + query); 
     269    //alert("@@@@in map-scripts::performProximitySearch() - query: " + query); 
    284270     
    285271    //var url = gs.xsltParams.library_name + "?a=q&s=RawQuery&rt=rd&c=" + gs.cgiParams.c + "&s1.rawquery=" + query + "&excerptid=jsonNodes"; 
    286272    var url = gs.xsltParams.library_name; 
    287273    var data = "a=q&s=RawQuery&rt=rd&c=" + gs.cgiParams.c + "&s1.rawquery=" + query + "&excerptid=jsonNodes"; 
    288     //console.log("*** performSearchForMarkers(): rawQuery query data = " + query); 
     274    //_gsDebug("*** performProximitySearch(): rawQuery query data = " + query); 
    289275     
    290276    $.ajax({type:"POST", url:url, data:data}) 
     
    293279        //console.log("*** responseText (first 250) = " + responseText.substring(0,256)); 
    294280         
    295         // The first time, docList.ids contains ONLY the main/visible doc's ID and its subsections' IDs. 
    296         // Any one of these will do to determine 
    297         if(_docList.ids.length > 0) { 
    298             var mainDocID = _docList.ids[0]; 
    299             var endIndex = mainDocID.indexOf('.'); 
    300             if(endIndex == -1) { endIndex = mainDocID.length; } 
    301             mainDocID = mainDocID.substring(0, endIndex); 
    302         } 
    303          
    304281        if(responseText.search("id=\"jsonNodes") != -1) 
    305282        { 
     
    310287 
    311288            var jsonNodes = eval(responseText.substring(startIndex+1, endIndex)); 
    312             //console.log("Number of matches returned from ajax rawQuery search = " + jsonNodes.length); 
     289            _gsDebug("@@@@ performProximitySearch - Number of matches returned from ajax rawQuery search = " + jsonNodes.length); 
    313290            if(jsonNodes && jsonNodes.length > 0) 
    314291            { 
     
    320297                    for(var j = 0; j < _docList.ids.length; j++) { 
    321298                        if(doc.nodeID == _docList.ids[j]) { 
    322                             found = true;                            
    323                             console.log("Found nearby ID " + doc.nodeID + " was already drawn:"); 
    324                             console.log(jsonNodes[i]); 
     299                            found = true; 
     300                            _gsDebug("performProximitySearch(): Found nearby ID " + doc.nodeID + " was already drawn:", jsonNodes[i]); 
    325301                            break; 
    326302                        } 
     
    329305                    if(!found) 
    330306                    { 
    331                         _docList[doc.nodeID] = doc; 
    332                         _docList.ids.push(doc.nodeID); 
    333  
    334                         // Some "nearby docs" are actually subsections of the main document, which are retrieved 
    335                         // as a nearby doc by performSearchForMarkers() BEFORE the subsection is ever expanded. 
    336                         // We need to distinguish between subsections of the main doc -- which should be displayed 
    337                         // in their specified opacity -- and other docs and their subsections which should be displayed 
    338                         // faded out. 
    339                         if(typeof(mainDocID) !== 'undefined' && doc.nodeID.includes(mainDocID)) { 
    340                             createMarkers(doc, {"mainDoc": true}); 
    341                         } else { 
    342                             createMarkers(doc, {"mainDoc": false}); 
    343                         }                        
     307                        _nearbyDocListByProximity.push(doc); 
     308                        createOverlayItems(doc, {"mainDoc": false});                     
    344309                    } 
    345310                     
     
    355320    }).fail(function(responseText, textStatus, errorThrown) // fail() has replaced error(), http://api.jquery.com/jquery.ajax/ 
    356321        { 
    357             console.log("In map-scripts.performSearchForMarkers(): Got an error in ajax call"); 
     322            console.log("In map-scripts.performProximitySearch(): Got an error in ajax call"); 
    358323            _searchRunning = false; 
    359324    }); 
     
    390355} 
    391356 
     357function toggleMapSection(options) 
     358{ 
     359     
     360    var sectionID = options["nodeID"]; 
     361     
     362    var titleClassifierEl = document.getElementById("title"+sectionID); 
     363    var jsonNodesStr = titleClassifierEl.getAttribute("data-gps-map-json"); 
     364    var jsonNodes = JSON.parse(jsonNodesStr); 
     365     
     366    if(options["expand"]){ 
     367        _gsDebug("expanding classifier - sectionID: " + sectionID);      
     368         
     369        if(jsonNodes && jsonNodes.length > 0) 
     370        { 
     371            for(var i = 0; i < jsonNodes.length; i++) 
     372            { 
     373                var doc = jsonNodes[i]; 
     374                if(_docList[doc.nodeID]) continue; // already in list, don't add again 
     375                 
     376                _docList[doc.nodeID] = doc; 
     377                _docList.ids.push(doc.nodeID); 
     378     
     379                var options = { 
     380                    "mainDoc": true // TODO: should this be true or false??? 
     381                }; 
     382                createOverlayItems(doc, options); 
     383            }                
     384        } 
     385         
     386    } else { // closing the bookshelf 
     387        _gsDebug("closing classifier - sectionID: " + sectionID); 
     388        if(jsonNodes && jsonNodes.length > 0) 
     389        { 
     390            for(var i = 0; i < jsonNodes.length; i++) 
     391            { 
     392                // remove the doc from _docList and its id from _docList.ids 
     393                // and remove its markers/shapes from the map 
     394                var nodeID = jsonNodes[i].nodeID; 
     395                var doc = _docList[nodeID]; 
     396                if(doc) { 
     397                    removeMarkersFromMap(doc); 
     398                     
     399                    delete _docList[nodeID];     
     400                     
     401                    var filtered_ids_to_keep = []; 
     402                    for(var j = 0; j < _docList.ids.length; j++) { 
     403                        if(_docList.ids[j] !== nodeID) { 
     404                            filtered_ids_to_keep.push(_docList.ids[j]); 
     405                        } 
     406                    } 
     407                     
     408                    _docList.ids = filtered_ids_to_keep; 
     409                     
     410                } else { 
     411                    console.log("**** In toggleMapSection: shouldn't happen - failed to find doc on closing node: " + nodeID); 
     412                } 
     413            }        
     414             
     415        } 
     416    } 
     417     
     418    _debugPrintDocList(); 
     419     
     420    mapEnabled = (_docList.ids.length > 0);  
     421     
     422    if(mapEnabled) { 
     423        showMap("toggleMapSection"); 
     424    } else { 
     425        hideMap("toggleMapSection"); 
     426    } 
     427     
     428     
     429} 
     430 
     431/* Given a doc, removes all its shapes doc.shapes from the map _map */ 
     432function removeMarkersFromMap(doc) {     
     433    for(var i = 0; i < doc.shapes.length; i++) { 
     434        var shape = doc.shapes[i]; 
     435        shape.setMap(null); 
     436    } 
     437} 
     438 
     439// In order for fitBounds to work out a non-zero bounds, have to use visibility, not display when hiding/showing the map. 
     440// AND should not set height to 0px when using visibility hidden. But not setting height to 0 means an invisible map takes up space. 
     441// In order for the resulting invisible map, that still takes up space, to not break the flow of the visible items 
     442// on the page, need to swap map between position relative when map visible versus position absolute when the map is hidden. 
     443// https://developers.google.com/maps/documentation/javascript/reference/map#Map.fitBounds 
     444function showMap(callingFunction) { 
     445     
     446    //$("#map_canvas").css({display:"block"}); 
     447    //$("#map_canvas").css({visibility:"visible", height:"100%"}); // not working in conjunction with hidden 0px 
     448    //$("#map_canvas").css({visibility:"visible", height: "400px"}); // but this works in conjunction with hidden 0px 
     449    $("#map_canvas").css({visibility:"visible", position: "relative"}); 
     450     
     451    if(!_DEBUGGING_) return; 
     452     
     453    //var message = "map_canvas display BLOCK"; 
     454    var message = "map_canvas visibility VISIBLE, position relative"; 
     455    if(typeof callingFunction !== 'undefined') { 
     456        message = "showMap() called from" + callingFunction + ":" + message; 
     457    } 
     458    console.log("### " + message); 
     459} 
     460 
     461function hideMap(callingFunction) { 
     462    //$("#map_canvas").css({display:"none"}); 
     463    //$("#map_canvas").css({visibility:"hidden", height:"0px"}); 
     464    $("#map_canvas").css({visibility:"hidden", position:"absolute"}); 
     465     
     466    if(!_DEBUGGING_) return; 
     467     
     468    //var message = "map_canvas display NONE"; 
     469    var message = "map_canvas visibility HIDDEN, position absolute"; 
     470    if(typeof callingFunction !== 'undefined') { 
     471        message = "hideMap() called from" + callingFunction + ":" + message; 
     472    } 
     473    console.log("### " + message);   
     474} 
     475 
    392476function updateMap() 
    393477{ 
    394     //console.log("@@@ updateMap()");    
     478    //console.log("@@@ updateMap()"); 
    395479    var markersOnMap = 0; 
    396480    var bounds =  new google.maps.LatLngBounds(); 
     481     
    397482    for(var i = 0; i < _docList.ids.length; i++) 
    398483    { 
     
    423508        } 
    424509         
    425         if(doc.shapes) { 
    426             console.log("@@@@ HERE IN doc.shapes"); 
     510        if(doc.shapes) {             
    427511            var docSection_overlay_bounds = ShapesUtil.overlayBounds(doc.shapes); 
    428512            // We now have the current document or document subsection's bounds. 
     
    438522    } 
    439523     
    440     //console.log("@@@ UpdateMap() : bounds = " + bounds);               
     524    _debugPrintBounds(bounds, "@@@ UpdateMap():"); 
     525     
     526     
    441527    if(markersOnMap > 1) 
    442528    { 
    443         _map.fitBounds(bounds); 
     529        _debugPrintBounds(_map.getBounds(), "@@@ UpdateMap() : BEFORE fitbounds, map");  
     530         
     531        _map.fitBounds(bounds);      
     532         
     533        _debugPrintBounds(_map.getBounds(), "@@@ UpdateMap() : AFTER fitbounds, map"); 
    444534    } else if (markersOnMap == 1) { 
    445535        //console.log("@@@ updating bounds with " + markersOnMap + " markers on the map"); 
     
    451541    } 
    452542} 
     543 
    453544 
    454545// TODO: FUNCTION DUPLICATED IN panoramaViewer.js 
     
    604695} 
    605696 
    606 function createMarkers(doc, options) { 
     697function createOverlayItems(doc, options) { 
    607698    if(doc.mapoverlay) { 
    608699        //console.log("Have shapes: " + doc.mapoverlay.toString()); 
     
    617708     
    618709    if(!shape.description) { 
    619         console.log("@@@@ " + shape.type.toString() + " had no description/label"); 
     710        _gsInfo("#### " + shape.type.toString() + " had no description/label"); 
    620711        return; 
    621712    } 
     
    632723    if(shape.type === google.maps.drawing.OverlayType.MARKER) { 
    633724        var marker = shape; 
    634         console.log("Coord for marker is " + coord.toString()); 
     725        _gsDebug("Coord for marker is " + coord.toString()); 
    635726         
    636727        marker.addListener('mouseover', function() { 
     
    644735    else { 
    645736        var coord = ShapesUtil.getLabelCoordinate(shape);        
    646         console.log("Coord for " + shape.type.toString() + " is " + coord.toString()); 
     737        _gsDebug("Coord for " + shape.type.toString() + " is " + coord.toString()); 
    647738        infoWindow.setPosition(coord); 
    648739        shape.addListener('mouseover', function() { 
     
    805896        var endIndex = responseText.indexOf("</"); 
    806897         
    807         var jsonNodes = eval(responseText.substring(startIndex+1, endIndex)); 
     898        var jsonNodesStr = responseText.substring(startIndex+1, endIndex); 
     899        var jsonNodes = eval(jsonNodesStr); //responseText.substring(startIndex+1, endIndex)); 
    808900        if(jsonNodes && jsonNodes.length > 0) 
    809901        { 
     902             
    810903            mapEnabled = true; 
    811              
     904            showMap("httpMapBrowseRequest"); 
     905             
     906            //var jsonNodesStr = "";             
    812907            for(var i = 0; i < jsonNodes.length; i++) 
    813908            { 
     
    816911                _docList.ids.push(doc.nodeID); 
    817912     
     913                //$("#div"+doc.nodeID).attr("data-gps-map-json", JSON.stringify(jsonNodes[i])); 
     914                //jsonNodesStr += JSON.stringify(jsonNodes[i]); // can't do this after createOverlayItems, as we get cyclical ref error 
    818915                var options = { 
    819916                    "mainDoc": true // TODO: should this be true or false??? 
    820917                }; 
    821                 createMarkers(doc, options); 
    822             } 
    823              
    824             $("#map_canvas").css({display:"block"}); 
     918                createOverlayItems(doc, options); 
     919            } 
     920             
     921            ///var tmp = $("#title"+sectionID);          
     922            ///console.log(tmp);        // WRONG 
     923            ///var tmp2 = document.getElementById("title"+sectionID); 
     924            ///console.log(tmp2);       // RIGHT, WHY? 
     925             
     926            // create data-* attribute to store this sectionID's JSON on the section's div           
     927            //$("#title"+sectionID).attr("data-gps-map-json", "hello world"); // TODO: Doesn't work. Why? 
     928            var titleClassifierEl = document.getElementById("title"+sectionID); 
     929            titleClassifierEl.setAttribute("data-gps-map-json", jsonNodesStr); 
    825930        } 
    826931         
     
    9361041            var docLink = response.substring(docLinkStart + 4, docLinkEnd); 
    9371042 
    938             _nearbyDocs.push({title:docLink, distance:dist, lat:lats[i], lng:lngs[i++]});  
     1043            _nearbyDocsByDistance.push({title:docLink, distance:dist, lat:lats[i], lng:lngs[i++]});  
    9391044             
    9401045            index = docLinkEnd; 
     
    9651070{ 
    9661071    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>'; 
    967     _nearbyDocs.sort(function(a, b){return (a.distance - b.distance);}); 
    968     for(var i = 0; i < _nearbyDocs.length; i++) 
     1072    _nearbyDocsByDistance.sort(function(a, b){return (a.distance - b.distance);}); 
     1073    for(var i = 0; i < _nearbyDocsByDistance.length; i++) 
    9691074    { 
    9701075     
    971         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>"; 
     1076        sortedTable += "<tr><td>" + prettifyDistance(_nearbyDocsByDistance[i].distance) + '</td><td onmouseover="clearTimeout(map_centering_timeout); map_centering_timeout = setTimeout(recenterMapF(' + _nearbyDocsByDistance[i].lat + ',' + _nearbyDocsByDistance[i].lng + '), 900)" >' + _nearbyDocsByDistance[i].title + "</td></tr>"; 
    9721077    } 
    9731078    sortedTable += "</table>"; 
     
    9961101{ 
    9971102    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>'; 
    998     _nearbyDocs.sort(function(a, b) 
     1103    _nearbyDocsByDistance.sort(function(a, b) 
    9991104    { 
    10001105        var firstTitleStartIndex = a.title.indexOf(">"); 
     
    10061111        return ((firstTitle.toLowerCase() == secondTitle.toLowerCase()) ? 0 : ((firstTitle.toLowerCase() > secondTitle.toLowerCase()) ? 1 : -1)); 
    10071112    }); 
    1008     for(var i = 0; i < _nearbyDocs.length; i++) 
    1009     { 
    1010         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>"; 
     1113    for(var i = 0; i < _nearbyDocsByDistance.length; i++) 
     1114    { 
     1115        sortedTable += "<tr><td>" + _nearbyDocsByDistance[i].distance + '</td><td onmouseover="clearTimeout(map_centering_timeout); map_centering_timeout = setTimeout(recenterMapF(' + _nearbyDocsByDistance[i].lat + ',' + _nearbyDocsByDistance[i].lng + '), 900)">' + _nearbyDocsByDistance[i].title + "</td></tr>"; 
    10111116    } 
    10121117    sortedTable += "</table>"; 
     
    10721177    return queryStringTerm; 
    10731178} 
     1179 
     1180function _gsInfo(message, optObject) { 
     1181    console.log(message); 
     1182    if(typeof optObject !== 'undefined') { 
     1183        console.log(optObject); 
     1184    } 
     1185} 
     1186 
     1187function _gsDebug(message, optObject) { 
     1188    if(_DEBUGGING_) { 
     1189        _gsInfo(message, optObject); 
     1190    } 
     1191} 
     1192 
     1193 
     1194function _debugPrintDocList() {  
     1195    if(!_DEBUGGING_) return; 
     1196     
     1197    console.log("@@@@ printing docList:"); 
     1198    for(var i = 0; i < _docList.ids.length; i++) 
     1199    {    
     1200        var doc = _docList.getDocByIndex(i); 
     1201        console.log("     At index = " + i + " ids[i]: " + _docList.ids[i]); 
     1202        console.log("     At index = " + i + " ids[i]: " + _docList.ids[i] + ", doc: " + doc.nodeID); 
     1203    } 
     1204} 
     1205 
     1206function _debugPrintBounds(bounds, message) { 
     1207    if(!_DEBUGGING_) return; 
     1208    var ne = bounds.getNorthEast(); 
     1209    var sw = bounds.getSouthWest();                
     1210    console.log(message + " bounds: ne = " + ne + ", sw = " + sw); 
     1211}