/// <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);
        }
        public void GetElevations(ESRI.ArcGIS.Client.Geometry.Polyline p)
        {
            string jsonGeometries = SerializePolyline(p);
            string opParams       = string.Format(System.Globalization.CultureInfo.InvariantCulture, "geometries={0}&f=json", jsonGeometries);

            this.invokeOperation("GetElevations", opParams, this._GetElevationsHandler);
        }
        void GeometryService_GeneralizeCompleted(object sender, GraphicsEventArgs e)
        {
            GraphicsLayer generalizedGraphicsLayer = MyMap.Layers["GeneralizedLineGraphicsLayer"] as GraphicsLayer;

            generalizedGraphicsLayer.ClearGraphics();

            foreach (Graphic g in e.Results)
            {
                g.Symbol = LayoutRoot.Resources["NewLineSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
                generalizedGraphicsLayer.Graphics.Add(g);

                ESRI.ArcGIS.Client.Geometry.Polyline p = g.Geometry as ESRI.ArcGIS.Client.Geometry.Polyline;

                foreach (ESRI.ArcGIS.Client.Geometry.PointCollection pc in p.Paths)
                {
                    foreach (MapPoint point in pc)
                    {
                        Graphic vertice = new Graphic()
                        {
                            Symbol   = LayoutRoot.Resources["NewMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol,
                            Geometry = point
                        };
                        generalizedGraphicsLayer.Graphics.Add(vertice);
                    }
                }
            }
            generalizedGraphicsLayer.Opacity = 0.75;
            SliderStackPanel.Visibility      = Visibility.Visible;
            GeneralizeButton.IsEnabled       = true;
        }
Esempio n. 4
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. 5
0
        private void MyDrawObject_DrawComplete(object sender, DrawEventArgs args)
        {
            MyDrawObject.IsEnabled = false;
            ESRI.ArcGIS.Client.Geometry.Polyline polyline = args.Geometry as ESRI.ArcGIS.Client.Geometry.Polyline;
            polyline.SpatialReference = MyMap.SpatialReference;

            Graphic polylineGraphic = new Graphic()
            {
                Geometry = polyline
            };
            List <Graphic> polylineList = new List <Graphic>();

            polylineList.Add(polylineGraphic);

            GeometryService geometryService =
                new GeometryService("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");

            geometryService.AutoCompleteCompleted += GeometryService_AutoCompleteCompleted;
            geometryService.Failed += GeometryService_Failed;

            GraphicsLayer  graphicsLayer = MyMap.Layers["ParcelsGraphicsLayer"] as GraphicsLayer;
            List <Graphic> polygonList   = new List <Graphic>();

            foreach (Graphic g in graphicsLayer.Graphics)
            {
                g.Geometry.SpatialReference = MyMap.SpatialReference;
                polygonList.Add(g);
            }

            geometryService.AutoCompleteAsync(polygonList, polylineList);
        }
Esempio n. 6
0
        /// <summary>
        /// Method converts ESRI ArcGIS Polyline object to ESRI ArcLogistics Polyline object.
        /// </summary>
        /// <param name="polyline">Polyline to convert.</param>
        /// <returns>ESRI ArcLogistics Polyline object.</returns>
        private ESRI.ArcLogistics.Geometry.Polyline _ConvertToArcLogisticsPolyline(
            ESRISDSGeometry.Polyline polyline)
        {
            Debug.Assert(polyline != null);

            var groups = new List <int>();
            var points = new List <ESRI.ArcLogistics.Geometry.Point>();

            for (int i = 0; i < polyline.Paths.Count; i++)
            {
                // Fill current group by count of Points in it.
                groups.Add(polyline.Paths[i].Count);

                var collection = polyline.Paths[i];

                // Get all points.
                foreach (var point in collection)
                {
                    points.Add(_ConvertToArcLogisticsPoint(point));
                }
            }

            var newPolyline = new ESRI.ArcLogistics.Geometry.Polyline(
                groups.ToArray(), points.ToArray());

            return(newPolyline);
        }
        private string SerializePolyline(ESRI.ArcGIS.Client.Geometry.Polyline p)
        {
            _length = ESRI.ArcGIS.Client.Geometry.Euclidian.Length(p) * 0.000621371192;

            string s = @"[{""spatialreference"":{""wkid"":";

            if (p.SpatialReference != null)
            {
                s = s + p.SpatialReference.WKID + "},";
            }

            s = s + "\"hasZ\":" + p.HasZ + ",";
            s = s + "\"hasM\":" + p.HasM + ",";
            s = s + "\"paths\":[[";

            for (int i = 0; i < p.Paths.Count; i++)
            {
                ESRI.ArcGIS.Client.Geometry.PointCollection path = p.Paths[i];
                foreach (MapPoint c in path)
                {
                    s = s + "[" + c.X + "," + c.Y + "],";
                }
            }
            s = s + "]]}]";

            return(s);
        }
        private void Route_Complete(object sender, CalculateRouteCompletedEventArgs args)
        {
            myDrawObject.IsEnabled = true;
            routeResultsGraphicsLayer.ClearGraphics();
            waypointGraphicsLayer.ClearGraphics();

            StringBuilder directions = new StringBuilder();

            ObservableCollection <RouteLeg> routeLegs = args.Result.Result.Legs;
            int numLegs          = routeLegs.Count;
            int instructionCount = 0;

            for (int n = 0; n < numLegs; n++)
            {
                if ((n % 2) == 0)
                {
                    AddStopPoint(ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(routeLegs[n].ActualStart.Longitude, routeLegs[n].ActualStart.Latitude)));
                    AddStopPoint(ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(routeLegs[n].ActualEnd.Longitude, routeLegs[n].ActualEnd.Latitude)));
                }
                else if (n == (numLegs - 1))
                {
                    AddStopPoint(ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(routeLegs[n].ActualEnd.Longitude, routeLegs[n].ActualEnd.Latitude)));
                }

                directions.Append(string.Format("--Leg #{0}--\n", n + 1));

                foreach (ItineraryItem item in routeLegs[n].Itinerary)
                {
                    instructionCount++;
                    directions.Append(string.Format("{0}. {1}\n", instructionCount, item.Text));
                }
            }

            Regex regex = new Regex("<[/a-zA-Z:]*>",
                                    RegexOptions.IgnoreCase | RegexOptions.Multiline);

            DirectionsContentTextBlock.Text = regex.Replace(directions.ToString(), string.Empty);
            DirectionsGrid.Visibility       = Visibility.Visible;

            RoutePath routePath = args.Result.Result.RoutePath;

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

            line.Paths.Add(new ESRI.ArcGIS.Client.Geometry.PointCollection());

            foreach (ESRI.ArcGIS.Client.Bing.RouteService.Location location in routePath.Points)
            {
                line.Paths[0].Add(ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(location.Longitude, location.Latitude)));
            }

            Graphic graphic = new Graphic()
            {
                Geometry = line,
                Symbol   = LayoutRoot.Resources["RoutePathSymbol"] as Symbol
            };

            routeResultsGraphicsLayer.Graphics.Add(graphic);
        }
        private void AddLineGraphics()
        {
            string geoRSSLine = @"<?xml version='1.0' encoding='utf-8'?>
                                    <feed xmlns='http://www.w3.org/2005/Atom' xmlns:georss='http://www.georss.org/georss'>
                                    <georss:line>-118.169, 34.016, -104.941, 39.7072, -96.724, 32.732</georss:line>
                                    <georss:line>-28.69, 14.16, -14.91, 23.702, -1.74, 13.72</georss:line>
                                </feed>";

            List<ESRI.ArcGIS.Client.Geometry.Polyline> polylineList = new List<ESRI.ArcGIS.Client.Geometry.Polyline>();

            using (System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(new System.IO.StringReader(geoRSSLine)))
            {
                while (xmlReader.Read())
                {
                    switch (xmlReader.NodeType)
                    {
                        case System.Xml.XmlNodeType.Element:
                            string nodeName = xmlReader.Name;
                            if (nodeName == "georss:line")
                            {
                                string lineString = xmlReader.ReadElementContentAsString();

                                string[] lineCoords = lineString.Split(',');

                                ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection();
                                for (int i = 0; i < lineCoords.Length; i += 2)
                                {
                                    MapPoint mp = new MapPoint(Convert.ToDouble(lineCoords[i]), Convert.ToDouble(lineCoords[i + 1]));
                                    MapPoint conv_mp = wm.FromGeographic(mp) as MapPoint;
                                    pointCollection.Add(conv_mp);
                                }

                                ESRI.ArcGIS.Client.Geometry.Polyline polyline = new ESRI.ArcGIS.Client.Geometry.Polyline();
                                polyline.Paths.Add(pointCollection);

                                polylineList.Add(polyline);

                            }
                            break;
                    }
                }
            }

            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;

            foreach (ESRI.ArcGIS.Client.Geometry.Polyline polyline in polylineList)
            {
                Graphic graphic = new Graphic()
                {
                    Symbol = DefaultLineSymbol,
                    Geometry = polyline
                };

                graphicsLayer.Graphics.Add(graphic);
            }
        }
        private void ClearButton_Click(object sender, EventArgs e)
        {
            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;

            graphicsLayer.ClearGraphics();
            _polyline = null;

            ((ApplicationBarIconButton)ApplicationBar.Buttons[0]).IsEnabled = false; // clear
            ((ApplicationBarIconButton)ApplicationBar.Buttons[1]).IsEnabled = false; // show graph
        }
