/// <summary> /// 设置地图为固定比例尺模式,并设定其比例尺(及显示范围和坐标系) /// </summary> /// <param name="mapFrame">地图数据框</param> /// <param name="nScale">比例尺</param> /// <param name="featureEnv">显示范围,值为null时不修改显示范围</param> /// <param name="spatialRef">坐标系,值为null是不修改坐标系</param> public static void SetMapScale(this IMapFrame mapFrame, double nScale, IEnvelope featureEnv = null, ISpatialReference spatialRef = null) { #region ArcGIS 9.3版本使用的代码 //if (spatialRef != null) // mapFrame.Map.SpatialReference = spatialRef; //if (featureEnv != null) // (mapFrame.Map as IActiveView).Extent = featureEnv; //mapFrame.ExtentType = esriExtentTypeEnum.esriExtentScale; //mapFrame.MapScale = nScale; #endregion #region ArcGIS 10.0及以上版本使用的代码 if (spatialRef != null) { mapFrame.Map.SpatialReference = spatialRef; } if (featureEnv != null) { ((IActiveView)mapFrame.Map).Extent = featureEnv; } IMapAutoExtentOptions mapAutoExtentOptions = mapFrame.Map as IMapAutoExtentOptions; mapAutoExtentOptions.AutoExtentType = esriExtentTypeEnum.esriExtentScale;//使用固定比例尺模式 if (nScale != 0.0) { mapAutoExtentOptions.AutoExtentScale = nScale; } #endregion }
/// <summary> /// 设置地图为固定比例尺模式,并设定其比例尺 /// </summary> public static void SetMapScale(this IMap map, double scale) { #region ArcGIS 10.0及以上版本使用的代码 IMapAutoExtentOptions mapAutoExtentOptions = map as IMapAutoExtentOptions; mapAutoExtentOptions.AutoExtentType = esriExtentTypeEnum.esriExtentScale;//使用固定比例尺模式 mapAutoExtentOptions.AutoExtentScale = scale; #endregion }
private void frmExtendSet_Load(object sender, EventArgs e) { if (this.Map != null) { this.Extend = (this.Map as IActiveView).Extent; if (this.Map.LayerCount > 0) { IEnumLayer layer = this.Map.get_Layers(null, true); layer.Reset(); for (ILayer layer2 = layer.Next(); layer2 != null; layer2 = layer.Next()) { if (((layer2 is IFeatureLayer) && ((layer2 as IFeatureLayer).FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon)) && ((layer2 as IFeatureLayer).FeatureClass.FeatureCount(null) > 0)) { this.cboLayers.Items.Add(new LayerObject(layer2)); } } if (this.cboLayers.Items.Count > 0) { this.cboLayers.SelectedIndex = 0; } } this.rdoLayerExtend.Enabled = this.cboLayers.Items.Count > 0; if (this.ClipGeometry != null) { this.rdoCustomExtend.Checked = true; this.method_0(this.ClipGeometry.Envelope); } else if (this.ExtendType == ExtendSetType.Range) { if (this.Map is IMapAutoExtentOptions) { IMapAutoExtentOptions map = this.Map as IMapAutoExtentOptions; if (map.AutoExtentBounds != null) { this.rdoCustomExtend.Checked = true; this.method_0(map.AutoExtentBounds); } else { this.method_0((this.Map as IActiveView).Extent); } } } else if (this.ExtendType == ExtendSetType.FullExtentRange) { this.method_0((this.Map as IActiveView).FullExtent); } else if (this.Map is IMapClipOptions) { if ((this.Map as IMapClipOptions).ClipType == esriMapClipType.esriMapClipMapExtent) { this.rdoCurrentMapExtend.Checked = true; this.method_0((this.Map as IActiveView).Extent); } else if ((this.Map as IMapClipOptions).ClipType == esriMapClipType.esriMapClipShape) { this.rdoCustomExtend.Checked = true; if ((this.Map as IMapClipOptions).ClipGeometry != null) { this.method_0((this.Map as IMapClipOptions).ClipGeometry.Envelope); } else { this.method_0((this.Map as IActiveView).Extent); } } } if (this.Map is IGraphicsContainerSelect) { this.rdoGraphicsExtend.Enabled = (this.Map as IGraphicsContainerSelect).ElementSelectionCount > 0; } } }