I am trying to draw a ruler on the map to allow users to measure distances.
I want to do 2 things:
1) Only allow 2 vertexes - I don't want the user to have to double click to end the line, I want first click to start the line and second click to end the line.
2) Display the distance as a label on the line as I am drawing the line ie the label changes as the line gets longer then is set as the last click hapens.
In v2 I used TrackShapesDraw to do a lot of this.
At the moment I can switch to drawing mode and draw lines on the map but can't do items 1 and 2 above. I could possible use VertexAdded and count each vertex to determine when the second vertex has been added but that doesn't feel correct. Also, how do you manually stop the line drawing?
I have searched the forums and found a number of similar how do I posts but no answers.
TrackMode.StraightLine nearly covers item 1 but unfortunately the user has to keep the mouse button pressed while they draw the line. My users are using tablets with a stylus which makes it hard to do this. I really need to have click start, click end.
The requirements you mentioned is somehow complex, we may need to create a brand new TrackInterativeOverlay to make it. I took a try and hope following code is what we are going to achieve.
rulerLineShape = new LineShape(new Collection<Vertex>() { new Vertex(interactionArguments.WorldX, interactionArguments.WorldY), new Vertex(interactionArguments.WorldX, interactionArguments.WorldY) });
if (!TrackShapeLayer.InternalFeatures.Contains(currentFeatureKey)) { TrackShapeLayer.InternalFeatures.Add(currentFeatureKey, new Feature(rulerLineShape)); } mouseDown++; return interactiveResult; }
Looks good and we are nearly there. Just one small problem.
The override of mouse down, up and move core seem to work whatever mode I’m in. I only want to draw a ruler when I’m in track mode. I fixed this by checking for the mode and returning if TrackMode == TrackMode.None.
I am not exactly sure what cases we want to achieve, if we use the TrackMode to see if it is None can only deal with pan, we cannot make any difference between TrackPolygon, TrackRectangle etc. If we want, we can use the same logic with TrackMode information used.
Thanks Yale. Works fine now. Hopefully anyone else trying to do the same thing will find this post as the code you wrote pretty much solves the problem. Maybe worth posting in the newsletter or code community as it provides examples of a number of techniques.