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

tfmiltz
11-01-2007, 01:09 AM
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

example:
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
Next
End If

Next



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
ors.MoveNext

Wend


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.

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.

Thanks.

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

tfmiltz
11-01-2007, 01:42 AM
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

tfmiltz
11-01-2007, 02:06 AM
JEebus

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.

Winwaed
11-01-2007, 07:26 AM
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.

Richard

tfmiltz
11-02-2007, 02:40 AM
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 !

Thanks

Tim Miltz

 
Web mp2kmag.com
mapforums.com