Esempio n. 1
0
 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);
 }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        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());
                }
            }
        }
Esempio n. 4
0
        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();
        }
        /// <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);
        }
Esempio n. 6
0
        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 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);
        }
		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();
		}
Esempio n. 9
0
        /// <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);
            }
        }
Esempio n. 10
0
        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;
        }
        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 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);
            }
        }
Esempio n. 13
0
        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);
        }
Esempio n. 14
0
        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 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>
        /// 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);
        }
Esempio n. 17
0
 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);
 }
Esempio n. 18
0
///        此方法为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;//这里根据自己的需要定义样式
        }
Esempio n. 19
0
 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);
     }
 }
        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;
        }
Esempio n. 21
0
        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);
            }
        }
Esempio n. 22
0
        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;

        }
Esempio n. 23
0
        /// <summary>
        /// Adds a polyline to this map layer.
        /// </summary>
        /// <param name="lc">
        /// The location collection that defines the polyline.
        /// </param>
        /// <param name="br">
        /// The brush used to render the polyline.
        /// </param>
        public void AddPolyline(ILocationCollection lc, Brush br)
        {
            var pc = new PointCollection();

            foreach (var p in lc)
            {
                pc.Add(Transform.GeographicToWebMercator(p as MapPoint));
            }

            var polyline = new Polyline();

            polyline.Paths.Add(pc);
            var graphic = new Graphic
            {
                Symbol = new SimpleLineSymbol {
                    Color = br
                },
                Geometry = polyline
            };

            Graphics.Add(graphic);
        }
        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;
            }
        }
Esempio n. 25
0
        private void map_MouseMove(object sender, MouseEventArgs e)
        {
            Map.Cursor = Cursors.Hand;
            if (originPoint != null && _isMeasuring)
            {
                _graphicCount = GraphicsLayer.Graphics.Count;
                int      g        = _graphicCount - 1;
                MapPoint p        = Map.ScreenToMap(e.GetPosition(Map));
                MapPoint midpoint = new MapPoint((p.X + originPoint.X) / 2, (p.Y + originPoint.Y) / 2);
                ESRI.ArcGIS.Client.Geometry.PointCollection polypoints = new ESRI.ArcGIS.Client.Geometry.PointCollection();
                ESRI.ArcGIS.Client.Geometry.Polygon         poly       = new ESRI.ArcGIS.Client.Geometry.Polygon();
                if (Type == MeasureType.Area && _points.Count > 2)
                {
                    Graphic graphic = GraphicsLayer.Graphics[0];
                    poly       = graphic.Geometry as ESRI.ArcGIS.Client.Geometry.Polygon;
                    polypoints = poly.Rings[0];
                    int lastPt = polypoints.Count - 1;
                    polypoints[lastPt] = p;
                }
                GraphicsLayer.Graphics[g - 2].Geometry = midpoint;
                (GraphicsLayer.Graphics[g - 1].Geometry as ESRI.ArcGIS.Client.Geometry.Polyline).Paths[0][1] = p;
                GraphicsLayer.Graphics[g].Geometry = midpoint;
                double angle = Math.Atan2((p.X - originPoint.X), (p.Y - originPoint.Y)) / Math.PI * 180 - 90;
                if (angle > 90 || angle < -90)
                {
                    angle -= 180;
                }
                RotatingTextSymbol symb = GraphicsLayer.Graphics[g].Symbol as RotatingTextSymbol;
                symb.Angle = angle;

                double dist      = Geodesic.GetSphericalDistance(originPoint, p);
                double distRound = RoundToSignificantDigit(dist);
                symb.Text = Convert.ToString(RoundToSignificantDigit(ConvertDistance(dist, DistanceUnits)));
                GraphicsLayer.Graphics[g].Symbol = symb;
                _segmentLength   = distRound;
                _tempTotalLength = totalLength + distRound;
                RotatingTextSymbol totSym;
                if (Type == MeasureType.Distance)
                {
                    totSym      = GraphicsLayer.Graphics[0].Symbol as RotatingTextSymbol;
                    totSym.Text = string.Format("Length Total:\n{0} {1}", RoundToSignificantDigit(ConvertDistance(_tempTotalLength, DistanceUnits)), DistanceUnits.ToString());
                    GraphicsLayer.Graphics[0].Symbol = totSym;
                }
                else
                {
                    totSym = GraphicsLayer.Graphics[1].Symbol as RotatingTextSymbol;
                    if (polypoints != null && polypoints.Count > 2)
                    {
                        double lastLen = Geodesic.GetSphericalDistance(polypoints[0], polypoints[polypoints.Count - 1]);
                        poly = GraphicsLayer.Graphics[0].Geometry as ESRI.ArcGIS.Client.Geometry.Polygon;
                        MapPoint anchor = poly.Extent.GetCenter();
                        ESRI.ArcGIS.Client.Geometry.PointCollection temppoints = new ESRI.ArcGIS.Client.Geometry.PointCollection();
                        foreach (MapPoint point in poly.Rings[0])
                        {
                            temppoints.Add(point);
                        }
                        temppoints.Add(poly.Rings[0][0]);
                        ESRI.ArcGIS.Client.Geometry.PointCollection pts = ToKmMapPoint(temppoints);
                        double area = GetArea(pts);
                        //double area = GetArea(ToKMMapPoint(polypoints));
                        totSym.Text = string.Format("Area:\n{0} {1}", RoundToSignificantDigit(area), AreaUnits.ToString());
                        GraphicsLayer.Graphics[1].Geometry = anchor;
                        GraphicsLayer.Graphics[1].Symbol   = totSym;
                    }
                }
            }
        }
