/// <summary> /// 解析字符串并绘制 /// </summary> /// <param name="GraphicId">id</param> /// <param name="GraphicInfo">图形信息 格式:polyline:blue,2|127,1,42.2&126.8&41.9</param> /// <param name="mapControl">需要绘制的地图对象,为空则往ShowMap上绘制</param> private void DrawPlaceLocation(string GraphicId, string GraphicInfo, MapGIS mapgis = null) { if (string.IsNullOrEmpty(GraphicId) || string.IsNullOrEmpty(GraphicInfo)) { return; } //各形状用*分隔 //polyline:blue,2|127,1,42.2&126.8,41.9 //polygon:blue,2,red|127,1,42.2&126.8,41.9 //circle:blue,2,red|127,1,42.2&2000 //rectangle:blue,2,red|127,1,42.2&127,1,42.2 //rectangle:blue,2,red|127,1,42.2&2000&1000 if (mapgis == null) { mapgis = ShowMap; } string[] info = GraphicInfo.Split('*'); for (int i = 0; i < info.Length; i++) { NameId++; GraphicInfo ginfo = getDrawInfo(info[i], mapgis); if (ginfo is PolylineInfo) { PolylineInfo g = ginfo as PolylineInfo; if (g == null) { continue; } mapgis.DrawPolyline(g.Points, GraphicId + "-" + NameId.ToString(), new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>(GraphicStyle.BorderColor.ToString(), g.BorderColor), new KeyValuePair <string, object>(GraphicStyle.BorderWidth.ToString(), g.BorderWidth), }, null); } if (ginfo is PolygonInfo) { PolygonInfo g = ginfo as PolygonInfo; if (g == null) { continue; } mapgis.DrawPolygon(g.Points, GraphicId + "-" + NameId.ToString(), new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>(GraphicStyle.BorderColor.ToString(), g.BorderColor), new KeyValuePair <string, object>(GraphicStyle.BorderWidth.ToString(), g.BorderWidth), new KeyValuePair <string, object>(GraphicStyle.FillColor.ToString(), g.FillColor), }, null); } if (ginfo is CircleInfo) { CircleInfo g = ginfo as CircleInfo; if (g == null) { continue; } mapgis.DrawCircle(g.CenterPoint, g.Radius, GraphicId + "-" + NameId.ToString(), new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>(GraphicStyle.BorderColor.ToString(), g.BorderColor), new KeyValuePair <string, object>(GraphicStyle.BorderWidth.ToString(), g.BorderWidth), new KeyValuePair <string, object>(GraphicStyle.FillColor.ToString(), g.FillColor), }, null); } if (ginfo is RectangleInfo) { RectangleInfo g = ginfo as RectangleInfo; if (g == null) { continue; } if (g.RightBottomPoint != null) { mapgis.DrawRectangle(g.LeftTopPoint, g.RightBottomPoint, GraphicId + "-" + NameId.ToString(), new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>(GraphicStyle.BorderColor.ToString(), g.BorderColor), new KeyValuePair <string, object>(GraphicStyle.BorderWidth.ToString(), g.BorderWidth), new KeyValuePair <string, object>(GraphicStyle.FillColor.ToString(), g.FillColor), }, null); } else { mapgis.DrawRectangle(g.LeftTopPoint, g.RectWidth, g.RectHeight, GraphicId + "-" + NameId.ToString(), new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>(GraphicStyle.BorderColor.ToString(), g.BorderColor), new KeyValuePair <string, object>(GraphicStyle.BorderWidth.ToString(), g.BorderWidth), new KeyValuePair <string, object>(GraphicStyle.FillColor.ToString(), g.FillColor), }, null); } } } }
/// <summary> /// 绘制地图 /// </summary> /// <param name="place">地点信息</param> /// <param name="mapgis">地图</param> private void DrawMap(ActivityPlaceInfo place, MapGIS mapgis = null) { GraphicInfo ginfo = getDrawInfo(place.Graphics, mapgis); if (ginfo is PolylineInfo) { PolylineInfo g = ginfo as PolylineInfo; if (g == null) { return; } mapgis.DrawPolyline(g.Points, place.Guid + "-0", new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>(GraphicStyle.BorderColor.ToString(), g.BorderColor), new KeyValuePair <string, object>(GraphicStyle.BorderWidth.ToString(), g.BorderWidth), }, null); } if (ginfo is PolygonInfo) { PolygonInfo g = ginfo as PolygonInfo; if (g == null) { return; } mapgis.DrawPolygon(g.Points, place.Guid + "-0", new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>(GraphicStyle.BorderColor.ToString(), g.BorderColor), new KeyValuePair <string, object>(GraphicStyle.BorderWidth.ToString(), g.BorderWidth), new KeyValuePair <string, object>(GraphicStyle.FillColor.ToString(), g.FillColor), }, null); } if (ginfo is CircleInfo) { CircleInfo g = ginfo as CircleInfo; if (g == null) { return; } mapgis.DrawCircle(g.CenterPoint, g.Radius, place.Guid + "-0" + "", new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>(GraphicStyle.BorderColor.ToString(), g.BorderColor), new KeyValuePair <string, object>(GraphicStyle.BorderWidth.ToString(), g.BorderWidth), new KeyValuePair <string, object>(GraphicStyle.FillColor.ToString(), g.FillColor), }, null); } if (ginfo is RectangleInfo) { RectangleInfo g = ginfo as RectangleInfo; if (g == null) { return; } if (g.RightBottomPoint != null) { mapgis.DrawRectangle(g.LeftTopPoint, g.RightBottomPoint, place.Guid + "-0", new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>(GraphicStyle.BorderColor.ToString(), g.BorderColor), new KeyValuePair <string, object>(GraphicStyle.BorderWidth.ToString(), g.BorderWidth), new KeyValuePair <string, object>(GraphicStyle.FillColor.ToString(), g.FillColor), }, null); } else { mapgis.DrawRectangle(g.LeftTopPoint, g.RectWidth, g.RectHeight, place.Guid + "-0", new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>(GraphicStyle.BorderColor.ToString(), g.BorderColor), new KeyValuePair <string, object>(GraphicStyle.BorderWidth.ToString(), g.BorderWidth), new KeyValuePair <string, object>(GraphicStyle.FillColor.ToString(), g.FillColor), }, null); } } }
/// <summary> /// 根据字符串获取图形类信息 /// </summary> /// <param name="info"></param> /// <returns></returns> public static GraphicInfo getDrawInfo(string info, MapGIS mapgis) { if (mapgis == null) { return(null); } info = info.Replace(" ", "").Replace("\n", ""); string[] gInfoArr = null; string[] gInfo = info.Split(':'); if (gInfo.Length == 2) { switch (gInfo[0]) { case "polyline": PolylineInfo lineInfo = new PolylineInfo(); gInfoArr = gInfo[1].Split('|'); if (gInfoArr.Length == 2) { //样式 string[] gStyle = gInfoArr[0].Split(','); if (gStyle.Length == 2) { lineInfo.BorderColor = gStyle[0]; double.TryParse(gStyle[1], out lineInfo.BorderWidth); } //点 string[] gPoints = gInfoArr[1].Split('&'); if (gPoints.Length > 0) { lineInfo.Points = new List <I_GS_MapBase.Portal.Types.MapPointEx>(); for (int i = 0; i < gPoints.Length; i++) { string[] p = gPoints[i].Split(','); lineInfo.Points.Add(mapgis.MainMap.MapPointFactory.Create(p[0].TryToDoubleZero(), p[1].TryToDoubleZero())); } } } return(lineInfo); case "polygon": PolygonInfo gonInfo = new PolygonInfo(); gInfoArr = gInfo[1].Split('|'); if (gInfoArr.Length == 2) { //样式 string[] gStyle = gInfoArr[0].Split(','); if (gStyle.Length == 3) { gonInfo.BorderColor = gStyle[0]; double.TryParse(gStyle[1], out gonInfo.BorderWidth); gonInfo.FillColor = gStyle[2]; } //点 string[] gPoints = gInfoArr[1].Split('&'); if (gPoints.Length > 0) { gonInfo.Points = new List <I_GS_MapBase.Portal.Types.MapPointEx>(); for (int i = 0; i < gPoints.Length; i++) { string[] p = gPoints[i].Split(','); gonInfo.Points.Add(mapgis.MainMap.MapPointFactory.Create(p[0].TryToDoubleZero(), p[1].TryToDoubleZero())); } } } return(gonInfo); case "circle": CircleInfo circleInfo = new CircleInfo(); gInfoArr = gInfo[1].Split('|'); if (gInfoArr.Length == 2) { //样式 string[] gStyle = gInfoArr[0].Split(','); if (gStyle.Length == 3) { circleInfo.BorderColor = gStyle[0]; double.TryParse(gStyle[1], out circleInfo.BorderWidth); circleInfo.FillColor = gStyle[2]; } //中心点 半径 string[] gPoints = gInfoArr[1].Split('&'); if (gPoints.Length == 2) { string[] p = gPoints[0].Split(','); circleInfo.CenterPoint = mapgis.MainMap.MapPointFactory.Create(p[0].TryToDoubleZero(), p[1].TryToDoubleZero()); circleInfo.Radius = gPoints[1].TryToDoubleZero(); } } return(circleInfo); case "rectangle": RectangleInfo rectangleInfo = new RectangleInfo(); gInfoArr = gInfo[1].Split('|'); if (gInfoArr.Length == 2) { //样式 string[] gStyle = gInfoArr[0].Split(','); if (gStyle.Length == 3) { rectangleInfo.BorderColor = gStyle[0]; double.TryParse(gStyle[1], out rectangleInfo.BorderWidth); rectangleInfo.FillColor = gStyle[2]; } string[] gPoints = gInfoArr[1].Split('&'); if (gPoints.Length == 3) { string[] p = gPoints[0].Split(','); rectangleInfo.LeftTopPoint = mapgis.MainMap.MapPointFactory.Create(p[0].TryToDoubleZero(), p[1].TryToDoubleZero()); rectangleInfo.RectWidth = gPoints[1].TryToDoubleZero(); rectangleInfo.RectHeight = gPoints[2].TryToDoubleZero(); } if (gPoints.Length == 2) { string[] p = gPoints[0].Split(','); rectangleInfo.LeftTopPoint = mapgis.MainMap.MapPointFactory.Create(p[0].TryToDoubleZero(), p[1].TryToDoubleZero()); string[] p2 = gPoints[1].Split(','); rectangleInfo.RightBottomPoint = mapgis.MainMap.MapPointFactory.Create(p2[0].TryToDoubleZero(), p2[1].TryToDoubleZero()); } } return(rectangleInfo); } } return(null); }