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.
Solved! Go to Solution.
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.
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
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.
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:
Hope this helps!
Tim
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();
}
}
Also use this line
So the function will run whenever your mouse is going over your map.
Let me know if that fixes it.
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.
I think instead of pause you need to remove it and then add it again after else.
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.
Awesome, glad you got it working!