Esempio n. 26
0
        private void ClientOnComputeFieldOfViewAsVectorCompleted(object sender, ComputeFieldOfViewAsVectorCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                Logger.Log("FieldOfViewModel.FovPoi", "Error generating FoV", e.Error.ToString(), Logger.Level.Error, true);
                return;
            }

            if ((e.Result == null || e.Result.Locations == null) || (e.Result.Locations.Count == 0)) return; // No FoV

            if (e.UserState != null)
            {
                Stream stream = File.Open(e.UserState.ToString(), FileMode.Create);
                BinaryFormatter bformatter = new BinaryFormatter();
                bformatter.Serialize(stream, e.Result);
                stream.Close();
            }

            //Kml.CreateKmlFile(@"c:\temp\fov.kml", e.Result.Locations.ToList());

            // Create polygon for map
            var coordinates = new ESRI.ArcGIS.Client.Geometry.PointCollection();
            var pts = new List<Point>();
            var camera = (MapPoint)webMercator.FromGeographic(new MapPoint(e.Result.RequestMessage.CameraLocation.Longitude, e.Result.RequestMessage.CameraLocation.Latitude));
            if (e.Result.RequestMessage.ViewAngle != 360) coordinates.Add(camera);
            foreach (var pnt in e.Result.Locations.Select(x => new MapPoint(x.Longitude, x.Latitude)))
            {
                pts.Add(new Point(pnt.X, pnt.Y));
                coordinates.Add((MapPoint)webMercator.FromGeographic(pnt)); /* Convert from WGS84 to Mercator projection */
            }
            Points = pts;
            if (e.Result.RequestMessage.ViewAngle != 360) coordinates.Add(camera);

            // Fill POI points
            //Poi.Points.Clear();
            //foreach (var pnt in e.Result.Locations.Select(x => new Point(x.Longitude, x.Latitude)))
            //{
            //    Poi.Points.Add(pnt);
            //}

            Execute.OnUIThread(() =>
            {
                try
                {
                    var pl = new Polyline();
                    pl.Paths.Add(coordinates);
                    var g = new Graphic
                    {
                        Symbol = new SimpleLineSymbol
                        {
                            Color = new SolidColorBrush(color),
                            Width = strokeWidth,
                            Style = SimpleLineSymbol.LineStyle.Solid
                        },
                        Geometry = pl
                    };
                    g.Attributes["ID"] = Poi.Id.ToString();

                    ClearGraphics();
                    GraphicsLayer.Graphics.Add(g);
                }
                catch (Exception ex)
                {
                    Logger.Log("FieldOfViewModel.FovPoi", "Error generating FoV", ex.Message, Logger.Level.Error, true);
                }
            });
        }
        /// <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;
        }
