onclick deactivate multi-funcations

807
5
01-10-2011 02:16 AM
simonmiles
New Contributor II
Hi there

i've got a map that displays my legend, navigation, has find tools and an identify tool all in docks. All worked well until i added in a measure tool, also in a dock, but i've hit a problem.

When i click on my measure distance button, both the measure and identify tool activate. I fingered out, with a little bit of help, how to deactivate/reactivate the navigation button once the measure tool has finished measuring, but cant work out how to deactivate/reactivate the Identify function. 

I think that i need to add in a .deactivate() in the below code and have tried a few things but i haven't managed to get it working. Any ideas?

<div dojotype="dijit.form.Button" onClick="navToolbar.deactivate() tb.activate(esri.toolbars.Draw.POLYLINE)"><img src="http://moon/images/measure.png" alt="measure distance"> Distance = <span id="distance"></span></div>

Thanks

Simon
0 Kudos
5 Replies
ChristopherPollard
Occasional Contributor
Simon,
Did you ever figure out the proper code structure?
I'm running into the same issue with drawing a polygon to do a query task.
Every click on the does a new identify as well as draws the polygon...
thanks
0 Kudos
HemingZhu
Occasional Contributor III
Simon,
Did you ever figure out the proper code structure?
I'm running into the same issue with drawing a polygon to do a query task.
Every click on the does a new identify as well as draws the polygon...
thanks


Here is my thought: Since Identify and measure tool all need a map's onclick handler to start. you could create a global variable such as actionType to differentiate the identify or measure action. In your handler use the logic to take different actions. Somthing like:

var actionType; //global vaiable

function init()
{
    ...
    dojo.connect(map, "onclick", clickAction);
    ...
}

function identifyBtn_click()
{
    actionType ="identify";
    ...
}
function measureBtn_click()
{
    actionType ="measure";
    ...
}
function clickAction(evt)
{
    switch (actionType) {
            case "identify":
              ...put identify logic here...
              break;
             case "measure":
              ...put measure logic here...
              break;
             ....
    }
}
Hope it will give you some idea. Good luck
0 Kudos
JillMaxwell
New Contributor


var actionType; //global vaiable

function init()
{
    ...
    dojo.connect(map, "onclick", clickAction);
    ...
}



function identifyBtn_click()
{
    actionType ="identify";
    ...
}
function measureBtn_click()
{
    actionType ="measure";
    ...
}
function clickAction(evt)
{
    switch (actionType) {
            case "identify":
              ...put identify logic here...
              break;
             case "measure":
              ...put measure logic here...
              break;
             ....
    }
}


I am having exactly the same problem.  I've copied your structure and the buffer part is working but the identify part is not. 

Could you offer some suggestions? 

Here's my code.

______________________

  var map, InfoqueryTask, Infoquery;
      var featureSet;
var navToolbar;
var actionMode ="identify"; //default
      function init() {
        var startExtent = new esri.geometry.Extent({"xmin":-11207421,"ymin":4469708,"xmax":-10718224,"ymax":4836606,"spatialReference":{"wkid":102100}} );

        //create map
        map = new esri.Map("mapDiv", {extent: startExtent});
dojo.connect(map, "onClick", doActionAccordingly);
dojo.connect(map, "onLoad", function() {
  map.disableDoubleClickZoom();
});

        var tiledLayer = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer");
        map.addLayer(tiledLayer);

        //create and add new layer
  
        
        var dynamicLayer = new esri.layers.ArcGISTiledMapServiceLayer("http://dingo.gapanalysisprogram.com/ArcGIS/rest/services/PADUS/PADUS_status/MapServer");
        map.addLayer(dynamicLayer);
dojo.connect(map, "onLoad", function() {
  map.disableDoubleClickZoom();
});
       

        //Listent for infoWindow onHide event
        dojo.connect(map.infoWindow, "onHide", function() {map.graphics.clear();});


        //build query task
        InfoqueryTask = new esri.tasks.QueryTask("http://dingo.gapanalysisprogram.com/ArcGIS/rest/services/PADUS/PADUS_status/MapServer/0");

      

        //build query filter
        Infoquery = new esri.tasks.Query();
        Infoquery.outSpatialReference = {"wkid":102100};
       Infoquery.returnGeometry = true;
        Infoquery.outFields = ["P_Des_Nm", "OBJECTID", "GIS_Acres", "GAP_Sts", "Own_Name", "Mang_Name"];


       navToolbar = new esri.toolbars.Navigation(map);
        dojo.connect(navToolbar, "onExtentHistoryChange", extentHistoryChangeHandler);
      }

      function extentHistoryChangeHandler() {
        dijit.byId("zoomprev").disabled = navToolbar.isFirstExtent();
        dijit.byId("zoomnext").disabled = navToolbar.isLastExtent();
      }
      esriConfig.defaults.io.proxyUrl = "http://dingo.gapanalysisprogram.com/proxy/proxy.ashx";
