Linking Waypoints and Pushpins?

aroberts
03-25-2008, 07:20 PM
I am placing Waypoints and Pushpins by iterating through a database that holds coords and a string (for the Pushpin name). I would like to detect whenever a Waypoint location is changed and move the corresponding Pushpin (since I can't label a Waypoint, I want the Pushpin for its label).

Since these are inherently linked in my database, what I really need to do is to detect the Waypoint move and update the database with its new coordinates (then re-plot the route from the database).

I have tried the SelectionChange and MouseUp events, but the firing order of those two events always makes the update one step behind.

Any suggestions to accomplish the "tracking" of a Pushpin so that it always follows the dragging of a Waypoint?



Thanks.

aroberts
03-28-2008, 05:23 PM
Never mind, I figured out a way to do it. Thanks for all the responses.

Eric Frost
03-29-2008, 02:42 AM
How did you do it?

Eric

aroberts
03-29-2008, 04:22 PM
A lot of workarounds. I worked from the selection of a PushPin rather than its associated WayPoint.

Creating the route:

As mentioned originally, I have a database that contains the fields Route(string), Lat (double), Lon (double), StopName (string), and Seq (integer). The user can build the route by placing Pushpins from a context menu (I intercept right-click and pop up a menu).

The table is filtered against the Route field. Upon the selection of a route, I clear any existing Routes and Pushpins, then iterate through the table and place Pushpins/Waypoints at the associated Lat and Lon values, as well as assign the Waypoint.ListPosition to the Seq field of the DB. When done, I call the Calculate method.

Detecting a moved Pushpin:

I used the SelectionChange event and QueryInterface method to test for a pushpin. Then, I set a global pushpin var to the NewSelection. In the MouseUp event, I re-queried to ensure that the selection was a pushpin (superfluous, but it didn't cost anything). If it was, then I started a 50ms timer. This is needed because the new position of the Pushpin isn't "set" until after the completion of the MouseUp event.

The timer event self-disables, and tests the current selection for (you guessed it) a Pushpin. I created a function called CheckMove that iterates through the underlying database table and locates the proper record based on the Seq (ListPosition) field in the DB. When located, if either Lat or Lon has changed, then it returns true.

If true, I call a procedure, RefreshMap that updates the change to the underlying database (using the Dataset.Locate method and the Seq/ListPosition).

Finally (whew), I clear and recreate the map from the updated DB.

The result: Any time that a Pushpin is moved, the Waypoint follows it and the route is updated.

I allow only the selection/move of Pushpins; any selection of a Waypoint is transferred to its associated Pushpin.

I hope that this rather long description is coherent. It would have been a trivial matter if only there were a few drag/drop or "symbol moved--oldposition/newposition" types of events. Alas, I was relegated to this rather klunky method.

 
Web mp2kmag.com
mapforums.com