Measurement Widget (Only show most recent distance)

412
2
Jump to solution
11-12-2020 02:18 PM
khanley
New Contributor II

Using Javascript 3.34

Is there a simple way to only show the most recent distance measured with the measurement widget instead of having the distance added to the previous distance every time you click? If not, is there a simple way to store the current value into a variable? I'm having a hard time tracking down where I can either find or calculate that value.

Thanks!

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

I do not see a documented way to access that value.

As a workaround, it does seem like there is a "result" property is available on the "measurement" widget object. This is not documented, so use at your own risk!

It looks like it does not convert units that the widget has chosen, but instead shows the units of the map (meters for web mercator). So you can access the value there, save it, and do what you need. It seems like it's not populated until after some asynchronous amount of time, so you need to use a setTimeout to get the value too (not very consistent - again, use at your own risk and only if you know what you're doing). Example here: https://codepen.io/gavinr/pen/eYzxjmJ?editors=0010

If there's something I'm missing and there's a better, documented way to do this that someone else will post later, please use that - this is not an ideal solution.

View solution in original post

0 Kudos
2 Replies
by Anonymous User
Not applicable

I do not see a documented way to access that value.

As a workaround, it does seem like there is a "result" property is available on the "measurement" widget object. This is not documented, so use at your own risk!

It looks like it does not convert units that the widget has chosen, but instead shows the units of the map (meters for web mercator). So you can access the value there, save it, and do what you need. It seems like it's not populated until after some asynchronous amount of time, so you need to use a setTimeout to get the value too (not very consistent - again, use at your own risk and only if you know what you're doing). Example here: https://codepen.io/gavinr/pen/eYzxjmJ?editors=0010

If there's something I'm missing and there's a better, documented way to do this that someone else will post later, please use that - this is not an ideal solution.

0 Kudos
khanley
New Contributor II

This is perfect. Thank you so much!

0 Kudos