Esempio n. 11
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);
            }
        }
Esempio n. 12
0
        public static ESRI.ArcGIS.Client.Geometry.Polyline LoadTrack( trksegTypeCollection trksegs )
        {
            trksegs.RequireArgument<trksegTypeCollection>( "trksegs" ).NotNull<trksegTypeCollection>();

            ESRI.ArcGIS.Client.Geometry.Polyline line = new ESRI.ArcGIS.Client.Geometry.Polyline();
            line.Paths = new ObservableCollection<ESRI.ArcGIS.Client.Geometry.PointCollection>();
            foreach( var trkseg in trksegs )
            {
                line.Paths.Add( LoadTrackSegment( trkseg.trkpt ) );
            }

            return line;
        }
        /// <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. 14
0
        private void MyDrawObject_DrawComplete(object sender, DrawEventArgs args)
        {
            MyDrawObject.IsEnabled = false;

            if (MyDrawObject.DrawMode == DrawMode.Point)
            {
                ESRI.ArcGIS.Client.Geometry.MapPoint point = args.Geometry as ESRI.ArcGIS.Client.Geometry.MapPoint;
                point.SpatialReference = MyMap.SpatialReference;
                System.Windows.Point screenPnt = MyMap.MapToScreen(point);

                // Account for difference between Map and application origin
                GeneralTransform     generalTransform   = MyMap.TransformToVisual(null);
                System.Windows.Point transformScreenPnt = generalTransform.Transform(screenPnt);

                IEnumerable <Graphic> selected =
                    parcelGraphicsLayer.FindGraphicsInHostCoordinates(transformScreenPnt);

                if (selected.ToArray().Length <= 0)
                {
                    MyDrawObject.IsEnabled = true;
                    return;
                }

                selectedGraphic = selected.ToList()[0] as Graphic;

                selectedGraphic.Select();

                MyDrawObject.DrawMode  = DrawMode.Polyline;
                MyDrawObject.IsEnabled = true;

                InfoTextBlock.Text = LayoutRoot.Resources["EndText"] as string;
            }
            else
            {
                ESRI.ArcGIS.Client.Geometry.Polyline polyline = args.Geometry as ESRI.ArcGIS.Client.Geometry.Polyline;
                polyline.SpatialReference = MyMap.SpatialReference;

                GeometryService geometryService =
                    new GeometryService("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");

                geometryService.ReshapeCompleted += GeometryService_ReshapeCompleted;
                geometryService.Failed           += GeometryService_Failed;

                geometryService.ReshapeAsync(selectedGraphic.Geometry, polyline);
            }
        }
        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 MyDrawObject_DrawComplete(object sender, ESRI.ArcGIS.Client.DrawEventArgs args)
        {
            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;

            ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
            {
                Geometry = args.Geometry,
                Symbol   = _activeSymbol,
            };
            graphicsLayer.Graphics.Add(graphic);

            if (args.Geometry is ESRI.ArcGIS.Client.Geometry.Polyline)
            {
                _polyline = args.Geometry as ESRI.ArcGIS.Client.Geometry.Polyline;
            }

            ((ApplicationBarIconButton)ApplicationBar.Buttons[0]).IsEnabled = true; // clear
            ((ApplicationBarIconButton)ApplicationBar.Buttons[1]).IsEnabled = true; // show graph
        }
