source: main/trunk/greenstone3/web/interfaces/default/js/map-scripts.js@ 32801

Last change on this file since 32801 was 32801, checked in by ak19, 5 years ago

Fixed the marker bug that it can be dragged when there is no user logged in.

  • Property svn:executable set to *
File size: 22.7 KB
Line 
1//var newLat, newLng = 0;
2var _docList = new Array();
3_docList.ids = new Array();
4_docList.getDocByIndex = function(index)
5{
6 return _docList[_docList.ids[index]];
7};
8
9var _map;
10var _intervalHandle;
11var _baseURL = document.URL.substring(0, document.URL.indexOf("?") + 1);
12var _retrievedClassifiers = new Array();
13var _preventLoopingSingleMarker = false;
14var _searchRunning = false;
15var _nearbyDocs = new Array();
16var _scrollThroughDefault = true;
17
18function initializeMapScripts()
19{
20 modifyFunctions();
21 setUpMap();
22
23 var jsonNodeDiv = $("#jsonNodes");
24 if(jsonNodeDiv.length)
25 {
26 var jsonNodes = eval(jsonNodeDiv.html());
27 if(jsonNodes && jsonNodes.length > 0)
28 {
29 for(var i = 0; i < jsonNodes.length; i++)
30 {
31 _docList[jsonNodes[i].nodeID] = jsonNodes[i];
32 _docList.ids.push(jsonNodes[i].nodeID);
33 createMarker(jsonNodes[i], true);
34 }
35 updateMap();
36 }
37 else
38 {
39 //$("#map_canvas").css({visibility:"hidden", height:"0px"});
40 $("#map_canvas").css({visibility:"hidden"});
41 }
42 }
43
44 _docList.loopIndex = 0;
45
46 if(_docList.ids.length > 1)
47 {
48 var startStopCheckbox = $("<input>", {"type": "checkbox", "checked": _scrollThroughDefault, "id": "scrollCheckbox"});
49 startStopCheckbox.click(function()
50 {
51 // http://stackoverflow.com/questions/901712/how-to-check-if-a-checkbox-is-checked-in-jquery
52 // http://stackoverflow.com/questions/5270689/attrchecked-checked-does-not-work
53
54 if($('#scrollCheckbox').is(':checked')) // OR: if(document.getElementById('scrollCheckbox').checked)
55 {
56 if(_intervalHandle == null)
57 {
58 _intervalHandle = setInterval(loopThroughMarkers, 2000);
59 }
60 }
61 else
62 {
63 clearInterval(_intervalHandle);
64 _intervalHandle = null;
65 }
66 });
67
68 var label = $("<span>Scroll through places</span>");
69 var container = $("<div>", {"class": "ui-widget-header ui-corner-all", "style": "clear:right; float:right; padding:0px 5px 3px 0px;"});
70 container.append(startStopCheckbox);
71 container.append(label);
72
73 $(container).insertAfter("#map_canvas");
74
75 if (_scrollThroughDefault) {
76 _intervalHandle = setInterval(loopThroughMarkers, 2000);
77 }
78
79 }
80}
81
82function setUpMap()
83{
84 var myOptions =
85 {
86 zoom: 2,
87 center: new google.maps.LatLng(0, 0),
88 mapTypeId: google.maps.MapTypeId.HYBRID
89 };
90 var $map_canvas = $("#map_canvas");
91
92 if ($map_canvas.length > 0) {
93 _map = new google.maps.Map($map_canvas[0], myOptions);
94 google.maps.event.addListener(_map, 'bounds_changed', performSearchForMarkers);
95 }
96}
97
98function performSearchForMarkers()
99{
100 if(_searchRunning)
101 {
102 return;
103 }
104
105 _searchRunning = true;
106
107 var bounds = _map.getBounds();
108
109 var neLat = bounds.getNorthEast().lat();
110 var neLng = bounds.getNorthEast().lng();
111 var swLat = bounds.getSouthWest().lat();
112 var swLng = bounds.getSouthWest().lng();
113
114 var latDistance = neLat - swLat;
115 var lngDistance = neLng - swLng;
116
117 //Check which increment to use for latitude (i.e. 0.001, 0.01, 0.1 or 1 degree increments)
118 var latDelta;
119 var latPrecision;
120 for(var i = 3; i >= 0; i--)
121 {
122 latDelta = (1 / Math.pow(10, i));
123 if((latDistance / latDelta) <= 5 || latDelta == 1)
124 {
125 latPrecision = i;
126 break;
127 }
128 }
129
130 //Check which increment to use for longitude (i.e. 0.001, 0.01, 0.1 or 1 degree increments)
131 var lngDelta;
132 for(var i = 3; i >= 0; i--)
133 {
134 lngDelta = (1 / Math.pow(10, i));
135 if((lngDistance / lngDelta) <= 5 || lngDelta == 1)
136 {
137 lngPrecision = i;
138 break;
139 }
140 }
141
142 if(latDelta == 0.1){latDelta = 1; latPrecision = 0; }
143 if(lngDelta == 0.1){lngDelta = 1; lngPrecision = 0; }
144
145 var query = "";
146 for(var i = 0; i <= Math.floor(latDistance / latDelta) + 1; i++)
147 {
148 for(var j = 0; j <= Math.floor(lngDistance / lngDelta) + 1; j++)
149 {
150 //Some necessary variables
151 var newLat = neLat - (latDelta * i);
152 var newLatString = "" + newLat;
153 var newLatTrunc;
154 if(newLat < 0){newLatTrunc = Math.ceil(newLat);}
155 else{newLatTrunc = Math.floor(newLat);}
156
157 var newLng = neLng - (lngDelta * j);
158 var newLngString = "" + newLng;
159 var newLngTrunc;
160 if(newLng < 0){newLngTrunc = Math.ceil(newLng);}
161 else{newLngTrunc = Math.floor(newLng);}
162
163 //Construct query
164 query += "(";
165 query += "LA:" + coordToAbsDirected(newLatTrunc, "lat");
166 if(latDelta != 1)
167 {
168 query += "+AND+";
169 query += "LA:" + newLatString.substring(newLatString.indexOf(".") + 1, newLatString.indexOf(".") + latPrecision + 1);
170 }
171 query += "+AND+";
172 query += "LN:" + coordToAbsDirected(newLngTrunc, "lng");
173 if(lngDelta != 1)
174 {
175 query += "+AND+";
176 query += "LN:" + newLngString.substring(newLngString.indexOf(".") + 1, newLngString.indexOf(".") + lngPrecision + 1);
177 }
178 query += ")";
179
180 if(i != (Math.floor(latDistance / latDelta) + 1) || j != (Math.floor(lngDistance / lngDelta) + 1)){ query += "+OR+"; }
181 }
182 }
183
184 //var url = gs.xsltParams.library_name + "?a=q&s=RawQuery&rt=rd&c=" + gs.cgiParams.c + "&s1.rawquery=" + query + "&excerptid=jsonNodes";
185 var url = gs.xsltParams.library_name;
186 var data = "a=q&s=RawQuery&rt=rd&c=" + gs.cgiParams.c + "&s1.rawquery=" + query + "&excerptid=jsonNodes";
187 $.ajax({type:"POST", url:url, data:data})
188 .success(function(responseText)
189 {
190 //console.log("*** responseText (first 250) = " + responseText.substring(0,256));
191
192 if(responseText.search("id=\"jsonNodes") != -1)
193 {
194 var startIndex = responseText.indexOf(">");
195 var endIndex = responseText.indexOf("</");
196
197 var jsonNodes = eval(responseText.substring(startIndex+1, endIndex));
198 if(jsonNodes && jsonNodes.length > 0)
199 {
200 for(var i = 0; i < jsonNodes.length; i++)
201 {
202 var doc = jsonNodes[i];
203
204 var found = false;
205 for(var j = 0; j < _docList.ids.length; j++){if(doc.nodeID == _docList.ids[j]){found = true; break;}}
206
207 if(!found)
208 {
209 _docList[doc.nodeID] = doc;
210 _docList.ids.push(doc.nodeID);
211
212 createMarker(doc, false);
213 }
214 }
215 }
216 }
217 else
218 {
219 console.log("No JSON information received");
220 }
221
222 _searchRunning = false;
223 }).fail(function(responseText, textStatus, errorThrown) // fail() has replaced error(), http://api.jquery.com/jquery.ajax/
224 {
225 console.log("In map-scripts.performSearchForMarkers(): Got an error in ajax call");
226 _searchRunning = false;
227 });
228}
229
230function coordToAbsDirected(coord, type)
231{
232 var value = "" + coord;
233 if(coord < 0)
234 {
235 value = value.substring(1);
236 if(type == "lat")
237 {
238 value += "S";
239 }
240 else
241 {
242 value += "W";
243 }
244 }
245 else
246 {
247 if(type == "lat")
248 {
249 value += "N";
250 }
251 else
252 {
253 value += "E";
254 }
255 }
256
257 return value;
258}
259
260function updateMap()
261{
262 var markersOnMap = 0;
263 var bounds = new google.maps.LatLngBounds();
264 for(var i = 0; i < _docList.ids.length; i++)
265 {
266 var doc = _docList.getDocByIndex(i);
267 if(doc.parentCL && doc.parentCL.style.display == "none")
268 {
269 doc.marker.setVisible(false);
270 continue;
271 }
272 else
273 {
274 doc.marker.setVisible(true);
275 markersOnMap++;
276 }
277
278 bounds.extend(new google.maps.LatLng(doc.lat, doc.lng));
279 }
280
281 if(markersOnMap > 1)
282 {
283 _map.fitBounds(bounds);
284 } else if (markersOnMap == 1) {
285 // sometimes a single point bounds are too small for the map to display, so use center and zoom instead of fitbounds.
286 _map.setCenter(bounds.getCenter());
287 _map.setZoom(18); // arbitrary value that looked nice for my example
288 }
289}
290
291function loopThroughMarkers()
292{
293 if(_docList.ids.length == 0)
294 {
295 return;
296 }
297
298 var visibleMarkers = new Array();
299 for(var i = 0; i < _docList.ids.length; i++)
300 {
301 var doc = _docList.getDocByIndex(i);
302 if(doc.marker.getVisible())
303 {
304 visibleMarkers.push(doc);
305 }
306 }
307
308 if(visibleMarkers.length < 2)
309 {
310 clearAllInfoBoxes();
311 return;
312 }
313
314 clearAllInfoBoxes();
315
316 var elem = null;
317 while(!elem)
318 {
319 if(_docList.loopIndex >= visibleMarkers.length)
320 {
321 _docList.loopIndex = 0;
322 }
323
324 var doc = visibleMarkers[_docList.loopIndex];
325 var elem = gs.jqGet("div" + doc.nodeID);
326 if(elem.length)
327 {
328 elem.css("background", "#BBFFBB");
329 setTimeout(function(){elem.css("background", "");}, 2000);
330 }
331 _docList.loopIndex++;
332 }
333 doc.marker.markerInfo.open(_map, doc.marker);
334}
335
336function attachClickHandler(marker, nodeID)
337{
338
339
340 google.maps.event.addListener(marker, 'click', function()
341 {
342 document.location.href = gs.xsltParams.library_name + "?a=d&ed=1&c=" + gs.cgiParams.c + "&d=" + nodeID + "&dt=hierarchy&p.a=b&p.sa=&p.s=ClassifierBrowse";
343 });
344
345 if (("docEdit" in gs.cgiParams) && (gs.cgiParams['docEdit'])) {
346 google.maps.event.addListener(marker, 'mouseup', function()
347 {
348 var lat = marker.getPosition().lat();
349 var lng = marker.getPosition().lng();
350 var collection = gs.cgiParams.c;;
351 var site_name = gs.xsltParams.site_name;
352
353 if (nodeID == "") {
354 nodeID = gs.cgiParams.d;
355 }
356 console.log("GPS Click handler in collection:" + collection + " in site: " + site_name + " for Doc: " + nodeID + "(" + lat + "," + lng + ")");
357
358 var callbackFunction = function(){console.log("Completed saving metadata changes. You must rebuild the collection for the changes to take effect.");};
359
360 // set 5th parameter, metapos (metadata position) or 7th param prevMetaValue (previous metadata value) to non-null if you want metamode=override to work
361 // if neither of these 2 are set, then metamode is changed to 'accumulate' instead.
362 gs.functions.setArchivesMetadata(collection, site_name, nodeID, "Latitude", null, lat, null, "override", function(){callbackFunction();});
363 gs.functions.setArchivesMetadata(collection, site_name, nodeID, "Longitude", null, lng, null, "override", function(){callbackFunction();});
364
365 });
366 }
367}
368
369function focusDocument(id)
370{
371 var doc = _docList[id];
372 if(doc)
373 {
374 clearInterval(_intervalHandle);
375 _intervalHandle = null;
376 _map.panTo(new google.maps.LatLng(doc.lat, doc.lng));
377 clearAllInfoBoxes();
378 doc.marker.markerInfo.open(_map, doc.marker);
379 var scrollCheckbox = $("#scrollCheckbox");
380 if(scrollCheckbox.checked)
381 {
382 scrollCheckbox.checked = false;
383 }
384 }
385}
386
387function clearAllInfoBoxes()
388{
389 for(var i = 0; i < _docList.ids.length; i++)
390 {
391 var doc = _docList.getDocByIndex(i);
392 doc.marker.markerInfo.close();
393 }
394}
395
396function createMarker(doc, mainMarker)
397{
398 var pos = new google.maps.LatLng(doc.lat,doc.lng);
399
400 var docEdit = (("docEdit" in gs.cgiParams) && (gs.cgiParams['docEdit']));
401 //var draggable_val = (docEdit) ? true : false;
402
403 // When user logs out, the very first page they're returned to has logout set
404 // If the user logged out when leaving docEdit on, then the very first page has docEdit=1 AND logout.
405 // In that case, don't allow editing. Subsequent pages in logged out mode have neither logout nor docEdit=1 set.
406 var loggedOutVar = ("logout" in gs.cgiParams);
407
408 // Don't allow dragging if either 1. docEdit not on OR 2. logout is in the cgiParams
409 var draggable_val = (!docEdit || loggedOutVar) ? false : true;
410
411 console.log(gs.cgiParams);
412
413 var marker
414 if(mainMarker)
415 {
416 marker = new google.maps.Marker
417 ({
418 position: pos,
419 title:doc.title,
420 map:_map,
421 draggable: draggable_val
422 });
423 }
424 else
425 {
426 marker = new google.maps.Marker
427 ({
428 position: pos,
429 title:doc.title,
430 map:_map,
431 icon:"interfaces/" + gs.xsltParams.interface_name + "/images/bluemarker.png",
432 draggable: draggable_val
433 });
434 }
435
436 console.log("doc = " + JSON.stringify(doc));
437
438 var docElement = gs.jqGet("div" + doc.nodeID);
439 var parent;
440 if(docElement)
441 {
442 parent = docElement.parentNode;
443 }
444
445 while(parent && parent.nodeName != "BODY")
446 {
447 if($(parent).attr("id") && $(parent).attr("id").search("divCL") != -1)
448 {
449 doc.parentCL = parent;
450 break;
451 }
452
453 parent = parent.parentNode;
454 }
455
456 var info = new google.maps.InfoWindow({content:doc.title});
457 marker.markerInfo = info;
458 doc.marker = marker;
459 attachClickHandler(marker, doc.nodeID);
460
461 ////////////////////////////////////////////////////// TEST
462
463 newLat = marker.getPosition().lat();
464 newLng = marker.getPosition().lng();
465 //console.log("Latitude " + newLat);
466 //console.log("Longitude " + newLng);
467 NewLatLng(newLat, newLng);
468// // Define the LatLng coordinates for the polygon's path.
469// var triangleCoords = [
470// {lat: 18.774, lng: -80.190},
471// {lat: 18.466, lng: -64.600},
472// {lat: 32.321, lng: -64.757},
473// {lat: 32.300, lng: -80.190},
474// {lat: 28.300, lng: -90.190}
475// ];
476//
477// // Construct the polygon.
478// var bermudaTriangle = new google.maps.Polygon({
479// paths: triangleCoords,
480// strokeColor: '#FF0000',
481// strokeOpacity: 0.8,
482// strokeWeight: 2,
483// fillColor: '#FF0000',
484// fillOpacity: 0.35
485// });
486// bermudaTriangle.setMap(map);
487}
488
489function NewLatLng(lat, lng)
490{
491 console.log("Latitude " + lat);
492 console.log("Longitude " + lng);
493}
494
495function getSubClassifier(sectionID)
496{
497 var url = gs.xsltParams.library_name + "?a=b&rt=s&s=ClassifierBrowse&c=" + gs.cgiParams.c + "&cl=" + sectionID + "&excerptid=jsonNodes";
498 $.ajax(url)
499 .success(function(responseText)
500 {
501 var startIndex = responseText.indexOf(">");
502 var endIndex = responseText.indexOf("</");
503
504 var jsonNodes = eval(responseText.substring(startIndex+1, endIndex));
505 if(jsonNodes && jsonNodes.length > 0)
506 {
507 for(var i = 0; i < jsonNodes.length; i++)
508 {
509 var doc = jsonNodes[i];
510 _docList[doc.nodeID] = doc;
511 _docList.ids.push(doc.nodeID);
512
513 createMarker(doc, false);
514 }
515
516 $("#map_canvas").css({"visibility": "visible", "height": ""});
517 }
518
519 updateMap();
520 })
521 .error(function()
522 {
523 console.log("Error getting subclassifiers");
524 return;
525 });
526}
527
528function performDistanceSearch(id, lat, lng, degrees)
529{
530 if(parseFloat(lat) > 180 || parseFloat(lat) < -180 || parseFloat(lng) > 180 || parseFloat(lat) < -180)
531 {
532 console.log("Latitude or longitude incorrectly formatted");
533 return;
534 }
535
536 if(lat.indexOf(".") == -1 || lng.indexOf(".") == -1 || (lat.indexOf(".") + 3) >= lat.length || (lng.indexOf(".") + 3) >= lng.length)
537 {
538 console.log("Latitude or longitude does not have the required precision for a distance search");
539 return;
540 }
541
542 var query = "";
543 for(var i = 0; i < degrees * 2; i++)
544 {
545 for (var j = 0; j < degrees * 2; j++)
546 {
547 var latDelta = (i - degrees) * 0.01;
548 var lngDelta = (j - degrees) * 0.01;
549
550 query += "(" + getDistanceQueryString(lat, latDelta, 2, "LA", ["N","S"]);
551 query += "+AND+";
552 query += getDistanceQueryString(lng, lngDelta, 2, "LN", ["E","W"]) + ")";
553
554 if(i != ((degrees * 2) - 1) || j != ((degrees * 2) - 1)){ query += "+OR+"; }
555 }
556 }
557
558 var inlineTemplate = '\
559 <xsl:template match="/" priority="5">\
560 <table id="nearbyDocs">\
561 <tr>\
562 <th><a href="javascript:sortByDistance();">Distance</a></th><th><a href="javascript:sortAlphabetically();">Document</a></th>\
563 </tr>\
564 <xsl:apply-templates select="//documentNode"/>\
565 </table>\
566 </xsl:template>\
567 \
568 <xsl:template match="documentNode" priority="5">\
569 <xsl:if test="@nodeID !=\''+id+'\'">\
570 <tr>\
571 <td>___<gsf:metadata name="Latitude"/>______<gsf:metadata name="Longitude"/>___</td>\
572 <td><gsf:link title="'+gs.text.doc.nearby_doc_tooltip+'" type="document"><gsf:metadata name="Title"/></gsf:link></td>\
573 </tr>\
574 </xsl:if>\
575 </xsl:template>';
576
577 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");
578 $.ajax(url)
579 .success(function(response)
580 {
581 response = response.replace(/<img src="[^"]*map_marker.png"[^>]*>/g, "");
582
583 var nearbyDocsArray = new Array();
584
585 var lats = new Array();
586 var lngs = new Array();
587 var matches = response.match(/___(-?[0-9\.]*)___/g);
588 for(var i = 0; i < matches.length; i += 2)
589 {
590 var matchLatFloat = parseFloat(matches[i].replace("___", ""));
591 var matchLngFloat = parseFloat(matches[i+1].replace("___", ""));
592
593 lats.push(matchLatFloat);
594 lngs.push(matchLngFloat);
595 var distance = Math.sqrt(Math.pow(matchLatFloat - parseFloat(lat), 2) + Math.pow(matchLngFloat - parseFloat(lng), 2)) * (40000.0/360.0);
596 var distanceString = "" + distance;
597 distanceString = distanceString.substring(0, 6);
598 response = response.replace(matches[i] + matches[i+1], distanceString);
599 }
600
601 var index = 0;
602 var i = 0;
603 while(true)
604 {
605 var distanceStart = response.indexOf("<td>", index);
606 if(distanceStart == -1)
607 {
608 break;
609 }
610 var distanceEnd = response.indexOf("</td>", distanceStart);
611
612 var docLinkStart = response.indexOf("<td>", distanceEnd);
613 var docLinkEnd = response.indexOf("</td>", docLinkStart);
614
615 var dist = response.substring(distanceStart + 4, distanceEnd);
616 var docLink = response.substring(docLinkStart + 4, docLinkEnd);
617
618 _nearbyDocs.push({title:docLink, distance:dist, lat:lats[i], lng:lngs[i++]});
619
620 index = docLinkEnd;
621 }
622
623 sortByDistance(lat,lng);
624
625 var toggle = $("#nearbyDocumentsToggle");
626 toggle.attr("src", gs.imageURLs.collapse);
627 gs.functions.makeToggle(toggle, $("#nearbyDocuments"));
628 });
629}
630
631var map_centering_timeout = null;
632function recenterMapF(lat, lng)
633{
634 return function() {
635 _map.setCenter(new google.maps.LatLng(lat, lng));
636 }
637}
638function recenterMap(lat, lng)
639{
640
641 _map.setCenter(new google.maps.LatLng(lat, lng));
642
643}
644function sortByDistance(base_lat,base_lng)
645{
646 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>';
647 _nearbyDocs.sort(function(a, b){return (a.distance - b.distance);});
648 for(var i = 0; i < _nearbyDocs.length; i++)
649 {
650
651 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>";
652 }
653 sortedTable += "</table>";
654
655 $("#nearbyDocuments").html(sortedTable);
656}
657function prettifyDistance(distance) {
658
659 var new_distance;
660 if (distance < 1) {
661 new_distance = (distance * 1000);
662 // Round to nearest whole number - don't need to show points of metres..
663 new_distance = Math.round(new_distance);
664 new_distance += " m";
665 }
666 else {
667 new_distance = distance +" km";
668
669 }
670 return new_distance;
671}
672
673
674
675function sortAlphabetically(base_lat, base_lng)
676{
677 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>';
678 _nearbyDocs.sort(function(a, b)
679 {
680 var firstTitleStartIndex = a.title.indexOf(">");
681 var firstTitleEndIndex = a.title.indexOf("<", firstTitleStartIndex);
682 var firstTitle = a.title.substring(firstTitleStartIndex + 1, firstTitleEndIndex);
683 var secondTitleStartIndex = b.title.indexOf(">");
684 var secondTitleEndIndex = b.title.indexOf("<", secondTitleStartIndex);
685 var secondTitle = b.title.substring(secondTitleStartIndex + 1, secondTitleEndIndex);
686 return ((firstTitle.toLowerCase() == secondTitle.toLowerCase()) ? 0 : ((firstTitle.toLowerCase() > secondTitle.toLowerCase()) ? 1 : -1));
687 });
688 for(var i = 0; i < _nearbyDocs.length; i++)
689 {
690 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>";
691 }
692 sortedTable += "</table>";
693
694 $("#nearbyDocuments").html(sortedTable);
695}
696
697function getDistanceQueryString(currentCoord, delta, precision, indexName, dirs)
698{
699 var query = "";
700 var coordFloat = parseFloat(currentCoord);
701
702 var newCoord = "" + (coordFloat + delta);
703 var beforeDec = newCoord.substring(0, newCoord.indexOf("."));
704
705 var dir = dirs[0];
706 if(coordFloat < 0)
707 {
708 dir = dirs[1];
709 beforeDec = beforeDec.substring(1);
710 }
711 beforeDec += dir;
712
713 var afterDec = newCoord.substring(newCoord.indexOf(".") + 1, newCoord.indexOf(".") + (precision) + 1);
714
715 return indexName + ":" + beforeDec + "+AND+" + indexName + ":" + afterDec;
716}
717
718function modifyFunctions()
719{
720 toggleSection = function(sectionID)
721 {
722 var section = gs.jqGet("div" + sectionID);
723 var sectionToggle = gs.jqGet("toggle" + sectionID);
724
725 if(sectionToggle == undefined)
726 {
727 return;
728 }
729
730 // Test if 'section' exists.
731 // ==> Because we're using jQuery to do this we need to test the length of the object returned
732 // http://stackoverflow.com/questions/920236/how-can-i-detect-if-a-selector-returns-null
733 if(section.length !== 0)
734 {
735 if(isExpanded(sectionID))
736 {
737 section.css("display", "none");
738 sectionToggle.attr("src", gs.imageURLs.expand);
739
740 if(openClassifiers[sectionID].length !== 0) //if(openClassifiers[sectionID] != undefined)
741 {
742 delete openClassifiers[sectionID];
743 }
744 }
745 else
746 {
747 section.css("display", "block");
748 sectionToggle.attr("src", gs.imageURLs.collapse);
749 openClassifiers[sectionID] = true;
750 }
751 updateOpenClassifiers();
752 updateMap();
753 }
754 else
755 {
756 httpRequest(sectionID);
757 }
758 }
759
760 httpRequest = function(sectionID)
761 {
762 if(!inProgress[sectionID])
763 {
764 inProgress[sectionID] = true;
765
766 var sectionToggle = gs.jqGet("toggle" + sectionID);
767 sectionToggle.attr("src", gs.imageURLs.loading);
768
769 var url = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/browse/" + sectionID.replace(/\./g, "/") + "?excerptid=div" + sectionID;
770
771 if(gs.cgiParams.berrybasket == "on")
772 {
773 url = url + "&berrybasket=on";
774 }
775
776 if(url.indexOf("#") != -1)
777 {
778 url = url.substring(0, url.indexOf("#"));
779 }
780
781 $.ajax(url)
782 .success(function(responseText)
783 {
784 var newDiv = $("<div>");
785 var sibling = gs.jqGet("title" + sectionID);
786 sibling.after(newDiv);
787
788 newDiv.html(responseText);
789 sectionToggle.attr("src", gs.imageURLs.collapse);
790 openClassifiers[sectionID] = true;
791
792 if(gs.cgiParams.berrybasket == "on")
793 {
794 checkout();
795 }
796 updateOpenClassifiers();
797 getSubClassifier(sectionID);
798 })
799 .error(function()
800 {
801 sectionToggle.attr("src", gs.imageURLs.expand);
802 })
803 .complete(function()
804 {
805 inProgress[sectionID] = false;
806 busy = false;
807 });
808 }
809 }
810}
Note: See TracBrowser for help on using the repository browser.