/// <summary> /// 添加图层 /// </summary> /// <param name="map"></param> /// <param name="tree"></param> /// <param name="cmd"></param> private void AddLayer(MapImage map, MyTree tree, string[] cmd) { if (cmd.Length != 3) { return; } decimal mapid = GetId(cmd[1]); decimal layerid = GetId(cmd[2]); //取得图层信息 DataTable layertable = MapDBClass.GetLayerinfo(mapid, layerid); if (layertable == null || layertable.Rows.Count <= 0) { return; } string layername = layertable.Rows[0]["LayerName"].ToString(); int type = 0; Int32.TryParse(layertable.Rows[0]["LayerType"].ToString(), out type); VectorLayer layer = new VectorLayer(layername, (VectorLayer.LayerType)type); layer.ID = layerid; layer.Style.EnableOutline = layertable.Rows[0]["EnableOutline"].ToString() == "1" ? true : false; layer.Style.Fill = new SolidBrush(Color.FromArgb((int)layertable.Rows[0]["Fill"])); layer.Style.Line = new Pen(Color.FromArgb((int)layertable.Rows[0]["Line"]), (int)layertable.Rows[0]["LineWidth"]); layer.Style.Outline = new Pen(Color.FromArgb((int)layertable.Rows[0]["Outline"]), (int)layertable.Rows[0]["OutlineWidth"]); Collection <Geometry> geometries = new Collection <Geometry>(); GeometryProvider provider = new GeometryProvider(geometries); layer.DataSource = provider; TreeNode node = new TreeNode(layername); node.Tag = layer; node.Checked = true; if (SetLayerStyle != null) { SetLayerStyle(layer, layer.Style.Fill, layer.Style.Line, layer.Style.Outline, layer.Style.EnableOutline, node); } string layertext = ""; switch (layer.Type) { case VectorLayer.LayerType.BaseLayer: layertext = Resources.BaseLayer; break; case VectorLayer.LayerType.PhotoLayer: layertext = Resources.PhotoLayer; break; case VectorLayer.LayerType.ReportLayer: layertext = Resources.ReportLayer; break; case VectorLayer.LayerType.MotionLayer: layertext = Resources.MotionPointLayer; break; case VectorLayer.LayerType.SaleLayer: layertext = Resources.SaleLayer; break; case VectorLayer.LayerType.AreaInformation: layertext = Resources.AreaInfoLayer; break; case VectorLayer.LayerType.Pricelayer: layertext = Resources.PriceLayer; break; case VectorLayer.LayerType.HireLayer: layertext = Resources.RentLayer; break; case VectorLayer.LayerType.OtherLayer: layertext = Resources.OtherLayer; break; } TreeNode mainnode = new TreeNode(layertext); mainnode.Checked = true; TreeNode findnode = FindNode(tree, layertext); if (findnode != null) { mainnode = findnode; } else if (layertext == Resources.BaseLayer) { if (tree.Nodes[0].Nodes.Count > 0) { if (tree.Nodes[0].Nodes[0].Text == Resources.PhotoLayer) { tree.Nodes[0].Nodes.Insert(1, mainnode); } else { tree.Nodes[0].Nodes.Insert(0, mainnode); } } else { tree.Nodes[0].Nodes.Add(mainnode); } } else { findnode = FindNode(tree, Resources.DataLayer); if (findnode == null) { findnode = new TreeNode(Resources.DataLayer); tree.Nodes[0].Nodes.Add(findnode); } findnode.Nodes.Add(mainnode); } mainnode.Nodes.Add(node); map.Map.AddLayer(layer); //取得元素信息 DataTable objecttable = MapDBClass.GetObject(mapid, layerid); for (int j = 0; j < objecttable.Rows.Count; j++) { decimal objectid = (decimal)objecttable.Rows[j]["ObjectId"]; byte[] data = (byte[])objecttable.Rows[j]["ObjectData"]; Geometry geometry = (Geometry)Common.DeserializeObject(data); geometry.ID = objectid; geometry.Select = false; geometries.Add(geometry); AddGeometryToTree(node, geometry, geometry.Text); } }