Hi
II have a widget
var measurement = new esri.dijit.Measurement({
map: map,
defaultAreaUnit: esri.Units.SQUARE_METERS,
defaultLengthUnit: esri.Units.METERS
}, dojo.byId('measurementDiv'));
//measurement.hideTool("location");
measurement.on("measure-end", function (evt) {
console.debug("Really ended?")
this.setTool(evt.activeTool, false);
enableID();
});
measurement.startup();
Define as above.
However the measure-end event is fired after each node of an area measure from the third node onwards. There follows a large error message
The task does, however keep going when area is being measured.
"TypeError: undefined is not a function at http://x/common/init.js?123:185:14 at null.<anonymous> (http://x/arcgis_js_api/library/3.10/3.10/init.js:777:175) at h.(anonymous function).g [as onMeasureEnd] (http://x/arcgis_js_api/library/3.10/3.10/init.js:239:390) at s._showArea (http://x/arcgis_js_api/library/3.10/3.10/js/esri/dijit/Measurement.js:35:330) at s._outputArea (http://x/arcgis_js_api/library/3.10/3.10/js/esri/dijit/Measurement.js:35:181) at null.<anonymous> (http://x/arcgis_js_api/library/3.10/3.10/init.js:173:473) at h.(anonymous function).g [as onAreasAndLengthsComplete] (http://x/arcgis_js_api/library/3.10/3.10/init.js:239:390) at e._successHandler (http://x/arcgis_js_api/library/3.10/3.10/init.js:490:174) at e._areasAndLengthsHandler (http://x/arcgis_js_api/library/3.10/3.10/init.js:916:267) at http://x/arcgis_js_api/library/3.10/3.10/init.js:174:23"
Strange? Or my fault?
ACM
UPDATE
Using the older dojo.connect
dojo.connect(measurement, "onMeasureEnd", function (activeTool, geometry) {
this.setTool(activeTool, false);
enableID();
});
And the event fires, as before on the third click, for area, but doesn't have the error, and re-enables my ID task.
It looks like the new widget is firing the OnMeasureEnd event each time a result for the area is required - the old tool only got the result on double click - ending the drawing.
the code worked fine in 3.8 & 3.9
Solved! Go to Solution.
Anyone any ideas on this? As it is it is a breaking change preventing me from moving to 3.10.
I'm not sure I would call this a bug, it's more like a needed enhancement. Anyway, here is some code that will provide a work around for your issue:
//Variable to keep track of whether the measurement has ended
var end = false;
//If the map is double clicked, and the polygon measure tool is currently selected, set end to true
map.on("dbl-click", function() {
if(dom.byId("dijit_form_ToggleButton_0").getAttribute("aria-pressed") == "true") {
end = true;
}
}
//If end is true, execute your functions
measure.on("measure-end", function() {
if (end == true) {
<your functions>
end = false;
}
}
There may be (and probably is) a more elegant way to do this but this fixed the problem you described.
Thanks for that - I'll try it later. But I do think it is a bug, or a t least a "Breaking Change" as the examples given measurement-amd | API Reference | ArcGIS API for JavaScript no longer work as the event no longer does what it says it does.
On-measure-end is quite clear in what it should do, an event that fires when measurement is ended. It doesn't. It fires when a polygon has been created and an intermediate measurement has been calculated.
This only fails for area. For length a result is returned with each click without firing the on-measure-end event.
Adrian,
This one looks like a bug to me. Do you have support? If so can you submit an issue to them for this so we can get it logged into the system as a bug.
Thanks
Kelly
Yep - got it with Esri(UK) at the moment, but not much movement.
logged as a bug
Esri Inc Bug: NIM#104292
I'll update here if I hear anything else, but as it is a bug it has now left the control of our local Esri.
This bug has been fixed in 3.11 - I've just tested it and the measure-end event only triggers when the area tool is double clicked rather than at each node.
There's also a few new events. Enjoy
This is kind of an older post but I was running into similar issues and wanted to share my workaround...
The documentation still says that this will work but I was still getting error messages
measurement.on("measure-end", function(evt){
this.setTool(evt.activeTool, false);
});
I changed my code to evt.toolName and was able to get around the error message coming up:
measureW.on("measure-end", function(evt)
{
measureW.setTool(evt.toolName, false);
});
If you need to be more specific you can modify the code to something like
if(evt.toolName == "location")
Hope this saves someone a little debugging time out there.