Esempio n. 28
0
        ///刘宇

        private Geometry ParsefromJson(string jsonResponse)
        {
            JsonObject       jsonObject = JObject.Parse(jsonResponse.ToString()) as JObject;
            SpatialReference pSpatial   = new SpatialReference();
            Geometry         pGeo       = null;

            if (jsonObject.Contains("", "")) //    .ContainsKey("geometries"))
            {
                JObject jsonObjectGeo = jsonObject["geometries"] as JObject;
                //空间参考信息

                /*      if (jsonObjectGeo.ContainsKey("spatialReference"))
                 *    {
                 *        pSpatial = this.myMap.SpatialReference;
                 *
                 *
                 *        //JsonObject pSpatialJson =jsonObjectGeo["spatialReference"] as JsonObject;
                 *
                 *        //   if(pSpatialJson.ContainsKey("wkid"))
                 *        //   {
                 *        //       pSpatial.WKID = Convert.ToInt16(pSpatialJson["wkid"].ToString());
                 *        //   }
                 *        //   else if(pSpatialJson.ContainsKey("wkt"))
                 *        //   {
                 *        //       pSpatial.WKT = pSpatialJson["wkt"].ToString();
                 *        //   }
                 *
                 *
                 *
                 *
                 *    }
                 * */
                //点线面对象,不考虑hasz和hasM
                if (jsonObjectGeo.ContainsKey("points"))
                {
                    JValue JsonPoints = jsonObjectGeo["points"];

                    if (JsonPoints is JsonArray)
                    {
                        if (JsonPoints.Count == 1)
                        {
                            MapPoint pPoint = new MapPoint();

                            //去掉中括号

                            string[] pStrPoints = JsonPoints[0].ToString().Substring(1, JsonPoints[0].ToString().Length - 2).Split(',');

                            pPoint.X = Convert.ToDouble(pStrPoints[0]);
                            pPoint.Y = Convert.ToDouble(pStrPoints[1]);

                            pGeo = pPoint;
                        }
                        //else
                        //{
                        //    ESRI.ArcGIS.Client.Geometry.PointCollection pPointCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection();
                        //    for (int i = 0; i < JsonPoints.Count; i++)
                        //    {
                        //        string pStr = JsonPoints[i].ToString();
                        //        MapPoint pPoint = new MapPoint();
                        //        string[] pStrPoints = JsonPoints[0].ToString().Substring(1, JsonPoints[0].ToString().Length - 2).Split(',');
                        //        pPoint.X = Convert.ToDouble(pStrPoints[0]);
                        //        pPoint.Y = Convert.ToDouble(pStrPoints[1]);
                        //        pPointCollection.Add(pPoint);
                        //    }

                        //    pGeo = pPointCollection as ESRI.ArcGIS.Client.Geometry.Geometry;
                        //}
                    }
                }
                else if (jsonObjectGeo.ContainsKey("paths"))
                {
                    JsonValue JsonPoints = jsonObjectGeo["paths"];

                    ESRI.ArcGIS.Client.Geometry.Polyline pPolyline = new ESRI.ArcGIS.Client.Geometry.Polyline();


                    ObservableCollection <ESRI.ArcGIS.Client.Geometry.PointCollection> pPointCollection = new ObservableCollection <ESRI.ArcGIS.Client.Geometry.PointCollection>();
                    // pPolyline.Paths

                    if (JsonPoints is JsonArray)
                    {
                        for (int i = 0; i < JsonPoints.Count; i++)
                        {
                            if (JsonPoints[i] is JsonArray)
                            {
                                ESRI.ArcGIS.Client.Geometry.PointCollection pPointCollections = new ESRI.ArcGIS.Client.Geometry.PointCollection();

                                JsonArray pInnerPoints = JsonPoints[i] as JsonArray;
                                for (int j = 0; j < pInnerPoints.Count; j++)
                                {
                                    string pStr = pInnerPoints[j].ToString();

                                    string[] pStrPoints = pInnerPoints[j].ToString().Substring(1, pInnerPoints[j].ToString().Length - 2).Split(',');
                                    MapPoint pPoint     = new MapPoint();
                                    pPoint.X = Convert.ToDouble(pStrPoints[0]);
                                    pPoint.Y = Convert.ToDouble(pStrPoints[1]);

                                    pPointCollections.Add(pPoint);
                                }

                                pPointCollection.Add(pPointCollections);
                            }
                        }

                        pPolyline.Paths = pPointCollection;

                        pGeo = pPolyline;
                    }
                }
                else if (jsonObjectGeo.ContainsKey("rings"))
                {
                    JsonValue JsonPoints = jsonObjectGeo["rings"];

                    ESRI.ArcGIS.Client.Geometry.Polygon pPolygon = new ESRI.ArcGIS.Client.Geometry.Polygon();



                    ObservableCollection <ESRI.ArcGIS.Client.Geometry.PointCollection> pPointCollection = new ObservableCollection <ESRI.ArcGIS.Client.Geometry.PointCollection>();


                    if (JsonPoints is JsonArray)
                    {
                        for (int i = 0; i < JsonPoints.Count; i++)
                        {
                            if (JsonPoints[i] is JsonArray)
                            {
                                ESRI.ArcGIS.Client.Geometry.PointCollection pPointCollections = new ESRI.ArcGIS.Client.Geometry.PointCollection();

                                JsonArray pInnerPoints = JsonPoints[i] as JsonArray;
                                for (int j = 0; j < pInnerPoints.Count; j++)
                                {
                                    string pStr = pInnerPoints[j].ToString();

                                    string[] pStrPoints = pInnerPoints[j].ToString().Substring(1, pInnerPoints[j].ToString().Length - 2).Split(',');
                                    MapPoint pPoint     = new MapPoint();
                                    pPoint.X = Convert.ToDouble(pStrPoints[0]);
                                    pPoint.Y = Convert.ToDouble(pStrPoints[1]);

                                    pPointCollections.Add(pPoint);
                                }

                                pPointCollection.Add(pPointCollections);
                            }
                        }

                        pPolygon.Rings = pPointCollection;

                        pGeo = pPolygon;
                    }
                }
            }



            pGeo.SpatialReference = pSpatial;

            return(pGeo);
        }
        /// <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;
        }
        private void DrawObject_DrawComplete(object sender, DrawEventArgs e)
        {
            if (this.DrawWidget != this.GetType())
            {
                return;
            }

            try
            {
                Graphic graphic = null;
                String  prefix  = "";

                MapPoint mapPoint;

                Envelope envelope = null;
                Polygon  polygon  = new Polygon();
                ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection();

                if (e.Geometry == null)
                {
                    MessageBox.Show("Click and Drag the mouse to define the shape.");
                    return;
                }

                if (this.DrawObject.DrawMode == DrawMode.Point)
                {
                    prefix   = "Point-";
                    mapPoint = e.Geometry as MapPoint;
                    graphic  = new Graphic()
                    {
                        Geometry = mapPoint,
                        Symbol   = this.ChooseSymbol(e.Geometry.GetType().Name)
                    };

                    double[] dimension = this.GetTextDimension(graphic);
                    if (dimension != null)
                    {
                        //MessageBox.Show("Width = " + dimension[0].ToString() + "\nHeight = " + dimension[1].ToString() + "\n" + _anchorX.ToString() + " " + _anchorY.ToString());
                    }

                    if (_isDrawingText == true)
                    {
                        prefix = "Text-";
                        // need to get text size into mapunits
                        mapPoint.X = mapPoint.X - dimension[0] * _anchorX; // x is subtract
                        mapPoint.Y = mapPoint.Y + dimension[1] * _anchorY; // y is add
                        graphic    = new Graphic()
                        {
                            Geometry = mapPoint,
                            Symbol   = this.ChooseSymbol(e.Geometry.GetType().Name)
                        };
                    }

                    if (_isDrawingMeasured == true)
                    {
                        prefix  = "Measured-";
                        graphic = this.CreateMeasuredGraphic(mapPoint);
                        if (graphic == null)
                        {
                            return;
                        }

                        Symbol symb = this.ChooseSymbol(graphic.Geometry.GetType().Name, true);
                        graphic.Symbol = symb;
                    }
                }
                else if (this.DrawObject.DrawMode == DrawMode.Polyline)
                {
                    prefix  = "Line-";
                    graphic = new Graphic()
                    {
                        Geometry = e.Geometry as Polyline,
                        Symbol   = this.ChooseSymbol(e.Geometry.GetType().Name)
                    };
                }
                else if (this.DrawObject.DrawMode == DrawMode.Polygon)
                {
                    prefix  = "Polygon-";
                    graphic = new Graphic()
                    {
                        Geometry = e.Geometry as Polygon,
                        Symbol   = this.ChooseSymbol(e.Geometry.GetType().Name)
                    };
                }
                else if (this.DrawObject.DrawMode == DrawMode.Circle)
                {
                    prefix  = "Circle-";
                    graphic = new Graphic()
                    {
                        Geometry = e.Geometry as Polygon,
                        Symbol   = this.ChooseSymbol(e.Geometry.GetType().Name)
                    };
                }
                else if (this.DrawObject.DrawMode == DrawMode.Triangle)
                {
                    prefix  = "Triangle-";
                    graphic = new Graphic()
                    {
                        Geometry = e.Geometry as Polygon,
                        Symbol   = this.ChooseSymbol(e.Geometry.GetType().Name)
                    };
                }
                else if (this.DrawObject.DrawMode == DrawMode.Rectangle)
                {
                    prefix   = "Rectangle-";
                    envelope = e.Geometry as Envelope;
                    pointCollection.Add(new MapPoint(envelope.XMin, envelope.YMin));
                    pointCollection.Add(new MapPoint(envelope.XMin, envelope.YMax));
                    pointCollection.Add(new MapPoint(envelope.XMax, envelope.YMax));
                    pointCollection.Add(new MapPoint(envelope.XMax, envelope.YMin));
                    pointCollection.Add(new MapPoint(envelope.XMin, envelope.YMin));
                    polygon.Rings.Add(pointCollection);
                    graphic = new Graphic()
                    {
                        Geometry = polygon,
                        Symbol   = this.ChooseSymbol("Polygon")
                    };
                }
                else if (this.DrawObject.DrawMode == DrawMode.Freehand)
                {
                    prefix = "Freehand-";
                }

                String id = prefix + DateTime.Now.ToString("HH:mm:ss");

                if (graphic != null)
                {
                    graphic.Attributes.Add("Id", id);
                    _graphicCheckBoxes.Add(new GraphicCheckbox()
                    {
                        Name = id, Checked = false
                    });
                    this.AddGraphic(graphic);
                    this.DrawObject.IsEnabled = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
            }
        }
Esempio n. 31
0
        public void HandleSeismicPoint(MapPoint touchPoint)
        {
            if (seismicLinesOn)
            {
                Graphic g = new Graphic();
                g.Geometry = touchPoint;
                g.Symbol = MyPointSymbol;
                MyGraphicsLayer.Graphics.Add(g);

                if (firstGraphic == null)
                {
                    firstGraphic = g;
                }
                else // with two points, we can call for the interpolated seismic line
                {
                    // Making the connecting line graphic
                    Graphic line = new Graphic();
                    line.Geometry = new Polyline();
                    ESRI.ArcGIS.Client.Geometry.PointCollection collection = new ESRI.ArcGIS.Client.Geometry.PointCollection();
                    collection.Add(g.Geometry as MapPoint);
                    collection.Add(firstGraphic.Geometry as MapPoint);
                    (line.Geometry as Polyline).Paths.Add(collection);
                    line.Symbol = MyLineSymbol;
                    MyGraphicsLayer.Graphics.Add(line);

                    SeismicLineView newSeismicLineView = new SeismicLineView(this.intAirAct)
                    {
                        MyPointOne = g,
                        MyPointTwo = firstGraphic,
                        MyLine = line,
                        MyLayer = MyGraphicsLayer,
                        MyCanvas = MyCanvas,
                        Center = MyMap.MapToScreen(touchPoint)
                    };

                    MyCanvas.backgroundScatterView.Items.Add(newSeismicLineView);
                    newSeismicLineView.GetCrossSectionAsync();

                    // Reset, to prepare for the next line
                    firstGraphic = null;
                    CancelSeismicLineDrawing();
                    GenerateNewSymbols();

                }
            }
        }
Esempio n. 32
0
 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);
 }
