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 5 of 5

AddPolyLine dilemma - is it GetLocation here that's problematic ?

This is a discussion on AddPolyLine dilemma - is it GetLocation here that's problematic ? within the MapPoint Desktop Discussion forums, part of the Map Forums category; Hi folks Using VB6 and the MapPointControl here I'll paste code as I find searching these boards, I've learned a ...

  1. #1
    tfmiltz is offline Member Green Belt
    Join Date
    Feb 2005

    AddPolyLine dilemma - is it GetLocation here that's problematic ?

    Hi folks

    Using VB6 and the MapPointControl here

    I'll paste code as I find searching these boards, I've learned a good bit from the code examples from peoples problems.

    I have a custom poly approach where I build an array of Location objects (zero based). I trap when CTRL is pressed to know when to add the point, as I want users to still have normal mouse function with the MapPoint ActiveX Map control - I THEN assign this to a final Shape Object for the current workspace using the .AddPolyLine

    Set oCurrentShapeFinal = MappointControl1.ActiveMap.Shapes.AddPolyline(oLoc ations)

    This works great. I of course require them to Close the polygon using right click exposure to Close - but that's not issue.

    I allow the user to SAVE this polygon, I figured gee, I should be able to comprise the users poly data with lat, lon and a verticeIndex to keep the order right.

    Because I let the user have multiple poly's on the MP control, I use a generic NAME property for current poly being edited with NewPoly. So just understand the outer loop is to isolate the shape I want.

    Dim dLat As Double
    Dim dLon As Double
    Dim oloc As MapPoint.Location
    lCnt = 0

    Dim objShape As MapPoint.Shape

    For Each objShape In MappointControl1.ActiveMap.Shapes

    If objShape.Name = "NewPoly" Then

    For iVertices = 0 To UBound(objShape.Vertices)
    ReDim Preserve dCurrentShapeLongitude(0 To lCnt)
    ReDim Preserve dCurrentShapeLatitude(0 To lCnt)

    CalcPos frmMapRef.MappointControl1.ActiveMap, objShape.Vertices(iVertices).Location, dLat, dLon
    dCurrentShapeLongitude(lCnt) = dLon
    dCurrentShapeLatitude(lCnt) = dLat
    lCnt = lCnt + 1
    End If


    All is well - any new users here, CalcPos can be found throughout this board. It's an outside function to get Lat Lon from XY on the MP Control. (Funny there is more ingenuity from this forum seemingly than inhouse at MS - no comment).

    Well, all was well until I went to let the user LOAD the shape back in.

    I thought, ok, I'll call the MP .GetLocation that allows me to create a new Location object (I need to rebuild an arrayed Location Object to feed to .AddPolyLine) from lat lon. I pulled ors - my recordset object ordered by verticeIndex from my 3 field table - ok 4 with key, but 3 fields used are lat, lon and vertice index on key.

    I use ltemp as a counter here - just a generic long (VB6 compiler actually performs better with longs, SIDE issue heh - strange but true)

    While Not ors.EOF

    ReDim Preserve oLocations(0 To lTemp)

    ReDim Preserve dCurrentShapeLongitude(0 To lTemp)
    ReDim Preserve dCurrentShapeLatitude(0 To lTemp)

    dCurrentShapeLongitude(lTemp) = ors.Fields("latitude")
    dCurrentShapeLatitude(lTemp) = ors.Fields("longitude")

    Set oLocations(lTemp) = MappointControl1.ActiveMap.GetLocation(dCurrentSha peLatitude(lTemp), dCurrentShapeLongitude(lTemp))
    lTemp = lTemp + 1


    Set oCurrentShapeFinal = MappointControl1.ActiveMap.Shapes.AddPolyline(oLoc ations)

    Well - no poly showed up. Where oCurrentShapeFinal works just fine when creating it as the user creates their poly ?
    Nothing here. No show. It shows fine when I feed it my arrayed Location Object using XY but apparantly ? my location object using GetLocation ? I'm just not sure, am I not getting the exact same arrayed location object rebuilding it thinking that lat lon would be enough to reconstruct it ?

    It is identical to my assignment of oCurrentShapeFinal that CLEARLY works in creating the polygons.

    Yet ?

    To my dismay - NO custom shape appeared on the MapPoint Control on passing my ressurected Location Object array to feed to the Shape object I sought to populate using AddPolyLine

    so here I am wondering, gee, what's going wrong here.

    Is it my Location object array ? that's not identical ?

    When the user creates the custom poly, I use

    Set oLocations(lPointMaxCnt) = MappointControl1.ActiveMap.XYToLocation(X, Y)

    I'm always impressed at the organization of the MP Object Model, but.

    Is a location object a location object a location object etc ?

    I mean, Whether I assign a location object using .XYToLocation OR .GetLocation ?

    isn't it the same result ?

    Either way, I THINK and FEEL that my arrayed location object is fine - reconstituting it from lat lon ordered by verticeIndex in a table.

    And I expect to be able to pass this arrayed location object to a shape object using .AddPolyLine(myLocationObjectHere)

    this works in creating the initial poly, but when I go to recreate 'as if' a user did this ? to give them the experience of 'Loading' a custom poly ?


    Nothing shows.

    So, I ask the community here, any insights ?

    thanks in advance.

    It's gonna be Eric, Winwaed, or Wilfried, prolly Wilfried ! ok ok - really, anyone who has any insights, please do share.


    I do hope the code I posted helps someone who may in some way be trying to even get to first base here !

    I'm just going for a triple (I really am not fan of baseball, but the allegory seems right)

    Not sure what the Homerun is with MP ! heh. Probably getting multiple control instances to not conflict with multiple app instances - did read that article on how to prevent that jittery window flux when doing that ! heh.

    Tim Miltz
    Last edited by tfmiltz; 11-01-2007 at 01:16 AM. Reason: correction

  2. #2
    tfmiltz is offline Member Green Belt
    Join Date
    Feb 2005

    Re: AddPolyLine dilemma - is it GetLocation here that's problematic ?

    Just to condense my point.

    I have a successful use of .AddPolyline on a shape object - passing it an arrayed Location Object (zero based).

    I use the .vertices(index).Location property to pass off to the CalcPos function to get me lat/lon + the index to store in a table.

    This is used to recreate the polygon.

    Yet ?

    When I go to recreate my array of location objects (same arrayed var actually that works in edit mode) ? I use the .GetLocation method because I can pass it lat/lon, which I figured would be enough data to recreate each vertice of the polygon.

    Yet ? After I repopulate my Location Object array ?

    and pass IT off - just like I do successfully when user creates the poly ?

    to the final Shape object using .AddPolyLine (my_arrayed_location_object_here) ?

    no shape on the mappoint control.

    yet same methodology SHORT - only difference I can see is how I create my location object.

    When I get a successful .AddPolyLine method fired off on a shape object ? I'm creating the Location object using XY, and latter case I create it using GetLocation using the Lat/Lon I store.

    I'm guessing it has something to do with my Location Object and how I'm creating it.

    But I'd think a location object is a location object is a location object whether I create it from lat/lon OR XY - for - .GetLocation works using lat lon, and XY works by XY.

    I made sure I set .Line.Forecolor just in case to vbBlack -

    This is just an unexpected hurdle in closing this poly issue ! pun intended !

    Thanks Wilfried in advance ! Cause I just know you're going to probably have some insight here.

    If I actually MADE any money, I'd forward you some. ! heh

    Tim Miltz

  3. #3
    tfmiltz is offline Member Green Belt
    Join Date
    Feb 2005

    Re: AddPolyLine dilemma - is it GetLocation here that's problematic ?


    X Y holds true

    I would NOT expect X Y to hold relative, er, absolute values to where I sought Lat Lon to state what is objecively REAL.

    Just tried X Y vals over lat lon - and got MOST of my shape back.

    I'll continue onward but this is sketchy to me- that MP won't let me feed it an array of lat/lon to create an arrayed location object and then feed IT to a shape object to fire off .AddPolyLine.

    Any insights welcome.

  4. #4
    Winwaed's Avatar
    Winwaed is offline Mapping-Tools.com Black Belt
    Join Date
    Feb 2004
    Blog Entries

    Re: AddPolyLine dilemma - is it GetLocation here that's problematic ?

    Try modifying your GetLocation call to include an altitude.
    Some of the documentation marks this as optional, but some does not. Try a dummy value of 100.

    Otherwise it must involve the control or be something subtle with what you are doing - I frequently create polygon shapes using lists of coordinates, albeit using the Application object (both GridImp and MPSuperShape do this under the hood). No problems.

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

  5. #5
    tfmiltz is offline Member Green Belt
    Join Date
    Feb 2005

    Smile Re: AddPolyLine dilemma - is it GetLocation here that's problematic ?

    Go figure

    I didn't think through that the lat lon pairs I saved ? I didn't save start point as last point

    well - I still won't do that for economy - BUT

    runtime I do now - outside of my loop assigning the arrayed location object ? - assign ONE MORE location - heh - no doubt assigning it to the start lat / lon to close the poly.

    This worked in the end.

    Thanks WinWaed -

    not only do you make MY day- you make the entire community's day here !


    Tim Miltz
    Last edited by tfmiltz; 11-02-2007 at 02:40 AM. Reason: name error

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Addpolyline from a dataset
    By micheln in forum MapPoint Desktop Discussion
    Replies: 3
    Last Post: 05-04-2007, 06:49 AM
  2. Shapes.AddPolyline is very slow
    By tdaffin in forum MapPoint Desktop Discussion
    Replies: 4
    Last Post: 01-27-2006, 07:08 AM
  3. Speeding up Getlocation queries? Help!
    By Solo4357 in forum Bing Maps and MapPoint Web Service
    Replies: 0
    Last Post: 10-13-2005, 02:34 PM
  4. Getlocation in VB .net
    By wallacech in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 12-11-2003, 02:27 PM
  5. addpolyline
    By Anonymous in forum Wish List
    Replies: 2
    Last Post: 04-25-2003, 03:50 PM

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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84