Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

Subscribe to receive our newsletter.
Subscribe Unsubscribe
Results 1 to 4 of 4

Where did I click on that line?

This is a discussion on Where did I click on that line? within the MapPoint Desktop Discussion forums, part of the Map Forums category; On my application I have a list box which displays a journey with time and location gathered from a GPS ...

  1. #1
    Jumbly is offline Junior Member White Belt
    Join Date
    Nov 2004
    Posts
    3

    Where did I click on that line?

    On my application I have a list box which displays a journey with time and location gathered from a GPS log. Next to it I draw a track on a map of the journey by generating a collection of locations for journey points and calling the AddPolyLine method to create a visible track to add to the shapes collection.

    When the user clicks on any journey point in the list box I go to that point on the map so the map display is updated with where he is.

    What I would like to do also is work the other way. Allow the user to click on the track and reposition the listbox display to the corresponding journey point. This is needed since the journey can consist of thousands of points and there is important other information gathered with the GPS signal.

    My first thought was to use the map SelectionChange event which fires when the user first clicks on the line. From that determine the what had been selected (the line) from the GetItemType method. But that is going no where! There are no parameters in the event that I can use to determine what part of the line was clicked - the whole line is selected, not a point or a line segment.


    Any ideas how I can work back to the location nearest to the point I clicked on the line?

    TIA

  2. #2
    Winwaed's Avatar
    Winwaed is offline Mapping-Tools.com Black Belt
    Join Date
    Feb 2004
    Location
    Irving,Texas
    Posts
    1,859
    Blog Entries
    60
    Hmm, I thought there was somewhere to get at a selected vertex, but I've just had a quick scan through the docs for the event and I can't see anything.

    If you have "thousands" of vertices it might be a bit slow, but you could try a brute-force search.
    Get the mouse position immediately after the event fireing.
    Start at the beginning, compare each location in the track against the mouse position. Do with with a simple "DistanceTo" call. Choose the vertex with the lowest distance.

    Depending on how complex your track is, there are probably ways to speed it up. Eg. if they tend to approximate straight lines then a simple "binary chop" algorithm will change the search space from N to log2(N).


    Richard
    Winwaed Software Technology LLC
    http://www.winwaed.com
    See http://www.mapping-tools.com for MapPoint Tools

  3. #3
    Jumbly is offline Junior Member White Belt
    Join Date
    Nov 2004
    Posts
    3
    Ouch! I was afraid I would have to find a brute strength answer. Unfortunately the tracks can be complex and often parallel (journey to and return). Hence picking out the nearest vertex could often miss the spot by hours.

    However you have got me thinking

    If i develop a brute strength scheme which provides alternative hits then I could examine the line equation between vertices and determine mathematically if the point lies on that line.

    Thanks

  4. #4
    Jumbly is offline Junior Member White Belt
    Join Date
    Nov 2004
    Posts
    3
    Solved

    Instead of plotting one long line for the track I split it up into segments no more than 15 minutes journey time long. Each journey segment is assigned a shape name which includes the listbox index of the first vertex on the line. When the user clicks on the track I use the name of the shape selected to work back to the listbox ensure the originating reading is selected and visible.

    So the user doesn't get to the nearest point on the track but within a reasonable region of the journey (given that reading at most every 30 seconds). It is slower to plot the track for a long journey but 15 minute segments is a good compromise.


    Thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to add click event for VB.Net ?
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 2
    Last Post: 12-31-2003, 01:15 AM
  2. Double Click on map
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 08-08-2003, 07:42 PM
  3. How can I create a line between two line with VB6
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 04-29-2003, 06:44 PM
  4. What happens when YOU click on a street?
    By schuchhardp in forum MapPoint Desktop Discussion
    Replies: 5
    Last Post: 01-03-2003, 11:37 AM
  5. As I draw a line and then a pushpin on that line, ....
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 07-16-2002, 09:35 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66