Hi, I saw a few older posts (three years old most recent) but I would like to capture length on each segment while using Measurement tool. I thought using "measure" event would work but that doesn't seem to fire. Can you help?
Here is how I am starting and capturing "measure" event...
var measurement;
$('#liMeasurementOn').click(function () {
var divMeasure = ""
$('#titlePane').append(divMeasure);
$('#titlePane').show();
$('#liMeasurementOn').hide();
$('#liMeasurementOff').show();
dojo.disconnect(connects);
measurement = new Measurement({
map: map,
lineSymbol: measureSymbol,
defaultLengthUnit: Units.FEET },
dom.byId("measurementDiv"));
measurement.startup();
measurement.hideTool("location");
dojo.connect(measurement,"measure", function() {
alert('here');
});
});
according to api "measure" is an event of Measurement https://developers.arcgis.com/javascript/jsapi/measurement-amd.html#event-measure
Solved! Go to Solution.
I modified one of the samples from the API's site here and it seems to be working:
Hi John,
I was able to achieve this by grabbing code from Tim Witt's sample here Javascript API - Advanced Draw widget.
Hope this helps!
Ryan
Thanks Ryan,
That is a pretty cool widget!
Do you know why the "measure" event is not firing in my situation?
When you use "dojo.connect" instead of "on", the event has a different name. Instead of "measure", it would be "onMeasure". You should get in the habit of using the "on" style. From the Events documentation:
Using the
on
method is preferable to usingconnect
for several reasons. First, the Dojo documentation states thatconnect
support will be removed in Dojo 2.0, and in fact,connect
is now a legacy convenience wrapper fordojo.on
. Secondly, especially in AMD style, it makes your code less verbose and is more similar to event attachment syntax in other JavaScript frameworks. Finally, foresri
components we add atarget
property to all "synthetic" events (not mouse or key events) which points to the component which fired the event. Since event handlers fire asynchronously and there is no guarantee of the context in which the event handler will fire, the value ofthis
is not dependable. However, the value ofevt.target
is dependable.
The documentation for the connect style events of the Measurement dijit only lists "onMeasureEnd". I don't know if this is an oversight or not.
Thank you Ken,
I actually tried both ways. Maybe I'm confusing "on connect events" with "on style events." "measure" is an "on style event" while as you point out "OnMeasureEnd" is an "on connect event." "measure-end", "measure-start" are other "on style events."
For example:
This fires:
measurement.on("measure-end", function () {
alert('here1');
});
This does not:
measurement.on("measure", function () {
alert('here');
});
I modified one of the samples from the API's site here and it seems to be working:
Thank you Ryan,
That works great! I've spent the afternoon trying to figure out why your fiddle worked but not my map.
Your example is using ArcGIS version 3.15, while I am using 3.8. It seems odd that it wouldn't work but I changed my map to version 3.15 and it works fine.
The measure event wasn't introduced until version 3.11. This is noted in the documentation.