Esempio n. 17
0
        //When the Draw Line button is clicked:
        //The skecth (a polyline graphic) will be created and will be added to the sketch layer
        //The sketch layer will be added to the map for display
        //2 map events will be registered for user's interaction
        private void AddGraphics_Click(object sender, RoutedEventArgs e)
        {
            //Take the first map widget from the view
            MapWidget mapWidget = OperationsDashboard.Instance.Widgets.First(w => w.GetType() == typeof(MapWidget)) as MapWidget;

            if (mapWidget == null || mapWidget.Map == null)
            {
                return;
            }

            MapWidget = mapWidget;
            client.Map map = MapWidget.Map;

            //First, remove any existing graphic layer on the map
            RemoveAllGraphicLayers();

            //Create the geometry (a polyline) for the sketch
            sketchGeometry = new client.Geometry.Polyline();
            sketchGeometry.SpatialReference = map.SpatialReference;
            sketchGeometry.Paths.Add(new client.Geometry.PointCollection());

            //Create the sketch with the geometry and a symbol
            client.Graphic sketch = new client.Graphic()
            {
                Symbol   = SimplePolylineSymbol.CreateLineSymbol(),
                Geometry = sketchGeometry,
            };

            //Add the sketch to the map sketch layer
            //mapSketchLyr.Graphics.Clear();
            mapSketchLyr.Graphics.Add(sketch);

            //Add the sketch layer back to the map
            map.Layers.Add(mapSketchLyr);

            //Register mouse click i.e. sketch begins
            //Register mouse double click i.e. sketch finishes
            map.MouseClick       += map_MouseClick;
            map.MouseDoubleClick += map_MouseDoubleClick;
            map.MouseMove        += map_MouseMove;
        }
