/// <summary> /// 坐标范围定位 /// </summary> /// <param name="coords"></param> public void ZoomTo(string coords) { featuresLayer.Features.Clear(); string[] coordArr = coords.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); GeoRegion region = new GeoRegion(); ObservableCollection<Point2DCollection> parts = new ObservableCollection<Point2DCollection>(); Point2DCollection ptnColl = new Point2DCollection(); Feature feature = new Feature(); foreach (string str in coordArr) { string tempCoord = str.Substring(1, str.Length - 2); //取出 1122.23232,773.211212 string[] tempPtn = tempCoord.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); Point2D pnt = new Point2D(Convert.ToDouble(tempPtn[0]), Convert.ToDouble(tempPtn[1])); ptnColl.Add(pnt); } if (ptnColl.Count < 3) //如果是矩形 { Point2D ptn1 = new Point2D(ptnColl[0].X, ptnColl[0].Y); Point2D ptn2= new Point2D(ptnColl[1].X, ptnColl[0].Y); Point2D ptn3 = new Point2D(ptnColl[0].X, ptnColl[1].Y); Point2D ptn4 = new Point2D(ptnColl[1].X, ptnColl[1].Y); ptnColl.Clear(); ptnColl.Add(ptn1); ptnColl.Add(ptn2); ptnColl.Add(ptn4); ptnColl.Add(ptn3); ptnColl.Add(ptn1); } parts.Add(ptnColl); region.Parts = parts; feature.Geometry = region; feature.Style = myCustomFillStyle; featuresLayer.Features.Add(feature); MyMap.ZoomTo(feature.Geometry.Bounds); }
坐标点的组织形式 “(124.23212,121243.2121);(983.423,412.4232);(141.23212,1443.2121);(983.423,4124.098)”