IMap map = null; //跟map同一層次的activeView對象,他們都是“地圖”的對象,map管理地圖內容,activeView管理顯示內容 IActiveView activeView = map as IActiveView; //獲取當前地圖顯示范圍 IEnvelope extent = activeView.Extent; //設置當前地圖顯示范圍,相當於用代碼實現縮放到某個范圍 activeView.Extent = extent; //獲取地圖全圖范圍 //地圖瀏覽功能中的全圖,他的范圍就是這樣獲取 IEnvelope fullExtent = activeView.FullExtent; //獲取地圖比例尺,同時可同於設置比例尺 double mapScale = map.MapScale; //獲取和設置地圖單位 esriUnits unit = map.MapUnits; //獲取和設置地圖的顯示單位 esriUnits unit2 = map.DistanceUnits; //刷新地圖 activeView.Refresh(); //屏幕長度(單位是像素)轉地圖實際長度 double mapLength = MapHelper.PixelsToMapUnits(activeView, 5); //獲取Map的所有FeatureLayer List<IFeatureLayer> lstFeatureLayer = MapHelper.GetAllFeatureLayerInMap(map); if (1 == 2) { //在Map中通過真實表名獲取圖層,對於sde的表名不能帶用戶名 IFeatureLayer featureLayer = MapHelper.GetFeatureLayerByDatasetName(map, "roadLine"); } foreach (IFeatureLayer featureLayer in lstFeatureLayer) { //圖層相關說明 //IFeatureLayer代表矢量圖層,而ILayer代表圖層,也是所有類型圖層接口都實現了ILayer,因此IFeatureLayer可以as到ILayer ILayer layer = featureLayer as ILayer; //獲取和設置圖層的可視狀態(就是圖層樹界面里圖層左邊的checkbox) bool visible = layer.Visible; //獲取或設置圖層名稱 string name = layer.Name; //通過圖層獲取featureClass,是獲取featureClass的方法之一。另一種方法是通過workspace獲取 //注意IFeatureLayer和IFeatureClass是兩個東西,雖然平時會都叫“圖層”。IFeatureClass是指物理表,而IFeatureLayer指物理表加載到地圖上形成的圖層,前者更多指數據,后者只圖層在地圖的展示設置,如樣式,標注等 IFeatureClass featureClass = featureLayer.FeatureClass; }