var addInferenceMouseHandlers = function()

in web_tool/js/handlers.js [1:95]


var addInferenceMouseHandlers = function(){
    //----------------------------------------------------------------------
    // Setup map selection handlers
    //----------------------------------------------------------------------
    gMap.addEventListener('mousemove', function(e){
        // Choose style
        var curSelPoly = null;
        if(!gShiftKeyDown){
            curSelPoly = getPolyAround(e.latlng, 1, false);
        }else{
            curSelPoly = getPolyAround(e.latlng, INFERENCE_WINDOW_SIZE, true, true);
        }
        
        if(gSelectionBox === null){
            gSelectionBox = L.polygon(curSelPoly, {
                color: "#000000",
                fillColor: "#ffffff",
                weight: 2
            });
            gSelectionBox.addTo(gMap);
        }else{
            if(!gAnimating){
                gSelectionBox.setStyle({
                    color: "#000000",
                    fillColor: "#ffffff",
                    weight: 2
                });
            }
            gSelectionBox.setLatLngs(curSelPoly);
        }
    });
    
    gMap.addEventListener('click', function(e){

        if(!gIsSessionActive){
            notifyFailMessage("Your session is inactive, please restart from the landing page")
            return
        }
        
        var curSelPoly = null;
        if(gShiftKeyDown){
            // Run the inference path
            curSelPoly = getPolyAround(e.latlng, INFERENCE_WINDOW_SIZE, true, true);
            if(gCurrentSelection === null){ // This condition creates the red selection box on the first click
                gCurrentSelection = L.polygon(curSelPoly, {
                    color: "#ff0000",
                    fillColor: "#ffffff",
                    weight: 2
                });
                gCurrentSelection.addTo(gMap);
            }else{
                gCurrentSelection.setLatLngs(curSelPoly);
            }
    
            requestPatches(curSelPoly);
        }else{
            // Run the add sample path
            if(gCurrentSelection !== null){
                if(isPointInsidePolygon(e.latlng, gCurrentSelection)){
                    if(gCurrentBasemapLayerName == DATASETS[gCurrentDataset]["basemapLayers"][0]["layerName"]){
                        curSelPoly = getPolyAround(e.latlng, 1, false);
                        var idx = gCurrentPatches.length-1;
                        doSendCorrection(e.latlng, idx);
                        
                        var circle = L.circle(
                            [e.latlng.lat, e.latlng.lng],
                            {
                                radius: 2,
                                color: CLASSES[gSelectedClassIdx]["color"],
                                weight: 1,
                                opacity: 1
                                //pane: "labels"
                            }
                        ).addTo(gMap);
                        gUserPointList.push([circle, gSelectedClassIdx]);
    
                        gMap.dragging.disable();
                        gNumClicks += 1
                        window.setTimeout(function(){
                            gNumClicks -= 1;
                            if(gNumClicks == 0){
                                gMap.dragging.enable();
                            }
                        }, 700);
                    }else{
                        notifyFailMessage("Please add corrections using the '"+DATASETS[gCurrentDataset]["basemapLayers"][0]["layerName"]+"' imagery layer.")
                    }
                }else{
                    console.debug("Click not in selection");
                }
            }
        }
    });

};