I'm using some of the code from the VS2010 MapSuite 4 Desktop samples, related to drawing shapes and then editing them. So this sample code works to get in a mode the edit the shapes...but how do I get out of that mode when editing is complete?
Case "btnTrackEdit"
winformsMap1.TrackOverlay.TrackMode =
winformsMap1.EditOverlay.EditShapesLayer.InternalFeatures.Add(feature)
TrackMode.NoneFor Each feature As Feature In winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeaturesNext
winformsMap1.EditOverlay.CalculateAllControlPoints()
winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear()
winformsMap1.Refresh(
New Overlay() {winformsMap1.EditOverlay, winformsMap1.TrackOverlay})Exit Select
Michael,
Thanks for your post and questions.
I think we may probably need to remove all the features in the EditShapesLayer, otherwise, those shapes still will be in edit modes.
Thanks.
Yale
Thanks Yale, but if I’m understanding you that would remove all user drawn shapes rather than just getting them out out “edit” mode? For example:
Map1.EditOverlay.EditShapesLayer.InternalFeatures.Clear()
Map1.Refresh()
Michael,
It depends on how we want to processed those edit features after editing. If we do not want to store it, just clear it as you mentioned above. While most of time, we probably need to store it to somewhere for example shape file or database, so before remove them, we need to extract out those features and store them decently.
Any more questions just feel free to let me know.
Thanks.
Yale
Thanks, what I’d like to happen is the user can draw from the many shape types (circle, ellipse, lines, etc). If they click a button to “edit” the drawn shapes they could modify the shapes, and move them. Then would just like to go out of edit mode to show the shapes again in a “normal” mode. Make sense?
Thanks,
Mike
Michael,
Thanks for your post and feedback.
It absolutely make sense, in fact, it is exactly the second option I mentioned above, the difference is that we do not store it database or disk shape file, we just store it in memory. Then just as you said, move those features from EditShapeFileLayer to the inmemoryFeatureLayer before clearing it.
Any more questions just feel free to let me know.
Thanks.
Yale
Thanks Yale - so something like this?
'move features from EditShapeFileLayer to the InMemoryFeatureLayer
Dim inMemoryLayer As New InMemoryFeatureLayer()
For Each drawnFeature As Feature In Map1.EditOverlay.EditShapesLayer.InternalFeatures
inMemoryLayer.InternalFeatures.Add(drawnFeature)
Next
Dim inMemoryOverlay As New LayerOverlay()
inMemoryOverlay.Layers.Add(“InMemoryFeatureLayer”, inMemoryLayer)
Map1.Overlays.Add(“InMemoryOverlay”, inMemoryOverlay)
It doesn’t work, but am I close?
Thanks,
Mike
Mike,
Yes, I think you are very close. What we need to be move instead of copy. So please try the following code, if still does not work, please wrap a small sample for me to recreate, I am always happy to review and fix it.
'move features from EditShapeFileLayer to the InMemoryFeatureLayer
Dim inMemoryLayer As New InMemoryFeatureLayer()
For Each drawnFeature As Feature In Map1.EditOverlay.EditShapesLayer.InternalFeatures
inMemoryLayer.InternalFeatures.Add(drawnFeature)
Next
Dim inMemoryOverlay As New LayerOverlay()
inMemoryOverlay.Layers.Add("InMemoryFeatureLayer", inMemoryLayer)
Map1.Overlays.Add("InMemoryOverlay", inMemoryOverlay)
Map1.EditOverlay.EditShapesLayer.InternalFeatures.Clear()
winformsMap1.Refresh()
Any more questions just feel free to let me know.
Thanks.
Yale
Thanks Yale. Here is a good quick example to demonstrate the problem. In the ThinkGeo “Winforms How Do I” VB sample project, if you edit the TrackAndEditShapes.vb code, in the button_Click event you can add this code from above:
Case “btnTrackNormal”
winformsMap1.TrackOverlay.TrackMode = TrackMode.None
'get out of “shape edit mode” and back to normal:
'move features from EditShapeFileLayer to the InMemoryFeatureLayer
Dim inMemoryLayer As New InMemoryFeatureLayer()
For Each drawnFeature As Feature In winformsMap1.EditOverlay.EditShapesLayer.InternalFeatures
inMemoryLayer.InternalFeatures.Add(drawnFeature)
Next
Dim inMemoryOverlay As New LayerOverlay()
inMemoryOverlay.Layers.Add(“InMemoryFeatureLayer”, inMemoryLayer)
winformsMap1.Overlays.Add(“InMemoryOverlay”, inMemoryOverlay)
'now clear out the EditShapeFileLayer
winformsMap1.EditOverlay.EditShapesLayer.InternalFeatures.Clear()
winformsMap1.Refresh()
Exit Select
If you then run the project, draw some objects, click the “edit” button and then try and click btnTrackNormal with this new code you’ll see that it just removes all the drawn objects rather than putting the drawn objects back to a “normal” mode. Can you help me tweak this code?
Mike,
Thanks for your post and sample code, I think what we have ignored is just setting styles for the inMemoryLayer. Try the following code which should work.
Case "btnTrackNormal"
winformsMap1.TrackOverlay.TrackMode = TrackMode.None
'get out of "shape edit mode" and back to normal:
'move features from EditShapeFileLayer to the InMemoryFeatureLayer
Dim inMemoryLayer As New InMemoryFeatureLayer()
For Each drawnFeature As Feature In winformsMap1.EditOverlay.EditShapesLayer.InternalFeatures
inMemoryLayer.InternalFeatures.Add(drawnFeature)
Next
inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = winformsMap1.EditOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle
inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = winformsMap1.EditOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle
inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = winformsMap1.EditOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle
inMemoryLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
Dim inMemoryOverlay As New LayerOverlay()
inMemoryOverlay.Layers.Add("InMemoryFeatureLayer", inMemoryLayer)
winformsMap1.Overlays.Add("InMemoryOverlay", inMemoryOverlay)
'now clear out the EditShapeFileLayer
winformsMap1.EditOverlay.EditShapesLayer.InternalFeatures.Clear()
winformsMap1.Refresh()
Exit Select
While, the code above shows a very obvious drawback, the procedure can only be handled one time, the next time it comes in an exception will be thrown to complain about the duplicated key was used to add an overlay. To solve this problem, one solution is to remove the overlay before adding it to map control.
If (winformsMap1.Overlays.Contains("InMemoryOverlay")) Then
winformsMap1.Overlays.Remove("InMemoryOverlay")
End If
winformsMap1.Overlays.Add("InMemoryOverlay", inMemoryOverlay)
Any more questions just feel free to let me know.
Thanks.
Yale
Thanks Yale, it’s definitely getting close now. When you click the arrow toolbar button (btnTrackNormal) after drawing and then editing some shapes it gets out of the “edit mode” and you can draw some more shapes. However when you Pencil icon to edit shapes again, the original shapes cannot be editied, only any newly drawn shapes. I think the user would expect to be able to edit the shapes repeatedly as needed. What is the final tweak to get that done?
Thanks,
Mike
Michael,
Thanks for your feedback.
Following code is definitely fixing the problem, have a try and let me know the result.
Case "btnTrackEdit"
winformsMap1.TrackOverlay.TrackMode = TrackMode.None
For Each feature As Feature In winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures
winformsMap1.EditOverlay.EditShapesLayer.InternalFeatures.Add(feature)
Next
Dim inmemoryFeatureLayer As InMemoryFeatureLayer = winformsMap1.FindFeatureLayer("InMemoryFeatureLayer")
If (Not inmemoryFeatureLayer Is Nothing) Then
For Each feature As Feature In inmemoryFeatureLayer.InternalFeatures
winformsMap1.EditOverlay.EditShapesLayer.InternalFeatures.Add(feature)
Next
inmemoryFeatureLayer.InternalFeatures.Clear()
End If
winformsMap1.EditOverlay.CalculateAllControlPoints()
winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear()
winformsMap1.Refresh()
Exit Select
Any more questions just feel free to let me know.
Thanks.
Yale
Michael,
Thanks for letting me know the status.
Yale