Using measurement widget does not interact very well with mouse events

1384
8
Jump to solution
08-02-2012 06:27 AM
OrlandoCarvajal
New Contributor III
Hi there,

I'm using the measurement widget in a JavaScript API application, but the users find the response from mouse events awkward. These are the issues I'm running into:
1. Too often you click on the map, but it seems like the map does not detect the click.
2. When you do a click on the map you should stop the mouse, wait a second and then click, otherwise it thinks like you are panning. Not sure if it's related to item 1. I have deactivated Panning on the map, so it doesn't pan anymore, but we still have to wait for a moment before clicking on the map. The sample from ESRI behaves totally this way: if you do a small drag while selecting the polygon or line vertices, the map gets locked to an endless panning behavior. I wonder if there's a way to change some setting or prevent other click events from being triggered.
3. The tool buttons behave inconsistently: you perform area or length measures one after the other, but for the location tool you need to click on the button every time you want to use it again. This is, the location tool deactivates automatically, whereas the length and area tools don't.
4. The tool buttons are actually toggle buttons: if you click them again they deactivate. How can I change that so they stay active until something else gets activated?
5. Would it be possible somehow access a tool activate event?

We are using IE8 and IE9. Should I rather switch to use the Draw toolbar y do the calculations by myself?

Cheers,
Orlando
0 Kudos
1 Solution

Accepted Solutions
JianHuang
Occasional Contributor III
Those buttons are dojo dijits. You can access them by measurement.area, measurement.distance and measurement.location. If you need to connect to the onClick event. Here is the code snippet.

          var measurement = new esri.dijit.Measurement({
            map: map
          }, dojo.byId('measurementDiv'));
         
          measurement.startup();
          dojo.connect(measurement.area, "onClick", function(){console.log("hello");});

View solution in original post

0 Kudos
8 Replies
JianHuang
Occasional Contributor III
Orlando,

Please see the answers between your questions.
1. Too often you click on the map, but it seems like the map does not detect the click.

If you click fast, it triggers mouse drag instead of mouse click.

2. When you do a click on the map you should stop the mouse, wait a second and then click, otherwise it thinks like you are panning. Not sure if it's related to item 1. I have deactivated Panning on the map, so it doesn't pan anymore, but we still have to wait for a moment before clicking on the map. The sample from ESRI behaves totally this way: if you do a small drag while selecting the polygon or line vertices, the map gets locked to an endless panning behavior. I wonder if there's a way to change some setting or prevent other click events from being triggered.

The same reason as question 1. Even you use drawToolbar, it behaves the same.

3. The tool buttons behave inconsistently: you perform area or length measures one after the other, but for the location tool you need to click on the button every time you want to use it again. This is, the location tool deactivates automatically, whereas the length and area tools don't.

This is by design. When using location tool, the location info constantly changes according to the current mouse location (mouse over). If keep the location tool active after you click on the map, the location info will change and the end user wouldn't know what the location is on the clicking point.

4. The tool buttons are actually toggle buttons: if you click them again they deactivate. How can I change that so they stay active until something else gets activated?

Please use setTool(toolName, activate) method to activate/deactivate tools.

5. Would it be possible somehow access a tool activate event?

you can capture the button click event of those toggle buttons.
0 Kudos
OrlandoCarvajal
New Contributor III
Hi Jiang,

Thanks for your answers. Could you please give me an example on how to catch the click event for the buttons of the measurement widget?

It would be nice to have the option to remove the behavior of showing coordinates while you move the mouse with the location tool. This is for the sake of consistency.

Shouldn't the the map behave such that when I'm in drawing the points for measuring of any type, the dragging on the map is completely disabled?

Something I didn't mention is that in the measurement sample, when you are setting the polygons points on the map, if you happen to do a drag -- whether it's accidental or on purpose -- the map starts panning and it gets locked on the panning. The only way to avoid this was to set map.isPan to true.

However, because I'm also using the navigation toolbar, setting map.isPan to true, seems to be causing another weird behavior: when I use the zoom in/out tools the map is drawing the zoom box, but doing panning! Should I provide you with an example?

My client was using an application written with the old ASP .Net ADF, and they ask me why if the old measuring is written in JavaScript, the "new" measurement reacts to the clicks so different. They didn't have the problems we are seeing now. I tell them that it's most likely a complete different development group at ESRI, and that they are using slightly different flavor of Javascript technology. I cannot even promise them that it'll get "fixed". What else should I say and expect about this?

Thanks in advance for your help,

Orlando
0 Kudos
JimWharton
New Contributor III
I too would like an example of how to subscribe to this toggle/click event.

I have an identify task setup that I'd like to disable while the measurement tools are being used. It's really kludgy to have identify popups while a user is trying to get a measurement. I can reconnect the event listner when the toggle button is off I'm sure.

I just can't find a way to subscribe.
0 Kudos
OrlandoCarvajal
New Contributor III
Hi Jian,

Could you please confirm that there's no such event for capturing the buttons' click?

Please, if you know, could you share something about the strange behaviors I described above?

Thanks,
Orlando
0 Kudos
JimWharton
New Contributor III
What I ended up doing is looking for the non-standard HTML attribute "aria-pressed". if it's set to true, I disconnect the click event.
0 Kudos
JianHuang
Occasional Contributor III
Those buttons are dojo dijits. You can access them by measurement.area, measurement.distance and measurement.location. If you need to connect to the onClick event. Here is the code snippet.

          var measurement = new esri.dijit.Measurement({
            map: map
          }, dojo.byId('measurementDiv'));
         
          measurement.startup();
          dojo.connect(measurement.area, "onClick", function(){console.log("hello");});
0 Kudos
AndrewDavis
New Contributor
Those buttons are dojo dijits. You can access them by measurement.area, measurement.distance and measurement.location. If you need to connect to the onClick event. Here is the code snippet.

          var measurement = new esri.dijit.Measurement({
            map: map
          }, dojo.byId('measurementDiv'));
         
          measurement.startup();
          dojo.connect(measurement.area, "onClick", function(){console.log("hello");});


Thank you for this. 

I am using the line above to see that I have clicked  on the distance tool inside the Measure Widget.  I am setting a Boolean variable to either true or false to try and suppress the info window on my map.

This works for the first click but then after I click again for the next measured waypoint, I get the info window, which I don't want, but it has the info of the original place where clicked.  Ex: Click on N Africa, measure to Rio, and when I click on Rio an info window comes up with info about Africa...

Is there a way to see which tool has focus to further suppress the map info window?

Andy..
0 Kudos
AdrianMarsden
Occasional Contributor III
After failing to write my own measure widget, I'm returning to this one, although it does have one main shortcoming (which mine didn't) and that is it fails to return the area measurement until the drawing is finished.

Is there an even I can hook into that intercepts the mouse clicks as the drawing is made and then returns the polygon at that point (or attributes of the polygon)?

Cheers

ACM

PS the other failing is it doesn't spell metres the way we do.;)
0 Kudos