private void task_QueryComplete(object sender, QueryEventArgs args) { base.OnProgress(100); if (args.FeatureSet != null) { ESRI.ArcGIS.Client.Geometry.PointCollection points = new ESRI.ArcGIS.Client.Geometry.PointCollection(); foreach (Graphic g in args.FeatureSet.Features) { if (g.Geometry is ESRI.ArcGIS.Client.Geometry.MapPoint) { points.Add(g.Geometry as ESRI.ArcGIS.Client.Geometry.MapPoint); if (this.SpatialReference == null) { if (g.Geometry.SpatialReference != null) this.SpatialReference = g.Geometry.SpatialReference; } } } MapSpatialReference = SpatialReference; HeatMapPoints = points; OnLayerChanged(); } base.Initialize(); }
private string SerializePolyline(ESRI.ArcGIS.Client.Geometry.Polyline p) { _length = ESRI.ArcGIS.Client.Geometry.Euclidian.Length(p) * 0.000621371192; string s = @"[{""spatialreference"":{""wkid"":"; if (p.SpatialReference != null) { s = s + p.SpatialReference.WKID + "},"; } s = s + "\"hasZ\":" + p.HasZ + ","; s = s + "\"hasM\":" + p.HasM + ","; s = s + "\"paths\":[["; for (int i = 0; i < p.Paths.Count; i++) { ESRI.ArcGIS.Client.Geometry.PointCollection path = p.Paths[i]; foreach (MapPoint c in path) { s = s + "[" + c.X + "," + c.Y + "],"; } } s = s + "]]}]"; return(s); }
private static ESRI.ArcGIS.Client.Geometry.Geometry GetPolygon(ShapeFileRecord record) { Polygon polygon = new Polygon(); for (int i = 0; i < record.NumberOfParts; i++) { // Determine the starting index and the end index // into the points array that defines the figure. int start = record.Parts[i]; int end; if (record.NumberOfParts > 1 && i != (record.NumberOfParts - 1)) { end = record.Parts[i + 1]; } else { end = record.NumberOfPoints; } ESRI.ArcGIS.Client.Geometry.PointCollection points = new ESRI.ArcGIS.Client.Geometry.PointCollection(); // Add line segments to the polyline for (int j = start; j < end; j++) { System.Windows.Point point = record.Points[j]; points.Add(new MapPoint(point.X, point.Y)); } polygon.Rings.Add(points); } return(polygon); }
public void Thermodynamic(double centerX, double centerY, double radius, string colour, int id, int typeid) { //画圆 GraphicsLayer Cityrode = map.Layers["GraphicsLayerRL"] as GraphicsLayer; //Cityrode.Graphics.Clear(); Graphic result = new Graphic(); radius = radius / 111321; List <MapPoint> points = new List <MapPoint>(); for (double i = 0; i <= 360; i++) { points.Add(new MapPoint((centerX - Math.Cos(Math.PI * i / 180.0) * radius), (centerY - Math.Sin(Math.PI * i / 180.0) * radius))); } //ESRI.ArcGIS.Client.Geometry. ESRI.ArcGIS.Client.Geometry.PointCollection pCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(points); ESRI.ArcGIS.Client.Geometry.Polygon g = new ESRI.ArcGIS.Client.Geometry.Polygon(); g.Rings.Add(pCollection); result.Geometry = g; SimpleFillSymbol sfs = new SimpleFillSymbol(); sfs.BorderBrush = new SolidColorBrush(Colors.Transparent); sfs.BorderThickness = 2; string[] str = colour.Split(','); sfs.Fill = new SolidColorBrush(Color.FromArgb(0x7f, Convert.ToByte(str[0]), Convert.ToByte(str[1]), Convert.ToByte(str[2]))); result.Symbol = sfs; result.MouseLeftButtonUp += delegate { HtmlPage.Window.Invoke("clickPonitsShowThermodynamic", id, typeid); }; Cityrode.Graphics.Add(result); ContainerManager.Map.PanTo(new ESRI.ArcGIS.Client.Geometry.Envelope((double)centerX, (double)centerY, (double)centerX, (double)centerY)); }
public void Round(double centerX, double centerY, double radius, string jsondata) { //定位点 Location(jsondata); //画圆 GraphicsLayer Cityrode = map.Layers["GraphicsLayer"] as GraphicsLayer; Cityrode.Graphics.Clear(); Graphic result = new Graphic(); //radius = radius / 111321; List <MapPoint> points = new List <MapPoint>(); for (double i = 0; i <= 360; i++) { points.Add(new MapPoint((centerX - Math.Cos(Math.PI * i / 180.0) * radius), (centerY - Math.Sin(Math.PI * i / 180.0) * radius))); } //ESRI.ArcGIS.Client.Geometry. ESRI.ArcGIS.Client.Geometry.PointCollection pCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(points); ESRI.ArcGIS.Client.Geometry.Polygon g = new ESRI.ArcGIS.Client.Geometry.Polygon(); g.Rings.Add(pCollection); result.Geometry = g; SimpleFillSymbol sfs = new SimpleFillSymbol(); sfs.BorderBrush = new SolidColorBrush(Colors.Transparent); sfs.BorderThickness = 2; sfs.Fill = new SolidColorBrush(Colors.Red); result.Symbol = sfs; Cityrode.Graphics.Add(result); ContainerManager.Map.PanTo(new ESRI.ArcGIS.Client.Geometry.Envelope((double)centerX, (double)centerY, (double)centerX, (double)centerY)); }
/// <summary> /// Create straight line geometry. /// </summary> /// <param name="route">Route.</param> /// <returns>Straight line route geometry.</returns> private ArcGISGeometry.Polyline _CreateStraightPolyline(Route route) { ArcGISGeometry.Polyline routeLine = new ArcGISGeometry.Polyline(); ArcGISGeometry.PointCollection pointCollection = new ArcGISGeometry.PointCollection(); List <Stop> routeStops = CommonHelpers.GetSortedStops(route); int startIndex = _GetStartIndex(routeStops); int processCount = _GetProcessStopCount(routeStops); // add stop map points for (int index = startIndex; index < processCount; ++index) { Stop stop = routeStops[index]; if (stop.MapLocation != null) { ArcGISGeometry.MapPoint mapPoint = _CreateProjectedMapPoint(stop.MapLocation.Value); pointCollection.Add(mapPoint); } } routeLine.Paths.Add(pointCollection); return(routeLine); }
private void drawPolygon() { MapPoint center = MyMap.Extent.GetCenter(); double lat = center.Y; double lon = center.X + 300; double latOffset = 300; double lonOffset = 300; ESRI.ArcGIS.Client.Geometry.PointCollection points = new ESRI.ArcGIS.Client.Geometry.PointCollection() { new MapPoint(lon - lonOffset, lat), new MapPoint(lon, lat + latOffset), new MapPoint(lon + lonOffset, lat), new MapPoint(lon, lat - latOffset), new MapPoint(lon - lonOffset, lat), new MapPoint(lon - 2 * lonOffset, lat + latOffset), new MapPoint(lon - 3 * lonOffset, lat), new MapPoint(lon - 2 * lonOffset, lat - latOffset), new MapPoint(lon - 1.5 * lonOffset, lat + latOffset), new MapPoint(lon - lonOffset, lat) }; ESRI.ArcGIS.Client.Geometry.Polygon polygon = new ESRI.ArcGIS.Client.Geometry.Polygon(); polygon.Rings.Add(points); polygon.SpatialReference = MyMap.SpatialReference; _unsimplifiedGraphic.Geometry = polygon; GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; _unsimplifiedGraphic.Symbol = LayoutRoot.Resources["PolygonFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol; graphicsLayer.Graphics.Add(_unsimplifiedGraphic); }
public static double PointToPolygonDistance(double x, double y, ObservableCollection <ESRI.ArcGIS.Client.Geometry.PointCollection> polygon) { bool inside = false; double minDistSq = double.MaxValue; for (int k = 0; k < polygon.Count; k++) { ESRI.ArcGIS.Client.Geometry.PointCollection ring = polygon[k]; int count = ring.Count; int j = count - 1; for (int i = 0; i < count; j = i++) { MapPoint a = ring[i]; MapPoint b = ring[j]; if ((a.Y > y != b.Y > y) && (x < (b.X - a.X) * (y - a.Y) / (b.Y - a.Y) + a.X)) { inside = !inside; } minDistSq = Math.Min(minDistSq, GetSegDistSq(x, y, a, b)); } } return((inside ? 1 : -1) * Math.Sqrt(minDistSq)); }
public void DrowGraphical(string url) { WebAPIHelper dt = new WebAPIHelper(); GraphicsLayer Cityrode = map.Layers["GraphicsLayerCq"] as GraphicsLayer; dt.GetDataCompleted += (s, args) => { List <MapGraphical> list = args.DataResult as List <MapGraphical>; foreach (var model in list) { SimpleFillSymbol style = new SimpleFillSymbol(); string[] str = model.colour.Split(','); List <MapPoint> MapPointList = new List <MapPoint>(); foreach (var po in model.MapPointList) { MapPointList.Add(new MapPoint { X = po.X, Y = po.Y }); } //Color ColorFill = ConvertToHtml(model.colour); Graphic graphic = new Graphic(); style.Fill = new SolidColorBrush(Color.FromArgb(0x7f, Convert.ToByte(str[0]), Convert.ToByte(str[1]), Convert.ToByte(str[2]))); ESRI.ArcGIS.Client.Geometry.PointCollection pCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(MapPointList); ESRI.ArcGIS.Client.Geometry.Polygon g = new ESRI.ArcGIS.Client.Geometry.Polygon(); g.Rings.Add(pCollection); graphic.Geometry = g; graphic.Symbol = style; //ESRI.ArcGIS.Client.Geometry.Polygon polygon = (ESRI.ArcGIS.Client.Geometry.Polygon)graphic.Geometry; //GraphicsLayerCq Cityrode.Graphics.Add(graphic); } }; dt.GetDataAsync <List <MapGraphical> >(url); }
public void drawBufferCircle(double radius, int pointCount, MapPoint currentPoint, GraphicsLayer gl) { MapPoint point = currentPoint; var pl = new ESRI.ArcGIS.Client.Geometry.Polyline(); var polygon = new ESRI.ArcGIS.Client.Geometry.Polygon(); var routePoint = new ESRI.ArcGIS.Client.Geometry.PointCollection(); for (int i = 1; i <= pointCount; i++) { double x; double y; x = (point.X + radius * Math.Cos(2 * Math.PI / pointCount * i)); y = (point.Y + radius * Math.Sin(2 * Math.PI / pointCount * i)); routePoint.Add(new MapPoint(x, y)); } routePoint.Add(routePoint[0]); polygon.Rings.Add(routePoint); GraphicsLayer mygraphicslayer = gl; mygraphicslayer.ClearGraphics(); Graphic graphic = new Graphic() { Geometry = polygon, Symbol = LayoutRoot.Resources["DefaultBufferSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol, }; mygraphicslayer.Graphics.Add(graphic); }
/// <summary> /// 84坐标系画圆,注意 84坐标系需要 radius需要除以111321 /// </summary> /// <param name="radius"></param> /// <param name="centerP"></param> /// <returns></returns> public static Graphic GetEllipseGraphic84(double radius, MapPoint centerP) { Graphic result = new Graphic(); List <MapPoint> points = new List <MapPoint>(); for (double i = 0; i <= 360; i++) { points.Add(new MapPoint(Math.Abs((centerP.X - Math.Cos(Math.PI * i / 180.0) * radius)), Math.Abs((centerP.Y - Math.Sin(Math.PI * i / 180.0) * radius)))); } ESRI.ArcGIS.Client.Geometry.PointCollection pCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(points); Polygon g = new Polygon(); g.Rings.Add(pCollection); result.Geometry = g; // result.Symbol = Tools.DrawStyleTools.GetEllipseFillSymbol(color);//这里根据自己的需要定义样式 RadialGradientBrush bursh = new RadialGradientBrush { GradientOrigin = new Point(0.5, 0.5) }; bursh.GradientStops.Add(new GradientStop { Color = Color.FromArgb(50, 0x46, 0x73, 0xcc), Offset = 0 }); bursh.GradientStops.Add(new GradientStop { Color = Color.FromArgb(50, 0x46, 0x73, 0xcc), Offset = 1 }); result.Symbol = new ESRI.ArcGIS.Client.Symbols.SimpleFillSymbol() { BorderBrush = new SolidColorBrush(Color.FromArgb(220, 0xad, 0xb9, 0xd2)), BorderThickness = 2, Fill = bursh }; return(result); }
public void Creat(GraphicsLayer layer, RegularGrid grid) { _GraphicsLayer = layer; var cellsize = grid.CellSize * 0.5; var polygon = new Polygon(); for (int i = 0; i < grid.NCell; i++) { var symbol = GetDefaultSymbol(polygon, System.Windows.Media.Colors.White); ESRI.ArcGIS.Client.Geometry.PointCollection pc = new ESRI.ArcGIS.Client.Geometry.PointCollection(); var buf = SpatialReferenceSystem.ToWebMercator(grid.CentroidX[i] - cellsize, grid.CentroidY[i] + cellsize); MapPoint p1 = new MapPoint(buf[0], buf[1]); buf = SpatialReferenceSystem.ToWebMercator(grid.CentroidX[i] + cellsize, grid.CentroidY[i] + cellsize); MapPoint p2 = new MapPoint(buf[0], buf[1]); buf = SpatialReferenceSystem.ToWebMercator(grid.CentroidX[i] + cellsize, grid.CentroidY[i] - cellsize); MapPoint p3 = new MapPoint(buf[0], buf[1]); buf = SpatialReferenceSystem.ToWebMercator(grid.CentroidX[i] - cellsize, grid.CentroidY[i] - cellsize); MapPoint p4 = new MapPoint(buf[0], buf[1]); buf = SpatialReferenceSystem.ToWebMercator(grid.CentroidX[i] - cellsize, grid.CentroidY[i] + cellsize); MapPoint p5 = new MapPoint(buf[0], buf[1]); pc.Add(p1); pc.Add(p2); pc.Add(p3); pc.Add(p4); pc.Add(p5); Graphic graphic = new Graphic(); Polygon ep = new Polygon(); ep.Rings.Add(pc); graphic.Geometry = ep; graphic.Symbol = symbol; graphic.Attributes.Add("ID", i); layer.Graphics.Add(graphic); } }
/// <summary> /// Initializes a new instance of the <see cref="HeatMapLayer"/> class. /// </summary> public HeatMapLayer() { GradientStopCollection stops = new GradientStopCollection(); stops.Add(new GradientStop() { Color = Colors.Transparent, Offset = 0 }); stops.Add(new GradientStop() { Color = Colors.Blue, Offset = .5 }); stops.Add(new GradientStop() { Color = Colors.Red, Offset = .75 }); stops.Add(new GradientStop() { Color = Colors.Yellow, Offset = .8 }); stops.Add(new GradientStop() { Color = Colors.White, Offset = 1 }); Gradient = stops; HeatMapPoints = new ESRI.ArcGIS.Client.Geometry.PointCollection(); //Create a separate thread for rendering the heatmap layer. renderThread = new BackgroundWorker() { WorkerReportsProgress = true, WorkerSupportsCancellation = true }; renderThread.ProgressChanged += new ProgressChangedEventHandler(renderThread_ProgressChanged); renderThread.RunWorkerCompleted += new RunWorkerCompletedEventHandler(renderThread_RunWorkerCompleted); renderThread.DoWork += new DoWorkEventHandler(renderThread_DoWork); }
private void task_QueryComplete(object sender, QueryEventArgs args) { base.OnProgress(100); if (args.FeatureSet != null) { ESRI.ArcGIS.Client.Geometry.PointCollection points = new ESRI.ArcGIS.Client.Geometry.PointCollection(); foreach (Graphic g in args.FeatureSet.Features) { if (g.Geometry is ESRI.ArcGIS.Client.Geometry.MapPoint) { points.Add(g.Geometry as ESRI.ArcGIS.Client.Geometry.MapPoint); if (this.SpatialReference == null) { if (g.Geometry.SpatialReference != null) { this.SpatialReference = g.Geometry.SpatialReference; } } } } MapSpatialReference = SpatialReference; HeatMapPoints = points; OnLayerChanged(); } base.Initialize(); }
private void DoLine() { QueryWithBuffer QWB; QWB = new QueryWithBuffer("DynamicGraphicLayer", PublicVARS.Distance); double _DIRECT; if (PublicVARS.MainGPS != null && PublicVARS.MainX != 0.0) { _DIRECT = 360 + 90 - PublicVARS.Direct; // 转为逆时针,0 度 为 try { if (PublicVARS.Speed <= 0) { return; } Polyline PL = new Polyline(); double degree = PublicVARS.Distance / (106 * 1000); // 距离米 换算成度 // GlobalLayers.MainX += 0.0005; // 模拟移动 // GlobalLayers.MainY -= 0.0005; double NextX; double NextY; NextX = PublicVARS.MainX + degree * Math.Cos(_DIRECT); NextY = PublicVARS.MainY - degree * Math.Sin(_DIRECT); ESRI.ArcGIS.Client.Geometry.PointCollection points = new ESRI.ArcGIS.Client.Geometry.PointCollection(); points.Add(new MapPoint(PublicVARS.MainX, PublicVARS.MainY)); points.Add(new MapPoint(NextX, NextY)); PL.Paths.Add(points); // 制作一个条状的缓冲区 Geometry g = PL; // 用一个团圆区做搜索视频范围 QWB.SetBuffGeom(g); GlobalLayers._MainMap.Dispatcher.Invoke( // 此结构是WIN GUI 处理多线程修改界面元素的保护 new Action( delegate { GlobalLayers.DynamicGraphicLayer.ClearGraphics(); Graphic Car = new Graphic(); Car.Geometry = new MapPoint(PublicVARS.MainX, PublicVARS.MainY); Car.Symbol = App.Current.Resources["CrimePointSymbol"] as Symbol; GlobalLayers.DynamicGraphicLayer.Graphics.Add(Car); // GlobalLayers._gqyvideocontrol.OpenCARVID(true, Car.Geometry as MapPoint); GlobalLayers._gqyvideocontrol.OpenVID(PublicVARS.MainVID, Car.Geometry as MapPoint); } )); QWB.ProcessBuffer(); } catch (Exception e) { MessageBox.Show(e.ToString()); } } }
public static Graphic ToGraphic(this string wkt, SpatialReference sourceSpatialReference = null, SpatialReference targetSpatialReference = null) { if (string.IsNullOrWhiteSpace(wkt) || !wkt.StartsWith("POLYGON ((")) return null; const string coordinatePrefix = "POLYGON (("; const string coordinateSuffix = "))"; if (sourceSpatialReference == null) { sourceSpatialReference = new SpatialReference(4326); } if (targetSpatialReference == null) { targetSpatialReference = new SpatialReference(4326); } var src = ProjectionInfo.FromEpsgCode(sourceSpatialReference.WKID); var dest = ProjectionInfo.FromEpsgCode(targetSpatialReference.WKID); var sr = targetSpatialReference; var strCoordinates = wkt.Substring(coordinatePrefix.Length, wkt.Length - coordinateSuffix.Length - coordinatePrefix.Length); var coordinatePairs = strCoordinates.Split(','); var coordinates = coordinatePairs.Select(pair => { var coordinate = pair.Split(' '); if (coordinate.Length != 2) throw new ArgumentException(string.Format("Cannot parse coordinate from WKT: {0}", pair)); return new {X = float.Parse(coordinate[0], CultureInfo.InvariantCulture), Y = float.Parse(coordinate[1], CultureInfo.InvariantCulture)}; // return new {X = float.Parse(coordinate[0], CultureInfo.InvariantCulture) + 155000, Y = float.Parse(coordinate[1], CultureInfo.InvariantCulture)+463000}; }); var polygon = new Polygon(); polygon.SpatialReference = sr; if (src == dest) { var pointCollection = new PointCollection(coordinates.Select(c => new MapPoint(c.X, c.Y))); polygon.Rings.Add(pointCollection); } else { var points = coordinates.SelectMany(c => new double[2] {c.X, c.Y}).ToArray(); Reproject.ReprojectPoints(points, null, src, dest, 0, points.Length / 2); var pointCollection = new PointCollection(Enumerable.Range(0, points.Length / 2).Select(i => new MapPoint(points[i * 2], points[(i * 2) + 1], sr))); polygon.Rings.Add(pointCollection); } var graphic = new Graphic(); graphic.Geometry = polygon; graphic.Symbol = new SimpleFillSymbol { BorderBrush = new SolidColorBrush(Colors.Black), BorderThickness = 4, Fill = new SolidColorBrush(Colors.Blue) { Opacity = 0.8f } }; return graphic; }
private void AddLineGraphics() { string geoRSSLine = @"<?xml version='1.0' encoding='utf-8'?> <feed xmlns='http://www.w3.org/2005/Atom' xmlns:georss='http://www.georss.org/georss'> <georss:line>-118.169, 34.016, -104.941, 39.7072, -96.724, 32.732</georss:line> <georss:line>-28.69, 14.16, -14.91, 23.702, -1.74, 13.72</georss:line> </feed>"; List<ESRI.ArcGIS.Client.Geometry.Polyline> polylineList = new List<ESRI.ArcGIS.Client.Geometry.Polyline>(); using (System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(new System.IO.StringReader(geoRSSLine))) { while (xmlReader.Read()) { switch (xmlReader.NodeType) { case System.Xml.XmlNodeType.Element: string nodeName = xmlReader.Name; if (nodeName == "georss:line") { string lineString = xmlReader.ReadElementContentAsString(); string[] lineCoords = lineString.Split(','); ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(); for (int i = 0; i < lineCoords.Length; i += 2) { MapPoint mp = new MapPoint(Convert.ToDouble(lineCoords[i]), Convert.ToDouble(lineCoords[i + 1])); MapPoint conv_mp = wm.FromGeographic(mp) as MapPoint; pointCollection.Add(conv_mp); } ESRI.ArcGIS.Client.Geometry.Polyline polyline = new ESRI.ArcGIS.Client.Geometry.Polyline(); polyline.Paths.Add(pointCollection); polylineList.Add(polyline); } break; } } } GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; foreach (ESRI.ArcGIS.Client.Geometry.Polyline polyline in polylineList) { Graphic graphic = new Graphic() { Symbol = DefaultLineSymbol, Geometry = polyline }; graphicsLayer.Graphics.Add(graphic); } }
private void AddLineGraphics() { string geoRSSLine = @"<?xml version='1.0' encoding='utf-8'?> <feed xmlns='http://www.w3.org/2005/Atom' xmlns:georss='http://www.georss.org/georss'> <georss:line>-118.169, 34.016, -104.941, 39.7072, -96.724, 32.732</georss:line> <georss:line>-28.69, 14.16, -14.91, 23.702, -1.74, 13.72</georss:line> </feed>"; List <ESRI.ArcGIS.Client.Geometry.Polyline> polylineList = new List <ESRI.ArcGIS.Client.Geometry.Polyline>(); using (System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(new System.IO.StringReader(geoRSSLine))) { while (xmlReader.Read()) { switch (xmlReader.NodeType) { case System.Xml.XmlNodeType.Element: string nodeName = xmlReader.Name; if (nodeName == "georss:line") { string lineString = xmlReader.ReadElementContentAsString(); string[] lineCoords = lineString.Split(','); ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(); for (int i = 0; i < lineCoords.Length; i += 2) { MapPoint mp = new MapPoint(Convert.ToDouble(lineCoords[i]), Convert.ToDouble(lineCoords[i + 1])); MapPoint conv_mp = wm.FromGeographic(mp) as MapPoint; pointCollection.Add(conv_mp); } ESRI.ArcGIS.Client.Geometry.Polyline polyline = new ESRI.ArcGIS.Client.Geometry.Polyline(); polyline.Paths.Add(pointCollection); polylineList.Add(polyline); } break; } } } GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; foreach (ESRI.ArcGIS.Client.Geometry.Polyline polyline in polylineList) { Graphic graphic = new Graphic() { Symbol = DefaultLineSymbol, Geometry = polyline }; graphicsLayer.Graphics.Add(graphic); } }
public void ResetValues() { _isMeasuring = false; originPoint = null; endPoint = null; lineCount = 0; _points = new ESRI.ArcGIS.Client.Geometry.PointCollection(); _lengths = new List <double>(); totalLength = 0; _tempTotalLength = 0; _segmentLength = 0; }
/// <summary> /// Create true line geometry. /// </summary> /// <param name="route">Route.</param> /// <returns>True polyline route geometry.</returns> private ArcGISGeometry.Polyline _CreateTruePolyline(Route route) { // Create follow street route. ArcGISGeometry.PointCollection pointCollection = new ArcGISGeometry.PointCollection(); IList <Stop> routeStops = CommonHelpers.GetSortedStops(route); int startIndex = _GetStartIndex(routeStops); int processCount = _GetProcessStopCount(routeStops); // add path to stop to drawing bool isStartFound = false; for (int stopIndex = startIndex; stopIndex < processCount; ++stopIndex) { Stop stop = routeStops[stopIndex]; // not show path to first stop if (isStartFound && stop.Path != null && !stop.Path.IsEmpty) { for (int index = 0; index < stop.Path.Groups.Length; ++index) { ArcLogisticsGeometry.Point[] points = stop.Path.GetGroupPoints(index); foreach (ArcLogisticsGeometry.Point point in points) { pointCollection.Add(_CreateProjectedMapPoint(point)); } } } if (!isStartFound) { isStartFound = (stop.StopType != StopType.Lunch); } } ArcGISGeometry.Polyline routeLine; if (pointCollection.Count > 0) { routeLine = new ArcGISGeometry.Polyline(); routeLine.Paths.Add(pointCollection); } else { routeLine = _CreateStraightPolyline(route); } return(routeLine); }
/// 此方法为ArcGIS for silverlight 中根据已知点生成圆状polygon(实为点集) /// /// 360度画圆 /// /// 半径Wgs-84坐标系下1度约等于 111194.872221777米 /// 中心点即为需要生成圆的基本点 /// 返回Graphic public static Geometry GetEllipseGraphic(double radius, MapPoint centerP) { ESRI.ArcGIS.Client.Geometry.PointCollection pCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(); for (double i = 0; i <= 360; i += 1) { pCollection.Add(new MapPoint((centerP.X - Math.Cos(Math.PI * i / 180.0) * radius), (centerP.Y - Math.Sin(Math.PI * i / 180.0) * radius))); } ESRI.ArcGIS.Client.Geometry.Polygon g = new ESRI.ArcGIS.Client.Geometry.Polygon(); g.Rings.Add(pCollection); return(g); // result.Symbol = this.LayoutRoot.Resources["DefaulFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;//这里根据自己的需要定义样式 }
public static ESRI.ArcGIS.Client.Geometry.Polygon ConvertPBSPolygonToEsriPolygon(PBS.Util.Polygon pPolygon) { ESRI.ArcGIS.Client.Geometry.Polygon ePolygon = new ESRI.ArcGIS.Client.Geometry.Polygon(); foreach (PBS.Util.PointCollection pPC in pPolygon.Rings) { ESRI.ArcGIS.Client.Geometry.PointCollection ePC = new ESRI.ArcGIS.Client.Geometry.PointCollection(); foreach (PBS.Util.Point pPoint in pPC) { ePC.Add(new MapPoint(pPoint.X, pPoint.Y)); } ePolygon.Rings.Add(ePC); } return(ePolygon); }
public void ShowImage(Stream fs) { if (fs.Length == 0) { return; } var selectedSensorImageRecord = coastalWatch.SelectedSensorImageRecord; var selectedLayer = Map.Layers[selectedSensorImageRecord.SensorName] as GraphicsLayer; coastalWatch.SelectedLayer = selectedLayer; if (!coastalWatch.KeepSeries) { selectedLayer.Graphics.Clear(); } var source = new BitmapImage(); source.SetSource(fs); ESRI.ArcGIS.Client.Geometry.PointCollection pc = new ESRI.ArcGIS.Client.Geometry.PointCollection(); MapPoint pt = new MapPoint(selectedSensorImageRecord.BBox[0], selectedSensorImageRecord.BBox[3]); pc.Add(pt); pt = new MapPoint(selectedSensorImageRecord.BBox[1], selectedSensorImageRecord.BBox[3]); pc.Add(pt); pt = new MapPoint(selectedSensorImageRecord.BBox[1], selectedSensorImageRecord.BBox[2]); pc.Add(pt); pt = new MapPoint(selectedSensorImageRecord.BBox[0], selectedSensorImageRecord.BBox[2]); pc.Add(pt); pt = new MapPoint(selectedSensorImageRecord.BBox[0], selectedSensorImageRecord.BBox[3]); pc.Add(pt); PictureFillSymbol symbl = new PictureFillSymbol() { Source = source, BorderThickness = 0 }; Graphic graphic = new Graphic(); ESRI.ArcGIS.Client.Geometry.Polygon ep = new Polygon(); ep.Rings.Add(pc); graphic.Geometry = ep; graphic.Symbol = symbl; graphic.Geometry.SpatialReference = new SpatialReference(4326); selectedLayer.Graphics.Add(graphic); selectedLayer.Refresh(); }
private void CreateRing() { this.Rings.Clear(); if (!double.IsNaN(Radius) && Radius > 0 && Center != null && PointCount > 2) { ESRI.ArcGIS.Client.Geometry.PointCollection pnts = new ESRI.ArcGIS.Client.Geometry.PointCollection(); for (int i = 0; i <= PointCount; i++) { double rad = 2 * Math.PI / PointCount * i; double x = Math.Cos(rad) * radius + Center.X; double y = Math.Sin(rad) * radius + Center.Y; pnts.Add(new MapPoint(x, y)); } this.Rings.Add(pnts); } }
/// <summary> /// Add leader lines to expanded cluster elements /// </summary> private void _CreateLeaderLines() { List <Graphic> _leaderLines = new List <Graphic>(); foreach (DataGraphicObject dataGraphic in _clusteringLayer.MapLayer.Graphics) { // TODO: remove hardcode LineSymbol simpleLineSymbol = new LineSymbol() { Color = (SolidColorBrush)App.Current.FindResource("ClusteringLineBrush"), Width = 2 }; ESRI.ArcGIS.Client.Geometry.PointCollection points = new ESRI.ArcGIS.Client.Geometry.PointCollection(); MapPoint graphicPosition = dataGraphic.Geometry as MapPoint; MapPoint startPoint = (MapPoint)_expandedClusterGraphic.Geometry; System.Windows.Point point = _mapctrl.map.MapToScreen(startPoint); MarkerSymbol symbol = dataGraphic.Symbol as MarkerSymbol; point.X -= symbol.OffsetX; point.Y -= symbol.OffsetY; MapPoint endPoint = _mapctrl.map.ScreenToMap(point); endPoint.X -= startPoint.X - graphicPosition.X; endPoint.Y -= startPoint.Y - graphicPosition.Y; points.Add(startPoint); points.Add(endPoint); Polyline lineGeometry = new Polyline(); lineGeometry.Paths.Add(points); Graphic lineGraphic = new Graphic() { Symbol = simpleLineSymbol, Geometry = lineGeometry }; _leaderLines.Add(lineGraphic); } foreach (Graphic graphic in _leaderLines) { _leaderLinesLayer.Graphics.Add(graphic); } }
private static void OnMapPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { GeodeticDistance gd = d as GeodeticDistance; Map oldMap = e.OldValue as Map; bool isActive = gd.IsActivated; if (isActive) { gd.IsActivated = false; } if (oldMap != null) { gd.layer.ClearGraphics(); } Map map = e.NewValue as Map; if (map != null) { //Create graphics layer and populate with the needed necessary graphics gd.layer = new GraphicsLayer(); gd.layer.Graphics.Add(gd.radiusFill); gd.layer.Graphics.Add(gd.greatCircleLine); gd.layer.Graphics.Add(gd.radiusLine); Polyline line = new Polyline(); ESRI.ArcGIS.Client.Geometry.PointCollection pnts = new ESRI.ArcGIS.Client.Geometry.PointCollection(); pnts.Add(new MapPoint()); pnts.Add(new MapPoint()); line.Paths.Add(pnts); gd.straightLine.Geometry = line; gd.layer.Graphics.Add(gd.straightLine); gd.layer.Graphics.Add(gd.midMarker); gd.textPoint = new Graphic() { Symbol = gd.textSymb }; gd.textPoint.SetZIndex(2); gd.layer.Graphics.Add(gd.textPoint); } gd.IsActivated = isActive; }
public static IObservable<ESRI.ArcGIS.Client.Geometry.PointCollection> DrawPoints(this Map map) { ESRI.ArcGIS.Client.Geometry.PointCollection pc = new ESRI.ArcGIS.Client.Geometry.PointCollection(); Subject<ESRI.ArcGIS.Client.Geometry.PointCollection> obvle = new Subject<ESRI.ArcGIS.Client.Geometry.PointCollection>(); map.GetClick() .Select(item => map.ScreenToMap(item.EventArgs.GetPosition(map))) .Subscribe(next => pc.Add(next)); map.GetDoubleClick() .Subscribe(next => { obvle.OnNext(pc); pc = new ESRI.ArcGIS.Client.Geometry.PointCollection(); }); return obvle; }
private void MyDrawObject_DrawComplete(object sender, DrawEventArgs args) { //ESRI.ArcGIS.Client.Geometry.Polyline polyline = args.Geometry as ESRI.ArcGIS.Client.Geometry.Polyline; args.Geometry.SpatialReference = MyMap.SpatialReference; Graphic graphic = new Graphic() { Geometry = args.Geometry }; graphic.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol; graphicsLayer.Graphics.Add(graphic); if (graphicsLayer.Graphics.Count == 2) { MyDrawObject.IsEnabled = false; GeometryService geometryService = new GeometryService("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"); geometryService.DistanceCompleted += GeometryService_DistanceCompleted; geometryService.Failed += GeometryService_Failed; DistanceParameters distanceParameters = new DistanceParameters() { DistanceUnit = LinearUnit.SurveyMile, Geodesic = true }; geometryService.DistanceAsync(graphicsLayer.Graphics[0].Geometry, graphicsLayer.Graphics[1].Geometry, distanceParameters); ResponseTextBlock.Text = "The distance between the points is... "; ESRI.ArcGIS.Client.Geometry.PointCollection points = new ESRI.ArcGIS.Client.Geometry.PointCollection(); points.Add(graphicsLayer.Graphics[0].Geometry as MapPoint); points.Add(graphicsLayer.Graphics[1].Geometry as MapPoint); ESRI.ArcGIS.Client.Geometry.Polyline polyline = new ESRI.ArcGIS.Client.Geometry.Polyline(); polyline.Paths.Add(points); Graphic linegraphic = new Graphic() { Geometry = polyline, Symbol = LayoutRoot.Resources["DefaultLineSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol }; lineLayer.Graphics.Add(linegraphic); } MyDrawObject.IsEnabled = true; }
private void UpdateCircle(string label, double radius, double startAngle, double endAngle) { var inLat = Poi.Position.Latitude; var inLon = Poi.Position.Longitude; var coordinates = new PointCollection(); for (var i = startAngle; i <= endAngle; i += 5) { double lat, lon; CoordinateUtils.CalculatePointSphere2D(inLat, inLon, radius, i, out lat, out lon); coordinates.Add((MapPoint)webMercator.FromGeographic(new MapPoint(lon, lat))); } if (endAngle - startAngle < 360) coordinates.Add((MapPoint)webMercator.FromGeographic(new MapPoint(inLon, inLat))); // Not a full circle, so add center too. coordinates.Add(coordinates[0]); // Add first point to close the circle Execute.OnUIThread(() => { var circle = GetImpactCircle(); if (circle == null) { var polygon = new Polygon(); polygon.Rings.Add(coordinates); var g = new Graphic { Symbol = new SimpleFillSymbol { BorderBrush = Brushes.Transparent, BorderThickness = 1, Fill = radialGradientBrush }, Geometry = polygon }; g.Attributes["ID"] = label; g.Attributes["UserId"] = Poi.Id.ToString(); // To distinguish it from other models CircleLayer.Graphics.Add(g); } else { var polygon = new Polygon(); polygon.Rings.Add(coordinates); circle.Geometry = polygon; CircleLayer.Refresh(); } }); }
private double GetArea(ESRI.ArcGIS.Client.Geometry.PointCollection points) { double tempArea = 0; double xDiff, yDiff, x1, x2, y1, y2; for (int i = 0; i < points.Count - 1; i++) { x1 = points[i].X; x2 = points[i + 1].X; y1 = points[i].Y; y2 = points[i + 1].Y; xDiff = x2 - x1; yDiff = y2 - y1; //tempArea += x1 * yDiff - y1 * xDiff; tempArea += (x1 + x2) * (y1 - y2); } return(Math.Abs(tempArea) / 2); }
public static void AddDebugGraphic(Cell c, GraphicsLayer graphicsLayer) { return; // COMMENT OUT TO SHOW CELLS if (graphicsLayer == null) { return; } Graphic graphic = new Graphic(); ObservableCollection <ESRI.ArcGIS.Client.Geometry.PointCollection> rings = new ObservableCollection <ESRI.ArcGIS.Client.Geometry.PointCollection>(); ESRI.ArcGIS.Client.Geometry.PointCollection pointList = new ESRI.ArcGIS.Client.Geometry.PointCollection(); SpatialReference geoReference = new SpatialReference(4326); pointList.Add(new MapPoint(c.X - c.Half, c.Y - c.Half, geoReference)); pointList.Add(new MapPoint(c.X - c.Half, c.Y + c.Half, geoReference)); pointList.Add(new MapPoint(c.X + c.Half, c.Y + c.Half, geoReference)); pointList.Add(new MapPoint(c.X + c.Half, c.Y - c.Half, geoReference)); pointList.Add(new MapPoint(c.X - c.Half, c.Y - c.Half, geoReference)); rings.Add(new ESRI.ArcGIS.Client.Geometry.PointCollection(pointList)); Color color = Colors.Black; Brush fill = new SolidColorBrush(Colors.Transparent); ESRI.ArcGIS.Client.Symbols.SimpleFillSymbol symbol = new ESRI.ArcGIS.Client.Symbols.SimpleFillSymbol(); symbol.Fill = fill; symbol.BorderBrush = new SolidColorBrush(Colors.Black); symbol.BorderThickness = 1; graphic.Symbol = symbol; Polygon polygon = new Polygon(); polygon.SpatialReference = geoReference; polygon.Rings.Add(pointList); graphic.Geometry = polygon; graphicsLayer.Graphics.Add(graphic); }
private ESRI.ArcGIS.Client.Geometry.PointCollection ToKmMapPoint(ESRI.ArcGIS.Client.Geometry.PointCollection points) { ESRI.ArcGIS.Client.Geometry.PointCollection pts = new ESRI.ArcGIS.Client.Geometry.PointCollection(); MapPoint pt = points[0]; if (MapUnits == ScaleBarUnit.DecimalDegrees) { foreach (MapPoint point in points) { double x = Geodesic.GetSphericalDistance(point, new MapPoint(pt.X, point.Y)); double y = Geodesic.GetSphericalDistance(point, new MapPoint(point.X, pt.Y)); pts.Add(new MapPoint(x, y)); } return(pts); } else { return(points); } }
private void AddPolygonGraphics() { string coordinateString1 = "130,5.59 118.42,3.92 117.3,23.3 143.2,22.9 130,5.59"; GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; ESRI.ArcGIS.Client.Geometry.PointCollectionConverter pointConverter = new ESRI.ArcGIS.Client.Geometry.PointCollectionConverter(); ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection1 = pointConverter.ConvertFromString(coordinateString1) as ESRI.ArcGIS.Client.Geometry.PointCollection; ESRI.ArcGIS.Client.Geometry.Polygon polygon1 = new ESRI.ArcGIS.Client.Geometry.Polygon(); polygon1.Rings.Add(pointCollection1); Graphic graphic = new Graphic() { Geometry = mercator.FromGeographic(polygon1), Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as Symbol }; graphicsLayer.Graphics.Add(graphic); }
private ESRI.ArcGIS.Client.Geometry.Geometry _CreateFrameGeometry() { ESRI.ArcGIS.Client.Geometry.Geometry geometry = null; _end = new ESRI.ArcLogistics.Geometry.Point(_start.Value.X, _start.Value.Y); if (_start.HasValue && _end.HasValue) { ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(); pointCollection.Add(new MapPoint(_start.Value.X, _start.Value.Y)); pointCollection.Add(new MapPoint(_start.Value.X, _end.Value.Y)); pointCollection.Add(new MapPoint(_end.Value.X, _end.Value.Y)); pointCollection.Add(new MapPoint(_end.Value.X, _start.Value.Y)); pointCollection.Add(new MapPoint(_start.Value.X, _start.Value.Y)); ESRI.ArcGIS.Client.Geometry.Polygon polygon = new ESRI.ArcGIS.Client.Geometry.Polygon(); polygon.Rings.Add(pointCollection); geometry = (ESRI.ArcGIS.Client.Geometry.Geometry)polygon; } return(geometry); }
private void UpdateTrackPath() { var pointCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(); var rings = new ObservableCollection<ESRI.ArcGIS.Client.Geometry.PointCollection>(); foreach (var l in Poi.Sensors["[lat]"].Data) { if (Poi.Sensors["[lon]"].Data.ContainsKey(l.Key)) { var pos = new MapPoint(Poi.Sensors["[lon]"].Data[l.Key], Poi.Sensors["[lat]"].Data[l.Key]); pointCollection.Add((MapPoint)webMercator.FromGeographic(pos)); } } rings.Add(pointCollection); p.Paths = rings; Track.Geometry = p; //Track.Geometry = line; }
public static Cell GetCentroidCell(ObservableCollection <ESRI.ArcGIS.Client.Geometry.PointCollection> polygon) { double area = 0; double x = 0; double y = 0; ESRI.ArcGIS.Client.Geometry.PointCollection points = polygon[polygon.Count - 1]; int pointCount = 0; foreach (var ring in polygon) { if (ring.Count > pointCount) { pointCount = ring.Count; points = ring; } } int count = points.Count; int j = count - 1; for (int i = 0; i < count; j = i++) { MapPoint a = points[i]; MapPoint b = points[j]; double f = a.X * b.Y - b.X * a.Y; x += (a.X + b.X) * f; y += (a.Y + b.Y) * f; area += f * 3; } if (area == 0) { return(new Cell(points[0].X, points[0].Y, 0, polygon)); } return(new Cell(x / area, y / area, 0, polygon)); }
private void AddPolygonGraphics() { string coordinateString1 = "14819406,1294088 13066124,751406 13191358,2880391 15570812,2713412 14819406,1294088"; GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; PointCollectionConverter pointConverter = new PointCollectionConverter(); ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection1 = pointConverter.ConvertFromString(coordinateString1) as ESRI.ArcGIS.Client.Geometry.PointCollection; ESRI.ArcGIS.Client.Geometry.Polygon polygon1 = new ESRI.ArcGIS.Client.Geometry.Polygon(); polygon1.Rings.Add(pointCollection1); Graphic graphic = new Graphic() { Geometry = polygon1, Symbol = DefaultFillSymbol }; graphicsLayer.Graphics.Add(graphic); }
private void RedrawGrid() { if (cellSize == 0 || columns == 0 || rows == 0) return; var tlLat = Poi.Position.Latitude; var tlLon = Poi.Position.Longitude; var width = cellSize * columns; var height = cellSize * rows; double trLat, trLon; CoordinateUtils.CalculatePointSphere2D(tlLat, tlLon, width, 90, out trLat, out trLon); double blLat, blLon; CoordinateUtils.CalculatePointSphere2D(tlLat, tlLon, height, 180, out blLat, out blLon); // Convert to map points var p = new Point(tlLon, tlLat).ToMapPoint(); tlLon = p.X; tlLat = p.Y; p = new Point(trLon, trLat).ToMapPoint(); trLon = p.X; trLat = p.Y; p = new Point(blLon, blLat).ToMapPoint(); blLon = p.X; blLat = p.Y; var deltaLat = Math.Abs(tlLat - blLat) / rows; var deltaLon = Math.Abs(trLon - tlLon) / columns; var labels = new List<string>(); for (int i = 1; i <= rows; i++) labels.Add(i.ToString()); labels.Add(""); // Empty label for last row for (int i = 1; i <= columns; i++) labels.Add(ToExcelColumnName(i)); labels.Add(""); // Empty label for last column Execute.OnUIThread(() => { var pts = new List<PointCollection>(); PointCollection labelCoordinates = new PointCollection(); PointCollection lineCoordinates; double fromLat = tlLat, fromLon = tlLon, toLat = tlLat, toLon = trLon; for (int i = 0; i <= rows; i++) { lineCoordinates = new PointCollection(); lineCoordinates.Add(new MapPoint(tlLon, fromLat)); lineCoordinates.Add(new MapPoint(trLon, fromLat)); pts.Add(lineCoordinates); labelCoordinates.Add(new MapPoint(tlLon, fromLat)); fromLat -= deltaLat; } for (int i = 0; i <= columns; i++) { lineCoordinates = new PointCollection(); lineCoordinates.Add(new MapPoint(fromLon, tlLat)); lineCoordinates.Add(new MapPoint(fromLon, blLat)); pts.Add(lineCoordinates); labelCoordinates.Add(new MapPoint(fromLon, tlLat)); fromLon += deltaLon; } var symbol = new SimpleLineSymbol { Color = SelectedColorBrush, Width = StrokeWidth, Style = SimpleLineSymbol.LineStyle.Dot }; var poiId = Poi.Id.ToString(); var graphics = new List<Graphic>(); var j = 0; foreach (var c in pts) { var pl = new Polyline(); pl.Paths.Add(c); var g = new Graphic { Symbol = symbol, Geometry = pl }; g.Attributes["ID"] = poiId; g.Attributes["NAME"] = labels[j]; graphics.Add(g); // Add label, except A or 1, as this intersects with the icon. if (!(string.Equals(labels[j], "A", StringComparison.InvariantCultureIgnoreCase) || string.Equals(labels[j], "1", StringComparison.InvariantCultureIgnoreCase))) { var gt = new Graphic { Symbol = CreateTextSymbol(labels[j]), Geometry = labelCoordinates[j] }; gt.Attributes["ID"] = poiId; graphics.Add(gt); } j++; } ClearGraphics(); GridLayer.Graphics.AddRange(graphics); }); }
private void DrawLine(PointCollection coordinates) { var pl = new Polyline(); pl.Paths.Add(coordinates); if (HighContrast) { var g = new Graphic { Symbol = new SimpleLineSymbol { Color = Brushes.White, Width = TrackWidth + 4, Style = SimpleLineSymbol.LineStyle.Solid }, Geometry = pl }; g.Attributes["ID"] = Poi.Id.ToString(); GraphicsLayer.Graphics.Add(g); } var g2 = new Graphic { Symbol = new SimpleLineSymbol { Color = new SolidColorBrush(TrackColor), Width = TrackWidth, Style = SimpleLineSymbol.LineStyle.Solid }, Geometry = pl }; g2.Attributes["ID"] = Poi.Id.ToString(); GraphicsLayer.Graphics.Add(g2); }
private client.Graphic CreateFan(client.Graphic g) { try { SimpleFillSymbol _sym = new SimpleFillSymbol() { Fill = new SolidColorBrush(Color.FromArgb(100, (byte)255, (byte)190, (byte)232)), BorderBrush = new SolidColorBrush(Color.FromArgb(100, (byte)197, (byte)0, (byte)255)), BorderThickness = 1 }; client.Graphic pPolyGraphic = new client.Graphic(); if (Traversal < 360) { double initBearing = Bearing; initBearing = Geo2Arithmetic(Bearing); //Need to convert from geographic angles (zero north clockwise) to arithmetic (zero east counterclockwise) if (Traversal == 0) Traversal = 1; double leftAngle = initBearing - (Traversal / 2.0); double rightAngle = initBearing + (Traversal / 2.0); double centerpointX = g.Geometry.Extent.GetCenter().X; double centerpointY = g.Geometry.Extent.GetCenter().Y; ObservableCollection<ESRI.ArcGIS.Client.Geometry.PointCollection> pcol = new ObservableCollection<ESRI.ArcGIS.Client.Geometry.PointCollection>(); ESRI.ArcGIS.Client.Geometry.PointCollection ptCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(); ptCollection.Add(g.Geometry as MapPoint); for (int i = System.Convert.ToInt16(leftAngle); i < rightAngle; i++) { double x = centerpointX + (Range * Math.Cos(DegreeToRadian(i))); double y = centerpointY + (Range * Math.Sin(DegreeToRadian(i))); ESRI.ArcGIS.Client.Geometry.MapPoint mPt = new MapPoint(x, y); ptCollection.Add(mPt); } ptCollection.Add(g.Geometry as MapPoint); ESRI.ArcGIS.Client.Geometry.Polygon pPoly = new ESRI.ArcGIS.Client.Geometry.Polygon(); pcol.Add(ptCollection); pPoly.Rings = pcol; pPolyGraphic.Geometry = pPoly; pPolyGraphic.Symbol = _sym; pPolyGraphic.Attributes.Add("Name", g.Attributes[_datasource.ObjectIdFieldName].ToString()); System.Diagnostics.Debug.WriteLine(g.Attributes[_datasource.ObjectIdFieldName].ToString()); } else { Circle pCircle = new Circle(); ESRI.ArcGIS.Client.Geometry.MapPoint mPt = new MapPoint(g.Geometry.Extent.GetCenter().X, g.Geometry.Extent.GetCenter().Y); pCircle.Center = mPt; pCircle.Radius = Range; pPolyGraphic.Symbol = _sym; pPolyGraphic.Geometry = pCircle; pPolyGraphic.Attributes.Add("Name", g.Attributes[_datasource.ObjectIdFieldName].ToString()); } return pPolyGraphic; } catch { return null; } }
/// <summary> /// Convert a polyline to a graphic. /// NOTE Although we could have used a Polyline to create the graphic, it would mean that we cannot specify the fill color, /// which is why I've chosen to convert it to a Polygon. /// </summary> /// <param name="ls"></param> /// <param name="g"></param> private void ConvertPolylineToGraphic(LineString ls, PoiGraphic g) { var polygon = new Polygon(); var pc = new PointCollection(); foreach (var point in ls.Line) { pc.Add(mercator.FromGeographic(new MapPoint(point.X, point.Y)) as MapPoint); } //if (pc.First().X != pc.Last().X || pc.First().Y != pc.Last().Y) // pc.Add(pc.First()); polygon.Rings.Add(pc); g.SetGeometry(polygon); }
/// <summary> /// Create graphics when base is web mercator /// </summary> /// <param name="rssGraphics"></param> private void AddWebMercatorGraphics(List<RssGraphic> rssGraphics) { int counter = 0; foreach (RssGraphic rssGraphic in rssGraphics) { Graphic graphic = new Graphic(); //mouse events graphic.MouseEnter += graphic_MouseEnter; graphic.MouseLeave += graphic_MouseLeave; //title graphic.Attributes.Add("Title", rssGraphic.title); //abstract string result = (Regex.Replace(rssGraphic.Description, @"<(.|\n)*?>", string.Empty)).TrimStart(new char[] { '\n' }); int loc = result.IndexOf("\n"); string abstactString = result.Substring(0, loc); if (abstactString.ToLower() == "null") { abstactString = "No description available"; } graphic.Attributes.Add("Abstract", abstactString); //magic for links happens here List<GeoLinks> links = ParseDescription(rssGraphic.Description); //links List<string> currentLinks = new List<string>(); foreach (GeoLinks link in links) { graphic.Attributes.Add(link.Title, link.Url); graphic.Attributes.Add(link.Title + "Visible", true); currentLinks.Add(link.Title); if (link.AddToMapInfo != null) { graphic.Attributes.Add("Add", link.AddToMapInfo); graphic.Attributes.Add("AddVisible", true); currentLinks.Add("Add"); } } //geometry string[] sPoints = rssGraphic.StringPolygon.Split(' '); if (counter == 6) { string aaaaa = string.Empty; } ESRI.ArcGIS.Client.Geometry.PointCollection pColl = new ESRI.ArcGIS.Client.Geometry.PointCollection(); for (int i = 0; i < sPoints.Length; i++) { MapPoint mp = new MapPoint(); double x = WebMercator.ToWebMercatorX(Convert.ToDouble(sPoints[i + 1])); double y = WebMercator.ToWebMercatorY(Convert.ToDouble(sPoints[i])); if (Double.IsNegativeInfinity(y)) y = -20000000; if (Double.IsPositiveInfinity(y)) y = 20000000; if (!IsExtremeNumber(x) && !IsExtremeNumber(y)) { mp.X = x; mp.Y = y; pColl.Add(mp); } i++; } if (pColl.Count > 0) { ESRI.ArcGIS.Client.Geometry.Polygon poly = new ESRI.ArcGIS.Client.Geometry.Polygon(); poly.Rings.Add(pColl); graphic.Geometry = poly; System.Diagnostics.Debug.WriteLine("poly: xmax: " + poly.Extent.XMax + " xmin: " + poly.Extent.XMin + " ymax: " + poly.Extent.YMax + " ymin: " + poly.Extent.YMin); _graphicsLyr.Graphics.Add(graphic); //result grid string sCleanLink = FindServiceLink(rssGraphic.Description); string sID = rssGraphic.title; sCleanLink = sCleanLink + "," + sID; _queryResultData.Add(new QueryResultData() { Title = rssGraphic.title, Description = rssGraphic.Description, IsEnable = true, graphic = graphic, sLink = sCleanLink, ID = sID }); } counter++; } UpdateUIAfterSearch(counter); }
/// <summary> /// Add leader lines to expanded cluster elements /// </summary> private void _CreateLeaderLines() { List<Graphic> _leaderLines = new List<Graphic>(); foreach (DataGraphicObject dataGraphic in _clusteringLayer.MapLayer.Graphics) { // TODO: remove hardcode LineSymbol simpleLineSymbol = new LineSymbol() { Color = (SolidColorBrush)App.Current.FindResource("ClusteringLineBrush"), Width = 2 }; ESRI.ArcGIS.Client.Geometry.PointCollection points = new ESRI.ArcGIS.Client.Geometry.PointCollection(); MapPoint graphicPosition = dataGraphic.Geometry as MapPoint; MapPoint startPoint = (MapPoint)_expandedClusterGraphic.Geometry; System.Windows.Point point = _mapctrl.map.MapToScreen(startPoint); MarkerSymbol symbol = dataGraphic.Symbol as MarkerSymbol; point.X -= symbol.OffsetX; point.Y -= symbol.OffsetY; MapPoint endPoint = _mapctrl.map.ScreenToMap(point); endPoint.X -= startPoint.X - graphicPosition.X; endPoint.Y -= startPoint.Y - graphicPosition.Y; points.Add(startPoint); points.Add(endPoint); Polyline lineGeometry = new Polyline(); lineGeometry.Paths.Add(points); Graphic lineGraphic = new Graphic() { Symbol = simpleLineSymbol, Geometry = lineGeometry }; _leaderLines.Add(lineGraphic); } foreach (Graphic graphic in _leaderLines) _leaderLinesLayer.Graphics.Add(graphic); }
private void UpdateLine() { var pl = new Polyline { Paths = new ObservableCollection<PointCollection>() }; var pc = new PointCollection { StartPoint.Mp, FinishPoint.Mp }; pl.Paths.Add(pc); Line.Geometry = pl; }
private void ConvertPolygonToGraphic(csCommon.Types.Geometries.Polygon p, PoiGraphic g) { var polygon = new Polygon(); foreach (var ls in p.LineStrings) { var pc = new PointCollection(); foreach (var point in ls.Line) { pc.Add(mercator.FromGeographic(new MapPoint(point.X, point.Y)) as MapPoint); } if (pc.First().X != pc.Last().X || pc.First().Y != pc.Last().Y) pc.Add(pc.First()); polygon.Rings.Add(pc); } g.SetGeometry(polygon); }
private void UpdateCircle(double radius) { var inLat = Poi.Position.Latitude; var inLon = Poi.Position.Longitude; var coordinates = new PointCollection(); for (var i = 0; i < 360; i += 10) { double lat; double lon; CoordinateUtils.CalculatePointSphere2D(inLat, inLon, radius, i, out lat, out lon); coordinates.Add((MapPoint)webMercator.FromGeographic(new MapPoint(lon, lat))); } Execute.OnUIThread(() => { coordinates.Add(coordinates[0]); // Add first Point to close the circle var circle = GetCircle(); if (circle == null) { var g = new Graphic(); g.Attributes["ID"] = Poi.Id.ToString(); switch (symbolStyle) { case SymbolStyle.Line: var pl = new Polyline(); pl.Paths.Add(coordinates); g.Symbol = new SimpleLineSymbol { Color = strokeBrush, Width = 3, Style = SimpleLineSymbol.LineStyle.Solid }; g.Geometry = pl; break; case SymbolStyle.Polygon: var polygon = new Polygon(); polygon.Rings.Add(coordinates); var color = new Color {A = 0x30, R = strokeBrush.Color.R, G = strokeBrush.Color.G, B = strokeBrush.Color.B}; var brush = new SolidColorBrush(color); g.Symbol = new SimpleFillSymbol { BorderBrush = strokeBrush, BorderThickness = 3, Fill = brush }; g.Geometry = polygon; break; } QueryLayer.Graphics.Add(g); } else { switch (symbolStyle) { case SymbolStyle.Line: var polyline = new Polyline(); polyline.Paths.Add(coordinates); circle.Geometry = polyline; var simpleLineSymbol = circle.Symbol as SimpleLineSymbol; if (simpleLineSymbol != null) simpleLineSymbol.Color = strokeBrush; break; case SymbolStyle.Polygon: var polygon = new Polygon(); polygon.Rings.Add(coordinates); circle.Geometry = polygon; var fillSymbol = circle.Symbol as SimpleFillSymbol; if (fillSymbol != null) { var color = new Color { A = 0x30, R = strokeBrush.Color.R, G = strokeBrush.Color.G, B = strokeBrush.Color.B }; var brush = new SolidColorBrush(color); fillSymbol.BorderBrush = strokeBrush; fillSymbol.Fill = brush; } break; } QueryLayer.Refresh(); } }); }
private ESRI.ArcGIS.Client.Geometry.Geometry _CreateFrameGeometry() { ESRI.ArcGIS.Client.Geometry.Geometry geometry = null; _end = new ESRI.ArcLogistics.Geometry.Point(_start.Value.X, _start.Value.Y); if (_start.HasValue && _end.HasValue) { ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(); pointCollection.Add(new MapPoint(_start.Value.X, _start.Value.Y)); pointCollection.Add(new MapPoint(_start.Value.X, _end.Value.Y)); pointCollection.Add(new MapPoint(_end.Value.X, _end.Value.Y)); pointCollection.Add(new MapPoint(_end.Value.X, _start.Value.Y)); pointCollection.Add(new MapPoint(_start.Value.X, _start.Value.Y)); ESRI.ArcGIS.Client.Geometry.Polygon polygon = new ESRI.ArcGIS.Client.Geometry.Polygon(); polygon.Rings.Add(pointCollection); geometry = (ESRI.ArcGIS.Client.Geometry.Geometry)polygon; } return geometry; }
/// <summary> /// Initializes a <see cref="Map"/> object based on a web map /// </summary> /// <param name="map">The map to initialize</param> /// <param name="e">The <see cref="GetMapCompletedEventArgs"/> object containing the web map's information. /// This is the event args type returned to the <see cref="Document.GetMapCompleted"/> event.</param> public static void InitializeFromWebMap(this Map map, GetMapCompletedEventArgs e, EventHandler<EventArgs> onLayerInitFailed = null) { map.Layers.Clear(); if (e.Map.Extent != null && e.Map.Extent.SpatialReference != null && e.Map.Extent.SpatialReference.IsWebMercator() && double.IsNegativeInfinity(e.Map.Extent.YMin) && double.IsPositiveInfinity(e.Map.Extent.YMax)) { e.Map.Extent.YMin = double.NaN; e.Map.Extent.YMax = double.NaN; } map.Extent = e.Map.Extent; List<Layer> layers = new List<Layer>(); List<Layer> basemapLayers = new List<Layer>(); IEnumerable<Layer> allLayers = e.Map.Layers.FlattenLayers(); List<string> featureCollectionLayerNames = new List<string>(); // Create collection of layers to add to the map based on the layers in the web map foreach (Layer layer in allLayers) { // Set ShowLegend to true for each layer. The framework handles layer visibility // in MapContents otherwise. layer.ShowLegend = true; if (layer is ESRI.ArcGIS.Client.Bing.TileLayer) ESRI.ArcGIS.Mapping.Core.LayerExtensions.SetUsesBingAppID((ESRI.ArcGIS.Client.Bing.TileLayer) layer, true); layer.ProcessWebMapProperties(e.DocumentValues); // Check whether any layers flagged for adding to the map have the same ID as the current one. Layers // with the same ID represent feature collections that show up as part of the same layer in the online // viewers, but are actually serialized as separate layers. if (!(layer is GraphicsLayer) || !layers.Any(l => l.ID == layer.ID || l.DisplayName == layer.DisplayName || featureCollectionLayerNames.Contains(layer.DisplayName))) { if ((bool)(layer.GetValue(ESRI.ArcGIS.Client.WebMap.Document.IsBaseMapProperty))) basemapLayers.Add(layer); layers.Add(layer); } else // Layer belongs to a multi-layer feature collection. Combine with layer already included in the list. { GraphicsLayer currentLayer = layers.First(l => l.ID == layer.ID || l.DisplayName == layer.DisplayName || featureCollectionLayerNames.Contains(layer.DisplayName)) as GraphicsLayer; GraphicsLayer newLayer = layer as GraphicsLayer; if (newLayer != null && newLayer.Graphics.Count > 0) { if (currentLayer != null && LayerExtensions.GetGeometryType(currentLayer) == LayerExtensions.GetGeometryType(newLayer)) { // Layers have the same geometry type - just copy the features from one to the other newLayer.Graphics.MoveTo(currentLayer.Graphics); } else if (currentLayer != null && currentLayer.Graphics.Count == 0) { // Geometry types don't match, but the layer already added to the list doesn't have any // features graphics. Override the renderer from the added layer with that from the current // one and copy over the features in the currently layer. currentLayer.Renderer = newLayer.Renderer; newLayer.Graphics.MoveTo(currentLayer.Graphics); } else { // Geometry types don't match, but both layers have features. We don't want to put the // features in the same layer because that eliminates the ability to configure the layer's // renderer. So create separate layers. // The layers will have the same name by default. To avoid having multiple layers with the // same name, append a suffix that indicates the geometry type, i.e. points, lines, or areas. if (currentLayer != null) { currentLayer.AppendGeometryToLayerName(); featureCollectionLayerNames.Add(layer.DisplayName); } newLayer.AppendGeometryToLayerName(); // The layers will have the same ID by default, which can cause unexpected behavior. // So give one of them a new ID. newLayer.ID = Guid.NewGuid().ToString("N"); layers.Add(newLayer); // Look in the web map's layers for other layers that have the same geometry type as the new // layer. Since the new layer has a new ID, and the logic here relies on ID to determine // whether to merge with another layer, we need to update the IDs of the layers yet to be // processed to match the new ID. IEnumerable<Layer> others = allLayers.Where( l => (l.ID == layer.ID) && LayerExtensions.GetGeometryType((GraphicsLayer)l) == LayerExtensions.GetGeometryType((GraphicsLayer)layer)); foreach (GraphicsLayer gLayer in others) gLayer.ID = newLayer.ID; } } } } #region Get Basemap Title if (basemapLayers.Count > 0 && e.DocumentValues.ContainsKey("baseMap")) { IDictionary<string, object> dict = e.DocumentValues["baseMap"] as IDictionary<string, object>; if (dict != null) { string baseMapTitle = "Basemap"; if (dict.ContainsKey("title")) { baseMapTitle = dict["title"] as string; if (!string.IsNullOrWhiteSpace(baseMapTitle)) LayerExtensions.SetLayerName(basemapLayers[0], baseMapTitle); } //Mark reference layers if (basemapLayers.Count > 1) { for (int i = 1; i < basemapLayers.Count; i++) { LayerExtensions.SetIsReferenceLayer(basemapLayers[i], true); //Do not show in map contents ESRI.ArcGIS.Client.Extensibility.LayerProperties.SetIsVisibleInMapContents(basemapLayers[i], false); } } } } #endregion e.Map.Layers.Clear(); foreach (Layer layer in layers) { if (onLayerInitFailed != null) layer.InitializationFailed += onLayerInitFailed; map.Layers.Add(layer); } #region Get map items and add any notes if (e.DocumentValues != null) { foreach (KeyValuePair<string, object> pair in e.DocumentValues) { if (pair.Key == "MapItems") { List<GraphicsLayer> noteLayers = new List<GraphicsLayer>(); #region Get note layers List<object> items = pair.Value as List<object>; if (items == null) continue; foreach (var item in items) { IDictionary<string, object> dict = item as IDictionary<string, object>; if (dict != null) { #region If note, add to notelayers if (dict.ContainsKey("__type") && dict["__type"].ToString() == "Note:#ESRI.ArcGIS.Mapping.Controls.ArcGISOnline") { if (dict.ContainsKey("Geometry") && dict.ContainsKey("Name")) { string name = dict["Name"] as string; IDictionary<string, object> gDict = dict["Geometry"] as IDictionary<string, object>; if (gDict == null) continue; ESRI.ArcGIS.Client.Geometry.Geometry geometry = null; if (gDict.ContainsKey("__type") && gDict["__type"] is string) { if (gDict["__type"].ToString() == "point:#ESRI.ArcGIS.Client.Geometry") { geometry = CreatePoint(gDict); } else if (gDict["__type"].ToString() == "Polyline:#ESRI.ArcGIS.Client.Geometry") { if (gDict.ContainsKey("paths") && gDict["paths"] is List<object>) { List<object> paths = gDict["paths"] as List<object>; Polyline line = new Polyline(); if (paths != null) { foreach (object path in paths) { List<object> points = path as List<object>; ESRI.ArcGIS.Client.Geometry.PointCollection pts = new ESRI.ArcGIS.Client.Geometry.PointCollection(); foreach (object point in points) { if (point is IDictionary<string, object>) pts.Add(CreatePoint(point as IDictionary<string, object>)); } line.Paths.Add(pts); } geometry = line; } } } else if (gDict["__type"].ToString() == "Polygon:#ESRI.ArcGIS.Client.Geometry") { if (gDict.ContainsKey("rings") && gDict["rings"] is List<object>) { List<object> rings = gDict["rings"] as List<object>; Polygon gon = new Polygon(); if (rings != null) { foreach (object ring in rings) { List<object> points = ring as List<object>; ESRI.ArcGIS.Client.Geometry.PointCollection pts = new ESRI.ArcGIS.Client.Geometry.PointCollection(); foreach (object point in points) { if (point is IDictionary<string, object>) pts.Add(CreatePoint(point as IDictionary<string, object>)); } gon.Rings.Add(pts); } geometry = gon; } } } } if (geometry != null && gDict.ContainsKey("spatialReference")) { IDictionary<string, object> srDict = gDict["spatialReference"] as IDictionary<string, object>; if (srDict != null) { if (srDict.ContainsKey("wkid")) geometry.SpatialReference = new SpatialReference() { WKID = Int32.Parse(srDict["wkid"].ToString()) }; else if (srDict.ContainsKey("wkt")) geometry.SpatialReference = new SpatialReference() { WKT = srDict["wkt"].ToString() }; } } if (geometry != null) { GraphicsLayer glayer = ESRI.ArcGIS.Mapping.Controls.ArcGISOnline.Note.CreateGraphicsLayer(name, new Graphic() { Geometry = geometry }, map); if (dict.ContainsKey("Visible")) { bool visible = true; try { visible = (bool)(dict["Visible"]); } catch { } glayer.Visible = visible; } noteLayers.Add(glayer); } } } #endregion } } if (noteLayers.Count > 0) { for (int i = noteLayers.Count - 1; i >= 0; i--) { if (noteLayers[i] != null) map.Layers.Add(noteLayers[i]); } } #endregion } } } #endregion }
public static ESRI.ArcGIS.Client.Geometry.PointCollection LoadTrackSegment( wptTypeCollection trksegs ) { trksegs.RequireArgument<wptTypeCollection>( "trksegs" ).NotNull<wptTypeCollection>(); ESRI.ArcGIS.Client.Geometry.PointCollection pts = new ESRI.ArcGIS.Client.Geometry.PointCollection(); foreach( var trkseg in trksegs ) { pts.Add( LoadWayPointGeometry( trkseg ) ); } return pts; }
public static GraphicCollection ToGraphic(this JObject geoJson, SpatialReference sourceSpatialReference = null) { var graphics = new GraphicCollection(); if (sourceSpatialReference == null) { sourceSpatialReference = new SpatialReference(4326); } var src = ProjectionInfo.FromEpsgCode(sourceSpatialReference.WKID); var dest = ProjectionInfo.FromEpsgCode(4326); var sr = new SpatialReference(4326); var jFeatures = geoJson["features"] as JArray; if (jFeatures == null) return null; foreach (var jFeature in jFeatures.OfType<JObject>()) { var jGeometry = jFeature["geometry"]; if (jGeometry == null) continue; var geometryType = (string)jGeometry["type"]; switch (geometryType) { case "MultiPolygon": var jPolygons = jGeometry["coordinates"] as JArray; if (jPolygons == null) continue; foreach (var jPolygon in jPolygons.OfType<JArray>()) { if (jPolygon.Count == 0) continue; var polygon = new Polygon(); polygon.SpatialReference = sr; foreach (var jLinearRing in jPolygon.OfType<JArray>()) { if (src == dest) { var pointCollection = new PointCollection(jLinearRing.OfType<JArray>().Select(point=>new MapPoint((double)point[0], (double)point[1], sourceSpatialReference))); polygon.Rings.Add(pointCollection); } else { // reproject var points = jLinearRing.OfType<JArray>().SelectMany(point=>new double[2]{(double)point[0], (double)point[1]}).ToArray(); Reproject.ReprojectPoints(points, null, src, dest, 0, points.Length/2); var pointCollection = new PointCollection(Enumerable.Range(0, points.Length / 2).Select(i=>new MapPoint(points[i*2], points[(i*2)+1], sr))); polygon.Rings.Add(pointCollection); } } var graphic = new Graphic(); graphic.Geometry = polygon; graphic.Symbol = new SimpleFillSymbol { BorderBrush = new SolidColorBrush(Colors.Black), BorderThickness = 4, Fill = new SolidColorBrush(Colors.Blue) { Opacity = 0.8f} }; graphics.Add(graphic); } break; default: throw new NotSupportedException(string.Format("Geometry type {0} is not supported. Supported geometry types are: MultiPolygon.", geometryType)); } } return graphics; }
private void ConvertGeometryToPolygon(PoI p, PoiGraphic g) { var polygon = new Polygon(); if (p.Geometry is csCommon.Types.Geometries.Polygon) { var geom = p.Geometry as csCommon.Types.Geometries.Polygon; foreach (var ls in geom.LineStrings) { var pc = new PointCollection(); foreach (var ps in ls.Line) { pc.Add(mercator.FromGeographic(new MapPoint(ps.X, ps.Y)) as MapPoint); } if (pc.First().X != pc.Last().X || pc.First().Y != pc.Last().Y) pc.Add(pc.First()); polygon.Rings.Add(pc); } g.SetGeometry(polygon); } else return; }
public static ESRI.ArcGIS.Client.Geometry.Polyline LoadRoute( wptTypeCollection rte ) { rte.RequireArgument<wptTypeCollection>( "rte" ).NotNull<wptTypeCollection>(); ESRI.ArcGIS.Client.Geometry.PointCollection pts = new ESRI.ArcGIS.Client.Geometry.PointCollection(); foreach( var pt in rte ) { pts.Add( LoadWayPointGeometry( pt ) ); } ESRI.ArcGIS.Client.Geometry.Polyline line = new ESRI.ArcGIS.Client.Geometry.Polyline() { Paths = new ObservableCollection<ESRI.ArcGIS.Client.Geometry.PointCollection>() { pts } }; return line; }
/* private BitmapImage LoadImageFromResource(string pResourceUrl) { var assembly = Assembly.GetExecutingAssembly(); var resources = assembly.GetManifestResourceNames(); using (Stream stream = assembly.GetManifestResourceStream(pResourceUrl)) { var bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.StreamSource = stream; bitmap.CacheOption = BitmapCacheOption.OnLoad; bitmap.EndInit(); bitmap.Freeze(); return bitmap; } }*/ #region ConvertPoints helpers private PointCollection ConvertPointsToPointCollection(BaseContent p) { if (p.Points == null || p.Points.Count == 0) return null; var pc = new PointCollection(); foreach (var po in p.Points) { pc.Add(mercator.FromGeographic(new MapPoint(po.X, po.Y)) as MapPoint); } return pc; }
// Plot points and lines highlighting the area where seismic line slices can be obtained, with the seismic line control public void PlotActualSeismicLines() { GraphicsLayer mygl = new GraphicsLayer(); mygl.ID = "ActiveSeismicLinePoints"; SimpleMarkerSymbol MyPointSymbol = new SimpleMarkerSymbol(); MyPointSymbol.Color = System.Windows.Media.Brushes.DarkGreen; MyPointSymbol.Size = 8.0; SimpleLineSymbol MyLineSymbol = new SimpleLineSymbol(); MyLineSymbol.Color = System.Windows.Media.Brushes.DarkGreen; MyLineSymbol.Width = 2.0; SpatialReference OriginalSpatialReference = new SpatialReference(4283); // GDA 1994 SpatialReference TargetSpatialReference = new SpatialReference(3857); // webmercator GeometryService mygeom = LayoutRoot.Resources["GeomService"] as GeometryService; GraphicCollection mygc = new GraphicCollection(); double[][] myPoints = new double[4][] { // (latitude,longitude), ie (y,x) new double[] {-28.1801364, 139.5568852}, new double[] {-28.1434989,139.5514607}, new double[] {-28.1278969,139.6851856}, new double[] {-28.1635794, 139.6987722} }; foreach (double[] da in myPoints) { Graphic g = new Graphic(); g.Geometry = new MapPoint(da[1], da[0]); g.Geometry.SpatialReference = OriginalSpatialReference; mygc.Add(g); } IList<Graphic> glist = mygeom.Project(mygc, TargetSpatialReference); foreach (Graphic g in glist) { g.Symbol = MyPointSymbol; mygl.Graphics.Add(g); //System.Diagnostics.Debug.WriteLine((g.Geometry as MapPoint).X + " " + (g.Geometry as MapPoint).Y); } Graphic lineOne = new Graphic(); lineOne.Geometry = new Polyline(); ESRI.ArcGIS.Client.Geometry.PointCollection lineCollectionOne = new ESRI.ArcGIS.Client.Geometry.PointCollection(); lineCollectionOne.Add((glist[0] as Graphic).Geometry as MapPoint); lineCollectionOne.Add((glist[1] as Graphic).Geometry as MapPoint); lineCollectionOne.Add((glist[2] as Graphic).Geometry as MapPoint); lineCollectionOne.Add((glist[3] as Graphic).Geometry as MapPoint); lineCollectionOne.Add((glist[0] as Graphic).Geometry as MapPoint); (lineOne.Geometry as Polyline).Paths.Add(lineCollectionOne); lineOne.Symbol = MyLineSymbol; mygl.Graphics.Add(lineOne); MyMap.Layers.Add(mygl); }
void RscGetRoutingCompleted(object sender, GetRoutingCompletedEventArgs e) { if (e.Result.Count() == 0) { Dtimer.Stop(); timer.Stop(); Ltimer.Stop(); return; } carloc.Clear(); _cari = 0; var lineLayer = MyMap.Layers["MyLineLayer"] as GraphicsLayer; if (lineLayer != null) lineLayer.ClearGraphics(); var builder = new StringBuilder(); if (e.Error == null) { Color color = Colors.Blue; for (int i = 0; i < e.Result.Count; i++) { string[] strArray = e.Result[i].Split(new char[] { ';' }); builder.Length = 0; int index = 2; while (index < (strArray.Length - 1)) { builder.Append(strArray[index] + ": "); index++; } string[] strArray2 = strArray[strArray.Length - 1].Split(new char[] { ',' }); string[] strArrayPoints = strArray[strArray.Length - 2].Split(new char[] { ',' }); int beginNode = int.Parse(strArray[3]); if (i==0) { otmpFirstArrays = strArrayPoints; } if ((strArray2.Length == 1) && (strArray2[0].Length > 1)) { //面 } else { var locations = new ESRI.ArcGIS.Client.Geometry.PointCollection(); CustomMapPoint location2; CustomMapPoint locPoint; if (strArray2[0].Equals(strArray2[strArray2.Length - 1])) { } else { var polyline = new ESRI.ArcGIS.Client.Geometry.Polyline(); for (index = strArray2.Length - 1; index >= 0; index--) { location2 = new CustomMapPoint( double.Parse(strArray2[index].Split(new char[] {' '})[1]), double.Parse(strArray2[index].Split(new char[] {' '})[0])) {Node = beginNode}; locations.Add(location2); } //添加坐标到小车轨迹 if (fcarloc.Count>0) { //取出轨迹数据的第一个点 var floc1 = new CustomMapPoint(double.Parse(otmpFirstArrays[0].Split(new char[] { ' ' })[1]), double.Parse(otmpFirstArrays[0].Split(new char[] { ' ' })[0])); var ffloc1 = fcarloc.ElementAt(0); var loc1 = new CustomMapPoint(double.Parse(strArrayPoints[0].Split(new char[] { ' ' })[1]), double.Parse(strArrayPoints[0].Split(new char[] { ' ' })[0])); var loc2 = new CustomMapPoint(double.Parse(strArrayPoints[strArrayPoints.Length - 1].Split(new char[] { ' ' })[1]), double.Parse(strArrayPoints[strArrayPoints.Length - 1].Split(new char[] { ' ' })[0])); CustomMapPoint oPoint = GetCarByName("car", MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer).Geometry as CustomMapPoint; if (i==0) { //当前车辆不在在轨迹上 if (!IsInLine(oPoint, otmpFirstArrays)) { //调节车辆最后所在轨迹段顺序 if (!Isclost(ffloc1, loc1, 0.0001) && !Isclost(ffloc1, loc2, 0.0001)) { for (index = 0; index < fcarloc.Count - 1; index++) { var tmoloc = fcarloc.ElementAt(index); carloc.Add(tmoloc); } } else { for (index = fcarloc.Count - 1; index >= 0; index--) { var tmoloc1 = fcarloc.ElementAt(index); carloc.Add(tmoloc1); } } } } if (i == 1) { //调节第一段轨迹段顺序 if (!Isclost(floc1, loc1, 0.00001) && !Isclost(floc1, loc2, 0.00001)) { for (index = 0; index < otmpFirstArrays.Length - 1; index++) { var tmoloc = new CustomMapPoint( double.Parse(otmpFirstArrays[index].Split(new char[] {' '})[1]), double.Parse(otmpFirstArrays[index].Split(new char[] {' '})[0])) {Node = beginNode}; carloc.Add(tmoloc); } } else { for (index = otmpFirstArrays.Length - 1; index >= 0; index--) { var tmoloc1 = new CustomMapPoint( double.Parse(otmpFirstArrays[index].Split(new char[] {' '})[1]), double.Parse(otmpFirstArrays[index].Split(new char[] {' '})[0])) {Node = beginNode}; carloc.Add(tmoloc1); } } OrderPoints(strArrayPoints, carloc.ElementAt(carloc.Count - 1), loc1, loc2, beginNode); } if(i>1) { OrderPoints(strArrayPoints, carloc.ElementAt(carloc.Count - 1), loc1, loc2, beginNode); } } polyline.Paths.Add(locations); if (lineLayer != null) lineLayer.Graphics.Add(new Graphic() { Geometry = polyline, Symbol = DefaultLineSymbol }); } } } } CustomMapPoint c = GetCarByName("car", MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer).Geometry as CustomMapPoint; for (int i = 0; i < carloc.Count-1; i++) { var item = carloc.ElementAt(i); if (Isclost(c, item, 0.0001)) { for (int y = 0; y < i + 2; y++) { if (carloc.Count > y + 1) { carloc.RemoveAt(0); } } } } _isgetlocing = false; timer.Begin(); }
/// <summary> /// Create graphics when base is 4326 /// </summary> /// <param name="rssGraphics"></param> private void Add4326Graphics(List<RssGraphic> rssGraphics) { int counter = 0; foreach (RssGraphic rssGraphic in rssGraphics) { Graphic graphic = new Graphic(); //mouse events graphic.MouseEnter += graphic_MouseEnter; graphic.MouseLeave += graphic_MouseLeave; //title graphic.Attributes.Add("Title", rssGraphic.title); //abstract string result = (Regex.Replace(rssGraphic.Description, @"<(.|\n)*?>", string.Empty)).TrimStart(new char[] { '\n' }); int loc = result.IndexOf("\n"); string abstactString = result.Substring(0, loc); if (abstactString.ToLower() == "null") { abstactString = "No description available"; } graphic.Attributes.Add("Abstract", abstactString); //magic for links happens here List<GeoLinks> links = ParseDescription(rssGraphic.Description); //links List<string> currentLinks = new List<string>(); foreach (GeoLinks link in links) { graphic.Attributes.Add(link.Title, link.Url); graphic.Attributes.Add(link.Title + "Visible", true); currentLinks.Add(link.Title); if (link.AddToMapInfo != null) { graphic.Attributes.Add("Add", link.AddToMapInfo); graphic.Attributes.Add("AddVisible", true); currentLinks.Add("Add"); } } //geometry string[] sPoints = rssGraphic.StringPolygon.Split(' '); ESRI.ArcGIS.Client.Geometry.PointCollection pColl = new ESRI.ArcGIS.Client.Geometry.PointCollection(); for (int i = 0; i < sPoints.Length; i++) { pColl.Add(new MapPoint(Convert.ToDouble(sPoints[i + 1]), Convert.ToDouble(sPoints[i]))); i++; } ESRI.ArcGIS.Client.Geometry.Polygon poly = new ESRI.ArcGIS.Client.Geometry.Polygon(); poly.Rings.Add(pColl); graphic.Geometry = poly; System.Diagnostics.Debug.WriteLine("Graphic extent: " + graphic.Geometry.Extent); _graphicsLyr.Graphics.Add(graphic); //result grid string sCleanLink = FindServiceLink(rssGraphic.Description); string sID = rssGraphic.title; sCleanLink = sCleanLink + "," + sID; _queryResultData.Add(new QueryResultData() { Title = rssGraphic.title, Description = rssGraphic.Description, IsEnable = true, graphic = graphic, sLink = sCleanLink, ID = sID }); counter++; } UpdateUIAfterSearch(counter); }
internal void UpdateLine() { Polyline pl = new Polyline(); pl.Paths = new ObservableCollection<PointCollection>(); PointCollection pc = new PointCollection(); pc.Add(Start.Mp); pc.Add(Finish.Mp); pl.Paths.Add(pc); Line.Geometry = pl; }