//private static void AddLayerToGroup(Aggregate aggregator, List<Layer> layers) //{ // // Add layers to the groups // foreach (Layer layer in layers) // { // Group group = null; // if (aggregator.Groups != null) // { // // Try to find the group for the layer // group = aggregator.Groups.FirstOrDefault(elm => elm.Name == layer.GroupName); // } // if (group == null) // { // // Group does not exist, create a new group // LayerLogic.AssignLayerToDefaultGroup(aggregator,layer); // } // else // { // // Add layer to the existing group // group.AddLayer(layer); // } // } //} private static void FillMapWindowData(MapWinProject mapWinProject, Aggregate aggregator, List <Layer> layers) { if (mapWinProject.MapWindow != null && mapWinProject.MapWindow.Layers != null && mapWinProject.MapWindow.Layers.Count == mapWinProject.MapwinGis.Layers.Count) { List <Group> groups = new List <Group>(); // Add Groups foreach (MapWinProject.Group prjGroup in mapWinProject.MapWindow.Groups) { Group group = LayerLogic.LoadGroupDataFromProjectFile(prjGroup); groups.Add(group); } // Add layers foreach (MapWinProject.LayerMapWin4 prjLayer in mapWinProject.MapWindow.Layers) { Layer layer = LayerLogic.LoadLayerDataFromProjectFile(prjLayer, layers); Group group = groups.FirstOrDefault(elm => elm.Name == prjLayer.GroupName); if (layer == null) { throw new Exception("Error loading layer"); } else if (group == null) { aggregator.CollectionLayer.Add(layer); } else { aggregator.CollectionLayer.Add(layer, group); } } } }
private static void AddLayers(MapWinProject mapWinProject, MapWinControl.MapWinControl mapWinControl, string projectFile, Aggregate aggregator) { // List met layers aanmaken // layers met alle data vullen // groups ophalen // layers toevoegen met de group erbij List <Layer> layers = new List <Layer>(); // check if there are layers in the projectfile if (mapWinProject.MapwinGis.Layers != null) { // Loop through all layers foreach (var prjLayer in mapWinProject.MapwinGis.Layers) { // Skip layer if the path to the layer does not exist in the projectfile if (prjLayer.Filename != string.Empty) { // Add layer to ocx int handle = LayerLogic.AddLayer(Path.GetFullPath(prjLayer.Filename), ZoomMode.ZoomToExtents, false, aggregator); if (handle != -1) { // Create the layer-object and add it to the temporary list of layers Layer layer = LayerLogic.FillMapWingisLayerData(handle, prjLayer); layers.Add(layer); // aggregator.Layers.Add(layer); // Restore the state of the layer RestoreLayerState(mapWinControl, prjLayer, handle); } } } // Restore the state of the map RestoreMapState(mapWinProject, mapWinControl, projectFile); // Fill data from the mapwindow-section FillMapWindowData(mapWinProject, aggregator, layers); //// Add the layers to a group //AddLayerToGroup(aggregator, layers); // Give aggregator signal that layer has been added aggregator.LayerAdded(); } }