/// <summary> /// 对公路网图层进行处理 线程安全 /// 如果有则将其提取到第一个位置 /// 如果没有直接加载 /// </summary> /// <param name="mapControl"></param> public ILayer DealRoutenetLayer(AxMapControl mapControl) { IGroupLayer myGroupLayer = null; int gIndex; int layerIndex; ILayer routeNetLayer = LayerUtil.QueryLayerInMap(mapControl, "公路网", ref myGroupLayer, out layerIndex, out gIndex); //如果公路网的数据没有加载,则直接加载 if (routeNetLayer == null) { routeNetLayer = ShapeSimpleHelper.OpenFile(Common.RouteNetFeaturePath); RouteLayerUtil.SetRouteLayerStyle(routeNetLayer); mapControl.AddLayer(routeNetLayer); } //否则 保证在第一个位置 也就是图层最上面 if (gIndex < 1 && layerIndex == 0) { routeNetLayer.Visible = true; } else { if (myGroupLayer != null) { myGroupLayer.Delete(routeNetLayer); } else { mapControl.Map.DeleteLayer(routeNetLayer); } mapControl.AddLayer(routeNetLayer); } return(routeNetLayer); }
/// <summary> /// 设置初始化的公路网样式 似乎加入地图的图层就不能再设置样式了 /// </summary> private void SetInitialRouteNetLayerStyle() { IGroupLayer myGroupLayer = null; int gIndex; int layerIndex; ILayer routeNetLayer = LayerUtil.QueryLayerInMap(this.axMapControl1, "公路网", ref myGroupLayer, out layerIndex, out gIndex); //从配置文件中设置公路网样式 if (routeNetLayer != null) { RouteLayerUtil.SetRouteLayerStyle(routeNetLayer); this.axMapControl1.Refresh(); } }
private void exCheckedListBox1_SelectedIndexChanged_1(object sender, EventArgs e) { Boolean IsEqual = false;//判断是否已经存在此图层 int i = exCheckedListBox1.SelectedIndex; var selectLayer = exCheckedListBox1.SelectedItem; //这里还可以用循环的方法 this.myCheckedlistBox.GetItemChecked(i) if (exCheckedListBox1.CheckedItems.Contains(selectLayer)) { string fullPath = selectLayer.ToString(); if (fullPath.Equals("降水量")) { ToRasterControl.OpenRasterLayer(rasterPath, fullPath); } else { if (fullPath.Substring(fullPath.LastIndexOf(".")) == ".shp") { fullPath = shapePath + fullPath;//这里发现+=和普通写法还是有区别的 //利用"\\"将文件路径分成两部分 int Position = fullPath.LastIndexOf("\\"); //文件目录 string FilePath = fullPath.Substring(0, Position); // string ShpName = fullPath.Substring(Position + 1); IWorkspaceFactory pWF; pWF = new ShapefileWorkspaceFactory(); IFeatureWorkspace pFWS; pFWS = (IFeatureWorkspace)pWF.OpenFromFile(FilePath, 0); IFeatureClass pFClass; pFClass = pFWS.OpenFeatureClass(ShpName); IFeatureLayer pFLayer; pFLayer = new FeatureLayer(); pFLayer.FeatureClass = pFClass; pFLayer.Name = pFClass.AliasName; // MainFrom.m_mapControl.Refresh(esriViewDrawPhase.esriViewGeography, null, null); if (pFLayer.Name == "公路网") { RouteLayerUtil.SetRouteLayerStyle(pFLayer); } IsEqual = Common.InsertShapeLayer(IsEqual, (ILayer)pFLayer); if (pFLayer.Name == "聚落") { LayerManager.ClassBreaksMap(pFLayer, "rkmidu", 5); } if (pFLayer.Name == "行政区") { LayerManager.UniqueValueRenderer(pFLayer, "name"); } if (pFLayer.Name == "乡村点") { LayerManager.SetFeaturePictureSymbol(pFLayer, Common.CountryPointImagePath, 15); } if (pFLayer.Name == "水系") { FeatureStyleUtil.SetFetureLineStyle(0, 92, 230, 2, pFLayer); } if (pFLayer.Name == "震前灾害点") { LayerManager.SetFeaturePictureSymbol(pFLayer, Common.BeforeDisaterImagePath, 15); } if (pFLayer.Name == "震后新增灾害点") { LayerManager.SetFeaturePictureSymbol(pFLayer, Common.AfterDisaterImagePath, 15); } if (pFLayer.Name == "断裂带") { FeatureStyleUtil.SetFetureLineStyle(0, 0, 0, 3, pFLayer); } if (pFLayer.Name == "地震烈度") { LayerManager.UniqueValueRendererEarthquake(pFLayer, "地震烈度"); } if (pFLayer.Name == "岩性") { LayerManager.UniqueValueRendererLithology(pFLayer, "岩性"); //LayerManager.UniqueValueRenderer(pFLayer, "name"); //LayerManager.SetFeaturePictureFillSymbol(pFLayer, Common.AfterDisaterImagePath); } //选择数据源 MainFrom.toolComboBox.Items.Add(pFLayer.Name); MainFrom.m_pTocControl.Update(); } else { //fullPath = rasterPath + fullPath; ToRasterControl.RaskCaulte(rasterPath, fullPath); ////这里将RasterLayerClass改为RasterLayer 即可以嵌入互操作类型 下同 //IRasterLayer rasterLayer = new RasterLayer(); //rasterLayer.CreateFromFilePath(fullPath); //// IRaster ir = (IRaster) rasterLayer; //IsEqual = Common.InsertLayer(IsEqual, rasterLayer); //MainFrom.m_pTocControl.Update(); } } } else { string layerName = selectLayer.ToString(); isLoad = true; if (layerName.Substring(layerName.LastIndexOf(".")) == ".shp") { //选择数据源 layerName = layerName.Substring(0, layerName.LastIndexOf(".")); MainFrom.toolComboBox.Items.Remove(layerName); } try { //这里需要注意的是矢量文件在图层中没有后缀名 而栅格文件在图层中有后缀名 如.tif MainFrom.m_mapControl.Map.DeleteLayer(LayerManager.returnIndexByLayerName(MainFrom.m_mapControl, layerName)); MainFrom.m_mapControl.Refresh(); MainFrom.m_pTocControl.Update(); } catch (Exception ex) { } } }