Esempio n. 18
0
        //Add a map point (from mouse click) to the geometry of the sketch
        //Create a temporary graphic to trace user's mouse movement
        void map_MouseClick(object sender, client.Map.MouseEventArgs e)
        {
            sketchGeometry.Paths[0].Add(e.MapPoint);


            //feedback layer
            feedBackLyr.Graphics.Clear();

            client.Map map = MapWidget.Map;

            #region Create a temporary graphic to trace user's mouse movement
            //Create a point collection using the last clicked point and the latest mouse position
            PointCollection pc = new PointCollection();
            pc.Add(sketchGeometry.Paths[0].Last());
            pc.Add(new MapPoint());

            //Create the geometry of the feedback line using the point collection
            client.Geometry.Polyline feedbackGeomrtry = new client.Geometry.Polyline();
            feedbackGeomrtry.SpatialReference = map.SpatialReference;
            feedbackGeomrtry.Paths.Add(pc);

            //Create the feedback line with the geometry and a symbol
            client.Graphic feedback = new client.Graphic()
            {
                Symbol   = SimplePolylineSymbol.CreateLineSymbol(),
                Geometry = feedbackGeomrtry,
            };
            #endregion

            //Add the feedback line to the feedback layer
            feedBackLyr.Graphics.Add(feedback);

            //Add the layer to the map if we haevn't done so
            if (!map.Layers.Contains(feedBackLyr))
            {
                map.Layers.Add(feedBackLyr);
            }
        }
        private ESRI.ArcGIS.Client.Geometry.Geometry getGeometry(string geometrytype)
        {
            switch (geometrytype)
            {
            case "Point":
                var point = new MapPoint(-16584535.1432908, 8580553.67499035);
                return(point);

            case "Polyline":
            {
                string coordinatestring = "-16584535.1432908,8580553.67499035 -16583535.1432908,8585553.67499035 -16580535.1432908,8575553.67499035";
                var    pointcollection  = new PointCollectionConverter().ConvertFromString(coordinatestring) as ESRI.ArcGIS.Client.Geometry.PointCollection;
                var    polygon          = new ESRI.ArcGIS.Client.Geometry.Polyline();
                polygon.Paths.Add(pointcollection);
                return(polygon);
            }

            case "Polygon":
            {
                string coordinatestring = "-16584535.1432908,8580553.67499035 -16583535.1432908,8585553.67499035 -16580535.1432908,8575553.67499035 -16584515.1432908,8580555.67499035 -16584535.1432908,8580553.67499035";
                var    pointcollection  = new PointCollectionConverter().ConvertFromString(coordinatestring) as ESRI.ArcGIS.Client.Geometry.PointCollection;
                var    polygon          = new ESRI.ArcGIS.Client.Geometry.Polygon();
                polygon.Rings.Add(pointcollection);
                return(polygon);
            }

            case "Multipoint":
                return(null);

            case "Envelope":
                return(null);

            default:
                return(null);
            }
        }
