How to copy an IMap using C# ?

808
3
Jump to solution
10-06-2012 07:10 PM
TaiBui
by
Occasional Contributor II
Hi friends,

I am having an IMap object on Form 1. This Imap (got from ActiveView.FocusMap()) includes elements that created by the statements:

IGraphicsContainer oGraphics = map as IGraphicsContainer;
oGraphics.AddElement(oElement, 0);

The Imap don't have layers.

Do you know how can I copy this Imap (its elements) to another Imap on another form (Form 2) ?

Thank you for your help !

Tai
0 Kudos
1 Solution

Accepted Solutions
NeilClemmons
Regular Contributor III
If you want to replace the map on the second form with the map from the first form then you can use IObjectCopy to create a deep clone of the Map.  If want to keep the map on the second form and simply add the elements from the other map to it, then you would need to loop through the elements in the first map and add them to the second map.  You may need to use IObjectCopy to deep clone the elements and add the clones to the second map to avoid reference issues.

View solution in original post

0 Kudos
3 Replies
AlexanderGray
Occasional Contributor III
You can't clone the map itself.  The only way I see this working, is looping through all the elements in one map and cloning them and adding them to the other map.  However a map is a lot more than layers and a graphicscontainer.  There are many properties that would need cloning.  You could also create a stream and use the map's Ipersiststream to save the map to the stream and then load it back into a different map object.
0 Kudos
NeilClemmons
Regular Contributor III
If you want to replace the map on the second form with the map from the first form then you can use IObjectCopy to create a deep clone of the Map.  If want to keep the map on the second form and simply add the elements from the other map to it, then you would need to loop through the elements in the first map and add them to the second map.  You may need to use IObjectCopy to deep clone the elements and add the clones to the second map to avoid reference issues.
0 Kudos
TaiBui
by
Occasional Contributor II
Yes. Thank you
0 Kudos