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