private void AssignLayerSymbologies(IMapFrame mapFrame) { foreach (ILayer layer in mapFrame.GetAllLayers()) { IMapLineLayer lineLayer = layer as IMapLineLayer; if (lineLayer != null) { ILineScheme original = lineLayer.Symbology; if (original != null) { ILineScheme newScheme = original.Clone() as ILineScheme; original.CopyProperties(newScheme); original.ResumeEvents(); } } //to correctly draw categories: IMapFeatureLayer featureLayer = layer as IMapFeatureLayer; if (featureLayer != null) { if (featureLayer.Symbology.NumCategories > 1) { featureLayer.DataSet.FillAttributes(); featureLayer.ApplyScheme(featureLayer.Symbology); } } } }
/// <summary> /// Reprojects all layers in the map frame so that they use the new /// projection ESRI string /// </summary> /// <param name="mapFrame">The map frame that contains all layers that should be reprojected</param> /// <param name="newProjEsriString">The ESRI WKT string of the new projection</param> public static void ReprojectMapFrame(IMapFrame mapFrame, string newProjEsriString) { //parse the projection ProjectionInfo newProjection = ProjectionInfo.FromEsriString(newProjEsriString); foreach (IMapLayer layer in mapFrame.GetAllLayers()) { if (layer.DataSet.CanReproject) { layer.DataSet.Reproject(newProjection); } } foreach (IMapGroup grp in mapFrame.GetAllGroups()) { grp.Projection = ProjectionInfo.FromEsriString(newProjEsriString); } mapFrame.Projection = newProjection; var parent = mapFrame.Parent as IMap; if (parent != null) { // this need to fire Map.ProjectionChanged event parent.Projection = newProjection; } }
/// <summary> /// Open attribute table /// </summary> private void AttributeTable_Click(object sender, EventArgs e) { IMapFrame mainMapFrame = App.Map.MapFrame; List<ILayer> layers = mainMapFrame.GetAllLayers(); foreach (ILayer layer in layers.Where(l => l.IsSelected)) { IFeatureLayer fl = layer as IFeatureLayer; if (fl == null) continue; ShowAttributes(fl); } }
/// <summary> /// Reprojects all layers in the map frame so that they use new projection /// </summary> /// <param name="mapFrame">The map frame that contains all layers that should be reprojected</param> /// <param name="newProjection">New projection</param> /// <param name="onCantReproject">Callback when layer can't be reprojected. Maybe null.</param> public static void ReprojectMapFrame(this IMapFrame mapFrame, ProjectionInfo newProjection, Action <ILayer> onCantReproject = null) { if (mapFrame == null) { throw new ArgumentNullException("mapFrame"); } if (newProjection == null) { throw new ArgumentNullException("newProjection"); } // assign rotation to projection transform depending on mapframe angle if (mapFrame.Angle != 0) { newProjection.Transform.Rotated = true; newProjection.Transform.Angle = mapFrame.Angle; } else { newProjection.Transform.Rotated = false; newProjection.Transform.Angle = 0; } foreach (var layer in mapFrame.GetAllLayers()) { if (layer.CanReproject) { layer.Reproject(newProjection); } else { onCantReproject?.Invoke(layer); } } foreach (var grp in mapFrame.GetAllGroups()) { grp.Projection = newProjection; } mapFrame.Projection = newProjection; var parent = mapFrame.Parent as IMap; if (parent != null) { // this need to fire Map.ProjectionChanged event parent.Projection = newProjection; } }
/// <summary> /// Reprojects all layers in the map frame so that they use new projection /// </summary> /// <param name="mapFrame">The map frame that contains all layers that should be reprojected</param> /// <param name="newProjection">New projection</param> /// <param name="onCantReproject">Callback when layer can't be reprojected. Maybe null.</param> public static void ReprojectMapFrame(this IMapFrame mapFrame, ProjectionInfo newProjection, Action <ILayer> onCantReproject = null) { if (mapFrame == null) { throw new ArgumentNullException("mapFrame"); } if (newProjection == null) { throw new ArgumentNullException("newProjection"); } foreach (var layer in mapFrame.GetAllLayers()) { if (layer.CanReproject) { layer.Reproject(newProjection); } else { if (onCantReproject != null) { onCantReproject(layer); } } } foreach (var grp in mapFrame.GetAllGroups()) { grp.Projection = newProjection; } mapFrame.Projection = newProjection; var parent = mapFrame.Parent as IMap; if (parent != null) { // this need to fire Map.ProjectionChanged event parent.Projection = newProjection; } }
/// <summary> /// Reprojects all layers in the map frame so that they use new projection. /// </summary> /// <param name="mapFrame">The map frame that contains all layers that should be reprojected.</param> /// <param name="newProjection">New projection.</param> /// <param name="onCantReproject">Callback when layer can't be reprojected. Maybe null.</param> public static void ReprojectMapFrame(this IMapFrame mapFrame, ProjectionInfo newProjection, Action <ILayer> onCantReproject = null) { if (mapFrame == null) { throw new ArgumentNullException(nameof(mapFrame)); } if (newProjection == null) { throw new ArgumentNullException(nameof(newProjection)); } foreach (var layer in mapFrame.GetAllLayers()) { if (layer.CanReproject) { layer.Reproject(newProjection); } else { onCantReproject?.Invoke(layer); } } foreach (var grp in mapFrame.GetAllGroups()) { grp.Projection = newProjection; } mapFrame.Projection = newProjection; if (mapFrame.Parent is IMap parent) { // this is needed to fire the Map.ProjectionChanged event parent.Projection = newProjection; } }