- Timestamp:
- 2019-06-07T20:30:54+12:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/web/interfaces/default/js/map-scripts.js
r33130 r33140 326 326 if(doc.parentCL && doc.parentCL.style.display == "none") 327 327 { 328 doc.marker.setVisible(false); 328 if(doc.shapes) { 329 for(var x = 0; x < doc.shapes.length; x++) { 330 doc.shapes[x].setVisible(false); 331 } 332 } else { 333 doc.marker.setVisible(false); 334 } 329 335 continue; 330 336 } 331 337 else 332 338 { 333 doc.marker.setVisible(true); 334 markersOnMap++; 339 if(doc.shapes) { 340 for(var x = 0; x < doc.shapes.length; x++) { 341 doc.shapes[x].setVisible(true); 342 } 343 } else { 344 doc.marker.setVisible(true); 345 } 346 markersOnMap++; // TODO: what do we do with this when we have shapes. This variable may be connected with centring the map? 335 347 } 336 348 … … 424 436 } 425 437 426 function attachClickHandler(marker, nodeID) 438 // Unused at present, called by draggableCreateMarker 439 // Map used to have editable markers. Now editable markers are restricted to the map-editor. 440 function attachDraggableClickHandler(marker, nodeID) 427 441 { 428 442 google.maps.event.addListener(marker, 'click', function() … … 493 507 } 494 508 495 function createMarkers(doc, mainMarker) { 496 if(doc.coords) { 497 for(var x = 0; x < doc.coords.length; x++) { 498 var coord = doc.coords[x]; 499 var coordInfo = getLatLngForCoord(doc.coords[x]); 500 pos = new google.maps.LatLng(coordInfo.lat,coordInfo.lng); 501 createMarker(doc, pos, mainMarker); 502 } 503 } else { 509 function createMarkers(doc, mainMarker) { 510 if(doc.mapoverlay) { 511 //console.log("Have shapes: " + doc.mapoverlay.toString()); 512 createShapes(doc, mainMarker); 513 } else { // backwards compatible to deal with Lat and Lng meta stored for doc 504 514 pos = new google.maps.LatLng(doc.lat,doc.lng); 505 515 createMarker(doc, pos, mainMarker); … … 507 517 } 508 518 509 519 function addInfoMarker(doc, shape) { 520 521 if(!shape.description) { 522 //console.log("@@@@ " + shape.type.toString() + " had no description/label"); 523 return; 524 } 525 526 // else add an InfoWindow for this shape using the label (shape.description) 527 528 // https://developers.google.com/maps/documentation/javascript/infowindows 529 // An InfoWindow's "position contains the LatLng at which this info window is anchored. 530 // Note: An InfoWindow may be attached either to a Marker object (in which case its position is based on the marker's location) 531 // or on the map itself at a specified LatLng. Opening an info window on a marker will automatically update the position." 532 var infoWindow = new google.maps.InfoWindow({content:shape.description}); // NOTE: if not setting content or position properties 533 // inside this constructor, need to call setContent/setPosition to set them 534 535 if(shape.type === google.maps.drawing.OverlayType.MARKER) { 536 var marker = shape; 537 //marker.addListener('mouseover', function() { 538 infoWindow.open(_map, marker); 539 //}); 540 attachClickHandler(marker, doc.nodeID); // do what the original code used to do here 541 } 542 else { 543 var coord = ShapesUtil.getLabelCoordinate(shape); 544 console.log("Coord for " + shape.type.toString() + " is " + coord.toString()); 545 infoWindow.setPosition(coord); 546 shape.addListener('mouseover', function() { 547 infoWindow.open(_map); 548 }); 549 shape.addListener('mouseout', function() { 550 infoWindow.close(); 551 }); 552 attachClickHandler(shape, doc.nodeID); // as above 553 } 554 } 555 556 // This function will create Google Shapes/Overlays and markers out of a given doc JSONNode's doc.mapOverlay 557 // (doc.mapOverlay shapes are stored as an array of JSON) and store the shapes/overlays in the doc.shapes array. 558 // Note: doc.coords are just an array of all the coordinates in a doc, not indicating to which shapes they belong. 559 // They're only **for searching** - for seaching which coords (hence docs) are in a map. 560 // Param mainMarker: if set to true, marker is red. If false, marker is blue 561 function createShapes(doc, mainMarker) 562 { 563 // for doc.shapes: don't store JSON anymore, convert them to google Shapes overlays and store them instead 564 doc.shapes = []; 565 for (var i=0; i<doc.mapoverlay.length; i++) { 566 var shape = ShapesUtil.JSONToShape(doc.mapoverlay[i]); 567 doc.shapes[i] = shape; 568 shape.setMap(_map); 569 shape["title"] = doc.title; 570 571 // Unset editable and draggable properties of shape 572 // And for markers, which are initialised to clickable besides, undo the clickability 573 // and set them 574 if(shape.type === google.maps.drawing.OverlayType.MARKER) { 575 var marker = shape; 576 // mainMarkers should be red 577 if(!mainMarker) { 578 marker["icon"] = "interfaces/" + gs.xsltParams.interface_name + "/images/bluemarker.png"; 579 } 580 marker.clickable = false; // only markers 581 } 582 583 shape.editable = false; 584 shape.draggable = false; 585 586 587 588 // doc[i]'s label = doc.shapes[i].description 589 addInfoMarker(doc, shape); 590 } 591 592 var docElement = gs.jqGet("div" + doc.nodeID); 593 var parent; 594 if(docElement) 595 { 596 parent = docElement.parentNode; 597 } 598 599 while(parent && parent.nodeName != "BODY") 600 { 601 if($(parent).attr("id") && $(parent).attr("id").search("divCL") != -1) 602 { 603 doc.parentCL = parent; 604 break; 605 } 606 607 parent = parent.parentNode; 608 } 609 } 610 611 // This method is only for backwards compatibility: for those collections with docs that only have Lat and Lng meta 612 // and no GPS.mapOverlay (and hence Coordinate) meta. 510 613 // Param mainMarker: if set to true, marker is red. If false, marker is blue 511 614 function createMarker(doc, pos, mainMarker) 615 { 616 var marker; 617 if(mainMarker) 618 { 619 marker = new google.maps.Marker 620 ({ 621 position: pos, 622 title:doc.title, 623 map:_map 624 }); 625 } 626 else 627 { 628 marker = new google.maps.Marker 629 ({ 630 position: pos, 631 title:doc.title, 632 map:_map, 633 icon:"interfaces/" + gs.xsltParams.interface_name + "/images/bluemarker.png" 634 }); 635 } 636 637 var docElement = gs.jqGet("div" + doc.nodeID); 638 var parent; 639 if(docElement) 640 { 641 parent = docElement.parentNode; 642 } 643 644 while(parent && parent.nodeName != "BODY") 645 { 646 if($(parent).attr("id") && $(parent).attr("id").search("divCL") != -1) 647 { 648 doc.parentCL = parent; 649 break; 650 } 651 652 parent = parent.parentNode; 653 } 654 655 var info = new google.maps.InfoWindow({content:doc.title}); 656 marker.markerInfo = info; 657 doc.marker = marker; 658 attachClickHandler(marker, doc.nodeID); 659 } 660 661 // TODO: with the following, it seems that clicking on shape expands the entire document 662 // Should it be that clicking on a shape should expand the doc section that contains that shape meta? 663 function attachClickHandler(shapeOrMarker, nodeID) 664 { 665 google.maps.event.addListener(shapeOrMarker, 'click', function() 666 { 667 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"; 668 }); 669 } 670 671 // TODO: 672 // Version of createMarker function containing Zeddy's modifications (pre-mapeditor?) to make markers 673 // on the public *map* (not on map-editor) draggable/editable and to save these edits/rebuild with them. 674 // Do we want to continue supporting editing on the main map? I thought we weren't going to and that editing 675 // was exclusive to the map-editor, with the public map only displaying the saved features? 676 function draggableCreateMarker(doc, pos, mainMarker) 512 677 { 513 678 var docEdit = (("docEdit" in gs.cgiParams) && (gs.cgiParams['docEdit'])); … … 522 687 var draggable_val = (!docEdit || loggedOutVar) ? false : true; 523 688 524 var marker 689 var marker; 525 690 if(mainMarker) 526 691 { … … 566 731 marker.markerInfo = info; 567 732 doc.marker = marker; 568 attach ClickHandler(marker, doc.nodeID);733 attachDraggableClickHandler(marker, doc.nodeID); 569 734 570 735 ////////////////////////////////////////////////////// TEST
Note:
See TracChangeset
for help on using the changeset viewer.