Exemple #1
0
        /// <summary>
        /// 删除节点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ctxDeleteNode_Click(object sender, EventArgs e)
        {
            Node node = advTreeMain.SelectedNode;

            try
            {
                string lyrName = node.Text;
                this.DeleteLayerByName(lyrName);
                //删除tif配置
                string path = Path.Combine(Path.GetDirectoryName(_projectPath), lyrName + ".xml");
                if (File.Exists(path))
                {
                    File.Delete(path);
                }

                //删除shp配置
                else if (node.Tag is NodeModel)
                {
                    GeometryBigType geoType = ((NodeModel)node.Tag).BigType;
                    switch (geoType)
                    {
                    case GeometryBigType.Point:
                        ShpPointConfig.DeleteLayer(lyrName);
                        _shpLoader.PntLyrList.Remove(lyrName);
                        break;

                    case GeometryBigType.Line:
                        ShpLineConfig.DeleteLayer(lyrName);
                        _shpLoader.LineLyrList.Remove(lyrName);
                        break;

                    case GeometryBigType.Polygon:
                        ShpPolygonConfig.DeleteLayer(lyrName);
                        _shpLoader.PolyLyrList.Remove(lyrName);
                        break;

                    default:
                        break;
                    }
                }
                node.Remove();
            }
            catch (Exception ex)
            {
                MsgBox.ShowInfo(ex.Message);
            }
        }
Exemple #2
0
        /// <summary>
        /// 导入Shp
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void ctxImportShp_Click(object sender, EventArgs e)
        { //第一个为图层节点
            Node pnode = advTreeMain.Nodes[0];
            //List<string> existlyrs = this.GetExistLayerNames();
            frmLoadVector frm = new frmLoadVector(new List <string>());

            if (frm.ShowDialog() == DialogResult.OK)
            {
                string name = string.Empty;
                string path = string.Empty;
                switch (frm.Reader.GeoBigType)
                {
                case GeometryBigType.Point:
                    name = frm.PntLayer.LayerName;
                    //图层去重
                    NodeModel checkModel = _projectModel.Nodes.Where(t => t.PNode == Guids.TCGL && t.NodeName == name).FirstOrDefault();
                    if (checkModel != null)
                    {
                        MsgBox.ShowInfo("当前名称的图层已经存在,请重命名或者导入其他数据");
                        return;
                    }
                    path = frm.PntLayer.ShpLayerPath;
                    ShpPointLayer pntLyr = frm.PntLayer;
                    //保存图层信息到配置文件
                    if (this.ShpPointLyrExits(pntLyr))
                    {
                        ShpPointConfig.DeleteLayer(pntLyr.LayerName);
                        _shpLoader.PntLyrList.Remove(pntLyr.LayerName);
                        this.DeleteLayerByName(pntLyr.LayerName);
                    }
                    ShpPointConfig.AppendLayer(pntLyr);
                    _shpLoader.LoadShpPointLayer(pntLyr);
                    break;

                case GeometryBigType.Line:
                    this.AddShpLineLayer(frm.LineLayer);
                    name = frm.LineLayer.LayerName;
                    path = frm.LineLayer.ShpLayerPath;
                    break;

                case GeometryBigType.Polygon:
                    name = frm.PolyLayer.LayerName;
                    //图层去重
                    checkModel = _projectModel.Nodes.Where(t => t.PNode == Guids.TCGL && t.NodeName == name).FirstOrDefault();
                    if (checkModel != null)
                    {
                        MsgBox.ShowInfo("当前名称的图层已经存在,请重命名或者导入其他数据");
                        return;
                    }
                    path = frm.PolyLayer.ShpLayerPath;
                    ShpPolygonLayer polyLyr = frm.PolyLayer;
                    if (this.ShpPolygonLyrExits(polyLyr))
                    {
                        ShpPolygonConfig.DeleteLayer(polyLyr.LayerName);
                        _shpLoader.PolyLyrList.Remove(polyLyr.LayerName);
                        this.DeleteLayerByName(polyLyr.LayerName);
                    }
                    ShpPolygonConfig.AppendLayer(polyLyr);
                    _shpLoader.LoadShpPolygonLayer(polyLyr);
                    break;

                default:
                    break;
                }


                NodeModel model = new NodeModel();
                model.PNode      = pnode.Name;
                model.NodeName   = name;
                model.ShowCheck  = true;
                model.ImageIndex = 2;
                model.NodeId     = Guid.NewGuid().ToString();
                model.CanRemove  = true;
                model.Path       = path;
                model.BigType    = frm.Reader.GeoBigType;
                pnode.Nodes.Add(CreateNode(model));
            }
        }