What I am trying to do is import a .pagx map template and use my active map (Layers) for the MapFrame in my template.
I am able to import my .pagx map template. When it is imported, a new Map is created (Layers1) which from the map template layout. I have tried setting the MapFrame's .Map property but this is readonly.
It might not be the correct way to do this, but I was hoping I could set this property to my active map.
var mv = MapView.Active;
var currentCamera = mv?.Camera;
QueuedTask.Run(() =>
{
IProjectMultiItem pagx = ItemFactory.Instance.Create(TemplatePath) as IProjectMultiItem;
Project.Current.ImportItem(pagx);
LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().Last();
// Get the layout from the layout template item
Layout layout = layoutItem.GetLayout();
if (mapFrame != null)
{
// Get map frame
var mapFrameMap = mapFrame.Map;
// Setting the mapFrameMap var does not make a change
//mapFrameMap = mv.Map;
mapFrame.Map = mv.Map;
if (currentCamera != null)
mapFrame.SetCamera(currentCamera);
}
});
Solved! Go to Solution.
I found that the mapFrame.Map is read only. I used the mapFrame.SetMap(mv.Map). This will set the map frame to my original map.
This does however still add a new Map (Layers1) to the project. Is this expected? If yes, would I just need to delete it once the Layout has been created?
I found that the mapFrame.Map is read only. I used the mapFrame.SetMap(mv.Map). This will set the map frame to my original map.
This does however still add a new Map (Layers1) to the project. Is this expected? If yes, would I just need to delete it once the Layout has been created?
For now, I am deleting the map item that is created (Layers1) from the project:
MapFrame mapFrame = layout.FindElement("Map Frame") as MapFrame;
MapProjectItem OriginalLayoutMap = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(item => item.Name.Equals(mapFrame.Map.Name));
// Set map frame to original active map
mapFrame.SetMap(OriginalActiveMap.Map);
// Delete new OriginalLayoutMap created
Project.Current.RemoveItem(OriginalLayoutMap);