//esri.config.defaults.io.proxyUrl = "http://www.gap.uidaho.edu/proxy.php";

esriConfig.defaults.io.alwaysUseProxy = false;



function doActionAccordingly(evt)

      {
          switch (actionMode)
          {
          case "identify":
          //identify query goes here
      function executeInfoQueryTask(evt) {
          dojo.disconnect(globals);
        map.infoWindow.hide();
        map.graphics.clear();
        featureSet = null;

        //onClick event returns the evt point where the user clicked on the map.
        //This is contains the mapPoint (esri.geometry.point) and the screenPoint (pixel xy where the user clicked).
        //set query geometry = to evt.mapPoint Geometry
        Infoquery.geometry = evt.mapPoint;

        //Execute task and call showResults on completion
        InfoqueryTask.execute(Infoquery, function(fset) {
          if (fset.features.length === 1) {
            showFeature(fset.features[0],evt);
          } else if (fset.features.length !== 0) {
            showFeatureSet(fset,evt);
          }
        });
      }

      function showFeature(feature,evt) {
        map.graphics.clear();

        //set symbol
        var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 2), new dojo.Color([255,255,0,0.5]));
        feature.setSymbol(symbol);

        //construct infowindow title and content
        var attr = feature.attributes;
        var title = attr.P_Des_Nm;
        var content = "Park Name : " + attr.P_Des_Nm
                    + "<br />GAP Status : " + attr.GAP_Sts
                    + "<br />Mang_Name : " + attr.Own_Name
                    + "<br />GIS_Acres : " + attr.GIS_Acres;
        map.graphics.add(feature);

        map.infoWindow.setTitle(title);
        map.infoWindow.setContent(content);

        $((evt) ? map.infoWindow.show(evt.screenPoint,map.getInfoWindowAnchor(evt.screenPoint)) : null);
      }

      function showFeatureSet(fset,evt) {
        //remove all graphics on the maps graphics layer
        map.graphics.clear();
        var screenPoint = evt.screenPoint;

        featureSet = fset;

        var numFeatures = featureSet.features.length;

        //QueryTask returns a featureSet.  Loop through features in the featureSet and add them to the infowindow.
        var title = "You have selected " + numFeatures + " protected areas.";
        var content = "Please select desired field from the list below.<br />";

        for (var i=0; i<numFeatures; i++) {
          var graphic = featureSet.features;
          content = content + graphic.attributes.P_Des_Nm + " Field (<A href='#' onclick='showFeature(featureSet.features[" + i + "]);'>show</A>)<br/>";
        }

        map.infoWindow.setTitle(title);
        map.infoWindow.setContent(content);
        map.infoWindow.show(screenPoint,map.getInfoWindowAnchor(evt.screenPoint));
      }
break;
       case "bufferQuery":
          //Geometry Service Endpoint