Esempio n. 20
0
 private ESRI.ArcGIS.Client.Geometry.Geometry getGeometry(string geometrytype)
 {
     switch (geometrytype)
     {
         case "Point":
             var point = new MapPoint(-16584535.1432908, 8580553.67499035);
             return point;
         case "Polyline":
             {
                 string coordinatestring = "-16584535.1432908,8580553.67499035 -16583535.1432908,8585553.67499035 -16580535.1432908,8575553.67499035";
                 var pointcollection = new PointCollectionConverter().ConvertFromString(coordinatestring) as ESRI.ArcGIS.Client.Geometry.PointCollection;
                 var polygon = new ESRI.ArcGIS.Client.Geometry.Polyline();
                 polygon.Paths.Add(pointcollection);
                 return polygon;
             }
         case "Polygon":
             {
                 string coordinatestring = "-16584535.1432908,8580553.67499035 -16583535.1432908,8585553.67499035 -16580535.1432908,8575553.67499035 -16584515.1432908,8580555.67499035 -16584535.1432908,8580553.67499035";
                 var pointcollection = new PointCollectionConverter().ConvertFromString(coordinatestring) as ESRI.ArcGIS.Client.Geometry.PointCollection;
                 var polygon = new ESRI.ArcGIS.Client.Geometry.Polygon();
                 polygon.Rings.Add(pointcollection);
                 return polygon;
             }
         case "Multipoint":
             return null;
         case "Envelope":
             return null;
         default:
             return null;
     }
 }
Esempio n. 21
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;
        }
        /// <summary>
        /// Extracts a polyline from the input element and applies style information to the placemark descriptor.
        /// </summary>
        /// <param name="kmlStyle">KML Style information.</param>
        /// <param name="line">Polyline geometry information.</param>
		/// <returns>A PlacemarkDescriptor object representing the feature.</returns>
        private static PlacemarkDescriptor ExtractPolyLine(KMLStyle kmlStyle, XElement line)
        {
			XNamespace kmlNS = line.Name.Namespace;
			XElement coord = line.Element(kmlNS + "coordinates");
            if (coord != null)
            {
                // Extract coordinates and build geometry
                ESRI.ArcGIS.Client.Geometry.PointCollection pts = ExtractCoordinates(coord);
                if (pts != null && pts.Count > 0)
                {
                    ESRI.ArcGIS.Client.Geometry.Polyline polyline = new ESRI.ArcGIS.Client.Geometry.Polyline();
                    polyline.Paths.Add(pts);

                    // Create symbol and use style information
                    LineSymbolDescriptor sym = new LineSymbolDescriptor();
                    sym.style = kmlStyle;

                    // Create feature descriptor from geometry and other information
                    return new PlacemarkDescriptor()
                    {
                        Geometry = polyline,
                        Symbol = sym
                    };
                }
            }

            return null;
        }
