Changeset 33186 for main/trunk


Ignore:
Timestamp:
2019-06-21T22:26:57+12:00 (5 years ago)
Author:
wy59
Message:

Lower opacity for other documents that are nearby. Discovered broken code: Locations classifier in ImagesGPS no longer displays a map.

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

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/web/interfaces/default/js/map-scripts-shapes-util.js

    r33169 r33186  
    580580}
    581581
     582
     583ShapesUtil.setOpacity = function (shape, opacity) {
     584    if (shape.type === google.maps.drawing.OverlayType.RECTANGLE
     585        || shape.type === google.maps.drawing.OverlayType.POLYGON
     586        || shape.type === google.maps.drawing.OverlayType.CIRCLE)
     587    {
     588        shape.fillOpacity = opacity;
     589    } else if (shape.type === google.maps.drawing.OverlayType.POLYLINE) {
     590        shape.strokeOpacity = opacity;
     591    }
     592    else {
     593        console.log("Can't set opacity on unrecognised shape: " + shape.type);     
     594    }
     595}
  • main/trunk/greenstone3/web/interfaces/default/js/map-scripts.js

    r33185 r33186  
    1818var _scrollThroughDefault = true; // TODO: default starts at true
    1919
     20var LOW_OPACITY = 0.1; // make surrounding docs' opacity 10%
     21
    2022function initializeMapScripts()
    2123{   
     
    3436            {
    3537                _docList[jsonNodes[i].nodeID] = jsonNodes[i];
    36                 _docList.ids.push(jsonNodes[i].nodeID);             
    37                 createMarkers(jsonNodes[i], true);
    38             }
     38                _docList.ids.push(jsonNodes[i].nodeID);
     39                var options = {
     40                    "mainDoc": true
     41                };
     42                console.log("#### " + jsonNodes[i].nodeID + " is a main doc: ");
     43                console.log(jsonNodes[i]);
     44                createMarkers(jsonNodes[i], options);
     45            }
     46           
    3947            updateMap();
    4048        }
     
    262270    {
    263271        //console.log("*** responseText (first 250) = " + responseText.substring(0,256));
     272       
     273        // The first time, docList.ids contains ONLY the main/visible doc's ID and its subsections' IDs.
     274        // Any one of these will do to determine
     275        if(_docList.ids.length > 0) {
     276            var mainDocID = _docList.ids[0];
     277            var endIndex = mainDocID.indexOf('.');
     278            if(endIndex == -1) { endIndex = mainDocID.length; }
     279            mainDocID = mainDocID.substring(0, endIndex);
     280        }
    264281       
    265282        if(responseText.search("id=\"jsonNodes") != -1)
     
    279296                   
    280297                    var found = false;
    281                     for(var j = 0; j < _docList.ids.length; j++){if(doc.nodeID == _docList.ids[j]){found = true; break;}}
     298                    for(var j = 0; j < _docList.ids.length; j++) {
     299                        if(doc.nodeID == _docList.ids[j]) {
     300                            found = true;                           
     301                            console.log("Found nearby ID " + doc.nodeID + " was already drawn:");
     302                            console.log(jsonNodes[i]);
     303                            break;
     304                        }
     305                    }
    282306                   
    283307                    if(!found)
     
    286310                        _docList.ids.push(doc.nodeID);
    287311
    288                         createMarkers(doc, false);
     312                        // Some "nearby docs" are actually subsections of the main document, which are retrieved
     313                        // as a nearby doc by performSearchForMarkers() BEFORE the subsection is ever expanded.
     314                        // We need to distinguish between subsections of the main doc -- which should be displayed
     315                        // in their specified opacity -- and other docs and their subsections which should be displayed
     316                        // faded out.
     317                        if(typeof(mainDocID) !== 'undefined' && doc.nodeID.includes(mainDocID)) {
     318                            createMarkers(doc, {"mainDoc": true});
     319                        } else {
     320                            createMarkers(doc, {"mainDoc": false});
     321                        }                       
    289322                    }
     323                   
    290324                }
    291325            }
     
    548582}
    549583
    550 function createMarkers(doc, mainMarker) {   
     584function createMarkers(doc, options) {
    551585    if(doc.mapoverlay) {
    552586        //console.log("Have shapes: " + doc.mapoverlay.toString());
    553         createShapes(doc, mainMarker);
     587        createShapes(doc, options);
    554588    } else { // backwards compatible to deal with Lat and Lng meta stored for doc
    555589        pos = new google.maps.LatLng(doc.lat,doc.lng);
    556         createMarker(doc, pos, mainMarker);
     590        createMarker(doc, pos, options);
    557591    }
    558592}
     
    604638// This function will create Google Shapes/Overlays and markers out of a given doc JSONNode's doc.mapOverlay
    605639// (doc.mapOverlay shapes are stored as an array of JSON) and store the shapes/overlays in the doc.shapes array.
    606 // Param mainMarker: if set to true, marker is red. If false, marker is blue
    607 function createShapes(doc, mainMarker)
     640function createShapes(doc, options)
    608641{   
     642    var isMainDoc = options["mainDoc"];
     643
    609644    // for doc.shapes: don't store JSON anymore, convert them to google Shapes overlays and store them instead
    610645    doc.shapes = [];
     
    624659        if(shape.type === google.maps.drawing.OverlayType.MARKER) {
    625660            var marker = shape;
    626             // mainMarkers should be red
    627             if(!mainMarker) {
     661            // markers of the main document should be red, else they'll be blue
     662            if(!isMainDoc) {
    628663                marker["icon"] = "interfaces/" + gs.xsltParams.interface_name + "/images/bluemarker.png";
    629664            }
     
    638673        } else {           
    639674            //console.log("Creating non-marker shape.");
     675           
     676            if(!isMainDoc) {
     677                ShapesUtil.setOpacity(shape, LOW_OPACITY);
     678            } // else the shape will be drawn at its configured opacity
    640679        }
    641680       
     
    643682        shape.draggable = false;
    644683       
    645         console.log("#### calling addInfoMarker");
     684       
    646685        // doc[i]'s label = doc.shapes[i].description
    647686        addInfoMarker(doc, shape);
     
    669708// This method is only for backwards compatibility: for those collections with docs that only have Lat and Lng meta
    670709// and no GPS.mapOverlay (and hence Coordinate) meta.
    671 // Param mainMarker: if set to true, marker is red. If false, marker is blue
    672 function createMarker(doc, pos, mainMarker)
    673 {
     710function createMarker(doc, pos, options)
     711{   
     712    var isMainMarker = options["mainDoc"];
     713   
    674714    var marker;
    675     if(mainMarker)
     715    if(isMainMarker)
    676716    {
    677717        marker = new google.maps.Marker
     
    750790                _docList[doc.nodeID] = doc;
    751791                _docList.ids.push(doc.nodeID);
    752 
    753                 createMarkers(doc, true);
     792   
     793                var options = {
     794                    "mainDoc": true // TODO: should this be true or false???
     795                };
     796                createMarkers(doc, options);
    754797            }
    755798           
Note: See TracChangeset for help on using the changeset viewer.