Esempio n. 33
0
 /// <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);
 }
Esempio n. 34
0
 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;
 }
Esempio n. 35
0
        /*
        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;
        }
Esempio n. 36
0
        // 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);
        }
        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;
        }
Esempio n. 38
0
        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;
        }
Esempio n. 39
0
        /// <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
        }
Esempio n. 40
0
        private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
        {
            GraphicsLayer graphicsLayer = MyMap.Layers["Data"] as GraphicsLayer;

            graphicsLayer.Graphics.Clear();

            Graphic point = new Graphic();

            point.Geometry = e.MapPoint;
            point.Symbol   = LayoutRoot.Resources["CustomStrobeMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;

            graphicsLayer.Graphics.Add(point);

            (this.DataContext as MainViewModel).Quake.Lat = e.MapPoint.Y;
            (this.DataContext as MainViewModel).Quake.Lon = e.MapPoint.X;
            this.Lat.Text       = Math.Round(e.MapPoint.Y, 5).ToString();
            this.Longitude.Text = Math.Round(e.MapPoint.X, 5).ToString();
            (this.DataContext as MainViewModel).IsLoading = true;

            Services.AzureStorageClient client = new AzureStorageClient();
            client.CalculateGeometryCompleted += (s, a) =>
            {
                (this.DataContext as MainViewModel).Quake     = a.Result;
                (this.DataContext as MainViewModel).IsLoading = false;
                GraphicsLayer graphics = MyMap.Layers["Data"] as GraphicsLayer;


                Graphic polygon = new Graphic();
                ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection1 = new ESRI.ArcGIS.Client.Geometry.PointCollection();
                pointCollection1.Add(new MapPoint(a.Result.LonCalc, a.Result.LatCalc, new SpatialReference(4326)));
                pointCollection1.Add(new MapPoint(a.Result.LonCw, a.Result.LatCw, new SpatialReference(4326)));
                pointCollection1.Add(new MapPoint(a.Result.LonCw2, a.Result.LatCw2, new SpatialReference(4326)));
                pointCollection1.Add(new MapPoint(a.Result.LonCalc2, a.Result.LatCalc2, new SpatialReference(4326)));

                pointCollection1.Add(new MapPoint(a.Result.LonCalc, a.Result.LatCalc, new SpatialReference(4326)));

                ESRI.ArcGIS.Client.Geometry.Polygon polygon1 = new ESRI.ArcGIS.Client.Geometry.Polygon();
                polygon1.Rings.Add(pointCollection1);


                polygon.Symbol   = LayoutRoot.Resources["DefaultFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
                polygon.Geometry = polygon1;

                graphics.Graphics.Add(polygon);
                // graphics.Graphics.Add(graphics.Graphics[0]);

                ESRI.ArcGIS.Client.Geometry.Polyline        polyline         = new ESRI.ArcGIS.Client.Geometry.Polyline();
                ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection2 = new ESRI.ArcGIS.Client.Geometry.PointCollection();
                pointCollection2.Add(new MapPoint(a.Result.LonCalc, a.Result.LatCalc, new SpatialReference(4326)));
                pointCollection2.Add(new MapPoint(a.Result.LonCalc2, a.Result.LatCalc2, new SpatialReference(4326)));

                polyline.Paths.Add(pointCollection2);

                Graphic line = new Graphic()
                {
                    Symbol = LayoutRoot.Resources["DefaultLineSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol,

                    Geometry = polyline
                };
                graphics.Graphics.Add(line);

                // GetStations();
            };
            client.CalculateGeometryAsync((this.DataContext as MainViewModel).Quake);
        }
        private Graphic CreateMeasuredGraphic(MapPoint mapPoint)
        {
            try
            {
                double dOut;
                double dX  = 0;
                double dY  = 0;
                double dL  = 0;
                double dA  = 0;
                double dAX = 0;
                double dAY = 0;

                RedlineMeasurementUnits rmuX = null;
                RedlineMeasurementUnits rmuY = null;
                RedlineMeasurementUnits rmuL = null;
                Polyline polyline            = null;
                Polygon  polygon             = null;

                Graphic reply = new Graphic();
                ESRI.ArcGIS.Client.Geometry.PointCollection ptColl = new ESRI.ArcGIS.Client.Geometry.PointCollection();

                if (double.TryParse(txtWidthM.Text, out dOut) == false)
                {
                    throw new Exception("Measure Width must be Numeric");
                }
                rmuX = (cboWidthUnits.SelectedItem as ComboBoxItem).Tag as RedlineMeasurementUnits;
                dX   = dOut / rmuX.Conversion;

                if (double.TryParse(txtHeightM.Text, out dOut) == false)
                {
                    throw new Exception("Measure Height must be Numeric");
                }
                rmuY = (cboHeightUnits.SelectedItem as ComboBoxItem).Tag as RedlineMeasurementUnits;
                dY   = dOut / rmuY.Conversion;

                if (double.TryParse(txtLengthA.Text, out dOut) == false)
                {
                    throw new Exception("Length must be Numeric");
                }
                rmuL = (cboLengthUnits.SelectedItem as ComboBoxItem).Tag as RedlineMeasurementUnits;
                dL   = dOut / rmuL.Conversion;

                if (double.TryParse(txtAzimuth.Text, out dOut) == false)
                {
                    throw new Exception("Azimuth must be Numeric");
                }
                dA = dOut;


                if (_drawMeasureMode == "Measured Line")
                {
                    polyline = new Polyline();
                    ptColl.Add(new MapPoint(mapPoint.X, mapPoint.Y, this.MapControl.SpatialReference));
                    ptColl.Add(new MapPoint(mapPoint.X + dX, mapPoint.Y + dY, this.MapControl.SpatialReference));
                    polyline.Paths.Add(ptColl);
                    reply.Geometry = polyline;
                }
                else if (_drawMeasureMode == "Azimuthed Line")
                {
                    polyline = new Polyline();
                    ptColl.Add(new MapPoint(mapPoint.X, mapPoint.Y, this.MapControl.SpatialReference));
                    dAX = mapPoint.X + Math.Cos(dA * (Math.PI / 180.0)) * dL;
                    dAY = mapPoint.Y + Math.Sin(dA * (Math.PI / 180.0)) * dL;

                    //txtAzimuth.Text = (double.Parse(txtAzimuth.Text) + 10.0).ToString();

                    ptColl.Add(new MapPoint(dAX, dAY, this.MapControl.SpatialReference));
                    polyline.Paths.Add(ptColl);
                    reply.Geometry = polyline;
                }
                else
                {
                    polygon = new Polygon();
                    ptColl.Add(new MapPoint(mapPoint.X, mapPoint.Y, this.MapControl.SpatialReference));
                    ptColl.Add(new MapPoint(mapPoint.X + dX, mapPoint.Y, this.MapControl.SpatialReference));
                    ptColl.Add(new MapPoint(mapPoint.X + dX, mapPoint.Y + dY, this.MapControl.SpatialReference));
                    ptColl.Add(new MapPoint(mapPoint.X, mapPoint.Y + dY, this.MapControl.SpatialReference));
                    ptColl.Add(new MapPoint(mapPoint.X, mapPoint.Y, this.MapControl.SpatialReference));
                    polygon.Rings.Add(ptColl);
                    reply.Geometry = polygon;
                }
                return(reply);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(null);
            }
        }
Esempio n. 42
0
        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);
            }
        }
Esempio n. 43
0
        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();
                }
            });
        }
Esempio n. 44
0
 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();
         }
     });
 }
Esempio n. 45
0
        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 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;
        }
Esempio n. 47
0
        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();
        }
Esempio n. 48
0
        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;
        }
Esempio n. 49
0
        private void map_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            e.Handled = true;
            Point pt = e.GetPosition(null);

            if (Math.Abs(pt.X - lastClick.X) < 2 && Math.Abs(pt.Y - lastClick.Y) < 2)
            {
                int lastone = GraphicsLayer.Graphics.Count - 1;
                GraphicsLayer.Graphics.RemoveAt(lastone);
                if (Type == MeasureType.Area)
                {
                    ESRI.ArcGIS.Client.Geometry.Polygon poly1 = GraphicsLayer.Graphics[0].Geometry as ESRI.ArcGIS.Client.Geometry.Polygon;
                    MapPoint firstpoint = poly1.Rings[0][0];
                    poly1.Rings[0].Add(new MapPoint(firstpoint.X, firstpoint.Y));
                    GraphicsLayer.Graphics[0].Geometry = poly1;
                }
                ResetValues();
            }
            else
            {
                if (_points.Count == 0)
                {
                    GraphicsLayer.Graphics.Clear();
                    if (Type == MeasureType.Area)
                    {
                        Graphic areaGraphic = new Graphic()
                        {
                            Symbol = FillSymbol
                        };

                        GraphicsLayer.Graphics.Add(areaGraphic);
                        Graphic areaTotalGraphic = new Graphic()
                        {
                            Symbol = new RotatingTextSymbol()
                        };
                        GraphicsLayer.Graphics.Add(areaTotalGraphic);
                    }
                }
                originPoint = Map.ScreenToMap(e.GetPosition(Map));
                endPoint    = Map.ScreenToMap(e.GetPosition(Map));
                ESRI.ArcGIS.Client.Geometry.Polyline        line   = new ESRI.ArcGIS.Client.Geometry.Polyline();
                ESRI.ArcGIS.Client.Geometry.PointCollection points = new ESRI.ArcGIS.Client.Geometry.PointCollection();
                points.Add(originPoint);
                points.Add(endPoint);
                line.Paths.Add(points);
                _points.Add(endPoint);
                if (_points.Count == 2)
                {
                    _points.Add(endPoint);
                }
                lineCount++;
                if (Type == MeasureType.Area && _points.Count > 2)
                {
                    ESRI.ArcGIS.Client.Geometry.Polygon poly = new ESRI.ArcGIS.Client.Geometry.Polygon();
                    poly.Rings.Add(_points);
                    GraphicsLayer.Graphics[0].Geometry = poly;
                }
                if (Type == MeasureType.Distance)
                {
                    Graphic totalTextGraphic = new Graphic()
                    {
                        Geometry = originPoint,
                        Symbol   = new RotatingTextSymbol()
                    };
                    GraphicsLayer.Graphics.Add(totalTextGraphic);
                }
                Graphic marker = new Graphic()
                {
                    Geometry = endPoint,
                    Symbol   = markerSymbol
                };
                GraphicsLayer.Graphics.Add(marker);
                Graphic lineGraphic = new Graphic()
                {
                    Geometry = line,
                    Symbol   = LineSymbol
                };
                GraphicsLayer.Graphics.Add(lineGraphic);
                Graphic textGraphic = new Graphic()
                {
                    Geometry = endPoint,
                    Symbol   = new RotatingTextSymbol()
                };
                textGraphic.SetZIndex(1);
                GraphicsLayer.Graphics.Add(textGraphic);
                totalLength += _segmentLength;
                _lengths.Add(_segmentLength);
                _segmentLength = 0;
                _isMeasuring   = true;
            }
            lastClick = pt;
        }
        /// <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
        }
Esempio n. 51
0
 // Make a point collection to be made into a rectangular shape, from an envelope
 private ESRI.ArcGIS.Client.Geometry.PointCollection GetPointCollectionFromEnvelope(Envelope env)
 {
     ESRI.ArcGIS.Client.Geometry.PointCollection pc = new ESRI.ArcGIS.Client.Geometry.PointCollection();
     pc.Add(new MapPoint(env.XMin, env.YMin));
     pc.Add(new MapPoint(env.XMin, env.YMax));
     pc.Add(new MapPoint(env.XMax, env.YMax));
     pc.Add(new MapPoint(env.XMax, env.YMin));
     pc.Add(new MapPoint(env.XMin, env.YMin));
     return pc;
 }
Esempio n. 52
0
        /// <summary>
        /// 将返回的json解析为Geometry,不考虑坐标包含M和Z,如果考虑,请改动即可。将ArcObjects的Geometry转为json的代码我正在测试。
        /// 作者:刘宇
        /// 时间2012年
        /// </summary>
        /// <param name="jsonResponse"></param>
        /// <returns></returns>

        public static Geometry ParsefromJson(JObject jsonObject)
        {
            try
            {
                //   JObject jsonObject = JObject.Parse(jsonResponse) as JObject;

                SpatialReference pSpatial = new SpatialReference();
                Geometry         pGeo     = null;

                if (jsonObject.Property("geometries") != null || jsonObject.Property("geometry") != null)
                {
                    //     JArray jsonGArray = jsonObject["geometries"] as JArray;
                    JArray  jsonGArray;
                    JObject jsonObjectGeo;

                    if (jsonObject.Property("geometry") != null)
                    {
                        jsonObjectGeo = jsonObject["geometry"] as JObject;
                    }
                    else
                    {
                        jsonGArray = jsonObject["geometries"] as JArray;
                        if (jsonGArray.Count() < 1)     // 只返回一个GEOM 对象
                        {
                            return(null);
                        }

                        jsonObjectGeo = jsonGArray[0] as JObject;
                    }


                    //空间参考信息
                    if (jsonObjectGeo.Property("spatialReference") != null)
                    {
                        pSpatial = new SpatialReference(4326);


                        //JsonObject pSpatialJson =jsonObjectGeo["spatialReference"] as JsonObject;

                        //   根据需要添加
                    }
                    //点线面对象,不考虑hasz和hasM
                    if (jsonObjectGeo.Property("points") != null)
                    {
                        JArray JsonPoints = jsonObjectGeo["points"] as JArray;

                        if (JsonPoints is JArray)
                        {
                            if (JsonPoints.Count() == 1)
                            {
                                MapPoint pPoint = new MapPoint();

                                //去掉中括号

                                string[] pStrPoints = JsonPoints[0].ToString().Substring(1, JsonPoints[0].ToString().Length - 2).Split(',');

                                pPoint.X = Convert.ToDouble(pStrPoints[0]);
                                pPoint.Y = Convert.ToDouble(pStrPoints[1]);

                                pGeo = pPoint;
                            }
                        }
                    }
                    else if (jsonObjectGeo.Property("paths") != null)
                    {
                        JArray JsonPoints = jsonObjectGeo["paths"] as JArray;

                        ESRI.ArcGIS.Client.Geometry.Polyline pPolyline = new ESRI.ArcGIS.Client.Geometry.Polyline();


                        ObservableCollection <ESRI.ArcGIS.Client.Geometry.PointCollection> pPointCollection = new ObservableCollection <ESRI.ArcGIS.Client.Geometry.PointCollection>();
                        // pPolyline.Paths

                        if (JsonPoints is JArray)
                        {
                            for (int i = 0; i < JsonPoints.Count(); i++)
                            {
                                if (JsonPoints[i] is JArray)
                                {
                                    ESRI.ArcGIS.Client.Geometry.PointCollection pPointCollections = new ESRI.ArcGIS.Client.Geometry.PointCollection();

                                    JArray pInnerPoints = JsonPoints[i] as JArray;
                                    for (int j = 0; j < pInnerPoints.Count; j++)
                                    {
                                        string pStr = pInnerPoints[j].ToString();

                                        string[] pStrPoints = pInnerPoints[j].ToString().Substring(1, pInnerPoints[j].ToString().Length - 2).Split(',');
                                        MapPoint pPoint     = new MapPoint();
                                        pPoint.X = Convert.ToDouble(pStrPoints[0]);
                                        pPoint.Y = Convert.ToDouble(pStrPoints[1]);

                                        pPointCollections.Add(pPoint);
                                    }

                                    pPointCollection.Add(pPointCollections);
                                }
                            }

                            pPolyline.Paths = pPointCollection;

                            pGeo = pPolyline;
                        }
                    }
                    else if (jsonObjectGeo.Property("rings") != null)
                    {
                        JArray JsonPoints = jsonObjectGeo["rings"] as JArray;

                        ESRI.ArcGIS.Client.Geometry.Polygon pPolygon = new ESRI.ArcGIS.Client.Geometry.Polygon();



                        ObservableCollection <ESRI.ArcGIS.Client.Geometry.PointCollection> pPointCollection = new ObservableCollection <ESRI.ArcGIS.Client.Geometry.PointCollection>();


                        if (JsonPoints is JArray)
                        {
                            for (int i = 0; i < JsonPoints.Count(); i++)
                            {
                                if (JsonPoints[i] is JArray)
                                {
                                    ESRI.ArcGIS.Client.Geometry.PointCollection pPointCollections = new ESRI.ArcGIS.Client.Geometry.PointCollection();

                                    JArray pInnerPoints = JsonPoints[i] as JArray;
                                    for (int j = 0; j < pInnerPoints.Count; j++)
                                    {
                                        string pStr = pInnerPoints[j].ToString();

                                        string[] pStrPoints = pInnerPoints[j].ToString().Substring(1, pInnerPoints[j].ToString().Length - 2).Split(',');
                                        MapPoint pPoint     = new MapPoint();
                                        pPoint.X = Convert.ToDouble(pStrPoints[0]);
                                        pPoint.Y = Convert.ToDouble(pStrPoints[1]);

                                        pPointCollections.Add(pPoint);
                                    }

                                    pPointCollection.Add(pPointCollections);
                                }
                            }

                            pPolygon.Rings = pPointCollection;

                            pGeo = pPolygon;
                        }
                    }
                }


                if (pGeo != null)
                {
                    pGeo.SpatialReference = pSpatial;
                }

                return(pGeo);
            }
            catch (Exception)   // 解析出现异常返回空
            {
                return(null);
            }
        }
 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);
     }
 }
Esempio n. 54
0
        void pbsLayer_TileLoaded(object sender, TileLoadEventArgs e)
        {
            Dispatcher.BeginInvoke(new Action(() =>
            {
                string key = e.Level + "/" + e.Row + "/" + e.Column;
                //avoid to draw a grid duplicately
                if (_dictDrawedGrids.ContainsKey(key))
                {
                    TileWatermark tw = null;
                    if (_dictDrawedGrids.TryGetValue(key, out tw))
                    {
                        _gLayer.Graphics.Remove(tw.GraphicBoundingBox);
                        _gLayer.Graphics.Remove(tw.GraphicTextLabel);
                        _dictDrawedGrids.TryRemove(key, out tw);
                    }
                }
                double xmin, ymin, xmax, ymax;
                CalculateTileBBox(e.Level, e.Row, e.Column, out xmin, out ymin, out xmax, out ymax);
                //polygon as bounding box
                Polygon boundingLine = new Polygon();
                ESRI.ArcGIS.Client.Geometry.PointCollection pc = new ESRI.ArcGIS.Client.Geometry.PointCollection();
                pc.Add(new MapPoint(xmin, ymax, map1.SpatialReference));
                pc.Add(new MapPoint(xmax, ymax, map1.SpatialReference));
                pc.Add(new MapPoint(xmax, ymin, map1.SpatialReference));
                pc.Add(new MapPoint(xmin, ymin, map1.SpatialReference));
                pc.Add(new MapPoint(xmin, ymax, map1.SpatialReference));
                boundingLine.Rings.Add(pc);
                SimpleFillSymbol sfs = new SimpleFillSymbol()
                {
                    //BorderThickness = 2.0,
                    BorderBrush = new SolidColorBrush(Color.FromArgb(200, 255, 255, 255)),
                };
                //dynamic-red, filecache-yellow, memcached-green
                if (e.GeneratedMethod == TileGeneratedSource.DynamicOutput)
                {
                    sfs.Fill = new SolidColorBrush(Color.FromArgb(80, 200, 0, 0));
                }
                else if (e.GeneratedMethod == TileGeneratedSource.FromFileCache)
                {
                    sfs.Fill = new SolidColorBrush(Color.FromArgb(80, 200, 200, 0));
                }
                else if (e.GeneratedMethod == TileGeneratedSource.FromMemcached)
                {
                    sfs.Fill = new SolidColorBrush(Color.FromArgb(80, 0, 200, 0));
                }
                Graphic gBoundingBox = new Graphic()
                {
                    Geometry = boundingLine,
                    Symbol   = sfs,
                };
                _gLayer.Graphics.Add(gBoundingBox);
                //textsymol
                MapPoint center    = new MapPoint((xmin + xmax) / 2, (ymin + ymax) / 2, map1.SpatialReference);
                TextSymbol tSymbol = new TextSymbol()
                {
                    FontSize   = 16,
                    Text       = "Level/Row/Column\r\n" + e.Level + "/" + e.Row + "/" + e.Column,
                    Foreground = new SolidColorBrush(Colors.White),
                };
                if (_service.DataSource.Type == DataSourceTypePredefined.MBTiles.ToString())
                {
                    tSymbol.Text = _service.DataSource.generateSymbolText(e.Level, e.Row, e.Column);
                }
                //where the tile comes from
                string generatedSource = FindResource("tbDynamic").ToString();
                //if tile comes from memcached
                if (e.GeneratedMethod == TileGeneratedSource.FromMemcached)
                {
                    generatedSource = FindResource("tbMemCached").ToString();
                }
                //if tile comes from file cache
                else if (e.GeneratedMethod == TileGeneratedSource.FromFileCache)
                {
                    generatedSource = FindResource("tbFileCache").ToString();
                }
                //if tile bytes count
                string bytesCount = e.TileBytes == null ? "null" : Math.Round(e.TileBytes.Length / 1024.0, 3).ToString() + "KB";
                tSymbol.Text     += "\r\noutput from: " + generatedSource + "\r\nsize: " + bytesCount;

                tSymbol.OffsetY = 16;
                tSymbol.OffsetX = MeasureTextWidth(tSymbol.Text, 16, "Verdana").Width / 2;
                Graphic gText   = new Graphic()
                {
                    Geometry = center,
                    Symbol   = tSymbol
                };
                _gLayer.Graphics.Add(gText);

                _dictDrawedGrids.TryAdd(key, new TileWatermark()
                {
                    GraphicBoundingBox = gBoundingBox,
                    GraphicTextLabel   = gText
                });
            }));
        }
Esempio n. 55
0
        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;
        }
Esempio n. 56
0
        /// <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);
        }
Esempio n. 57
0
        private static ESRI.ArcGIS.Client.Geometry.Geometry GetPolygon(ShapeFileRecord record)
        {
            Random           rnd          = new Random();
            Polygon          polygon      = new Polygon();
            SpatialReference geoReference = new SpatialReference(4326);

            try
            {
                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
                    bool isWebMercator = false;
                    if (record.Points.Count > 0)
                    {
                        if (record.Points[0].Y < -90 || record.Points[0].Y > 90)
                        {
                            isWebMercator = true;
                        }
                        else
                        {
                            polygon.SpatialReference = geoReference;
                        }
                    }
                    for (int j = start; j < end; j++)
                    {
                        if (record.NumberOfPoints < 5000 || rnd.Next(0, 5) == 1)
                        {
                            System.Windows.Point point = record.Points[j];
                            if (isWebMercator)
                            {
                                points.Add(new MapPoint(point.X, point.Y));
                            }
                            else
                            {
                                points.Add(new MapPoint(point.X, point.Y, geoReference));
                            }
                            if (leftMostPoint == 0)
                            {
                                leftMostPoint   = point.X;
                                rightMostPoint  = point.X;
                                topMostPoint    = point.Y;
                                bottomMostPoint = point.Y;
                            }
                            else
                            {
                                if (point.X < leftMostPoint)
                                {
                                    leftMostPoint = point.X;
                                }
                                if (point.X > rightMostPoint)
                                {
                                    rightMostPoint = point.X;
                                }
                                if (point.Y < topMostPoint)
                                {
                                    topMostPoint = point.Y;
                                }
                                if (point.Y > bottomMostPoint)
                                {
                                    bottomMostPoint = point.Y;
                                }
                            }
                        }
                    }

                    polygon.Rings.Add(points);
                }
            }
            catch (Exception ex)
            {
                //
            }
            return(polygon);
        }
Esempio n. 58
0
        /// <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);
        }
Esempio n. 59
0
        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();
        }
Esempio n. 60
0
        /// <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);
        }