var gsvc = new esri.tasks.GeometryService("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
queryTask = new esri.tasks.QueryTask("http://dingo.gapanalysisprogram.com/ArcGIS/rest/services/PADUS/PADUS_owner/MapServer/0");



// Query
var bufferquery = new esri.tasks.Query();

// +++++Listen for map onClick event+++++
dojo.connect(map, "onClick", function(evt) {
         //dojo.disconnect(globals);
map.graphics.clear();
var bufferparams = new esri.tasks.BufferParameters();
bufferparams.geometries = [ evt.mapPoint ];
// Buffer in linear units such as meters, km, miles etc.
bufferparams.distances = [ dojo.byId('bufferDistance').value ];
bufferparams.unit = esri.tasks.GeometryService.UNIT_STATUTE_MILE;
bufferparams.bufferSpatialReference = new esri.SpatialReference({"wkid": 3089});
bufferparams.outSpatialReference = new esri.SpatialReference({"wkid": 3089});
gsvc.buffer(bufferparams);
dojo.byId('messages').innerHTML = "<b>Creating Buffer Using Geometry Service...</b>";
});

// +++++Listen for GeometryService onBufferComplete event+++++
dojo.connect(gsvc, "onBufferComplete", function(geometries) {
var symbol = new esri.symbol.SimpleFillSymbol("none", new esri.symbol.SimpleLineSymbol("dashdot", new dojo.Color([255,0,0]), 2), new dojo.Color([255,255,0,0.25]));
var graphic = new esri.Graphic(geometries[0],symbol);
map.graphics.add(graphic);

bufferquery.returnGeometry = true;

bufferquery.outFields = ["P_Des_Nm","P_Loc_Nm","Own_Name","Mang_Name"];
bufferquery.outSpatialReference = map.spatialReference;
bufferquery.geometry = geometries[0];
//query.where = "quadrangle_name='Adairville'"
queryTask.execute(bufferquery);

dojo.byId('messages').innerHTML = "<b>Executing Query with Result Buffer Geometry...</b>";
});

// +++++Listen for QueryTask executecomplete event+++++
dojo.connect(queryTask, "onComplete", function(fset) {
//create symbol for selected features
var symbol = new esri.symbol.SimpleMarkerSymbol();
symbol.style = esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE;
symbol.setSize(8);
symbol.setColor(new dojo.Color([255,255,0,0.5]));

//var infoTemplate = new esri.InfoTemplate("Block: ${BLOCK}", "${*}");
var resultFeatures = fset.features;
for (var i=0, il=resultFeatures.length; i<il; i++) {
console.log(resultFeatures);
var graphic = resultFeatures;
graphic.setSymbol(symbol);
map.graphics.add(graphic);
}
var pareas = returnRecordNums(fset);
var r = "";
r = "<b>The protected areas within the buffer are <i>" + pareas + "</i>.</b>";
dojo.byId('messages').innerHTML = r;
});

function returnRecordNums(fset){
var features = fset.features;
var pas = "";
for (var x = 0; x < features.length; x++) {
pas = pas + ", " + features.attributes['P_Des_Nm'];
}
return pas;
}
// remember reset actionMode ="identify" after finish buffer query
actionMode = "identify";
//alert('buffer');

break;  
          }
   
      }
      function bufferBtn_onclick()
{
//set action mode to buffer
actionMode ="bufferQuery";
}
      dojo.addOnLoad(init);
    </script>
0 Kudos
JeremyAdams
New Contributor
I hav a similar issue.  I'm trying to use an info window to get parcel infromation, but i want to be able to use the measure tool when i need to WITHOUT the infoWindow poping up.  My idea around this was to simply change my 'onClick' event to 'onDblClick' to call the function for the infoWindow.  That way i can single click when using the measure tool.

The problem is that when i Double Click on the map it just zooms in to that location, no infoWindow is displayed. 

I've added map.disableDoubleClickZoom(); to my init() code but that doesn't seem to do any good because the map still zooms in and still DOESNT call my infoWindow
0 Kudos
HemingZhu
Occasional Contributor III
jmaxwell1562;98218 wrote:
I am having exactly the same problem.  I've copied your structure and the buffer part is working but the identify part is not. 


Could you offer some suggestions? 

Jill, The logic flow is right though it is kind hard to read. I rearranged your code so it might be easier for you to debug. Here is the code (i might have typos or syn errors, you have to look into when debugging).