Esempio n. 23
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);
        }
        private void MyDrawObject_DrawComplete(object sender, ESRI.ArcGIS.Client.DrawEventArgs args)
        {
            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
            ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
            {
                Geometry = args.Geometry,
                Symbol = _activeSymbol,
            };
            graphicsLayer.Graphics.Add(graphic);

            if (args.Geometry is ESRI.ArcGIS.Client.Geometry.Polyline)
                _polyline = args.Geometry as ESRI.ArcGIS.Client.Geometry.Polyline;

            ((ApplicationBarIconButton)ApplicationBar.Buttons[0]).IsEnabled = true; // clear
            ((ApplicationBarIconButton)ApplicationBar.Buttons[1]).IsEnabled = true; // show graph
        }
        private void ClearButton_Click(object sender, EventArgs e)
        {
            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
            graphicsLayer.ClearGraphics();
            _polyline = null;

            ((ApplicationBarIconButton)ApplicationBar.Buttons[0]).IsEnabled = false; // clear
            ((ApplicationBarIconButton)ApplicationBar.Buttons[1]).IsEnabled = false; // show graph
        }
Esempio n. 26
0
        async void _myDrawObject_DrawComplete(object sender, DrawEventArgs e)
        {
            if (e.Geometry == null)
            {
                ChartContainer.Visibility = System.Windows.Visibility.Collapsed;
                return;
            }

            try
            {
                _myDrawObject.IsEnabled = false;

                this.Cursor = Cursors.Wait;

                _lineGraphicLayer.Graphics[0].Geometry = e.Geometry;

                if (_cts != null)
                {
                    _cts.Cancel();
                }

                _cts = new CancellationTokenSource();

                Geoprocessor geoprocessorTask = new Geoprocessor(
                    "http://elevation.arcgis.com/arcgis/rest/services/Tools/ElevationSync/GPServer/Profile");

                List <GPParameter> parameters = new List <GPParameter>();
                parameters.Add(new GPFeatureRecordSetLayer("InputLineFeatures", e.Geometry));
                parameters.Add(new GPString("returnM", "true"));
                parameters.Add(new GPString("returnZ", "true"));

                GPExecuteResults results = await geoprocessorTask.ExecuteTaskAsync(parameters, _cts.Token);

                if (results == null || results.OutParameters.Count == 0 || (results.OutParameters[0] as GPFeatureRecordSetLayer).FeatureSet.Features.Count == 0)
                {
                    MessageBox.Show("Fail to get elevation data. Draw another line");
                    return;
                }

                ESRI.ArcGIS.Client.Geometry.Polyline elevationLine =
                    (results.OutParameters[0] as GPFeatureRecordSetLayer).FeatureSet.Features[0].Geometry
                    as ESRI.ArcGIS.Client.Geometry.Polyline;

                foreach (MapPoint p in elevationLine.Paths[0])
                {
                    p.M = Math.Round(p.M / 1000, 2);
                    p.Z = Math.Round(p.Z, 2);
                }

                MapPoint lastPoint = elevationLine.Paths[0][elevationLine.Paths[0].Count - 1];

                lblDistance.Text = string.Format("Total Distance {0} Kilometers", lastPoint.M.ToString());

                (ElevationChart.Series[0] as LineSeries).ItemsSource = elevationLine.Paths[0];

                ChartContainer.Visibility = System.Windows.Visibility.Visible;
            }
            catch (Exception ex)
            {
                if (ex is ServiceException)
                {
                    MessageBox.Show(String.Format("{0}: {1}", (ex as ServiceException).Code.ToString(),
                                                  (ex as ServiceException).Details[0]), "Error", MessageBoxButton.OK);
                    return;
                }
            }
            finally
            {
                this.Cursor = Cursors.Arrow;
            }
        }
