private void btnCamAni_Click(object sender, RoutedEventArgs e) { var tmp = from e0 in uc.objManager.zLayers.Values from e1 in e0.pModels.Values where e1 is pSymbolObject select e1; pSymbolObject obj = (pSymbolObject)tmp.ElementAt(rd.Next(tmp.Count())); uc.camera.aniLook(obj.VecLocation); }
void showNodeVL(bool isShow) { pSymbolObject pso, nobj; double topvalue = 0.15; double warningvalue = 0.1; IEnumerable <PowerBasicObject> tmpobjs = root.earth.objManager.getAllObjListBelongtoCategory("节点"); if (isShow) { foreach (PowerBasicObject obj in tmpobjs.Where(p => p.busiRunData != null)) { pso = obj as pSymbolObject; double v = (0.85 + 0.3 * rd.NextDouble()) - 1;//(pso.busiRunData as RunDataNodeP).voltPUV - 1; Color color; color = v < 0 ? Colors.Blue : Colors.Red; v = Math.Abs(v); if (v > warningvalue) { v = v > topvalue ? topvalue : v; v = v / topvalue; color = MyClassLibrary.Share2D.MediaHelper.getColorSaturation(v, color); if (pso.submodels.Count == 0) { nobj = new pSymbolObject(pso.parent) { id = pso.id + "node", location = pso.location, symbolid = "渐变圆", isH = true, groundHeight = WpfEarthLibrary.Para.SymbolHeight * 0.9 }; pso.submodels.Add(nobj.id, nobj); } else { nobj = pso.submodels.Values.First() as pSymbolObject; } nobj.color = color; nobj.scaleX = 0.0007f; nobj.scaleY = nobj.scaleZ = 0.001f; } else { pso.submodels.Clear(); } } } else { foreach (PowerBasicObject obj in tmpobjs.Where(p => p.busiRunData != null)) { obj.submodels.Clear(); } } }
void loadModel() { //读取数据 curprjkey = 13; dtallproject = DataLayer.DataProvider.getDataTableFromSQL("select * from map_project"); dtproject = DataLayer.DataProvider.getDataTableFromSQL(string.Format("select * from map_project where id={0}", curprjkey)); curprj = dtproject.Rows[0]; string sqlwhere = PrjHelper.genProjectsExpress(curprjkey, dtallproject); string sqlwhere2 = PrjHelper.genProjectsExpress(curprjkey, dtallproject, "t1."); dtobject = DataLayer.DataProvider.getDataTableFromSQL(string.Format("select t1.*,t2.layer from map_object t1 join map_svg_layer t2 on t1.layerid=t2.id where points is not null and {0}", sqlwhere2)); dtlayer = DataLayer.DataProvider.getDataTableFromSQL(string.Format("select * from map_svg_layer where {0}", sqlwhere)); dttext = DataLayer.DataProvider.getDataTableFromSQL(string.Format("select t1.*,t2.layer from map_svg_text t1 join map_svg_layer t2 on t1.layerid=t2.id where points is not null and {0}", sqlwhere2)); dtsymbol = DataLayer.DataProvider.getDataTableFromSQL(string.Format("select t2.svgsymbolid,t2.name,t2.viewbox,t2.preserveAspectRatio,t1.shapetype,t1.data,t1.fill,t1.stroke,t1.width from map_svg_symbolitem t1 join map_svg_symbol t2 on t1.symbolid=t2.id where t2.svgsymbolid in (select distinct replace(symbolid,'#','') from map_object where points is not null and ({0})) and ({0})", sqlwhere)); //仅使用了的图元 dtstyle = DataLayer.DataProvider.getDataTableFromSQL(string.Format("select * from map_svg_style where {0}", sqlwhere)); int KGID = 11; dtshareobject = DataLayer.DataProvider.getDataTableFromSQL(string.Format("select * from map_share_object where prjid={0} or layername='区县图层'", KGID)); //生成图元字典,图元字典内容会被传送到d3d生成公用材质,下面的厂站,将使用图元字典中的键值来决定在d3d中的材质 genSymbolBrush(); //另外直接添加材质, SubstationEntityDisH2为键值 //uc.objManager.AddSymbol("","SubstationEntityDisH2", "SubstationEntityDisH2.dds"); //生成几何体资源字典,几何体资源字典内容会被传送到d3d生成公用几何体数据,下面的数据呈现用的柱体,将使用几何体字典中的键值来决定在d3d中的形态 genGeomeries(); //添加对象层 foreach (DataRow item in dtlayer.Rows) { uc.objManager.AddLayer(item["layer"].ToString(), item["id"].ToString(), item["layer"].ToString()); //示例中以层的名字为键值 } int idx = 0; //对象 bool isfind; PowerBasicObject obj; pLayer containerLayer; foreach (DataRow item in dtobject.AsEnumerable().OrderBy(p => p.Field <int>("prjid"))) { obj = null; if (item["shapetype"].ToString() == "dot") { isfind = uc.objManager.zLayers.TryGetValue(item["layer"].ToString(), out containerLayer); //查找是否有对象所属层 if (isfind) { isfind = containerLayer.pModels.TryGetValue(item["id"].ToString(), out obj); if (!isfind) { obj = new pSymbolObject(containerLayer) { id = item["id"].ToString(), name = item["objname"].ToString(), location = item["points"].ToString(), symbolid = item["symbolid"].ToString().Replace("#", ""), //材质Key isH = true }; if ((obj as pSymbolObject).symbolid == "SwitchStationOpen") { if (obj.busiData == null) { obj.busiData = new busiBase(obj); } obj.busiData.busiSort = "开关站"; (obj as pSymbolObject).color = Colors.Aqua; obj.visualMaxDistance = 10; } else if ((obj as pSymbolObject).symbolid == "SubstationEntityDisH") { if (obj.busiData == null) { obj.busiData = new busiBase(obj); } obj.busiData.busiSort = "变电站"; (obj as pSymbolObject).color = Colors.Lime; } else if ((obj as pSymbolObject).symbolid == "Pole") { if (obj.busiData == null) { obj.busiData = new busiBase(obj); } obj.busiData.busiSort = "杆塔"; (obj as pSymbolObject).color = Color.FromRgb(0xCC, 0xFF, 0xFF); obj.visualMaxDistance = 5; } //(obj as pSymbolObject).aniTwinkle.isDoAni = true; Regex regex = new Regex("translate\\(.*\\) ?rotate\\(.*\\) ?scale\\((\\d*.?\\d*), ?(\\d*.?\\d*)\\)", RegexOptions.Multiline); Match m = regex.Match(item["data"].ToString()); if (m.Success) { (obj as pSymbolObject).scaleX = (float)(uc.objManager.zSymbols[(obj as pSymbolObject).symbolid].sizeX * Math.Pow(double.Parse(m.Groups[1].Value), 0.7) / 400); (obj as pSymbolObject).scaleY = (float)(uc.objManager.zSymbols[(obj as pSymbolObject).symbolid].sizeY * Math.Pow(double.Parse(m.Groups[1].Value), 0.7) / 400); } else { (obj as pSymbolObject).scaleX = (obj as pSymbolObject).scaleY = 0.025f; } containerLayer.AddObject(item["id"].ToString(), obj);//也可直接加如:containerLayer.pModels.Add(item["id"].ToString(), obj); } } if (idx == 0) { obj = new pModel3D(containerLayer) //测试实物模型用,暂无效 { id = item["id"].ToString() + "3d", name = item["objname"].ToString(), location = item["points"].ToString(), Model3DType = EPowerModel3DType.风电 }; containerLayer.AddObject(item["id"].ToString() + "3d", obj); idx++; } } else if (item["shapetype"].ToString() == "path") { isfind = uc.objManager.zLayers.TryGetValue(item["layer"].ToString(), out containerLayer); if (isfind) { isfind = containerLayer.pModels.TryGetValue(item["id"].ToString(), out obj); if (!isfind) { obj = new pPowerLine(containerLayer) { id = item["id"].ToString(), name = item["objname"].ToString(), strPoints = item["points"].ToString(), color = Color.FromRgb(0xFF, 0xCC, 0x00), arrowColor = Colors.Blue, isFlow = true, thickness = 0.002f }; //(obj as pPowerLine).aniDraw.aniType=EAniType.绘制; //注意:只有aniDraw属性可以是擦除或绘制两者之一,其它的动画属性大多没有可选性,请不要更改它们的动画类型 //(obj as pPowerLine).aniDraw.isDoAni = true; //(obj as pPowerLine).aniTwinkle.isDoAni = true; //zh注:对不合理的过近的相邻点进行处理,这部分应放入位置数据入库前 PointCollection pc = PointCollection.Parse(item["points"].ToString()); PointCollection newpc = new PointCollection(); newpc.Add(pc[0]); for (int i = 1; i < pc.Count; i++) { if ((pc[i] - pc[i - 1]).Length > 0.00001) { if (i < pc.Count - 1) { Vector v1 = pc[i] - pc[i - 1]; v1.Normalize(); Vector v2 = pc[i + 1] - pc[i]; v2.Normalize(); if (v1 != v2) { newpc.Add(pc[i]); } } else { newpc.Add(pc[i]); } } } (obj as pPowerLine).strPoints = newpc.ToString(); if (newpc.Count > 1) { containerLayer.pModels.Add(item["id"].ToString(), obj); } } } idx++; } } }
void bworker_DoWork(object sender, DoWorkEventArgs e) { //重置处理状态 IEnumerable <PowerBasicObject> allobj = uc.objManager.getAllObjList(); foreach (PowerBasicObject tmpobj in allobj) { tmpobj.isHandled = false; } //重载处理注:示例中的图形对象分两部分,一部分为原架构对象,始终加载,另一部分为模拟添加对象,动态加载,实际项目中可以按sql语句确定的范围全体重新加载 //始终加载部分 foreach (DataRow item in dtobject.AsEnumerable().OrderBy(p => p.Field <int>("prjid"))) { string id = item["id"].ToString(); string layername = item["layer"].ToString(); pLayer layer; uc.objManager.zLayers.TryGetValue(layername, out layer); PowerBasicObject tmpobj; layer.pModels.TryGetValue(id, out tmpobj); tmpobj.isHandled = true; if (bworker.CancellationPending) { return; } } //读取数据库,动态加载部分 string s = @"select t1.*,t2.layer from map_object t1 join map_svg_layer t2 on t1.layerid=t2.id where t1.prjid=57 and distancemin<{0} and distancemax>{0} and reflongitude>{1} and reflongitude<{2} and reflatitude>{3} and reflatitude<{4} "; string sql = string.Format(s, olddictance, oldminjd, oldmaxjd, oldminwd, oldmaxwd); dtobject2 = DataLayer.DataProvider.getDataTableFromSQL(sql); PowerBasicObject obj; bool isfind; pLayer containerLayer; foreach (DataRow item in dtobject2.AsEnumerable().OrderBy(p => p.Field <int>("prjid"))) { obj = null; if (item["shapetype"].ToString() == "dot") { isfind = uc.objManager.zLayers.TryGetValue(item["layer"].ToString(), out containerLayer); //查找是否有对象所属层 if (isfind) { isfind = containerLayer.pModels.TryGetValue(item["id"].ToString(), out obj); if (!isfind) { obj = new pSymbolObject(containerLayer) { id = item["id"].ToString(), name = item["objname"].ToString(), location = item["points"].ToString(), symbolid = item["symbolid"].ToString().Replace("#", ""), //材质Key isH = true, }; (obj as pSymbolObject).color = Colors.Aqua; obj.visualMinDistance = double.Parse(item["distancemin"].ToString()); obj.visualMaxDistance = double.Parse(item["distancemax"].ToString()); (obj as pSymbolObject).scaleX = (obj as pSymbolObject).scaleY = 0.005f; containerLayer.AddObject(item["id"].ToString(), obj);//也可直接加如:containerLayer.pModels.Add(item["id"].ToString(), obj); } obj.isHandled = true; } } if (bworker.CancellationPending) { return; } } //清理不再有效对象 foreach (pLayer dlayer in uc.objManager.zLayers.Values) { int idx = 0; while (idx < dlayer.pModels.Values.Count) { KeyValuePair <string, PowerBasicObject> kv = dlayer.pModels.ElementAt(idx); if (!kv.Value.isHandled) { dlayer.pModels.Remove(kv.Key); } else { idx++; } } } }
///<summary>解析svg文件</summary> void loadFromSvg(string filename) { //示例从svg中读取非地理数据展现 XmlReaderSettings settings = new XmlReaderSettings(); settings.ConformanceLevel = ConformanceLevel.Document; settings.IgnoreWhitespace = true; settings.IgnoreComments = false; ; //settings.LineNumberOffset = 2; XmlReader reader = XmlReader.Create(filename, settings); string elename; string id, fill, stroke, width, height, data, layer, symbol, translate, rotate, scale, zclass, shapetype, layerid; id = layerid = ""; int depth; //解析图元用 bool istext = false; Brush brush = null; DrawingGroup drawgroup = new DrawingGroup(); GeometryDrawing aDrawing; WpfEarthLibrary.pSymbol psymbol = null; //层 WpfEarthLibrary.pLayer player = null; while (reader.Read()) { if (reader.NodeType == XmlNodeType.CDATA) { string tmp = reader.Value; string[] stringSeparators = new string[] { "\n" }; string[] ss = tmp.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries); foreach (string s in ss) { Regex regex = new Regex(".(.*?) {stroke:(.*?); fill:(.*?) }", RegexOptions.Multiline); Match m = regex.Match(s); if (m.Success) { string stylename = m.Groups[1].Value; stroke = m.Groups[2].Value; fill = m.Groups[3].Value; //zh注:style暂未实现 } } } if (reader.IsStartElement()) { elename = reader.Name; switch (elename) { case "svg": // svg string tmp2 = getPropertyValue(reader, "viewBox"); if (tmp2 != null) { Rect svgviewbox = Rect.Parse(tmp2); uc.earthManager.planeViewBox = svgviewbox; //必须设置,方能自动调整相机到适当位置,若显现看起来没居中,是图形与viewbox不完全匹配,可手动调整这个viewbox数值以居中 } break; case "symbol": // 图元符号 depth = reader.Depth; if (reader.HasAttributes) { string symbolid = getPropertyValue(reader, "id"); string viewbox = getPropertyValue(reader, "viewBox"); reader.MoveToElement(); //开始一个图元的处理,创建一个图元对象并加入到uc.objmanager的图元字典中,以便框架生成公用材质供厂站使用,在本示例中,仅breakor使用到了公用图元 drawgroup = new DrawingGroup(); Rect symbolviewbox = new Rect(0, 0, 2, 2); if (!string.IsNullOrWhiteSpace(viewbox)) { symbolviewbox = Rect.Parse(viewbox); } psymbol = new pSymbol() { id = symbolid, name = symbolid, sizeX = symbolviewbox.Width, sizeY = symbolviewbox.Height }; uc.objManager.zSymbols.Add(symbolid, psymbol); istext = false; } while (reader.Read()) { if (reader.Depth == depth && reader.NodeType == XmlNodeType.EndElement) { //结束一个图元处理,对图元的brush赋值 if (!istext) { DrawingBrush myDrawingBrush = new DrawingBrush(); myDrawingBrush.Drawing = drawgroup; psymbol.brush = myDrawingBrush; } break; } switch (reader.Name) { case "circle": if (reader.HasAttributes) { fill = getPropertyValue(reader, "fill"); stroke = "rgb(0, 0, 0)"; width = getPropertyValue(reader, "stroke-width"); data = getPropertyValue(reader, "cx") + "," + getPropertyValue(reader, "cy") + "|" + getPropertyValue(reader, "r"); reader.MoveToElement(); //绘图元元素 Regex regex = new Regex("(\\d*.?\\d*,\\d*.?\\d*)\\|(\\d*.?\\d*)", RegexOptions.Multiline); Match m = regex.Match(data); if (m.Success) { Point pc = Point.Parse(m.Groups[1].Value); double r = double.Parse(m.Groups[2].Value); EllipseGeometry geo = new EllipseGeometry(pc, r, r); aDrawing = new GeometryDrawing(); aDrawing.Geometry = geo; Pen pen = new Pen(); double thickness = double.Parse(width); thickness = thickness < 2 ? 2 : thickness; pen.Thickness = thickness; //brush = ;//defaultbrush;//强制缺省用黄色//brush = anaBrush(item["fill"].ToString()); brush = new SolidColorBrush(Colors.Red); pen.Brush = brush; aDrawing.Pen = pen; drawgroup.Children.Add(aDrawing); } } break; case "ellipse": if (reader.HasAttributes) { fill = getPropertyValue(reader, "fill"); stroke = "rgb(0, 0, 0)"; width = getPropertyValue(reader, "stroke-width"); double cx = double.Parse(getPropertyValue(reader, "cx")); double cy = double.Parse(getPropertyValue(reader, "cy")); double rx = double.Parse(getPropertyValue(reader, "rx")); double ry = double.Parse(getPropertyValue(reader, "ry")); reader.MoveToElement(); //绘图元元素 Point pc = new Point(cx, cy); EllipseGeometry geo = new EllipseGeometry(pc, rx, ry); aDrawing = new GeometryDrawing(); aDrawing.Geometry = geo; Pen pen = new Pen(); double thickness = double.Parse(width); thickness = thickness < 2 ? 2 : thickness; pen.Thickness = thickness; brush = Brushes.Yellow; //注,色彩应从fill取,示例没做转换,直接使用黄色 pen.Brush = brush; aDrawing.Pen = pen; drawgroup.Children.Add(aDrawing); } break; case "rect": if (reader.HasAttributes) { fill = getPropertyValue(reader, "fill"); stroke = "rgb(0, 0, 0)"; width = getPropertyValue(reader, "width"); height = getPropertyValue(reader, "height"); data = getPropertyValue(reader, "cx") + "," + getPropertyValue(reader, "cy") + "|" + getPropertyValue(reader, "r"); reader.MoveToElement(); //绘图元元素 RectangleGeometry geo = new RectangleGeometry(); geo.Rect = new Rect(0, 0, double.Parse(width), double.Parse(height)); aDrawing = new GeometryDrawing(); aDrawing.Geometry = geo; aDrawing.Brush = new SolidColorBrush(Colors.Aqua); drawgroup.Children.Add(aDrawing); } break; case "path": if (reader.HasAttributes) { fill = getPropertyValue(reader, "fill"); stroke = "rgb(0, 0, 0)"; width = getPropertyValue(reader, "stroke-width"); data = getPropertyValue(reader, "d"); reader.MoveToElement(); //绘图元元素 Geometry geo = PathGeometry.Parse(data); aDrawing = new GeometryDrawing(); aDrawing.Geometry = geo; brush = Brushes.Orange; aDrawing.Brush = brush; Pen pen = new Pen(); pen.Thickness = double.Parse(width); brush = Brushes.Blue; pen.Brush = brush; aDrawing.Pen = pen; drawgroup.Children.Add(aDrawing); } break; case "line": if (reader.HasAttributes) { //<line stroke="rgb(0, 0, 0)" stroke-width="1.000000" x1="50.000000" y1="7.499999" x2="13.193920" y2="71.250001" /> stroke = getPropertyValue(reader, "stroke"); width = getPropertyValue(reader, "stroke-width"); data = string.Format("M {0} {1} L {2} {3}", getPropertyValue(reader, "x1"), getPropertyValue(reader, "y1"), getPropertyValue(reader, "x2"), getPropertyValue(reader, "y2")); reader.MoveToElement(); //绘图元元素 } break; case "text": if (reader.HasAttributes) { stroke = getPropertyValue(reader, "stroke"); reader.MoveToElement(); //绘图元元素 psymbol.brush = Brushes.SkyBlue; istext = true; } break; } } break; case "g": depth = reader.Depth; if (reader.HasAttributes) { reader.MoveToAttribute("id"); layer = reader.Value; reader.MoveToElement(); //开始一个层,在uc.objmanager中创建一个层 player = uc.objManager.AddLayer(layer, layer, layer); } while (reader.Read()) { if (reader.Depth == depth && reader.NodeType == XmlNodeType.EndElement) { break; } if (reader.Name == "use" && reader.NodeType == XmlNodeType.Element) { shapetype = "dot"; id = getPropertyValue(reader, "id"); fill = getPropertyValue(reader, "fill"); stroke = getPropertyValue(reader, "stroke"); symbol = getPropertyValue(reader, "xlink:href"); zclass = getPropertyValue(reader, "class"); //data = getPropertyValue(reader, "transform"); double x = double.Parse(getPropertyValue(reader, "x")); double y = double.Parse(getPropertyValue(reader, "y")); double w = double.Parse(getPropertyValue(reader, "width")); double h = double.Parse(getPropertyValue(reader, "height")); reader.MoveToElement(); //点类对象,此处示例代码假定点对象使用了图元 symbol = symbol.Replace("#", ""); double aspect = uc.objManager.zSymbols[symbol].sizeX / uc.objManager.zSymbols[symbol].sizeY; //从图元取宽高比 pSymbolObject obj = new pSymbolObject(player) { id = id, name = id, planeLocation = (new Point(x + w / 2, y + h / 2)).ToString(), //注:应赋值到planeLocation(平面坐标用),而不是location(经纬度坐标用),另外,校验位置到中心点 symbolid = symbol, scaleX = 0.005f, // 0.005为从svg平面空间到3D空间的缩放系数,可自行调整大小 scaleY = (float)(0.005 * aspect), color = Colors.LightBlue, isH = true }; player.AddObject(id, obj); } else if (reader.Name == "path" && reader.NodeType == XmlNodeType.Element) { shapetype = "path"; id = getPropertyValue(reader, "id"); fill = getPropertyValue(reader, "fill"); stroke = getPropertyValue(reader, "stroke"); width = getPropertyValue(reader, "stroke-width"); data = getPropertyValue(reader, "d"); zclass = getPropertyValue(reader, "class"); reader.MoveToElement(); //线对象 if (!string.IsNullOrWhiteSpace(id)) { pPowerLine obj = new pPowerLine(player) { id = id, name = id, color = Color.FromRgb(0xFF, 0x66, 0x00), isFlow = true, //是否显示潮流 thickness = 0.002f, //线宽 arrowSize = 0.005f //潮流箭头大小 }; // 处理path短写,生成点集,对更复杂的短写,需借助path对象生成点集 string tmp = data; tmp = tmp.Replace("M", ""); string[] ps = tmp.Split('L'); string points = ""; int idx = 0; foreach (string s in ps) { if (idx != 0) { points += " "; } Point pt = Point.Parse(s); points += pt.ToString(); idx++; } //zh注:对不合理的过近的相邻点进行处理,必须进行此步检查,否则在3D空间不能正常生成3D线条 PointCollection pc = PointCollection.Parse(points); PointCollection newpc = new PointCollection(); newpc.Add(pc[0]); for (int i = 1; i < pc.Count; i++) { if ((pc[i] - pc[i - 1]).Length > 20) { if (i < pc.Count - 1) { Vector v1 = pc[i] - pc[i - 1]; v1.Normalize(); Vector v2 = pc[i + 1] - pc[i]; v2.Normalize(); if (v1 != v2) { newpc.Add(pc[i]); } } else { newpc.Add(pc[i]); } } } (obj as pPowerLine).strPoints = newpc.ToString(); obj.planeStrPoints = newpc.ToString(); // //注:应赋值到planeStrPoints,而不是strPoints if (newpc.Count > 1) { player.pModels.Add(id, obj); } //处理潮流,在本demo中,ConnectNode_Layer层中的线不显示潮流箭头 if (player.id == "ConnectNode_Layer") { obj.isFlow = false; } } } else if (reader.Name == "text" && reader.NodeType == XmlNodeType.Element) { stroke = getPropertyValue(reader, "stroke"); double x = double.Parse(getPropertyValue(reader, "x")); double y = double.Parse(getPropertyValue(reader, "y")); string fontfamily = getPropertyValue(reader, "font-family"); string fontsize = getPropertyValue(reader, "font-size"); zclass = getPropertyValue(reader, "class"); reader.Read(); string text = reader.Value; reader.MoveToElement(); if (text == "线") { } //文字对象 double w = 40; // w 和 h用来修正位置 double h = -10; float scalexy = float.Parse(fontsize) / 16f * 0.8f; if (player.id == "Text_Layer") { pText obj = new pText(player) { id = Helpler.getGUID(), //生成guid串,确保key值唯一 name = text, text = text, planeLocation = (new Point(x + w / 2, y + h / 2)).ToString(), //注:应赋值到planeLocation(平面坐标用),而不是location(经纬度坐标用),另外,校验位置到中心点 isH = true, //是否水平放置 color = Colors.White, scaleX = scalexy, scaleY = scalexy, }; player.AddObject(text, obj); } } else if (reader.Name == "rect" && reader.NodeType == XmlNodeType.Element) { fill = getPropertyValue(reader, "fill"); stroke = getPropertyValue(reader, "stroke"); double x = double.Parse(getPropertyValue(reader, "x")); double y = double.Parse(getPropertyValue(reader, "y")); double w = double.Parse(getPropertyValue(reader, "width")); double h = double.Parse(getPropertyValue(reader, "height")); reader.Read(); reader.MoveToElement(); //厂站对象 if (player.id == "Other_Layer") { pSymbolObject obj = new pSymbolObject(player) { id = Helpler.getGUID(), //生成guid串,确保key值唯一 planeLocation = (new Point(x + w / 2, y + h / 2)).ToString(), //注:应赋值到planeLocation(平面坐标用),而不是location(经纬度坐标用),另外,校验位置到中心点 isH = true, brush = Brushes.White, color = Colors.Red, scaleX = (float)(w * 0.0005), //0.0005为映射到3D空间的尺寸调整系数 scaleY = (float)(h * 0.0005) }; player.AddObject(obj.id, obj); } } } break; } } } //==============清理空白层 int idxi = 0; while (idxi < uc.objManager.zLayers.Count) { if (uc.objManager.zLayers.Values.ElementAt(idxi).pModels.Count == 0) { uc.objManager.zLayers.Remove(uc.objManager.zLayers.Keys.ElementAt(idxi)); } else { idxi++; } } }
void init() { symbolkeys = root.earth.objManager.zSymbols.Values.Where(p => p.sort == "car").Select(p => p.id).ToList(); int symcount = symbolkeys.Count; //模拟站桩 rangelayer = root.earth.objManager.AddLayer("carrangelayer", "carrangelayer", "carrangelayer"); carlayer = root.earth.objManager.AddLayer("carlayer", "carlayer", "carlayer"); Rect range = root.earth.objManager.getBounds(); for (int i = 0; i < 30; i++) { int tmpi = rd.Next(symcount); Point loca = new Point(range.X + range.Width * rd.NextDouble(), range.Y + range.Height * rd.NextDouble()); pSymbolObject nobj = new pSymbolObject(carlayer) { id = "car" + i, name = "充电站" + i, symbolid = symbolkeys[tmpi], location = loca.ToString(), isH = true, scaleX = 0.0025f, scaleY = 0.0025f, color = Color.FromRgb(0xFF, 0x66, 0x00) }; if (nobj.busiData == null) { nobj.busiData = new busiBase(nobj); } nobj.busiData.busiValue1 = (5 + rd.Next(6)); //覆盖半径 nobj.busiData.busiStr1 = symbolkeys[tmpi]; //名称 nobj.busiData.busiDatetime = DateTime.Now.AddDays(rd.Next(2000)); //投运时间 nobj.busiData.busiSort = "充电桩"; nobj.busiData.busiBrush = root.earth.objManager.zSymbols[nobj.symbolid].brush; carlayer.AddObject(nobj.id, nobj); //台账 AccountCar acc = new AccountCar() { id = nobj.id, name = nobj.name, address = "A区B街", cap = 100 * (1 + rd.Next(10)), frhour = 3 + rd.Next(10), geo = nobj.location, nums = 1 + rd.Next(5), ptype = nobj.busiData.busiStr1, rad = 2 + rd.Next(10), rcmode = (AccountCar.Ertype)rd.Next(3), rdate = DateTime.Now.AddDays(100 + rd.Next(8000)).ToString("yyyy年MM月"), region = "某区", rmode = (AccountCar.Ermode)rd.Next(4), vl = 380 }; nobj.busiAccount = acc; //范围 pSymbolObject robj = new pSymbolObject(rangelayer) { id = i + "carrange", symbolid = "充电桩覆盖范围", location = loca.ToString(), isH = true, isUseColor = false }; robj.scaleX = robj.scaleY = (float)(nobj.busiData.busiValue1 / 100); if (robj.busiData == null) { robj.busiData = new busiBase(robj); } robj.busiData.busiSort = "覆盖范围"; rangelayer.AddObject(robj.id, robj); } root.earth.UpdateModel(); //初始化图例 lstType.ItemsSource = root.earth.objManager.zSymbols.Values.Where(p => p.sort == "car"); //分类占比 cht.DataSource = from e0 in root.earth.objManager.getObjList("充电桩") group e0 by e0.busiData.busiStr1 into g select new { argu = g.Key, value = g.Count() }; lstObj.ItemsSource = root.earth.objManager.getObjList("充电桩"); }