Measure distances sample - written in AMD

1317
9
Jump to solution
11-07-2014 07:23 AM
TracySchloss
Frequent Contributor

I want to do a very basic distance measure, but I also need identify in my project.  I'm not seeing/understanding whether or not I can manage the listeners for that dijit in order to pause and remove my identify task as needed.  I thought about using the Measure Distances example Measure distances | ArcGIS API for JavaScript which uses the GeometryService to get the length. 

That example is written in legacy.  When I tried to rewrite it in AMD, I'm getting an error, "Cannot read property 'setImmediateClick' of undefined"  That seems like I'm trying to use something before it's initialized or loaded, but I'm not sure what.

Maybe someone can figure out what I did wrong.  I haven't used the LengthsParameters before in GeometryService and I haven't used the Draw toolbar much either.

http://jsfiddle.net/xksqx3an/

0 Kudos
1 Solution

Accepted Solutions
TracySchloss
Frequent Contributor

I've used pausable for dojo/on in several other projects for just such a situation.  I ended up adding a Boolean 'identifyEnabled' and setting it to true/false in your windowPop function.  Then I changed my runIdentifies to only execute when identifyEnabled is true.  That seems to have taken care of my problem.

View solution in original post

0 Kudos
9 Replies
TimWitt2
MVP Alum

Hey Tracy,

You could create a measurement checkbox and while the measurement checkbox is checked your identify task won't run.

See the first couple of lines in my app.

Full Mapping Application - JSFiddle

    //Identify Task

    on(registry.byId("identifyDiv"),"click", activateIdentify);

    function activateIdentify(evt){

      if (dijit.byId('identifyDiv').checked) {

          identifyListener = map.on("click", executeIdentifyTask);

          

        }

        else {

          identifyListener.remove();

        }

      }

Hope this helps!

Tim

TracySchloss
Frequent Contributor

That could work.  I was hoping to be able to suspend the identify just by clicking on one of the tools in the measurement dijit and having it resume once the measurement was complete. 

I tried originally listening for the measure-start and measure-end events to pause my identify, but it was firing anyway.

0 Kudos
TimWitt2
MVP Alum

Tracy,

look at my last post here: https://community.esri.com/message/421034#421034

You can check if a part of the measurement widget is active:

  1.   function windowPop(){ 
  2.   if (measurement.area.checked || measurement.distance.checked || measurement.location.checked){ 
  3.   map.setInfoWindowOnClick(false); 
  4.   } else
  5.   map.setInfoWindowOnClick(true); 
  6.   } 
  7.   } 
  8.  
  9.   measurement.on("measure-end", function (){ 
  10.   map.setInfoWindowOnClick(true); 
  11.   }); 

Hope this helps!

Tim

TracySchloss
Frequent Contributor

That seems to work OK for the first time I measure.  When I measure a 2nd time, it's still doing the identify, even though I think I have it turned off. I have my identifyHandler defined as pausable, so I don't have keep destroying it.

var identifyHandler = on.pausable(map, 'click', runIdentifies);

I added lines to suspend my identify, but that didn't make a difference. 

function windowPop(){ 

    if (measurement.area.checked || measurement.distance.checked || measurement.location.checked){ 

    console.log("measurement checked");

    map.setInfoWindowOnClick(false);

   identifyHandler.pause(); 

    } else { 

    console.log("measurement not checked");

    map.setInfoWindowOnClick(true); 

identifyHandler.resume();

    } 

    } 

0 Kudos
TimWitt2
MVP Alum

Also use this line

  1.   map.on("mouse-over", windowPop); 

So the function will run whenever your mouse is going over your map.

Let me know if that fixes it.

0 Kudos
TracySchloss
Frequent Contributor

Sorry, I should have mentioned.  I have that line in there too.  I'm not quite sure why it works OK the 1st time, but doesn't the rest of the time.  I would assume that something like measurement.distance.checked would be more the current state of the tool and not an event like 'click' on the tool itself. 

0 Kudos
TimWitt2
MVP Alum

I think instead of pause you need to remove it and then add it again after else.

0 Kudos
TracySchloss
Frequent Contributor

I've used pausable for dojo/on in several other projects for just such a situation.  I ended up adding a Boolean 'identifyEnabled' and setting it to true/false in your windowPop function.  Then I changed my runIdentifies to only execute when identifyEnabled is true.  That seems to have taken care of my problem.

0 Kudos
TimWitt2
MVP Alum

Awesome, glad you got it working!

0 Kudos