[33146] | 1 | var mapEnabled = true; // variable to detect when map-scripts have been included into document_scripts.js and classifier_scripts.js
|
---|
| 2 |
|
---|
[32771] | 3 | //var newLat, newLng = 0;
|
---|
[25023] | 4 | var _docList = new Array();
|
---|
| 5 | _docList.ids = new Array();
|
---|
| 6 | _docList.getDocByIndex = function(index)
|
---|
| 7 | {
|
---|
| 8 | return _docList[_docList.ids[index]];
|
---|
| 9 | };
|
---|
| 10 |
|
---|
| 11 | var _map;
|
---|
| 12 | var _intervalHandle;
|
---|
| 13 | var _baseURL = document.URL.substring(0, document.URL.indexOf("?") + 1);
|
---|
| 14 | var _retrievedClassifiers = new Array();
|
---|
| 15 | var _preventLoopingSingleMarker = false;
|
---|
| 16 | var _searchRunning = false;
|
---|
| 17 | var _nearbyDocs = new Array();
|
---|
[33168] | 18 | var _scrollThroughDefault = true; // TODO: default starts at true
|
---|
[25023] | 19 |
|
---|
| 20 | function initializeMapScripts()
|
---|
[33168] | 21 | {
|
---|
| 22 | //console.log("@@@@ initializeMapScripts()");
|
---|
| 23 |
|
---|
[26429] | 24 | var jsonNodeDiv = $("#jsonNodes");
|
---|
| 25 | if(jsonNodeDiv.length)
|
---|
[25023] | 26 | {
|
---|
[33128] | 27 | //console.log("@@@ JSON node div html: " + jsonNodeDiv.html());
|
---|
[33126] | 28 | var jsonNodes = eval(jsonNodeDiv.html());
|
---|
[33125] | 29 |
|
---|
[33168] | 30 | renderMap();
|
---|
[25023] | 31 | if(jsonNodes && jsonNodes.length > 0)
|
---|
| 32 | {
|
---|
| 33 | for(var i = 0; i < jsonNodes.length; i++)
|
---|
| 34 | {
|
---|
| 35 | _docList[jsonNodes[i].nodeID] = jsonNodes[i];
|
---|
[33128] | 36 | _docList.ids.push(jsonNodes[i].nodeID);
|
---|
| 37 | createMarkers(jsonNodes[i], true);
|
---|
[25023] | 38 | }
|
---|
| 39 | updateMap();
|
---|
| 40 | }
|
---|
[25369] | 41 | else
|
---|
| 42 | {
|
---|
[33128] | 43 | //hiding the map
|
---|
[33168] | 44 | mapEnabled = false;
|
---|
| 45 | $("#map_canvas").css({display:"none"});
|
---|
| 46 | return;
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
[25023] | 49 | _docList.loopIndex = 0;
|
---|
| 50 |
|
---|
| 51 | if(_docList.ids.length > 1)
|
---|
| 52 | {
|
---|
[32604] | 53 | var startStopCheckbox = $("<input>", {"type": "checkbox", "checked": _scrollThroughDefault, "id": "scrollCheckbox"});
|
---|
[26429] | 54 | startStopCheckbox.click(function()
|
---|
[26160] | 55 | {
|
---|
[30736] | 56 | // http://stackoverflow.com/questions/901712/how-to-check-if-a-checkbox-is-checked-in-jquery
|
---|
| 57 | // http://stackoverflow.com/questions/5270689/attrchecked-checked-does-not-work
|
---|
| 58 |
|
---|
| 59 | if($('#scrollCheckbox').is(':checked')) // OR: if(document.getElementById('scrollCheckbox').checked)
|
---|
| 60 | {
|
---|
[26160] | 61 | if(_intervalHandle == null)
|
---|
| 62 | {
|
---|
| 63 | _intervalHandle = setInterval(loopThroughMarkers, 2000);
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 | else
|
---|
| 67 | {
|
---|
| 68 | clearInterval(_intervalHandle);
|
---|
| 69 | _intervalHandle = null;
|
---|
| 70 | }
|
---|
[26429] | 71 | });
|
---|
[26160] | 72 |
|
---|
[26429] | 73 | var label = $("<span>Scroll through places</span>");
|
---|
| 74 | var container = $("<div>", {"class": "ui-widget-header ui-corner-all", "style": "clear:right; float:right; padding:0px 5px 3px 0px;"});
|
---|
| 75 | container.append(startStopCheckbox);
|
---|
| 76 | container.append(label);
|
---|
[26160] | 77 |
|
---|
| 78 | $(container).insertAfter("#map_canvas");
|
---|
[32604] | 79 |
|
---|
| 80 | if (_scrollThroughDefault) {
|
---|
| 81 | _intervalHandle = setInterval(loopThroughMarkers, 2000);
|
---|
| 82 | }
|
---|
[26160] | 83 |
|
---|
[25023] | 84 | }
|
---|
| 85 | }
|
---|
| 86 |
|
---|
[33168] | 87 | function renderMap()
|
---|
[25023] | 88 | {
|
---|
[33168] | 89 | //console.log("@@@@in map-scripts::renderMap()");
|
---|
[25023] | 90 | var myOptions =
|
---|
[32607] | 91 | {
|
---|
[25023] | 92 | zoom: 2,
|
---|
| 93 | center: new google.maps.LatLng(0, 0),
|
---|
| 94 | mapTypeId: google.maps.MapTypeId.HYBRID
|
---|
| 95 | };
|
---|
[32771] | 96 | var $map_canvas = $("#map_canvas");
|
---|
| 97 |
|
---|
| 98 | if ($map_canvas.length > 0) {
|
---|
[33168] | 99 | //console.log("docList is " + _docList.toString());
|
---|
[32771] | 100 | _map = new google.maps.Map($map_canvas[0], myOptions);
|
---|
[33168] | 101 | //console.log("@@@ created Google _map");
|
---|
| 102 |
|
---|
[32771] | 103 | google.maps.event.addListener(_map, 'bounds_changed', performSearchForMarkers);
|
---|
| 104 | }
|
---|
[25023] | 105 | }
|
---|
| 106 |
|
---|
| 107 | function performSearchForMarkers()
|
---|
| 108 | {
|
---|
[33168] | 109 | //console.log("@@@ performSearchForMarkers()");
|
---|
| 110 |
|
---|
| 111 | var bounds = _map.getBounds();
|
---|
| 112 | var ne = bounds.getNorthEast();
|
---|
| 113 | var sw = bounds.getSouthWest();
|
---|
| 114 |
|
---|
| 115 | //console.log("bounds: ne = " + ne + ", sw = " + sw);
|
---|
| 116 |
|
---|
| 117 |
|
---|
[25023] | 118 | if(_searchRunning)
|
---|
| 119 | {
|
---|
[33168] | 120 | //console.log("*** performSearchForMarkers(): already running search => not initiating an additional search");
|
---|
[25023] | 121 | return;
|
---|
| 122 | }
|
---|
| 123 |
|
---|
[33125] | 124 |
|
---|
[25023] | 125 | _searchRunning = true;
|
---|
| 126 |
|
---|
| 127 | var bounds = _map.getBounds();
|
---|
| 128 |
|
---|
| 129 | var neLat = bounds.getNorthEast().lat();
|
---|
| 130 | var neLng = bounds.getNorthEast().lng();
|
---|
| 131 | var swLat = bounds.getSouthWest().lat();
|
---|
| 132 | var swLng = bounds.getSouthWest().lng();
|
---|
| 133 |
|
---|
| 134 | var latDistance = neLat - swLat;
|
---|
| 135 | var lngDistance = neLng - swLng;
|
---|
| 136 |
|
---|
| 137 | //Check which increment to use for latitude (i.e. 0.001, 0.01, 0.1 or 1 degree increments)
|
---|
| 138 | var latDelta;
|
---|
| 139 | var latPrecision;
|
---|
| 140 | for(var i = 3; i >= 0; i--)
|
---|
| 141 | {
|
---|
| 142 | latDelta = (1 / Math.pow(10, i));
|
---|
| 143 | if((latDistance / latDelta) <= 5 || latDelta == 1)
|
---|
| 144 | {
|
---|
| 145 | latPrecision = i;
|
---|
| 146 | break;
|
---|
| 147 | }
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | //Check which increment to use for longitude (i.e. 0.001, 0.01, 0.1 or 1 degree increments)
|
---|
| 151 | var lngDelta;
|
---|
[33185] | 152 | var lngPrecision;
|
---|
[25023] | 153 | for(var i = 3; i >= 0; i--)
|
---|
| 154 | {
|
---|
| 155 | lngDelta = (1 / Math.pow(10, i));
|
---|
| 156 | if((lngDistance / lngDelta) <= 5 || lngDelta == 1)
|
---|
| 157 | {
|
---|
| 158 | lngPrecision = i;
|
---|
| 159 | break;
|
---|
| 160 | }
|
---|
| 161 | }
|
---|
[32607] | 162 |
|
---|
| 163 | if(latDelta == 0.1){latDelta = 1; latPrecision = 0; }
|
---|
| 164 | if(lngDelta == 0.1){lngDelta = 1; lngPrecision = 0; }
|
---|
[25023] | 165 |
|
---|
[33125] | 166 | /*
|
---|
[25023] | 167 | var query = "";
|
---|
| 168 | for(var i = 0; i <= Math.floor(latDistance / latDelta) + 1; i++)
|
---|
| 169 | {
|
---|
| 170 | for(var j = 0; j <= Math.floor(lngDistance / lngDelta) + 1; j++)
|
---|
| 171 | {
|
---|
| 172 | //Some necessary variables
|
---|
| 173 | var newLat = neLat - (latDelta * i);
|
---|
| 174 | var newLatString = "" + newLat;
|
---|
| 175 | var newLatTrunc;
|
---|
| 176 | if(newLat < 0){newLatTrunc = Math.ceil(newLat);}
|
---|
| 177 | else{newLatTrunc = Math.floor(newLat);}
|
---|
| 178 |
|
---|
| 179 | var newLng = neLng - (lngDelta * j);
|
---|
| 180 | var newLngString = "" + newLng;
|
---|
| 181 | var newLngTrunc;
|
---|
| 182 | if(newLng < 0){newLngTrunc = Math.ceil(newLng);}
|
---|
| 183 | else{newLngTrunc = Math.floor(newLng);}
|
---|
| 184 |
|
---|
| 185 | //Construct query
|
---|
| 186 | query += "(";
|
---|
| 187 | query += "LA:" + coordToAbsDirected(newLatTrunc, "lat");
|
---|
| 188 | if(latDelta != 1)
|
---|
| 189 | {
|
---|
| 190 | query += "+AND+";
|
---|
| 191 | query += "LA:" + newLatString.substring(newLatString.indexOf(".") + 1, newLatString.indexOf(".") + latPrecision + 1);
|
---|
| 192 | }
|
---|
| 193 | query += "+AND+";
|
---|
| 194 | query += "LN:" + coordToAbsDirected(newLngTrunc, "lng");
|
---|
| 195 | if(lngDelta != 1)
|
---|
| 196 | {
|
---|
| 197 | query += "+AND+";
|
---|
| 198 | query += "LN:" + newLngString.substring(newLngString.indexOf(".") + 1, newLngString.indexOf(".") + lngPrecision + 1);
|
---|
| 199 | }
|
---|
| 200 | query += ")";
|
---|
| 201 |
|
---|
| 202 | if(i != (Math.floor(latDistance / latDelta) + 1) || j != (Math.floor(lngDistance / lngDelta) + 1)){ query += "+OR+"; }
|
---|
| 203 | }
|
---|
| 204 | }
|
---|
[33125] | 205 | */
|
---|
| 206 | var query = "";
|
---|
| 207 | var iMax = Math.floor(latDistance / latDelta) + 1;
|
---|
[33185] | 208 | var jMax = Math.floor(lngDistance / lngDelta) + 1;
|
---|
[33125] | 209 | for(var i = 0; i <= iMax; i++) //for(var i = 0; i <= Math.floor(latDistance / latDelta) + 1; i++)
|
---|
| 210 | {
|
---|
| 211 | for(var j = 0; j <= jMax; j++) //for(var j = 0; j <= Math.floor(lngDistance / lngDelta) + 1; j++)
|
---|
| 212 | {
|
---|
| 213 | //Some necessary variables
|
---|
| 214 | var newLat = neLat - (latDelta * i);
|
---|
| 215 | var newLatString = "" + newLat;
|
---|
| 216 | var newLatTrunc;
|
---|
| 217 | if(newLat < 0){newLatTrunc = Math.ceil(newLat);}
|
---|
| 218 | else{newLatTrunc = Math.floor(newLat);}
|
---|
| 219 |
|
---|
| 220 | var newLng = neLng - (lngDelta * j);
|
---|
| 221 | var newLngString = "" + newLng;
|
---|
| 222 | var newLngTrunc;
|
---|
| 223 | if(newLng < 0){newLngTrunc = Math.ceil(newLng);}
|
---|
| 224 | else{newLngTrunc = Math.floor(newLng);}
|
---|
| 225 |
|
---|
| 226 | //Construct query
|
---|
| 227 | query += "(";
|
---|
| 228 | query += "CS:\"" + coordToAbsDirected(newLatTrunc, "lat");
|
---|
| 229 | //query += "CS:\"" + coordToAbsDirected(newLatTrunc, "lat") + "\" \"" + coordToAbsDirected(newLngTrunc, "lng") + "\""; //query += "LA:" + coordToAbsDirected(newLatTrunc, "lat");
|
---|
| 230 | if(latDelta != 1)
|
---|
| 231 | {
|
---|
| 232 | query += newLatString.substring(newLatString.indexOf(".") + 1, newLatString.indexOf(".") + latPrecision + 1);
|
---|
| 233 | }
|
---|
| 234 | query += " ";
|
---|
| 235 | //query += "+AND+";
|
---|
| 236 |
|
---|
| 237 | //query += "LN:" + coordToAbsDirected(newLngTrunc, "lng");
|
---|
| 238 | query += coordToAbsDirected(newLngTrunc, "lng");
|
---|
| 239 | if(lngDelta != 1)
|
---|
| 240 | {
|
---|
| 241 | query += newLngString.substring(newLngString.indexOf(".") + 1, newLngString.indexOf(".") + lngPrecision + 1);
|
---|
| 242 | }
|
---|
| 243 | query += "\"";
|
---|
| 244 | query += ")";
|
---|
| 245 |
|
---|
| 246 | //if(i != (Math.floor(latDistance / latDelta) + 1) || j != (Math.floor(lngDistance / lngDelta) + 1)){ query += "+OR+"; }
|
---|
| 247 | if(i != iMax || j != jMax){ query += "+OR+"; }
|
---|
| 248 | }
|
---|
| 249 | }
|
---|
[25023] | 250 |
|
---|
[33125] | 251 | // This works, why not from the double loop above?
|
---|
| 252 | //query = "(CS:\"" + coordToAbsDirected(newLatTrunc, "lat") + " " + coordToAbsDirected(newLngTrunc, "lng") + "\")";
|
---|
| 253 | //alert("@@@@in map-scripts::performSearchForMarkers() - query: " + query);
|
---|
| 254 |
|
---|
[30736] | 255 | //var url = gs.xsltParams.library_name + "?a=q&s=RawQuery&rt=rd&c=" + gs.cgiParams.c + "&s1.rawquery=" + query + "&excerptid=jsonNodes";
|
---|
| 256 | var url = gs.xsltParams.library_name;
|
---|
| 257 | var data = "a=q&s=RawQuery&rt=rd&c=" + gs.cgiParams.c + "&s1.rawquery=" + query + "&excerptid=jsonNodes";
|
---|
[33168] | 258 | //console.log("*** performSearchForMarkers(): rawQuery query data = " + query);
|
---|
| 259 |
|
---|
[30736] | 260 | $.ajax({type:"POST", url:url, data:data})
|
---|
[26429] | 261 | .success(function(responseText)
|
---|
[25023] | 262 | {
|
---|
[30736] | 263 | //console.log("*** responseText (first 250) = " + responseText.substring(0,256));
|
---|
| 264 |
|
---|
[26429] | 265 | if(responseText.search("id=\"jsonNodes") != -1)
|
---|
[25023] | 266 | {
|
---|
[26429] | 267 | var startIndex = responseText.indexOf(">");
|
---|
| 268 | var endIndex = responseText.indexOf("</");
|
---|
| 269 |
|
---|
[33128] | 270 | //console.log("@@@@ performSearch, got response: " + responseText);
|
---|
[33125] | 271 |
|
---|
[26429] | 272 | var jsonNodes = eval(responseText.substring(startIndex+1, endIndex));
|
---|
[33168] | 273 | //console.log("Number of matches returned from ajax rawQuery search = " + jsonNodes.length);
|
---|
[26429] | 274 | if(jsonNodes && jsonNodes.length > 0)
|
---|
[25023] | 275 | {
|
---|
[26429] | 276 | for(var i = 0; i < jsonNodes.length; i++)
|
---|
[25023] | 277 | {
|
---|
[26429] | 278 | var doc = jsonNodes[i];
|
---|
| 279 |
|
---|
| 280 | var found = false;
|
---|
| 281 | for(var j = 0; j < _docList.ids.length; j++){if(doc.nodeID == _docList.ids[j]){found = true; break;}}
|
---|
| 282 |
|
---|
| 283 | if(!found)
|
---|
[25023] | 284 | {
|
---|
[26429] | 285 | _docList[doc.nodeID] = doc;
|
---|
| 286 | _docList.ids.push(doc.nodeID);
|
---|
[25023] | 287 |
|
---|
[33128] | 288 | createMarkers(doc, false);
|
---|
[25023] | 289 | }
|
---|
| 290 | }
|
---|
| 291 | }
|
---|
| 292 | }
|
---|
[26429] | 293 | else
|
---|
| 294 | {
|
---|
| 295 | console.log("No JSON information received");
|
---|
| 296 | }
|
---|
| 297 |
|
---|
| 298 | _searchRunning = false;
|
---|
[30736] | 299 | }).fail(function(responseText, textStatus, errorThrown) // fail() has replaced error(), http://api.jquery.com/jquery.ajax/
|
---|
| 300 | {
|
---|
| 301 | console.log("In map-scripts.performSearchForMarkers(): Got an error in ajax call");
|
---|
| 302 | _searchRunning = false;
|
---|
[26429] | 303 | });
|
---|
[25023] | 304 | }
|
---|
| 305 |
|
---|
| 306 | function coordToAbsDirected(coord, type)
|
---|
| 307 | {
|
---|
| 308 | var value = "" + coord;
|
---|
| 309 | if(coord < 0)
|
---|
| 310 | {
|
---|
| 311 | value = value.substring(1);
|
---|
| 312 | if(type == "lat")
|
---|
| 313 | {
|
---|
| 314 | value += "S";
|
---|
| 315 | }
|
---|
| 316 | else
|
---|
| 317 | {
|
---|
| 318 | value += "W";
|
---|
| 319 | }
|
---|
| 320 | }
|
---|
| 321 | else
|
---|
| 322 | {
|
---|
| 323 | if(type == "lat")
|
---|
| 324 | {
|
---|
| 325 | value += "N";
|
---|
| 326 | }
|
---|
| 327 | else
|
---|
| 328 | {
|
---|
| 329 | value += "E";
|
---|
| 330 | }
|
---|
| 331 | }
|
---|
| 332 |
|
---|
| 333 | return value;
|
---|
| 334 | }
|
---|
| 335 |
|
---|
| 336 | function updateMap()
|
---|
| 337 | {
|
---|
[33168] | 338 | //console.log("@@@ updateMap()");
|
---|
[32607] | 339 | var markersOnMap = 0;
|
---|
| 340 | var bounds = new google.maps.LatLngBounds();
|
---|
[25023] | 341 | for(var i = 0; i < _docList.ids.length; i++)
|
---|
| 342 | {
|
---|
| 343 | var doc = _docList.getDocByIndex(i);
|
---|
| 344 | if(doc.parentCL && doc.parentCL.style.display == "none")
|
---|
| 345 | {
|
---|
[33140] | 346 | if(doc.shapes) {
|
---|
| 347 | for(var x = 0; x < doc.shapes.length; x++) {
|
---|
| 348 | doc.shapes[x].setVisible(false);
|
---|
| 349 | }
|
---|
| 350 | } else {
|
---|
| 351 | doc.marker.setVisible(false);
|
---|
| 352 | }
|
---|
[25023] | 353 | continue;
|
---|
| 354 | }
|
---|
| 355 | else
|
---|
| 356 | {
|
---|
[33140] | 357 | if(doc.shapes) {
|
---|
[33168] | 358 | for(var x = 0; x < doc.shapes.length; x++) {
|
---|
[33140] | 359 | doc.shapes[x].setVisible(true);
|
---|
[33169] | 360 | markersOnMap += ShapesUtil.numberOfCoordinatesInBounds(doc.shapes[x]);
|
---|
| 361 | }
|
---|
[33140] | 362 | } else {
|
---|
| 363 | doc.marker.setVisible(true);
|
---|
[33168] | 364 | markersOnMap++;
|
---|
[33140] | 365 | }
|
---|
[33168] | 366 |
|
---|
[25023] | 367 | }
|
---|
[33128] | 368 |
|
---|
[33173] | 369 | if(doc.shapes) {
|
---|
| 370 | console.log("@@@@ HERE IN doc.shapes");
|
---|
[33185] | 371 | var docSection_overlay_bounds = ShapesUtil.overlayBounds(doc.shapes);
|
---|
| 372 | // We now have the current document or document subsection's bounds.
|
---|
| 373 | // Use this to extend the overall bounds (the cumulative bounds for all nearby documents,
|
---|
| 374 | // or at least the cumulative bounds for this document with all its subsections).
|
---|
| 375 | bounds.extend(docSection_overlay_bounds.getNorthEast());
|
---|
| 376 | bounds.extend(docSection_overlay_bounds.getSouthWest());
|
---|
[33168] | 377 | }
|
---|
[33125] | 378 | else {
|
---|
[33168] | 379 | var doc_latlng = new google.maps.LatLng(doc.lat, doc.lng);
|
---|
| 380 | bounds.extend(doc_latlng);
|
---|
[33125] | 381 | }
|
---|
[25023] | 382 | }
|
---|
| 383 |
|
---|
[33168] | 384 | //console.log("@@@ UpdateMap() : bounds = " + bounds);
|
---|
[32607] | 385 | if(markersOnMap > 1)
|
---|
| 386 | {
|
---|
[33168] | 387 | _map.fitBounds(bounds);
|
---|
[32607] | 388 | } else if (markersOnMap == 1) {
|
---|
[33168] | 389 | //console.log("@@@ updating bounds with " + markersOnMap + " markers on the map");
|
---|
| 390 | //console.log(bounds);
|
---|
| 391 |
|
---|
| 392 | // sometimes a single point bounds are too small for the map to display, so use center and zoom instead of fitbounds.
|
---|
| 393 | _map.setCenter(bounds.getCenter());
|
---|
| 394 | _map.setZoom(18); // arbitrary value that looked nice for my example
|
---|
[32607] | 395 | }
|
---|
[25023] | 396 | }
|
---|
| 397 |
|
---|
[33148] | 398 | // TODO: FUNCTION DUPLICATED IN panoramaViewer.js
|
---|
[33125] | 399 | function getLatLngForCoord(coord) {
|
---|
| 400 |
|
---|
| 401 | // https://stackoverflow.com/questions/2559318/how-to-check-for-an-undefined-or-null-variable-in-javascript
|
---|
| 402 | if(!coord) {
|
---|
| 403 | // some_variable is either null, undefined, 0, NaN, false, or an empty string
|
---|
| 404 | console.log("@@@@ In map-scripts::getLatLngForCoord(): no or invalid coord info");
|
---|
| 405 | return null;
|
---|
| 406 | }
|
---|
| 407 |
|
---|
| 408 | // coord is of the form: "37S77 157E53"
|
---|
| 409 | // lat will be 37S77, lng 157E53.
|
---|
| 410 | var indexOfSpace = coord.indexOf(" ");
|
---|
| 411 | if(indexOfSpace === -1) {
|
---|
| 412 | console.log("@@@@ In map-scripts::getLatLngForCoord(): bad format for coord " + coord);
|
---|
| 413 | return null;
|
---|
| 414 | }
|
---|
| 415 | var latitude = coord.substring(0, indexOfSpace);
|
---|
| 416 | var longitude = coord.substring(indexOfSpace+1);
|
---|
| 417 | return {lat: latitude, lng: longitude}; // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects
|
---|
| 418 | }
|
---|
| 419 |
|
---|
[25023] | 420 | function loopThroughMarkers()
|
---|
| 421 | {
|
---|
| 422 | if(_docList.ids.length == 0)
|
---|
| 423 | {
|
---|
| 424 | return;
|
---|
| 425 | }
|
---|
| 426 |
|
---|
| 427 | var visibleMarkers = new Array();
|
---|
| 428 | for(var i = 0; i < _docList.ids.length; i++)
|
---|
| 429 | {
|
---|
[33145] | 430 | var doc = _docList.getDocByIndex(i);
|
---|
[33184] | 431 | if(typeof doc.shapes !== 'undefined') {
|
---|
[33168] | 432 | for(var x = 0; x < doc.shapes.length; x++) {
|
---|
[33184] | 433 | var shape = doc.shapes[x];
|
---|
[33168] | 434 | if(shape.type === google.maps.drawing.OverlayType.MARKER && shape.getVisible())
|
---|
| 435 | {
|
---|
| 436 | visibleMarkers.push(doc);
|
---|
| 437 | }
|
---|
| 438 | }
|
---|
| 439 | }
|
---|
| 440 | if(doc.marker && doc.marker.getVisible())
|
---|
[25023] | 441 | {
|
---|
[33168] | 442 | visibleMarkers.push(doc);
|
---|
| 443 | }
|
---|
[25023] | 444 | }
|
---|
| 445 |
|
---|
| 446 | if(visibleMarkers.length < 2)
|
---|
| 447 | {
|
---|
| 448 | clearAllInfoBoxes();
|
---|
| 449 | return;
|
---|
| 450 | }
|
---|
| 451 |
|
---|
[25868] | 452 | clearAllInfoBoxes();
|
---|
| 453 |
|
---|
| 454 | var elem = null;
|
---|
[33168] | 455 | while(!elem) // TODO: why redefine elem? Why does this work, and only this, but not while(true) or while(doc.marker) or while(!AnythingFalse)???
|
---|
| 456 | // Some clever behaviour here, but no documentation on the cleverness. Hard to understand
|
---|
[25023] | 457 | {
|
---|
[25868] | 458 | if(_docList.loopIndex >= visibleMarkers.length)
|
---|
| 459 | {
|
---|
| 460 | _docList.loopIndex = 0;
|
---|
| 461 | }
|
---|
[25023] | 462 |
|
---|
[25868] | 463 | var doc = visibleMarkers[_docList.loopIndex];
|
---|
[33168] | 464 | elem = gs.jqGet("div" + doc.nodeID); // TODO: this used to redefine elem by doing var elem = <....>
|
---|
[26429] | 465 | if(elem.length)
|
---|
[25868] | 466 | {
|
---|
[26429] | 467 | elem.css("background", "#BBFFBB");
|
---|
| 468 | setTimeout(function(){elem.css("background", "");}, 2000);
|
---|
[25868] | 469 | }
|
---|
[33168] | 470 | _docList.loopIndex ++;
|
---|
| 471 | }
|
---|
| 472 | //console.log("@@@@ DOC:");
|
---|
| 473 | //console.log(doc);
|
---|
| 474 |
|
---|
| 475 | if(doc.marker) {
|
---|
| 476 | doc.marker.markerInfo.open(_map, doc.marker); // TODO: how does doc have a value here? Where is the value set at this block level?
|
---|
[25023] | 477 | }
|
---|
[33168] | 478 |
|
---|
| 479 | if(doc.shapes) {
|
---|
| 480 | for(var x = 0; x < doc.shapes.length; x++) {
|
---|
| 481 | var shape = doc.shapes[i];
|
---|
| 482 | if(shape.type === google.maps.drawing.OverlayType.MARKER) {
|
---|
| 483 | shape.markerInfo.open(_map, shape);
|
---|
| 484 | } else {
|
---|
| 485 | shape.markerInfo.open(_map);
|
---|
| 486 | }
|
---|
| 487 | }
|
---|
| 488 | }
|
---|
[25023] | 489 | }
|
---|
| 490 |
|
---|
| 491 |
|
---|
| 492 | function focusDocument(id)
|
---|
[33172] | 493 | {
|
---|
[25023] | 494 | var doc = _docList[id];
|
---|
| 495 | if(doc)
|
---|
| 496 | {
|
---|
| 497 | clearInterval(_intervalHandle);
|
---|
[26160] | 498 | _intervalHandle = null;
|
---|
[33173] | 499 |
|
---|
[33172] | 500 | if(doc.shapes) {
|
---|
| 501 | var docShapesBounds = ShapesUtil.overlayBounds(doc.shapes);
|
---|
| 502 | _map.panToBounds(docShapesBounds); // https://developers.google.com/maps/documentation/javascript/reference/map#Map.panToBounds
|
---|
[33125] | 503 | } else {
|
---|
| 504 | _map.panTo(new google.maps.LatLng(doc.lat, doc.lng));
|
---|
| 505 | }
|
---|
[33172] | 506 |
|
---|
[25023] | 507 | clearAllInfoBoxes();
|
---|
[33172] | 508 | if(doc.shapes) { // TODO
|
---|
| 509 | //console.log("Opening infowindow for doc " + doc.nodeID);
|
---|
| 510 | for(var x = 0; x < doc.shapes.length; x++) {
|
---|
| 511 | if(doc.shapes[x].markerInfo) {
|
---|
| 512 | doc.shapes[x].markerInfo.open(_map); // label
|
---|
| 513 | }
|
---|
| 514 | else {
|
---|
| 515 | console.log("No infowindow for doc " + doc.nodeID + "'s shape " + doc.shapes[x].type);
|
---|
| 516 | }
|
---|
| 517 | }
|
---|
| 518 | //openInfoBoxes(doc);
|
---|
| 519 | } else { // only Lat and Lng meta, so we have just one marker per doc, which will have the doc title not label
|
---|
| 520 | doc.marker.markerInfo.open(_map, doc.marker); // doc title
|
---|
| 521 | }
|
---|
[26429] | 522 | var scrollCheckbox = $("#scrollCheckbox");
|
---|
[26161] | 523 | if(scrollCheckbox.checked)
|
---|
| 524 | {
|
---|
| 525 | scrollCheckbox.checked = false;
|
---|
| 526 | }
|
---|
[25023] | 527 | }
|
---|
| 528 | }
|
---|
| 529 |
|
---|
| 530 | function clearAllInfoBoxes()
|
---|
| 531 | {
|
---|
| 532 | for(var i = 0; i < _docList.ids.length; i++)
|
---|
| 533 | {
|
---|
| 534 | var doc = _docList.getDocByIndex(i);
|
---|
[33172] | 535 |
|
---|
| 536 | if(doc.shapes) {
|
---|
| 537 | for(var x = 0; x < doc.shapes.length; x++) {
|
---|
| 538 | if(doc.shapes[x].markerInfo) {
|
---|
| 539 | //console.log("Closing infowindow for doc " + _docList.ids[i]);
|
---|
| 540 | doc.shapes[x].markerInfo.close();
|
---|
| 541 | }
|
---|
| 542 | }
|
---|
| 543 | }
|
---|
| 544 | else { // only Lat and Lng meta, so we have just one marker per doc
|
---|
| 545 | doc.marker.markerInfo.close();
|
---|
| 546 | }
|
---|
[25023] | 547 | }
|
---|
| 548 | }
|
---|
| 549 |
|
---|
[33140] | 550 | function createMarkers(doc, mainMarker) {
|
---|
| 551 | if(doc.mapoverlay) {
|
---|
| 552 | //console.log("Have shapes: " + doc.mapoverlay.toString());
|
---|
| 553 | createShapes(doc, mainMarker);
|
---|
| 554 | } else { // backwards compatible to deal with Lat and Lng meta stored for doc
|
---|
[33125] | 555 | pos = new google.maps.LatLng(doc.lat,doc.lng);
|
---|
[33128] | 556 | createMarker(doc, pos, mainMarker);
|
---|
[33125] | 557 | }
|
---|
[33128] | 558 | }
|
---|
| 559 |
|
---|
[33140] | 560 | function addInfoMarker(doc, shape) {
|
---|
| 561 |
|
---|
| 562 | if(!shape.description) {
|
---|
[33173] | 563 | console.log("@@@@ " + shape.type.toString() + " had no description/label");
|
---|
[33140] | 564 | return;
|
---|
| 565 | }
|
---|
| 566 |
|
---|
| 567 | // else add an InfoWindow for this shape using the label (shape.description)
|
---|
| 568 |
|
---|
| 569 | // https://developers.google.com/maps/documentation/javascript/infowindows
|
---|
| 570 | // An InfoWindow's "position contains the LatLng at which this info window is anchored.
|
---|
| 571 | // Note: An InfoWindow may be attached either to a Marker object (in which case its position is based on the marker's location)
|
---|
| 572 | // or on the map itself at a specified LatLng. Opening an info window on a marker will automatically update the position."
|
---|
| 573 | var infoWindow = new google.maps.InfoWindow({content:shape.description}); // NOTE: if not setting content or position properties
|
---|
| 574 | // inside this constructor, need to call setContent/setPosition to set them
|
---|
| 575 |
|
---|
| 576 | if(shape.type === google.maps.drawing.OverlayType.MARKER) {
|
---|
[33172] | 577 | var marker = shape;
|
---|
| 578 | console.log("Coord for marker is " + coord.toString());
|
---|
| 579 |
|
---|
[33143] | 580 | marker.addListener('mouseover', function() {
|
---|
[33140] | 581 | infoWindow.open(_map, marker);
|
---|
[33143] | 582 | });
|
---|
| 583 | marker.addListener('mouseout', function() {
|
---|
| 584 | infoWindow.close();
|
---|
| 585 | });
|
---|
[33140] | 586 | attachClickHandler(marker, doc.nodeID); // do what the original code used to do here
|
---|
| 587 | }
|
---|
| 588 | else {
|
---|
| 589 | var coord = ShapesUtil.getLabelCoordinate(shape);
|
---|
| 590 | console.log("Coord for " + shape.type.toString() + " is " + coord.toString());
|
---|
| 591 | infoWindow.setPosition(coord);
|
---|
| 592 | shape.addListener('mouseover', function() {
|
---|
| 593 | infoWindow.open(_map);
|
---|
| 594 | });
|
---|
| 595 | shape.addListener('mouseout', function() {
|
---|
| 596 | infoWindow.close();
|
---|
| 597 | });
|
---|
| 598 | attachClickHandler(shape, doc.nodeID); // as above
|
---|
| 599 | }
|
---|
[33168] | 600 | shape.markerInfo = infoWindow;
|
---|
[33173] | 601 | //console.log("######## Added markerInfo object to shape");
|
---|
[33140] | 602 | }
|
---|
[33128] | 603 |
|
---|
[33140] | 604 | // This function will create Google Shapes/Overlays and markers out of a given doc JSONNode's doc.mapOverlay
|
---|
| 605 | // (doc.mapOverlay shapes are stored as an array of JSON) and store the shapes/overlays in the doc.shapes array.
|
---|
[33128] | 606 | // Param mainMarker: if set to true, marker is red. If false, marker is blue
|
---|
[33140] | 607 | function createShapes(doc, mainMarker)
|
---|
| 608 | {
|
---|
| 609 | // for doc.shapes: don't store JSON anymore, convert them to google Shapes overlays and store them instead
|
---|
| 610 | doc.shapes = [];
|
---|
[33168] | 611 |
|
---|
[33140] | 612 | for (var i=0; i<doc.mapoverlay.length; i++) {
|
---|
[33168] | 613 | //console.log("in: mapoverlay["+i+"] =" + JSON.stringify(doc.mapoverlay[i]));
|
---|
| 614 | var shape = ShapesUtil.JSONToShape(doc.mapoverlay[i]);
|
---|
| 615 | //console.log("out: shape = " + JSON.stringify(shape));
|
---|
| 616 |
|
---|
[33140] | 617 | doc.shapes[i] = shape;
|
---|
| 618 | shape.setMap(_map);
|
---|
[33168] | 619 | //shape["title"] = doc.title; // TODO: Think on it some more.
|
---|
[33140] | 620 |
|
---|
| 621 | // Unset editable and draggable properties of shape
|
---|
| 622 | // And for markers, which are initialised to clickable besides, undo the clickability
|
---|
| 623 | // and set them
|
---|
| 624 | if(shape.type === google.maps.drawing.OverlayType.MARKER) {
|
---|
| 625 | var marker = shape;
|
---|
| 626 | // mainMarkers should be red
|
---|
| 627 | if(!mainMarker) {
|
---|
| 628 | marker["icon"] = "interfaces/" + gs.xsltParams.interface_name + "/images/bluemarker.png";
|
---|
| 629 | }
|
---|
| 630 | marker.clickable = false; // only markers
|
---|
[33168] | 631 | /*
|
---|
| 632 | console.log("@@@ map-scripts::addInfoMarker - marker.position");
|
---|
| 633 | console.log("Lat is " + typeof(marker.position.lat()));
|
---|
| 634 | console.log(marker.position.lat());
|
---|
| 635 | console.log("Long is " + typeof(marker.position.lng()));
|
---|
| 636 | console.log(marker.position.lng());
|
---|
| 637 | */
|
---|
| 638 | } else {
|
---|
| 639 | //console.log("Creating non-marker shape.");
|
---|
[33140] | 640 | }
|
---|
| 641 |
|
---|
| 642 | shape.editable = false;
|
---|
| 643 | shape.draggable = false;
|
---|
| 644 |
|
---|
[33172] | 645 | console.log("#### calling addInfoMarker");
|
---|
[33140] | 646 | // doc[i]'s label = doc.shapes[i].description
|
---|
| 647 | addInfoMarker(doc, shape);
|
---|
[33172] | 648 | }
|
---|
[33140] | 649 |
|
---|
| 650 | var docElement = gs.jqGet("div" + doc.nodeID);
|
---|
| 651 | var parent;
|
---|
| 652 | if(docElement)
|
---|
| 653 | {
|
---|
| 654 | parent = docElement.parentNode;
|
---|
| 655 | }
|
---|
| 656 |
|
---|
| 657 | while(parent && parent.nodeName != "BODY")
|
---|
| 658 | {
|
---|
| 659 | if($(parent).attr("id") && $(parent).attr("id").search("divCL") != -1)
|
---|
| 660 | {
|
---|
| 661 | doc.parentCL = parent;
|
---|
| 662 | break;
|
---|
| 663 | }
|
---|
| 664 |
|
---|
| 665 | parent = parent.parentNode;
|
---|
| 666 | }
|
---|
| 667 | }
|
---|
| 668 |
|
---|
| 669 | // This method is only for backwards compatibility: for those collections with docs that only have Lat and Lng meta
|
---|
| 670 | // and no GPS.mapOverlay (and hence Coordinate) meta.
|
---|
| 671 | // Param mainMarker: if set to true, marker is red. If false, marker is blue
|
---|
[33128] | 672 | function createMarker(doc, pos, mainMarker)
|
---|
| 673 | {
|
---|
[33140] | 674 | var marker;
|
---|
| 675 | if(mainMarker)
|
---|
| 676 | {
|
---|
| 677 | marker = new google.maps.Marker
|
---|
| 678 | ({
|
---|
| 679 | position: pos,
|
---|
| 680 | title:doc.title,
|
---|
| 681 | map:_map
|
---|
| 682 | });
|
---|
| 683 | }
|
---|
| 684 | else
|
---|
| 685 | {
|
---|
| 686 | marker = new google.maps.Marker
|
---|
| 687 | ({
|
---|
| 688 | position: pos,
|
---|
| 689 | title:doc.title,
|
---|
| 690 | map:_map,
|
---|
| 691 | icon:"interfaces/" + gs.xsltParams.interface_name + "/images/bluemarker.png"
|
---|
| 692 | });
|
---|
| 693 | }
|
---|
| 694 |
|
---|
| 695 | var docElement = gs.jqGet("div" + doc.nodeID);
|
---|
| 696 | var parent;
|
---|
| 697 | if(docElement)
|
---|
| 698 | {
|
---|
| 699 | parent = docElement.parentNode;
|
---|
| 700 | }
|
---|
| 701 |
|
---|
| 702 | while(parent && parent.nodeName != "BODY")
|
---|
| 703 | {
|
---|
| 704 | if($(parent).attr("id") && $(parent).attr("id").search("divCL") != -1)
|
---|
| 705 | {
|
---|
| 706 | doc.parentCL = parent;
|
---|
| 707 | break;
|
---|
| 708 | }
|
---|
| 709 |
|
---|
| 710 | parent = parent.parentNode;
|
---|
| 711 | }
|
---|
| 712 |
|
---|
| 713 | var info = new google.maps.InfoWindow({content:doc.title});
|
---|
| 714 | marker.markerInfo = info;
|
---|
| 715 | doc.marker = marker;
|
---|
| 716 | attachClickHandler(marker, doc.nodeID);
|
---|
| 717 | }
|
---|
| 718 |
|
---|
| 719 | // TODO: with the following, it seems that clicking on shape expands the entire document
|
---|
| 720 | // Should it be that clicking on a shape should expand the doc section that contains that shape meta?
|
---|
| 721 | function attachClickHandler(shapeOrMarker, nodeID)
|
---|
| 722 | {
|
---|
| 723 | google.maps.event.addListener(shapeOrMarker, 'click', function()
|
---|
| 724 | {
|
---|
| 725 | 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";
|
---|
| 726 | });
|
---|
| 727 | }
|
---|
| 728 |
|
---|
[32771] | 729 | function NewLatLng(lat, lng)
|
---|
| 730 | {
|
---|
| 731 | console.log("Latitude " + lat);
|
---|
| 732 | console.log("Longitude " + lng);
|
---|
| 733 | }
|
---|
| 734 |
|
---|
[25023] | 735 | function getSubClassifier(sectionID)
|
---|
| 736 | {
|
---|
[26429] | 737 | var url = gs.xsltParams.library_name + "?a=b&rt=s&s=ClassifierBrowse&c=" + gs.cgiParams.c + "&cl=" + sectionID + "&excerptid=jsonNodes";
|
---|
| 738 | $.ajax(url)
|
---|
| 739 | .success(function(responseText)
|
---|
[25023] | 740 | {
|
---|
[26429] | 741 | var startIndex = responseText.indexOf(">");
|
---|
| 742 | var endIndex = responseText.indexOf("</");
|
---|
| 743 |
|
---|
| 744 | var jsonNodes = eval(responseText.substring(startIndex+1, endIndex));
|
---|
| 745 | if(jsonNodes && jsonNodes.length > 0)
|
---|
[25023] | 746 | {
|
---|
[26429] | 747 | for(var i = 0; i < jsonNodes.length; i++)
|
---|
[25023] | 748 | {
|
---|
[26429] | 749 | var doc = jsonNodes[i];
|
---|
| 750 | _docList[doc.nodeID] = doc;
|
---|
| 751 | _docList.ids.push(doc.nodeID);
|
---|
[25023] | 752 |
|
---|
[33147] | 753 | createMarkers(doc, true);
|
---|
[25023] | 754 | }
|
---|
| 755 |
|
---|
[26429] | 756 | $("#map_canvas").css({"visibility": "visible", "height": ""});
|
---|
[25023] | 757 | }
|
---|
[26429] | 758 |
|
---|
| 759 | updateMap();
|
---|
[33168] | 760 | //console.log("getSub Classifier -> updateMap()");
|
---|
[26429] | 761 | })
|
---|
| 762 | .error(function()
|
---|
| 763 | {
|
---|
[33168] | 764 | //console.log("Error getting subclassifiers");
|
---|
[26429] | 765 | return;
|
---|
| 766 | });
|
---|
[25023] | 767 | }
|
---|
| 768 |
|
---|
[33125] | 769 | function performDistanceSearchWithCoordinates(id, coord, degrees)
|
---|
| 770 | {
|
---|
[33127] | 771 | var coordInfo = getLatLngForCoord(coord);
|
---|
[33125] | 772 | if(!coordInfo) {
|
---|
| 773 | console.log("@@@ ERROR in map-scripts::performDistanceSearchWithCoordinates: coordInfo is null");
|
---|
| 774 | }
|
---|
| 775 | performDistanceSearch(id, coordInfo.lat, coordInfo.lng, degrees);
|
---|
| 776 | }
|
---|
| 777 |
|
---|
[25023] | 778 | function performDistanceSearch(id, lat, lng, degrees)
|
---|
| 779 | {
|
---|
| 780 | if(parseFloat(lat) > 180 || parseFloat(lat) < -180 || parseFloat(lng) > 180 || parseFloat(lat) < -180)
|
---|
| 781 | {
|
---|
| 782 | console.log("Latitude or longitude incorrectly formatted");
|
---|
| 783 | return;
|
---|
| 784 | }
|
---|
| 785 |
|
---|
| 786 | if(lat.indexOf(".") == -1 || lng.indexOf(".") == -1 || (lat.indexOf(".") + 3) >= lat.length || (lng.indexOf(".") + 3) >= lng.length)
|
---|
| 787 | {
|
---|
| 788 | console.log("Latitude or longitude does not have the required precision for a distance search");
|
---|
| 789 | return;
|
---|
| 790 | }
|
---|
| 791 |
|
---|
| 792 | var query = "";
|
---|
| 793 | for(var i = 0; i < degrees * 2; i++)
|
---|
| 794 | {
|
---|
| 795 | for (var j = 0; j < degrees * 2; j++)
|
---|
| 796 | {
|
---|
| 797 | var latDelta = (i - degrees) * 0.01;
|
---|
| 798 | var lngDelta = (j - degrees) * 0.01;
|
---|
| 799 |
|
---|
[33168] | 800 | //query += "(" + getDistanceQueryStringOldApproach(lat, latDelta, 2, "LA", ["N","S"]);
|
---|
| 801 | //query += "+AND+";
|
---|
| 802 | //query += getDistanceQueryStringOldApproach(lng, lngDelta, 2, "LN", ["E","W"]) + ")";
|
---|
[25023] | 803 |
|
---|
[33168] | 804 | query += "(" + getDistanceQueryStringTerm(lat, lng, latDelta, lngDelta, 2, "CS") + ")";
|
---|
| 805 |
|
---|
[25023] | 806 | if(i != ((degrees * 2) - 1) || j != ((degrees * 2) - 1)){ query += "+OR+"; }
|
---|
| 807 | }
|
---|
| 808 | }
|
---|
| 809 |
|
---|
| 810 | var inlineTemplate = '\
|
---|
| 811 | <xsl:template match="/" priority="5">\
|
---|
| 812 | <table id="nearbyDocs">\
|
---|
| 813 | <tr>\
|
---|
[32624] | 814 | <th><a href="javascript:sortByDistance();">Distance</a></th><th><a href="javascript:sortAlphabetically();">Document</a></th>\
|
---|
[25023] | 815 | </tr>\
|
---|
| 816 | <xsl:apply-templates select="//documentNode"/>\
|
---|
| 817 | </table>\
|
---|
| 818 | </xsl:template>\
|
---|
| 819 | \
|
---|
| 820 | <xsl:template match="documentNode" priority="5">\
|
---|
[32624] | 821 | <xsl:if test="@nodeID !=\''+id+'\'">\
|
---|
[25023] | 822 | <tr>\
|
---|
| 823 | <td>___<gsf:metadata name="Latitude"/>______<gsf:metadata name="Longitude"/>___</td>\
|
---|
[32624] | 824 | <td><gsf:link title="'+gs.text.doc.nearby_doc_tooltip+'" type="document"><gsf:metadata name="Title"/></gsf:link></td>\
|
---|
[25023] | 825 | </tr>\
|
---|
[32624] | 826 | </xsl:if>\
|
---|
[25023] | 827 | </xsl:template>';
|
---|
[32624] | 828 |
|
---|
| 829 | 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");
|
---|
[26429] | 830 | $.ajax(url)
|
---|
| 831 | .success(function(response)
|
---|
[25023] | 832 | {
|
---|
[26429] | 833 | response = response.replace(/<img src="[^"]*map_marker.png"[^>]*>/g, "");
|
---|
[25023] | 834 |
|
---|
[26429] | 835 | var nearbyDocsArray = new Array();
|
---|
[25023] | 836 |
|
---|
[26429] | 837 | var lats = new Array();
|
---|
| 838 | var lngs = new Array();
|
---|
| 839 | var matches = response.match(/___(-?[0-9\.]*)___/g);
|
---|
| 840 | for(var i = 0; i < matches.length; i += 2)
|
---|
| 841 | {
|
---|
| 842 | var matchLatFloat = parseFloat(matches[i].replace("___", ""));
|
---|
| 843 | var matchLngFloat = parseFloat(matches[i+1].replace("___", ""));
|
---|
[25023] | 844 |
|
---|
[26429] | 845 | lats.push(matchLatFloat);
|
---|
| 846 | lngs.push(matchLngFloat);
|
---|
| 847 | var distance = Math.sqrt(Math.pow(matchLatFloat - parseFloat(lat), 2) + Math.pow(matchLngFloat - parseFloat(lng), 2)) * (40000.0/360.0);
|
---|
[32624] | 848 | var distanceString = "" + distance;
|
---|
| 849 | distanceString = distanceString.substring(0, 6);
|
---|
[26429] | 850 | response = response.replace(matches[i] + matches[i+1], distanceString);
|
---|
| 851 | }
|
---|
| 852 |
|
---|
| 853 | var index = 0;
|
---|
| 854 | var i = 0;
|
---|
| 855 | while(true)
|
---|
| 856 | {
|
---|
| 857 | var distanceStart = response.indexOf("<td>", index);
|
---|
| 858 | if(distanceStart == -1)
|
---|
[25023] | 859 | {
|
---|
[26429] | 860 | break;
|
---|
[25023] | 861 | }
|
---|
[26429] | 862 | var distanceEnd = response.indexOf("</td>", distanceStart);
|
---|
[25023] | 863 |
|
---|
[26429] | 864 | var docLinkStart = response.indexOf("<td>", distanceEnd);
|
---|
| 865 | var docLinkEnd = response.indexOf("</td>", docLinkStart);
|
---|
| 866 |
|
---|
[32624] | 867 | var dist = response.substring(distanceStart + 4, distanceEnd);
|
---|
[26429] | 868 | var docLink = response.substring(docLinkStart + 4, docLinkEnd);
|
---|
[25023] | 869 |
|
---|
[32624] | 870 | _nearbyDocs.push({title:docLink, distance:dist, lat:lats[i], lng:lngs[i++]});
|
---|
[25023] | 871 |
|
---|
[26429] | 872 | index = docLinkEnd;
|
---|
[25023] | 873 | }
|
---|
[26429] | 874 |
|
---|
[32624] | 875 | sortByDistance(lat,lng);
|
---|
[26429] | 876 |
|
---|
| 877 | var toggle = $("#nearbyDocumentsToggle");
|
---|
| 878 | toggle.attr("src", gs.imageURLs.collapse);
|
---|
| 879 | gs.functions.makeToggle(toggle, $("#nearbyDocuments"));
|
---|
| 880 | });
|
---|
[25023] | 881 | }
|
---|
| 882 |
|
---|
[32624] | 883 | var map_centering_timeout = null;
|
---|
| 884 | function recenterMapF(lat, lng)
|
---|
[25023] | 885 | {
|
---|
[32624] | 886 | return function() {
|
---|
| 887 | _map.setCenter(new google.maps.LatLng(lat, lng));
|
---|
| 888 | }
|
---|
| 889 | }
|
---|
| 890 | function recenterMap(lat, lng)
|
---|
| 891 | {
|
---|
| 892 |
|
---|
| 893 | _map.setCenter(new google.maps.LatLng(lat, lng));
|
---|
| 894 |
|
---|
| 895 | }
|
---|
| 896 | function sortByDistance(base_lat,base_lng)
|
---|
| 897 | {
|
---|
| 898 | 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>';
|
---|
[25023] | 899 | _nearbyDocs.sort(function(a, b){return (a.distance - b.distance);});
|
---|
| 900 | for(var i = 0; i < _nearbyDocs.length; i++)
|
---|
[32624] | 901 | {
|
---|
| 902 |
|
---|
| 903 | 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>";
|
---|
[25023] | 904 | }
|
---|
| 905 | sortedTable += "</table>";
|
---|
| 906 |
|
---|
[26429] | 907 | $("#nearbyDocuments").html(sortedTable);
|
---|
[25023] | 908 | }
|
---|
[32624] | 909 | function prettifyDistance(distance) {
|
---|
[25023] | 910 |
|
---|
[32624] | 911 | var new_distance;
|
---|
| 912 | if (distance < 1) {
|
---|
| 913 | new_distance = (distance * 1000);
|
---|
| 914 | // Round to nearest whole number - don't need to show points of metres..
|
---|
| 915 | new_distance = Math.round(new_distance);
|
---|
| 916 | new_distance += " m";
|
---|
| 917 | }
|
---|
| 918 | else {
|
---|
| 919 | new_distance = distance +" km";
|
---|
| 920 |
|
---|
| 921 | }
|
---|
| 922 | return new_distance;
|
---|
| 923 | }
|
---|
| 924 |
|
---|
| 925 |
|
---|
| 926 |
|
---|
| 927 | function sortAlphabetically(base_lat, base_lng)
|
---|
[25023] | 928 | {
|
---|
[32624] | 929 | 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>';
|
---|
[25023] | 930 | _nearbyDocs.sort(function(a, b)
|
---|
| 931 | {
|
---|
| 932 | var firstTitleStartIndex = a.title.indexOf(">");
|
---|
| 933 | var firstTitleEndIndex = a.title.indexOf("<", firstTitleStartIndex);
|
---|
| 934 | var firstTitle = a.title.substring(firstTitleStartIndex + 1, firstTitleEndIndex);
|
---|
| 935 | var secondTitleStartIndex = b.title.indexOf(">");
|
---|
| 936 | var secondTitleEndIndex = b.title.indexOf("<", secondTitleStartIndex);
|
---|
| 937 | var secondTitle = b.title.substring(secondTitleStartIndex + 1, secondTitleEndIndex);
|
---|
| 938 | return ((firstTitle.toLowerCase() == secondTitle.toLowerCase()) ? 0 : ((firstTitle.toLowerCase() > secondTitle.toLowerCase()) ? 1 : -1));
|
---|
| 939 | });
|
---|
| 940 | for(var i = 0; i < _nearbyDocs.length; i++)
|
---|
| 941 | {
|
---|
[32624] | 942 | 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>";
|
---|
[25023] | 943 | }
|
---|
| 944 | sortedTable += "</table>";
|
---|
| 945 |
|
---|
[26429] | 946 | $("#nearbyDocuments").html(sortedTable);
|
---|
[25023] | 947 | }
|
---|
| 948 |
|
---|
[33168] | 949 | function getDistanceQueryStringOldApproach(currentCoord, delta, precision, indexName, directions)
|
---|
[25023] | 950 | {
|
---|
[33168] | 951 | console.error("**** Old Approach called!!!");
|
---|
| 952 |
|
---|
[25023] | 953 | var query = "";
|
---|
| 954 | var coordFloat = parseFloat(currentCoord);
|
---|
| 955 |
|
---|
| 956 | var newCoord = "" + (coordFloat + delta);
|
---|
| 957 | var beforeDec = newCoord.substring(0, newCoord.indexOf("."));
|
---|
| 958 |
|
---|
[33168] | 959 | var direction = directions[0];
|
---|
[25023] | 960 | if(coordFloat < 0)
|
---|
| 961 | {
|
---|
[33168] | 962 | // negative value
|
---|
| 963 | direction = directions[1];
|
---|
| 964 | beforeDec = beforeDec.substring(1); // skip over '-' at front
|
---|
[25023] | 965 | }
|
---|
[33168] | 966 | beforeDec += direction;
|
---|
[25023] | 967 |
|
---|
| 968 | var afterDec = newCoord.substring(newCoord.indexOf(".") + 1, newCoord.indexOf(".") + (precision) + 1);
|
---|
| 969 |
|
---|
| 970 | return indexName + ":" + beforeDec + "+AND+" + indexName + ":" + afterDec;
|
---|
| 971 | }
|
---|
[33168] | 972 |
|
---|
| 973 | function coordValToIndexToken(coordValStr, delta, precision, directions)
|
---|
| 974 | {
|
---|
| 975 | var coordValFloat = parseFloat(coordValStr);
|
---|
| 976 |
|
---|
| 977 | var deltaCoordValStr = "" + (coordValFloat + delta);
|
---|
| 978 | var beforeDec = deltaCoordValStr.substring(0, deltaCoordValStr.indexOf("."));
|
---|
| 979 |
|
---|
| 980 | var direction = directions[0];
|
---|
| 981 | if(coordValFloat < 0)
|
---|
| 982 | {
|
---|
| 983 | // negative value
|
---|
| 984 | direction = directions[1];
|
---|
| 985 | beforeDec = beforeDec.substring(1); // skip over '-' at front
|
---|
| 986 | }
|
---|
| 987 |
|
---|
| 988 | var beforeDecWithDirection = beforeDec + direction;
|
---|
| 989 |
|
---|
| 990 | var afterDecPrecision = deltaCoordValStr.substring(deltaCoordValStr.indexOf(".") + 1, deltaCoordValStr.indexOf(".") + (precision) + 1);
|
---|
| 991 |
|
---|
| 992 | var indexToken = beforeDecWithDirection + afterDecPrecision;
|
---|
| 993 |
|
---|
| 994 | return indexToken;
|
---|
| 995 | }
|
---|
| 996 |
|
---|
| 997 | function getDistanceQueryStringTerm(currentLat,currentLng, deltaLat, deltaLng, precision, indexName)
|
---|
| 998 | {
|
---|
| 999 | var latToken = coordValToIndexToken(currentLat,deltaLat,precision,["N","S"]);
|
---|
| 1000 | var lngToken = coordValToIndexToken(currentLng,deltaLng,precision,["E","W"]);
|
---|
| 1001 |
|
---|
| 1002 | var queryStringTerm = indexName + ":\"" + latToken + " " + lngToken + "\"";
|
---|
| 1003 |
|
---|
| 1004 | return queryStringTerm;
|
---|
| 1005 | }
|
---|