Esempio n. 27
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. 28
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);
            }
        }
        /// <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. 30
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. 31
0
        internal void UpdateLine(GoogleDirections gd)
        {
            Execute.OnUIThread(() =>
            {
                var m = new WebMercator();

                var ps = DecodeLatLong(gd.Directions.Polyline.points);

                var pl = new ESRI.ArcGIS.Client.Geometry.Polyline {Paths = new ObservableCollection<PointCollection>()};
                var pc = new PointCollection();
                foreach (var p in ps)
                {
                    pc.Add((MapPoint) m.FromGeographic(new MapPoint(p.Longitude, p.Latitude)));
                }

                pl.Paths.Add(pc);
                _line.Geometry = pl;
                _line.SetZIndex(0);
            });
        }
        private void Route_Complete(object sender, CalculateRouteCompletedEventArgs args)
        {
            myDrawObject.IsEnabled = true;
            routeResultsGraphicsLayer.ClearGraphics();
            waypointGraphicsLayer.ClearGraphics();

            StringBuilder directions = new StringBuilder();

            ObservableCollection<RouteLeg> routeLegs = args.Result.Result.Legs;
            int numLegs = routeLegs.Count;
            int instructionCount = 0;
            for (int n = 0; n < numLegs; n++)
            {
                if ((n % 2) == 0)
                {
                    AddStopPoint(ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(routeLegs[n].ActualStart.Longitude, routeLegs[n].ActualStart.Latitude)));
                    AddStopPoint(ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(routeLegs[n].ActualEnd.Longitude, routeLegs[n].ActualEnd.Latitude)));
                }
                else if (n == (numLegs - 1))
                {
                    AddStopPoint(ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(routeLegs[n].ActualEnd.Longitude, routeLegs[n].ActualEnd.Latitude)));
                }

                directions.Append(string.Format("--Leg #{0}--\n", n + 1));

                foreach (ItineraryItem item in routeLegs[n].Itinerary)
                {
                    instructionCount++;
                    directions.Append(string.Format("{0}. {1}\n", instructionCount, item.Text));
                }
            }

            Regex regex = new Regex("<[/a-zA-Z:]*>",
                RegexOptions.IgnoreCase | RegexOptions.Multiline);

            DirectionsContentTextBlock.Text = regex.Replace(directions.ToString(), string.Empty);
            DirectionsGrid.Visibility = Visibility.Visible;

            RoutePath routePath = args.Result.Result.RoutePath;

            Polyline line = new ESRI.ArcGIS.Client.Geometry.Polyline();
            line.Paths.Add(new ESRI.ArcGIS.Client.Geometry.PointCollection());

            foreach (ESRI.ArcGIS.Client.Bing.RouteService.Location location in routePath.Points)
                line.Paths[0].Add(ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(location.Longitude, location.Latitude)));

            Graphic graphic = new Graphic()
            {
                Geometry = line,
                Symbol = LayoutRoot.Resources["RoutePathSymbol"] as Symbol
            };
            routeResultsGraphicsLayer.Graphics.Add(graphic);
        }
        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;
        }
 /// <summary>
 /// Create needed polyline.
 /// </summary>
 /// <param name="route">Route.</param>
 private void _CreatePolyline(Route route)
 {
     if (route.Stops.Count != 0)
     {
         // Create True route or straight polyline depends on map display settings.
         if (App.Current.MapDisplay.TrueRoute)
         {
             _routeLine = _CreateTruePolyline(route);
         }
         else
         {
             _routeLine = _CreateStraightPolyline(route);
         }
     }
 }
Esempio n. 35
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;
        }
Esempio n. 36
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);
        }
Esempio n. 37
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;
        }
        /// <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;
        }