var map, InfoqueryTask;
var featureSet;
var navToolbar;
var actionMode ="identify"; //default
var gsvc;
var queryTask;
function init() {
   
    esriConfig.defaults.io.proxyUrl = "http://dingo.gapanalysisprogram.com/proxy/proxy.ashx";
    //esri.config.defaults.io.proxyUrl = "http://www.gap.uidaho.edu/proxy.php";
    esriConfig.defaults.io.alwaysUseProxy = false;
   
    var startExtent = new esri.geometry.Extent({"xmin":-11207421,"ymin":4469708,"xmax":-10718224,"ymax":4836606,"spatialReference":{"wkid":102100}} );

    //create map
    map = new esri.Map("mapDiv", {extent: startExtent});
    dojo.connect(map, "onClick", doActionAccordingly);
    dojo.connect(map, "onLoad", function() {
        map.disableDoubleClickZoom();
    });

    var tiledLayer = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer");
    map.addLayer(tiledLayer);

    //create and add new layer
    var dynamicLayer = new esri.layers.ArcGISTiledMapServiceLayer("http://dingo.gapanalysisprogram.com/ArcGIS/rest/services/PADUS/PADUS_status/MapServer");
    map.addLayer(dynamicLayer);
   
    //Listent for infoWindow onHide event
    dojo.connect(map.infoWindow, "onHide", function() {map.graphics.clear();});
    //build query task
    InfoqueryTask = new esri.tasks.QueryTask("http://dingo.gapanalysisprogram.com/ArcGIS/rest/services/PADUS/PADUS_status/MapServer/0");
    dojo.connect(InfoqueryTask, "onComplete", onInfoqueryComplete);
   
    navToolbar = new esri.toolbars.Navigation(map);
    dojo.connect(navToolbar, "onExtentHistoryChange", extentHistoryChangeHandler);
  
    //Geometry Service Endpoint
    gsvc = new esri.tasks.GeometryService("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
    // +++++Listen for GeometryService onBufferComplete event+++++
    dojo.connect(gsvc, "onBufferComplete", onBufferComplete);
    queryTask = new esri.tasks.QueryTask("http://dingo.gapanalysisprogram.com/ArcGIS/rest/services/PADUS/PADUS_owner/MapServer/0");
    // +++++Listen for QueryTask executecomplete event+++++
    dojo.connect(queryTask, "onComplete", onQueryComplete);
}

function extentHistoryChangeHandler() {
    dijit.byId("zoomprev").disabled = navToolbar.isFirstExtent();
    dijit.byId("zoomnext").disabled = navToolbar.isLastExtent();
}

function executeInfoQueryTask(evt) {
    dojo.disconnect(globals);
    map.infoWindow.hide();
    map.graphics.clear();
    featureSet = null;
    //build query filter
    var Infoquery = new esri.tasks.Query();
    Infoquery.outSpatialReference = { "wkid": 102100 };
    Infoquery.returnGeometry = true;
    Infoquery.outFields = ["P_Des_Nm", "OBJECTID", "GIS_Acres", "GAP_Sts", "Own_Name", "Mang_Name"];
    Infoquery.geometry = evt.mapPoint;
    //Execute task and call showResults on completion
    InfoqueryTask.execute(Infoquery);
}
function onInfoqueryComplete(fset) {
    if (fset.features.length === 1) {
        showFeature(fset.features[0],evt);
    }
    else if (fset.features.length !== 0) {
        showFeatureSet(fset,evt);
    }
}
function showFeature(feature,evt) {
    map.graphics.clear();
    //set symbol
    var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 2), new dojo.Color([255,255,0,0.5]));
    feature.setSymbol(symbol);

    //construct infowindow title and content
    var attr = feature.attributes;
    var title = attr.P_Des_Nm;
    var content = "Park Name : " + attr.P_Des_Nm
        + "<br />GAP Status : " + attr.GAP_Sts
        + "<br />Mang_Name : " + attr.Own_Name
        + "<br />GIS_Acres : " + attr.GIS_Acres;
    map.graphics.add(feature);

    map.infoWindow.setTitle(title);
    map.infoWindow.setContent(content);

    $((evt) ? map.infoWindow.show(evt.screenPoint,map.getInfoWindowAnchor(evt.screenPoint)) : null);
}
function showFeatureSet(fset,evt) {
    //remove all graphics on the maps graphics layer
    map.graphics.clear();
    var screenPoint = evt.screenPoint;

    featureSet = fset;

    var numFeatures = featureSet.features.length;

    //QueryTask returns a featureSet. Loop through features in the featureSet and add them to the infowindow.
    var title = "You have selected " + numFeatures + " protected areas.";
    var content = "Please select desired field from the list below.<br />";

    for (var i=0; i<numFeatures; i++) {
        var graphic = featureSet.features;
        content = content + graphic.attributes.P_Des_Nm + " Field (<A href='#' onclick='showFeature(featureSet.features[" + i + "]);'>show</A>)<br/>";
    }

    map.infoWindow.setTitle(title);
    map.infoWindow.setContent(content);
    map.infoWindow.show(screenPoint,map.getInfoWindowAnchor(evt.screenPoint));
}
function executeBuffer(evt)
{
    // Query
    var bufferquery = new esri.tasks.Query();
    map.graphics.clear();
    var bufferparams = new esri.tasks.BufferParameters();
    bufferparams.geometries = [evt.mapPoint];
    // Buffer in linear units such as meters, km, miles etc.
    bufferparams.distances = [dojo.byId('bufferDistance').value];
    bufferparams.unit = esri.tasks.GeometryService.UNIT_STATUTE_MILE;
    bufferparams.bufferSpatialReference = new esri.SpatialReference({ "wkid": 3089 });
    bufferparams.outSpatialReference = new esri.SpatialReference({ "wkid": 3089 });
    gsvc.buffer(bufferparams);
    dojo.byId('messages').innerHTML = "<b>Creating Buffer Using Geometry Service...</b>";
}
function onBufferComplete(geometries) {
    var symbol = new esri.symbol.SimpleFillSymbol("none", new esri.symbol.SimpleLineSymbol("dashdot", new dojo.Color([255,0,0]), 2), new dojo.Color([255,255,0,0.25]));
    var graphic = new esri.Graphic(geometries[0],symbol);
    map.graphics.add(graphic);

    bufferquery.returnGeometry = true;

    bufferquery.outFields = ["P_Des_Nm","P_Loc_Nm","Own_Name","Mang_Name"];
    bufferquery.outSpatialReference = map.spatialReference;
    bufferquery.geometry = geometries[0];
    //query.where = "quadrangle_name='Adairville'"
    queryTask.execute(bufferquery);

    dojo.byId('messages').innerHTML = "<b>Executing Query with Result Buffer Geometry...</b>";
}
function onQueryComplete(fset) {
    //create symbol for selected features
    var symbol = new esri.symbol.SimpleMarkerSymbol();
    symbol.style = esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE;
    symbol.setSize(8);
    symbol.setColor(new dojo.Color([255,255,0,0.5]));

    //var infoTemplate = new esri.InfoTemplate("Block: ${BLOCK}", "${*}");
    var resultFeatures = fset.features;
    for (var i=0, il=resultFeatures.length; i<il; i++) {
    console.log(resultFeatures);
    var graphic = resultFeatures;
    graphic.setSymbol(symbol);
    map.graphics.add(graphic);
    }
    var pareas = returnRecordNums(fset);
    var r = "";
    r = "<b>The protected areas within the buffer are <i>" + pareas + "</i>.</b>";
    dojo.byId('messages').innerHTML = r;
   
}
function returnRecordNums(fset) {
    var features = fset.features;
    var pas = "";
    for (var x = 0; x < features.length; x++) {
        pas = pas + ", " + features.attributes['P_Des_Nm'];
    }
    return pas;
}
function doActionAccordingly(evt)
{
    switch (actionMode)
    {
        case "identify":
          executeInfoQueryTask(evt);
          break;
        case "bufferQuery":
          executeBuffer(evt);
          // remember reset actionMode ="identify" after finish buffer query
          actionMode = "identify";
          //alert('buffer');
          break;
}

}
function bufferBtn_onclick()
{
    //set action mode to buffer
    actionMode ="bufferQuery";
}
dojo.addOnLoad(init);
0 Kudos