Changeset 33168
- Timestamp:
- 2019-06-20T17:13:50+12:00 (5 years ago)
- Location:
- main/trunk/greenstone3/web/interfaces/default/js
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/web/interfaces/default/js/classifier_scripts.js
r33153 r33168 46 46 } 47 47 updateOpenClassifiers(); 48 if(typeof mapEnabled !== 'undefined'){ 48 if(typeof mapEnabled !== 'undefined' && mapEnabled){ 49 //console.log("Classifier scripts -> updateMap()"); 49 50 updateMap(); 50 51 } … … 154 155 } 155 156 updateOpenClassifiers(); 156 if(typeof mapEnabled !== 'undefined' ){157 if(typeof mapEnabled !== 'undefined' && mapEnabled){ 157 158 getSubClassifier(sectionID); 158 159 } -
main/trunk/greenstone3/web/interfaces/default/js/map-scripts-shapes-util.js
r33140 r33168 1 2 // https://stackoverflow.com/questions/3284808/getting-the-bounds-of-a-polyline-in-google-maps-api-v3 3 4 google.maps.Polyline.prototype.getBounds = function() { 5 var bounds = new google.maps.LatLngBounds(); 6 this.getPath().forEach(function(item, index) { 7 bounds.extend(new google.maps.LatLng(item.lat(), item.lng())); 8 }); 9 return bounds; 10 }; 11 12 google.maps.Polygon.prototype.getBounds = function() { 13 var bounds = new google.maps.LatLngBounds(); 14 this.getPath().forEach(function(item, index) { 15 bounds.extend(new google.maps.LatLng(item.lat(), item.lng())); 16 }); 17 return bounds; 18 }; 1 19 2 20 … … 516 534 } 517 535 518 536 ShapesUtil.overlayBounds = function (overlays) { 537 538 539 var extended_bounds = new google.maps.LatLngBounds(); 540 541 for (var i=0; i<overlays.length; i++) { 542 543 var overlay_item = overlays[i]; 544 545 if (ShapesUtil.overlayItemIsShape(overlay_item)) { 546 var shape = overlay_item; 547 548 var bounds = shape.getBounds(); 549 var ne = bounds.getNorthEast(); 550 var sw = bounds.getSouthWest(); 551 extended_bounds.extend(ne); 552 extended_bounds.extend(sw); 553 } 554 else { 555 var marker = overlay_item; 556 var latlng = marker.getPosition(); 557 extended_bounds.extend(latlng); 558 } 559 } 560 561 return extended_bounds; 562 563 } 564 -
main/trunk/greenstone3/web/interfaces/default/js/map-scripts.js
r33148 r33168 16 16 var _searchRunning = false; 17 17 var _nearbyDocs = new Array(); 18 var _scrollThroughDefault = true; 18 var _scrollThroughDefault = true; // TODO: default starts at true 19 19 20 20 function initializeMapScripts() 21 { 22 setUpMap();23 21 { 22 //console.log("@@@@ initializeMapScripts()"); 23 24 24 var jsonNodeDiv = $("#jsonNodes"); 25 25 if(jsonNodeDiv.length) … … 28 28 var jsonNodes = eval(jsonNodeDiv.html()); 29 29 30 renderMap(); 30 31 if(jsonNodes && jsonNodes.length > 0) 31 32 { … … 41 42 { 42 43 //hiding the map 43 //$("#map_canvas").css({visibility:"hidden", height:"0px"});44 $("#map_canvas").css({ visibility:"hidden"}); // if you comment this out, add a log message saying "suppressing hiding map"45 }46 }47 44 mapEnabled = false; 45 $("#map_canvas").css({display:"none"}); 46 return; 47 } 48 } 48 49 _docList.loopIndex = 0; 49 50 … … 84 85 } 85 86 86 function setUpMap() 87 { 88 //alert("@@@@in map-scripts::setUpMap()"); 89 87 function renderMap() 88 { 89 //console.log("@@@@in map-scripts::renderMap()"); 90 90 var myOptions = 91 91 { … … 97 97 98 98 if ($map_canvas.length > 0) { 99 //console.log("docList is " + _docList.toString()); 99 100 _map = new google.maps.Map($map_canvas[0], myOptions); 101 //console.log("@@@ created Google _map"); 102 100 103 google.maps.event.addListener(_map, 'bounds_changed', performSearchForMarkers); 101 104 } … … 104 107 function performSearchForMarkers() 105 108 { 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 106 118 if(_searchRunning) 107 119 { 120 //console.log("*** performSearchForMarkers(): already running search => not initiating an additional search"); 108 121 return; 109 122 } 110 111 123 112 124 … … 243 255 var url = gs.xsltParams.library_name; 244 256 var data = "a=q&s=RawQuery&rt=rd&c=" + gs.cgiParams.c + "&s1.rawquery=" + query + "&excerptid=jsonNodes"; 257 //console.log("*** performSearchForMarkers(): rawQuery query data = " + query); 258 245 259 $.ajax({type:"POST", url:url, data:data}) 246 260 .success(function(responseText) … … 256 270 257 271 var jsonNodes = eval(responseText.substring(startIndex+1, endIndex)); 272 //console.log("Number of matches returned from ajax rawQuery search = " + jsonNodes.length); 258 273 if(jsonNodes && jsonNodes.length > 0) 259 274 { … … 320 335 function updateMap() 321 336 { 337 //console.log("@@@ updateMap()"); 322 338 var markersOnMap = 0; 323 339 var bounds = new google.maps.LatLngBounds(); … … 331 347 doc.shapes[x].setVisible(false); 332 348 } 333 markersOnMap= doc.shapes.length;349 //markersOnMap += doc.shapes.length; 334 350 } else { 335 351 doc.marker.setVisible(false); … … 340 356 { 341 357 if(doc.shapes) { 342 for(var x = 0; x < doc.shapes.length; x++) { 358 //console.log("@@@ making doc.shapes["+x+"] visible"); 359 for(var x = 0; x < doc.shapes.length; x++) { 343 360 doc.shapes[x].setVisible(true); 344 361 } 345 markersOnMap = doc.shapes.length; 362 markersOnMap += doc.shapes.length; 363 //alert("HERE I AM " + markersOnMap); 364 346 365 } else { 347 366 doc.marker.setVisible(true); 348 }349 markersOnMap++;350 }351 367 markersOnMap++; 368 } 369 370 } 352 371 353 372 if(doc.coords) { 373 //console.log("@@@@ HERE IN doc.coords"); 354 374 for(var x = 0; x < doc.coords.length; x++) { 355 375 var coord = doc.coords[x]; … … 358 378 } 359 379 } 380 381 if(doc.mapoverlay) { 382 console.log("@@@@ HERE IN doc.mapoverlay"); 383 var overlay_bounds = ShapesUtil.overlayBounds(doc.shapes); 384 bounds.extend(overlay_bounds.getNorthEast()); 385 bounds.extend(overlay_bounds.getSouthWest()); 386 } 360 387 else { 361 bounds.extend(new google.maps.LatLng(doc.lat, doc.lng)); 362 } 363 } 364 388 var doc_latlng = new google.maps.LatLng(doc.lat, doc.lng); 389 bounds.extend(doc_latlng); 390 } 391 } 392 393 //console.log("@@@ UpdateMap() : bounds = " + bounds); 365 394 if(markersOnMap > 1) 366 395 { 367 _map.fitBounds(bounds);396 _map.fitBounds(bounds); 368 397 } else if (markersOnMap == 1) { 369 // sometimes a single point bounds are too small for the map to display, so use center and zoom instead of fitbounds. 370 _map.setCenter(bounds.getCenter()); 371 _map.setZoom(18); // arbitrary value that looked nice for my example 398 //console.log("@@@ updating bounds with " + markersOnMap + " markers on the map"); 399 //console.log(bounds); 400 401 // sometimes a single point bounds are too small for the map to display, so use center and zoom instead of fitbounds. 402 _map.setCenter(bounds.getCenter()); 403 _map.setZoom(18); // arbitrary value that looked nice for my example 372 404 } 373 405 } … … 406 438 { 407 439 var doc = _docList.getDocByIndex(i); 408 if(doc.marker.getVisible()) 409 { 410 visibleMarkers.push(doc); 411 } 440 if(typeof doc.shapes !== 'undefined') { 441 for(var x = 0; x < doc.shapes.length; x++) { 442 var shape = doc.shapes[i]; 443 if(shape.type === google.maps.drawing.OverlayType.MARKER && shape.getVisible()) 444 { 445 visibleMarkers.push(doc); 446 } 447 } 448 } 449 if(doc.marker && doc.marker.getVisible()) 450 { 451 visibleMarkers.push(doc); 452 } 412 453 } 413 454 … … 421 462 422 463 var elem = null; 423 while(!elem) 464 while(!elem) // TODO: why redefine elem? Why does this work, and only this, but not while(true) or while(doc.marker) or while(!AnythingFalse)??? 465 // Some clever behaviour here, but no documentation on the cleverness. Hard to understand 424 466 { 425 467 if(_docList.loopIndex >= visibleMarkers.length) … … 429 471 430 472 var doc = visibleMarkers[_docList.loopIndex]; 431 var elem = gs.jqGet("div" + doc.nodeID);473 elem = gs.jqGet("div" + doc.nodeID); // TODO: this used to redefine elem by doing var elem = <....> 432 474 if(elem.length) 433 475 { … … 435 477 setTimeout(function(){elem.css("background", "");}, 2000); 436 478 } 437 _docList.loopIndex++; 438 } 439 doc.marker.markerInfo.open(_map, doc.marker); 479 _docList.loopIndex ++; 480 } 481 //console.log("@@@@ DOC:"); 482 //console.log(doc); 483 484 if(doc.marker) { 485 doc.marker.markerInfo.open(_map, doc.marker); // TODO: how does doc have a value here? Where is the value set at this block level? 486 } 487 488 if(doc.shapes) { 489 for(var x = 0; x < doc.shapes.length; x++) { 490 var shape = doc.shapes[i]; 491 if(shape.type === google.maps.drawing.OverlayType.MARKER) { 492 shape.markerInfo.open(_map, shape); 493 } else { 494 shape.markerInfo.open(_map); 495 } 496 } 497 } 440 498 } 441 499 … … 503 561 504 562 if(shape.type === google.maps.drawing.OverlayType.MARKER) { 505 var marker = shape; 563 var marker = shape; 506 564 marker.addListener('mouseover', function() { 507 565 infoWindow.open(_map, marker); … … 524 582 attachClickHandler(shape, doc.nodeID); // as above 525 583 } 584 shape.markerInfo = infoWindow; 526 585 } 527 586 … … 535 594 // for doc.shapes: don't store JSON anymore, convert them to google Shapes overlays and store them instead 536 595 doc.shapes = []; 596 537 597 for (var i=0; i<doc.mapoverlay.length; i++) { 538 var shape = ShapesUtil.JSONToShape(doc.mapoverlay[i]); 598 //console.log("in: mapoverlay["+i+"] =" + JSON.stringify(doc.mapoverlay[i])); 599 var shape = ShapesUtil.JSONToShape(doc.mapoverlay[i]); 600 //console.log("out: shape = " + JSON.stringify(shape)); 601 539 602 doc.shapes[i] = shape; 540 603 shape.setMap(_map); 541 shape["title"] = doc.title;604 //shape["title"] = doc.title; // TODO: Think on it some more. 542 605 543 606 // Unset editable and draggable properties of shape … … 551 614 } 552 615 marker.clickable = false; // only markers 616 /* 617 console.log("@@@ map-scripts::addInfoMarker - marker.position"); 618 console.log("Lat is " + typeof(marker.position.lat())); 619 console.log(marker.position.lat()); 620 console.log("Long is " + typeof(marker.position.lng())); 621 console.log(marker.position.lng()); 622 */ 623 } else { 624 //console.log("Creating non-marker shape."); 553 625 } 554 626 555 627 shape.editable = false; 556 628 shape.draggable = false; 557 558 629 559 630 … … 672 743 673 744 updateMap(); 745 //console.log("getSub Classifier -> updateMap()"); 674 746 }) 675 747 .error(function() 676 748 { 677 console.log("Error getting subclassifiers");749 //console.log("Error getting subclassifiers"); 678 750 return; 679 751 }); … … 711 783 var lngDelta = (j - degrees) * 0.01; 712 784 713 query += "(" + getDistanceQueryString(lat, latDelta, 2, "LA", ["N","S"]); 714 query += "+AND+"; 715 query += getDistanceQueryString(lng, lngDelta, 2, "LN", ["E","W"]) + ")"; 785 //query += "(" + getDistanceQueryStringOldApproach(lat, latDelta, 2, "LA", ["N","S"]); 786 //query += "+AND+"; 787 //query += getDistanceQueryStringOldApproach(lng, lngDelta, 2, "LN", ["E","W"]) + ")"; 788 789 query += "(" + getDistanceQueryStringTerm(lat, lng, latDelta, lngDelta, 2, "CS") + ")"; 716 790 717 791 if(i != ((degrees * 2) - 1) || j != ((degrees * 2) - 1)){ query += "+OR+"; } … … 858 932 } 859 933 860 function getDistanceQueryString(currentCoord, delta, precision, indexName, dirs) 861 { 934 function getDistanceQueryStringOldApproach(currentCoord, delta, precision, indexName, directions) 935 { 936 console.error("**** Old Approach called!!!"); 937 862 938 var query = ""; 863 939 var coordFloat = parseFloat(currentCoord); … … 866 942 var beforeDec = newCoord.substring(0, newCoord.indexOf(".")); 867 943 868 var dir = dirs[0];944 var direction = directions[0]; 869 945 if(coordFloat < 0) 870 946 { 871 dir = dirs[1]; 872 beforeDec = beforeDec.substring(1); 873 } 874 beforeDec += dir; 947 // negative value 948 direction = directions[1]; 949 beforeDec = beforeDec.substring(1); // skip over '-' at front 950 } 951 beforeDec += direction; 875 952 876 953 var afterDec = newCoord.substring(newCoord.indexOf(".") + 1, newCoord.indexOf(".") + (precision) + 1); … … 878 955 return indexName + ":" + beforeDec + "+AND+" + indexName + ":" + afterDec; 879 956 } 957 958 function coordValToIndexToken(coordValStr, delta, precision, directions) 959 { 960 var coordValFloat = parseFloat(coordValStr); 961 962 var deltaCoordValStr = "" + (coordValFloat + delta); 963 var beforeDec = deltaCoordValStr.substring(0, deltaCoordValStr.indexOf(".")); 964 965 var direction = directions[0]; 966 if(coordValFloat < 0) 967 { 968 // negative value 969 direction = directions[1]; 970 beforeDec = beforeDec.substring(1); // skip over '-' at front 971 } 972 973 var beforeDecWithDirection = beforeDec + direction; 974 975 var afterDecPrecision = deltaCoordValStr.substring(deltaCoordValStr.indexOf(".") + 1, deltaCoordValStr.indexOf(".") + (precision) + 1); 976 977 var indexToken = beforeDecWithDirection + afterDecPrecision; 978 979 return indexToken; 980 } 981 982 function getDistanceQueryStringTerm(currentLat,currentLng, deltaLat, deltaLng, precision, indexName) 983 { 984 var latToken = coordValToIndexToken(currentLat,deltaLat,precision,["N","S"]); 985 var lngToken = coordValToIndexToken(currentLng,deltaLng,precision,["E","W"]); 986 987 var queryStringTerm = indexName + ":\"" + latToken + " " + lngToken + "\""; 988 989 return queryStringTerm; 990 }
Note:
See TracChangeset
for help on using the changeset viewer.