Exemplo n.º 1
0
 public MapServices(Map map, Uri uri)
 {
     _routeLayer = new MapShapeLayer();
     _mapTrucks  = map;
     _mapTrucks.ShapeLayers.Add(_routeLayer);
     _baseUri = uri;
 }
Exemplo n.º 2
0
        public override async void MapViewTapped(MapView mapView, MapViewInputEventArgs e, bool drawing)
        {
            if (!drawing)
            {
                var graphic = await GraphicsLayer.HitTestAsync(mapView, e.Position);

                if (graphic != null)
                {
                    OnItemTapped(int.Parse($"{graphic.Attributes[CURR_GEO]}"));
                }
                return;
            }

            MapPoint newPoint = (MapPoint)GeometryEngine.Project(e.Location, SpatialReferences.Wgs84);

            if (_drawPointList.Count == 0)
            {
                AddGraphic(newPoint, DRAFT, MapShapeLayer.GetSymbol(GeoMarkerType.Point, GeoStatus.Hilight));
            }
            else
            {
                Polyline line = new Polyline(new MapPoint[] { _drawPointList.Last(), newPoint });
                AddGraphic(line, DRAFT, MapShapeLayer.GetSymbol(GeoMarkerType.Line, GeoStatus.Hilight));
            }

            _drawPointList.Add(newPoint);
        }
Exemplo n.º 3
0
        private void AddGeofenceToMap([NotNull] Geofence fence)
        {
            if (fence == null)
            {
                throw new ArgumentNullException("fence");
            }

            var geocircle = (Geocircle)fence.Geoshape;
            var circle    = new MapPolygon
            {
                FillColor = Color.FromArgb(128, 0, 0, 255),
                Locations = GetCircleLocations(geocircle.Center, geocircle.Radius)
            };

            // Get the first shape layer for the circles, or add a new one to accomodate
            var shapeLayer = ExampleMap.ShapeLayers.FirstOrDefault();

            if (shapeLayer == null)
            {
                shapeLayer = new MapShapeLayer();
                ExampleMap.ShapeLayers.Add(shapeLayer);
            }
            shapeLayer.Shapes.Add(circle);

            var pushpin = new Pushpin();

            pushpin.Tapped += (sender, args) => ShowPinMessage(fence);

            MapLayer.SetPosition(pushpin, new Location(geocircle.Center.Latitude, geocircle.Center.Longitude));
            ExampleMap.Children.Add(pushpin);

            _mapFenceElements.Add(fence.Id, new MapElements {
                Circle = circle, Pin = pushpin
            });
        }
Exemplo n.º 4
0
 public void Remove(MapShapeLayer routeLayer)
 {
     if (routeLayer.Shapes.Count > 0)
     {
         routeLayer.Shapes.RemoveAt(0);
     }
 }
Exemplo n.º 5
0
 public void RemoveItineraries(MapShapeLayer _routeLayer)
 {
     foreach (Itinerary _itinerary in Itineraries)
     {
         _itinerary.Remove(_routeLayer);
     }
 }
Exemplo n.º 6
0
 public MapServices(Map map, Uri uri)
 {
   _routeLayer = new MapShapeLayer();
   _mapTrucks = map;
   _mapTrucks.ShapeLayers.Add(_routeLayer);
   _baseUri = uri;
 }
Exemplo n.º 7
0
        /// <summary>
        /// Show advised route from player's initial location to spear's landing location.
        /// </summary>
        public static void DrawThrownRoute()
        {
            try
            {
                MapPolyline routeLine = new MapPolyline();
                routeLine.Locations = new LocationCollection();
                routeLine.Color     = Windows.UI.Colors.Red;
                routeLine.Width     = 5.0;

                routeLine.Locations.Add(new Location
                {
                    Latitude  = SatanController.CurrentPlayer.Location.Latitude,
                    Longitude = SatanController.CurrentPlayer.Location.Longitude
                });
                routeLine.Locations.Add(new Location
                {
                    Latitude  = SpearHandler.Gungnir.Location.Latitude,
                    Longitude = SpearHandler.Gungnir.Location.Longitude
                });
                MapShapeLayer shapeLayer = new MapShapeLayer();
                shapeLayer.Shapes.Add(routeLine);
//                Map.ShapeLayers.Add(shapeLayer);
            }
            catch
            {
                //Message dialog, description + Title
                SatanController.ShowMessage("Something went wrong with drawing the route to the spear.", "Error");
            }
        }
        public BingMapsView()
        {
            this.InitializeComponent();

            routeLayer = new MapShapeLayer();
            MyMap.ShapeLayers.Add(routeLayer);
        }
Exemplo n.º 9
0
        public MainPage()
        {
            this.InitializeComponent();

            shapeLayer = new MapShapeLayer();
            MyMap.ShapeLayers.Add(shapeLayer);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Change the polylines on the map.
        /// </summary>
        private static void ShapesChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
        {
            MapControl mapControl = (MapControl)dependencyObject;

            if (args.OldValue != null)
            {
                // remove all old polylines from the map:
                mapControl.map.ShapeLayers.Clear();
            }

            if (args.NewValue != null)
            {
                MapShapeLayer routeLayer = new MapShapeLayer();

                List <Shape> shapes = (List <Shape>)args.NewValue;
                foreach (var shape in shapes)
                {
                    MapPolyline polyline = new MapPolyline();
                    polyline.Color = Color.FromArgb(255, 0x4f, 0x64, 0xba);
                    polyline.Width = 6;

                    LocationCollection locations = new LocationCollection();
                    foreach (var point in shape.Points)
                    {
                        locations.Add(new Location(point.Latitude, point.Longitude));
                    }

                    polyline.Locations = locations;
                    routeLayer.Shapes.Add(polyline);
                }

                mapControl.map.ShapeLayers.Add(routeLayer);
            }
        }
Exemplo n.º 11
0
 public void DisplayItineraries(MapShapeLayer _routeLayer, Boolean _lowPerfo)
 {
     RemoveItineraries(_routeLayer);
     foreach (Itinerary _itinerary in Itineraries)
     {
         _itinerary.Display(_routeLayer, _lowPerfo);
     }
 }
 void MyMap_Tapped(object sender, TappedRoutedEventArgs e)
 {
     var pos = e.GetPosition(MyMap);
     Bing.Maps.Location location = new Bing.Maps.Location();
     miniTockeShapeLayer = new MapShapeLayer();
     MyMap.TryPixelToLocation(pos, out location);
     GetAddressByLocation(location);
     locationCollection.Add(location);
 }
Exemplo n.º 13
0
        /// <summary>
        /// Selects the desired style, provided the <see cref="MapShapeLayer"/> instance, containing the shape.
        /// </summary>
        /// <param name="context">The context, associated with each shape.</param>
        /// <param name="container">The <see cref="MapShapeLayer"/> instance.</param>
        public void SelectStyle(MapShapeStyleContext context, MapShapeLayer container)
        {
            if (context == null || container == null)
            {
                return;
            }

            this.SelectStyleCore(context, container);
        }
        private void btnClear_Click(object sender, RoutedEventArgs e)
        {
            //Get a reference to our overlay that has the test data in it.
            LayerOverlay layerOverlay = (LayerOverlay)mapView.Overlays["layerOverlay"];
            //Get a refrence to the results MapShapeLayer and clear out any prior results if they exist.
            MapShapeLayer results = (MapShapeLayer)layerOverlay.Layers["Results"];

            results.MapShapes.Clear();
            mapView.Refresh();
        }
Exemplo n.º 15
0
        // Delegate methods
        internal PolylineManager(Map map)
        {
            this.map = map;

            polylines = new Dictionary<IMapPolyline, MapPolyline>();

            // Layer to hold the polylines
            polylinesLayer = new MapShapeLayer();
            map.ShapeLayers.Add(polylinesLayer);
        }
Exemplo n.º 16
0
 /// <summary>
 /// Apply a single style to all shapes in a MapShapeLayer.
 /// </summary>
 /// <param name="polyLayer">MapShapeLayer to apply style to.</param>
 /// <param name="style">Style to apply to layers.</param>
 public static void ApplyStyle(MapShapeLayer polyLayer, ShapeStyle style)
 {
     if (polyLayer != null)
     {
         foreach (var p in polyLayer.Shapes)
         {
             ApplyStyle(p, style);
         }
     }
 }
Exemplo n.º 17
0
        //Add the asynchronous GetDirections method to call the Routes Web API to get the
        // directions.The MapPolyline class is then used to draw the route of travel upon the map.
        async private void GetDirections(Location location)
        {
            try
            {
                this.WayPoints.Add(string.Format("{0}, {1}",
                                                 location.Latitude, location.Longitude));
                if (this.WayPoints.Count < 2)
                {
                    return;
                }
                HttpClient    client  = new HttpClient();
                StringBuilder builder = new StringBuilder("http://dev.virtualearth.net/REST/V1/Routes/Driving?o=xml&");
                for (int index = 0; index < this.WayPoints.Count; index++)
                {
                    builder.Append(
                        string.Format("wp.{0}={1}&", index, this.WayPoints[index]));
                }
                builder.Append("routePathOutput=Points&avoid=minimizeTolls&key=");
                builder.Append(this.BingMapsKey);
                HttpResponseMessage response = await client.GetAsync(builder.ToString());

                response.EnsureSuccessStatusCode();
                Stream stream = await response.Content.ReadAsStreamAsync();

                XDocument document = XDocument.Load(stream);
                var       query    = from p
                                     in document.Descendants(this.BingMapsNamespace + "Point")
                                     select new
                {
                    Latitude  = p.Element(this.BingMapsNamespace + "Latitude").Value,
                    Longitude = p.Element(this.BingMapsNamespace + "Longitude").Value
                };
                layer    = new MapShapeLayer();
                polyline = new MapPolyline();
                foreach (var point in query)
                {
                    double latitude, longitude;
                    double.TryParse(point.Latitude, out latitude);
                    double.TryParse(point.Longitude, out longitude);
                    polyline.Locations.Add(new Location(latitude, longitude));
                }
                polyline.Color = Colors.Red;
                polyline.Width = 5;
                layer.Shapes.Add(polyline);
                this.Map.ShapeLayers.Add(layer);
                var distance = (from d in document.Descendants(this.BingMapsNamespace + "TravelDistance")
                                select d).First().Value;
                this.txtDistance.Text =
                    string.Format("{0} KM", distance.ToString());
            }
            catch (Exception)
            {
                await ShowDialog("Destination distance cannot be resolved! Please Refresh the map");
            }
        }
Exemplo n.º 18
0
        public ucDrawShape(HMCon con, TUC_HMDevXManager.TUC_HMDevXManager hmDevMgr, WpfMapDrawBase map, MapShapeLayer layer, int layerIndex)
            : base(con, hmDevMgr, map)
        {
            InitializeComponent();

            _layer            = layer;
            _layerIndex       = layerIndex;
            gcAttr.DataSource = _attrTable;

            InDrawingStatus(false);
        }
Exemplo n.º 19
0
        private async void LoadMap()
        {
            this.BingMap.Credentials = this.BingAPIKey;
            this.BingMap.MapType = Bing.Maps.MapType.Road;

            // Add shape layer to the map
            this.shapeLayer = new MapShapeLayer();
            this.BingMap.ShapeLayers.Add(this.shapeLayer);
            await this.RefreshMap();
            this.DrawBuffer();
        }
Exemplo n.º 20
0
        public override void Init(IGeoInfo geo, bool isCur, List <Envelope> shapeList, List <MapPoint> pointList)
        {
            GraphicsLayer.Graphics.Clear();

            _polyList = geo.ConvertTo <ShapeGeoInfo>().Polygons ?? new Dictionary <int, Polygon>();
            foreach (var poly in _polyList)
            {
                AddGraphic(poly.Value, CURR_GEO, $"{poly.Key}", MapShapeLayer.GetSymbol(GeoMarkerType.Fill, isCur ? GeoStatus.Normal : GeoStatus.Reference));
                shapeList.Add(poly.Value.Extent);
            }
        }
Exemplo n.º 21
0
        private void MyMap_OnLoaded(object sender, RoutedEventArgs e)
        {
            var map           = (Bing.Maps.Map)sender;
            var mapShapeLayer = new MapShapeLayer();
            var polyLine      = new MapPolyline();

            var activities = map.Tag as List <Activity>;

            if (activities == null)
            {
                return;
            }

            var pinNumber = 0;

            foreach (var activity in activities
                     .GroupBy(x => x.Latitude + x.Longitude) //ignore dupe coordinates
                     .Select(g => g.First())
                     .OrderBy(x => x.Timestamp))
            {
                // ReSharper disable CompareOfFloatsByEqualityOperator
                if (activity.Latitude != 0 && activity.Longitude != 0)
                {
                    polyLine.Locations.Add(new Location(activity.Latitude, activity.Longitude));

                    pinNumber++;
                    var pin = new Pushpin();
                    pin.Text     = pinNumber.ToString();
                    pin.FontSize = 13; //this size works good for single or double digits

                    MapLayer.SetPosition(pin, new Location(activity.Latitude, activity.Longitude));
                    map.Children.Add(pin);
                }
                // ReSharper restore CompareOfFloatsByEqualityOperator
            }

            polyLine.Width = 3;
            mapShapeLayer.Shapes.Add(polyLine);
            map.ShapeLayers.Add(mapShapeLayer);

            //Calculate a bounding box for the route
            var t = activities.Where(x => x.Latitude != 0).Max(x => x.Latitude);
            var b = activities.Where(x => x.Latitude != 0).Min(x => x.Latitude);
            var l = activities.Where(x => x.Longitude != 0).Min(x => x.Longitude);
            var r = activities.Where(x => x.Longitude != 0).Max(x => x.Longitude);

            //Pad the box
            var latPad  = (t - b) * .3;
            var longPad = (r - l) * .3;

            map.SetView(new LocationRect(new Location(t + latPad, l - longPad), new Location(b - latPad, r + longPad)), MapAnimationDuration.None);
        }
        async private void GetDirections(Location location)
        {
            this.Waypoints.Add(string.Format("{0}, {1}", location.Latitude, location.Longitude));
            if (this.Waypoints.Count < 2)
            {
                return;
            }

            HttpClient    hC = new HttpClient();
            StringBuilder sB = new StringBuilder("http://dev.virtualearth.net/REST/V1/Routes/Driving?o=xml&");

            for (int index = 0; index < this.Waypoints.Count; index++)
            {
                sB.Append(
                    string.Format("wp.{0}={1}&", index, this.Waypoints[index]));
            }
            sB.Append("avoid=minimizeTolls&key=");
            sB.Append(this.BingMapsKey);
            HttpResponseMessage rM = await hC.GetAsync(sB.ToString());

            rM.EnsureSuccessStatusCode();
            Stream s = await rM.Content.ReadAsStreamAsync();

            XDocument dT    = XDocument.Load(s);
            var       query = from p
                              in dT.Descendants(this.BingMapsNamespace + "ManeuverPoint")
                              select new
            {
                Latitude  = p.Element(this.BingMapsNamespace + "Latitude").Value,
                Longitude = p.Element(this.BingMapsNamespace + "Longitude").Value
            };
            MapShapeLayer layer    = new MapShapeLayer();
            MapPolyline   polyline = new MapPolyline();

            foreach (var point in query)
            {
                double latitude, longitude;
                double.TryParse(point.Latitude, out latitude);
                double.TryParse(point.Longitude, out longitude);
                polyline.Locations.Add(new Location(latitude, longitude));
            }
            polyline.Color = Colors.Red;
            polyline.Width = 5;
            layer.Shapes.Add(polyline);
            this.MyMap.ShapeLayers.Add(layer);
            var distance = (from d in dT.Descendants
                                (this.BingMapsNamespace + "TravelDistance")
                            select d).First().Value;

            this.DistanceTextBlock.Text =
                string.Format("{0} Kms", distance.ToString());
        }
Exemplo n.º 23
0
        private async void LoadMap()
        {
            this.BingMap.RightTapped += this.BingMap_RightTapped;
            this.BingMap.Credentials  = "{enter-your-bing-maps-key-here}";
            this.BingMap.MapType      = Bing.Maps.MapType.Road;

            // Add shape layer to the map
            this.shapeLayer = new MapShapeLayer();
            this.BingMap.ShapeLayers.Add(this.shapeLayer);
            await this.RefreshMap();

            this.DrawBuffer();
        }
        public MainPage()
        {
            this.InitializeComponent();

            // Shapes are added to a MapShapeLayer.
            mShapeLayer = new MapShapeLayer();
            map.ShapeLayers.Add(mShapeLayer);

            // Pushpins are added to a MapLayer.
            mPinLayer = new MapLayer();
            map.Children.Add(mPinLayer);

            mPolyShapeLocations = new LocationCollection();
        }
Exemplo n.º 25
0
        private MapShapeLayer CreateMapShapeLayer(Location startLocation, Location endLocation)
        {
            MapShapeLayer shapeLayer = new MapShapeLayer();
            MapPolyline polyline = new MapPolyline();

            polyline.Locations = new LocationCollection { startLocation, endLocation };
            polyline.Color = Color.FromArgb(255,255,120,56);
            polyline.Width = 10;

            shapeLayer.Shapes.Add(polyline);
            mainMap.ShapeLayers.Add(shapeLayer);

            return shapeLayer;
        }
        private void DrawBusRoute()
        {
            if (goBusRouteCollection.Count == 0 && backBusRouteCollection.Count == 0)
            {
                return;
            }

            //Go Direction
            MapPolyline busGoRoutePolyLine = new MapPolyline();

            busGoRoutePolyLine.Locations = new LocationCollection();
            busGoRoutePolyLine.Color     = Colors.Red;
            busGoRoutePolyLine.Width     = 5;

            var tempLocations = new LocationCollection();

            foreach (LocationPointWithId locationPointWithId in goBusRouteCollection)
            {
                Location location = new Location(locationPointWithId.latitude, locationPointWithId.longitude);
                tempLocations.Add(location);
            }

            busGoRoutePolyLine.Locations = tempLocations;

            //Back Direction
            MapPolyline busBackRoutePolyLine = new MapPolyline();

            busBackRoutePolyLine.Locations = new LocationCollection();
            busBackRoutePolyLine.Color     = Colors.Blue;
            busBackRoutePolyLine.Width     = 5;

            var tempBackLocations = new LocationCollection();

            foreach (LocationPointWithId locationPointWithId in backBusRouteCollection)
            {
                Location location = new Location(locationPointWithId.latitude, locationPointWithId.longitude);
                tempBackLocations.Add(location);
            }

            busBackRoutePolyLine.Locations = tempBackLocations;

            MapShapeLayer busRouteShapeLayer = new MapShapeLayer();

            busRouteShapeLayer.Shapes.Add(busGoRoutePolyLine);
            busRouteShapeLayer.Shapes.Add(busBackRoutePolyLine);

            mapControl.ShapeLayers.Clear();
            mapControl.ShapeLayers.Add(busRouteShapeLayer);
        }
Exemplo n.º 27
0
        void InitializeMapData()
        {
            _geolocator = new Geolocator();
            FMobject = new FillModel();
            DMobject = new DataModel();
            POMobject = new PoliceOfficeModel();
            routeLayer = new MapShapeLayer();
            myMap.ShapeLayers.Add(routeLayer);
            FMobject.FillingModel();
            LV_POList.ItemsSource = FMobject.GovernrateList[0].POfficeList;

            var loc = new Bing.Maps.Location(29.837452, 31.362296);
            myMap.Center = loc;
            myMap.ZoomLevel = 6;
        }
        private void CreateButton_Click(object sender, RoutedEventArgs e)
        {
            if (locationCollection.Count > 0)
            {
                //ClearMap();

                MapShapeLayer shapeLayer = new MapShapeLayer();

                MapPolygon polygon = new MapPolygon();
                polygon.FillColor = Windows.UI.Colors.Blue;
                polygon.Locations = locationCollection;
                shapeLayer.Shapes.Add(polygon);
                MyMap.ShapeLayers.Add(shapeLayer);
            }
        }
Exemplo n.º 29
0
        public MapView()
        {
#if WINDOWS_APP
            _map = new Map();

            _shapeLayer = new MapShapeLayer();
            _pinLayer   = new MapLayer();
            _map.ShapeLayers.Add(_shapeLayer);
            _map.Children.Add(_pinLayer);
#elif WINDOWS_PHONE_APP
            _map = new MapControl();
#endif

            this.Children.Add(_map);
        }
Exemplo n.º 30
0
        async void loader_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (String.Equals(e.PropertyName, "ArmedFences") || String.Equals(e.PropertyName, "TriggerFence"))
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    List <Geofence> result = loader.ArmedFences;

                    // Add application fences
                    MapShapeLayer fences = new MapShapeLayer();
                    MapLayer pushpins    = new MapLayer();
                    foreach (Geofence f in result)
                    {
                        Geocircle c1      = f.Geoshape as Geocircle;
                        MapPolyline fence = new MapPolyline();
                        fence.Color       = Colors.Red;
                        fence.Width       = 5;
                        fence.Locations   = DrawMapsCircle(c1.Center, c1.Radius);
                        fences.Shapes.Add(fence);

                        Pushpin p    = new Pushpin();
                        p.Background = new SolidColorBrush(Colors.Red);
                        ToolTipService.SetToolTip(p, f.Id);
                        MapLayer.SetPosition(p, new Location(c1.Center.Latitude, c1.Center.Longitude));
                        pushpins.Children.Add(p);
                    }

                    // Add trigger fence
                    Geocircle c2        = loader.TriggerFence.Geoshape as Geocircle;
                    MapPolyline trigger = new MapPolyline();
                    trigger.Color       = Colors.Gray;
                    trigger.Width       = 5;
                    trigger.Locations   = DrawMapsCircle(c2.Center, c2.Radius);
                    fences.Shapes.Add(trigger);

                    myMap.ShapeLayers.Clear();
                    myMap.ShapeLayers.Add(fences);

                    // Clear existing pushpins
                    var existingLayers = myMap.Children.Where(c => c is MapLayer).ToArray();
                    for (int i = 0; i < existingLayers.Count(); i++)
                    {
                        myMap.Children.Remove(existingLayers[i]);
                    }
                    myMap.Children.Add(pushpins);
                });
            }
        }
Exemplo n.º 31
0
        async void loader_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (String.Equals(e.PropertyName, "ArmedFences") || String.Equals(e.PropertyName, "TriggerFence"))
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    List<Geofence> result = loader.ArmedFences;

                    // Add application fences
                    MapShapeLayer fences = new MapShapeLayer();
                    MapLayer pushpins = new MapLayer();
                    foreach (Geofence f in result)
                    {
                        Geocircle c1 = f.Geoshape as Geocircle;
                        MapPolyline fence = new MapPolyline();
                        fence.Color = Colors.Red;
                        fence.Width = 5;
                        fence.Locations = DrawMapsCircle(c1.Center, c1.Radius);
                        fences.Shapes.Add(fence);

                        Pushpin p = new Pushpin();
                        p.Background = new SolidColorBrush(Colors.Red);
                        ToolTipService.SetToolTip(p, f.Id);
                        MapLayer.SetPosition(p, new Location(c1.Center.Latitude, c1.Center.Longitude));
                        pushpins.Children.Add(p);
                    }

                    // Add trigger fence
                    Geocircle c2 = loader.TriggerFence.Geoshape as Geocircle;
                    MapPolyline trigger = new MapPolyline();
                    trigger.Color = Colors.Gray;
                    trigger.Width = 5;
                    trigger.Locations = DrawMapsCircle(c2.Center, c2.Radius);
                    fences.Shapes.Add(trigger);

                    myMap.ShapeLayers.Clear();
                    myMap.ShapeLayers.Add(fences);

                    // Clear existing pushpins
                    var existingLayers = myMap.Children.Where(c => c is MapLayer).ToArray();
                    for (int i = 0; i < existingLayers.Count(); i++)
                    {
                        myMap.Children.Remove(existingLayers[i]);
                    }
                    myMap.Children.Add(pushpins);
                });
            }
        }
Exemplo n.º 32
0
        private void TestForm_Load(object sender, EventArgs e)
        {
            winformsMap1.MapUnit       = GeographyUnit.DecimalDegree;
            winformsMap1.CurrentExtent = new RectangleShape(-96.8531, 33.1084, -96.8461, 33.106);
            winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 198, 255, 255));

            //Displays the World Map Kit as a background.
            ThinkGeo.MapSuite.DesktopEdition.WorldMapKitWmsDesktopOverlay worldMapKitDesktopOverlay = new ThinkGeo.MapSuite.DesktopEdition.WorldMapKitWmsDesktopOverlay();
            winformsMap1.Overlays.Add(worldMapKitDesktopOverlay);

            LineShape lineShape = new LineShape();

            lineShape.Vertices.Add(new Vertex(-96.8511, 33.1089));
            lineShape.Vertices.Add(new Vertex(-96.8504, 33.108));
            lineShape.Vertices.Add(new Vertex(-96.85, 33.1077));
            lineShape.Vertices.Add(new Vertex(-96.8498, 33.1076));
            lineShape.Vertices.Add(new Vertex(-96.8482, 33.1076));

            LineShape lineShape2 = new LineShape();

            lineShape2.Vertices.Add(new Vertex(-96.8497, 33.1084));
            lineShape2.Vertices.Add(new Vertex(-96.8506, 33.1072));

            //MapShapeLayer to display the three features (line to split, splitting line and intersection point).
            MapShapeLayer mapShapeLayer = new MapShapeLayer();

            //For the line to split.
            MapShape lineMapShape1 = new MapShape(new Feature(lineShape));

            lineMapShape1.ZoomLevels.ZoomLevel01.DefaultLineStyle    = LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.Green, 2, true);
            lineMapShape1.ZoomLevels.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            mapShapeLayer.MapShapes.Add("Line1", lineMapShape1);

            //For the splitting line.
            MapShape lineMapShape2 = new MapShape(new Feature(lineShape2));

            lineMapShape2.ZoomLevels.ZoomLevel01.DefaultLineStyle    = LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.Red, 1, true);
            lineMapShape2.ZoomLevels.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            mapShapeLayer.MapShapes.Add("Line2", lineMapShape2);

            LayerOverlay layerOverlay = new LayerOverlay();

            layerOverlay.Layers.Add(mapShapeLayer);

            winformsMap1.Overlays.Add(layerOverlay);

            winformsMap1.Refresh();
        }
Exemplo n.º 33
0
        private MapShapeLayer CreateMapShapeLayer(Location startLocation, Location endLocation)
        {
            MapShapeLayer shapeLayer = new MapShapeLayer();
            MapPolyline   polyline   = new MapPolyline();

            polyline.Locations = new LocationCollection {
                startLocation, endLocation
            };
            polyline.Color = Color.FromArgb(255, 255, 120, 56);
            polyline.Width = 10;

            shapeLayer.Shapes.Add(polyline);
            mainMap.ShapeLayers.Add(shapeLayer);

            return(shapeLayer);
        }
        public MainPage()
        {
            this.InitializeComponent();

            mRoutePlaybackTimer          = new DispatcherTimer();
            mRoutePlaybackTimer.Interval = new TimeSpan(0, 0, 0, 0, 50);
            mRoutePlaybackTimer.Tick    += mRoutePlaybackTimer_Tick;

            mRouteLayer = new MapShapeLayer();
            map.ShapeLayers.Add(mRouteLayer);

            mMapLayer = new MapLayer();
            map.Children.Add(mMapLayer);

            mMarkerPin = new Pushpin();
        }
Exemplo n.º 35
0
        public void Display(MapShapeLayer _routeLayer, Boolean _lowPerfo)
        {
            if (!DownloadSucceeded || (Points.Length < 2))
            {
                return;
            }

            LocationCollection ItineraryList = new LocationCollection();
            MapPolyline        routeLine     = new MapPolyline();

            double _numberPoints = EncodedItineraries.Count();

            foreach (String _encodedItinerary in EncodedItineraries)
            {
                //Get the route line data
                List <GpsLocation> _routePath = DecodePolyline(_encodedItinerary);

                int RATIO = (_lowPerfo)?30:3;

                if (_routePath.Count >= 2)
                {
                    for (int _idx = _routePath.Count - 1; _idx >= RATIO - 1; _idx = _idx - RATIO)
                    {
                        for (int _idxRatio = 0; _idxRatio < RATIO - 1; _idxRatio++)
                        {
                            _routePath.RemoveAt(_idx - _idxRatio);
                        }
                    }

                    foreach (GpsLocation _location in _routePath)
                    {
                        ItineraryList.Add(new Bing.Maps.Location(_location.Latitude, _location.Longitude));
                    }
                }
            }


            //Create a MapPolyline of the route and add it to the map
            routeLine = new MapPolyline()
            {
                Color     = Colors.Red,
                Locations = ItineraryList,
                Width     = 5
            };

            _routeLayer.Shapes.Add(routeLine);
        }
Exemplo n.º 36
0
        private void AddPolyline(string routeColor, LocationCollection collection)
        {
            byte          r          = byte.Parse(routeColor.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
            byte          g          = byte.Parse(routeColor.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);
            byte          b          = byte.Parse(routeColor.Substring(4, 2), System.Globalization.NumberStyles.HexNumber);
            MapShapeLayer shapeLayer = new MapShapeLayer();
            MapPolyline   polyline   = new MapPolyline();

            polyline.Locations = collection;
            polyline.Color     = Color.FromArgb(180, r, g, b);
            polyline.Width     = 8;
            shapeLayer.Shapes.Add(polyline);
            shuttleMap.ShapeLayers.Add(shapeLayer);

            // clean up
            polyline   = null;
            shapeLayer = null;
        }
Exemplo n.º 37
0
        /// <summary>
        /// Apply a single style to all shapes in a MapLayer and a MapShapeLayer.
        /// </summary>
        /// <param name="pinLayer">MapLayer to apply style to.</param>
        /// <param name="polyLayer">MapShapeLayer to apply style to.</param>
        /// <param name="style">Style to apply to layers.</param>
        public static void ApplyStyle(MapLayer pinLayer, MapShapeLayer polyLayer, ShapeStyle style)
        {
            if (pinLayer != null)
            {
                foreach (var p in pinLayer.Children)
                {
                    ApplyStyle(p as FrameworkElement, style);
                }
            }

            if (polyLayer != null)
            {
                foreach (var p in polyLayer.Shapes)
                {
                    ApplyStyle(p, style);
                }
            }
        }
Exemplo n.º 38
0
        public MeasureTrackInteractiveOverlay()
        {
            measuringMode      = MeasuringInMode.DecimalDegree;
            measureCustomeMode = MeasureCustomeMode.Select;
            shapeLayer         = new MapShapeLayer();
            textBlock          = new TextBlock {
                Visibility = Visibility.Collapsed
            };
            OverlayCanvas.Children.Add(textBlock);
            PolygonTrackMode = PolygonTrackMode.LineOnly;
            RenderMode       = RenderMode.DrawingVisual;
            InitializeColumns(TrackShapeLayer);
            InitializeColumns(TrackShapesInProcessLayer, false);

            SetStylesForInMemoryFeatureLayer(TrackShapeLayer);
            SetStylesForInMemoryFeatureLayer(TrackShapesInProcessLayer);
            stateController = new StateController <Collection <MapShape> >();
            stateController.Add(new Collection <MapShape>());
        }
        public MapView()
        {
#if WINDOWS_APP
            _map = new Map();

            _shapeLayer = new MapShapeLayer();
            _map.ShapeLayers.Add(_shapeLayer);

            _pinLayer = new MapLayer();
            _map.Children.Add(_pinLayer);
            _map.PointerPressedOverride += _map_PointerPressedOverride;
#elif WINDOWS_PHONE_APP
            _map = new MapControl();
            _map.PointerPressed += _map_PointerPressed;
#endif

            this.Children.Add(_map);

            SetMapBindings();
        }
Exemplo n.º 40
0
        async private Task DrawPath()
        {
            loading.Visibility = Visibility.Visible;
            // form and send request
            string tmpSourseLoc = Convert.ToString(sourseLocation.Latitude).Substring(0, Convert.ToString(sourseLocation.Latitude).IndexOf(',')) + '.' + Convert.ToString(sourseLocation.Latitude).Substring(Convert.ToString(sourseLocation.Latitude).IndexOf(',') + 1, Convert.ToString(sourseLocation.Latitude).Length - Convert.ToString(sourseLocation.Latitude).IndexOf(',') - 1);
            tmpSourseLoc += "," + Convert.ToString(sourseLocation.Longitude).Substring(0, Convert.ToString(sourseLocation.Longitude).IndexOf(',')) + '.' + Convert.ToString(sourseLocation.Longitude).Substring(Convert.ToString(sourseLocation.Longitude).IndexOf(',') + 1, Convert.ToString(sourseLocation.Longitude).Length - Convert.ToString(sourseLocation.Longitude).IndexOf(',') - 1);
            string tmpAimLoc = Convert.ToString(AimLocation.Latitude).Substring(0, Convert.ToString(AimLocation.Latitude).IndexOf(',')) + '.' + Convert.ToString(AimLocation.Latitude).Substring(Convert.ToString(AimLocation.Latitude).IndexOf(',') + 1, Convert.ToString(AimLocation.Latitude).Length - Convert.ToString(AimLocation.Latitude).IndexOf(',') - 1);
            tmpAimLoc += "," + Convert.ToString(AimLocation.Longitude).Substring(0, Convert.ToString(AimLocation.Longitude).IndexOf(',')) + '.' + Convert.ToString(AimLocation.Longitude).Substring(Convert.ToString(AimLocation.Longitude).IndexOf(',') + 1, Convert.ToString(AimLocation.Longitude).Length - Convert.ToString(AimLocation.Longitude).IndexOf(',') - 1);
            var url = "http://dev.virtualearth.net/REST/V1/Routes/Driving?o=json&wp.0=" +
                        tmpSourseLoc +
                        "&wp.1=" +
                        tmpAimLoc +
                        "&optmz=distance&rpo=Points&key=" + "2YNtFFMLLBJhNArw7AGF~J1bD5V8AXTm26ao0o20rRw~AqSRI8WDH0Mx820MLWME4SM-ye-FewEHmO7vj5O4vSDrNdVWsnRXo3I-LUhllJrB";
             Uri geocodeRequest = new Uri(url);
            BingMapHelper.Response r = await GetResponse(geocodeRequest);

            if (r.StatusCode != 404)
            {
                // Delete lables from map
                myMap.Children.Clear();
                myMap.ShapeLayers.Clear();

                // Draw Path via server answer 
                geolocator = new Geolocator();
                MapPolyline routeLine = new MapPolyline();
                routeLine.Locations = new LocationCollection();
                routeLine.Color = Windows.UI.Colors.RoyalBlue;
                routeLine.Width = 6.0;

                int bound = ((BingMapHelper.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates.GetUpperBound(0);

                sourseLocation.Latitude = ((BingMapHelper.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates[0][0];
                sourseLocation.Longitude = ((BingMapHelper.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates[0][1];

                AimLocation.Latitude = ((BingMapHelper.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates[bound][0];
                AimLocation.Longitude = ((BingMapHelper.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates[bound][1];

                var sourceLocation = new Bing.Maps.Location(sourseLocation.Latitude, sourseLocation.Longitude);
                myMap.Children.Add(pin);
                myMap.Children.Add(pinAim);

                var destinationLocation = new Bing.Maps.Location(AimLocation.Latitude, AimLocation.Longitude);
                myMap.SetView(sourceLocation, myMap.ZoomLevel);
                for (int i = 0; i < bound; i++)
                {
                    routeLine.Locations.Add(new Location
                        {
                            Latitude = ((BingMapHelper.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates[i][0],
                            Longitude = ((BingMapHelper.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates[i][1]
                        });
                }
                MapShapeLayer shapeLayer = new MapShapeLayer();
                shapeLayer.Shapes.Add(routeLine);
                myMap.ShapeLayers.Add(shapeLayer);
            }
            else
            {
                MessageDialog dialog = new MessageDialog("Маршрут построить не удалось. Попробуйте снова. \r\nЕсли ошибка повторится вновь, просим уведомить нас о ней через форму обратной связи.", "Ошибка построения маршрута #007100");
                await dialog.ShowAsync();
            }
            loading.Visibility = Visibility.Collapsed;
        }
Exemplo n.º 41
0
        public static async void GetDirections(Map myMap, Border RouteResults)
        {
            MapShapeLayer routeLayer = new MapShapeLayer();
            myMap.ShapeLayers.Add(routeLayer);

            Uri routeRequest = new Uri(string.Format(
                "http://dev.virtualearth.net/REST/V1/Routes/Driving?wp.0={0},{1}&wp.1={2},{3}&rpo=Points&key={4}", staticObjects.CurrentLatitude, staticObjects.CurrentLongitude, staticObjects.GoalLatitude, staticObjects.GoalLongitude, myMap.Credentials));

            //Make a request and get the response
            Response r = await GetResponse(routeRequest);

            if (r != null &&
                r.ResourceSets != null &&
                r.ResourceSets.Length > 0 &&
                r.ResourceSets[0].Resources != null &&
                r.ResourceSets[0].Resources.Length > 0)
            {
                Route route = r.ResourceSets[0].Resources[0] as Route;

                //Get the route line data
                double[][] routePath = route.RoutePath.Line.Coordinates;
                LocationCollection locations = new LocationCollection();

                for (int i = 0; i < routePath.Length; i++)
                {
                    if (routePath[i].Length >= 2)
                    {
                        locations.Add(new Bing.Maps.Location(routePath[i][0],
                                        routePath[i][1]));
                    }
                }

                MapPolyline routeLine = new MapPolyline()
                {
                    Color = Colors.Indigo,
                    Locations = locations,
                    Width = 7
                };

                routeLayer.Shapes.Add(routeLine);

                BitmapImage srcStart = new BitmapImage();
                srcStart.UriSource = new Uri(App.fbProfilePicture, UriKind.Absolute);
                ImageBrush imgStart = new ImageBrush();
                imgStart.ImageSource = srcStart;
                Ellipse start = new Ellipse() { Fill = imgStart, Height = 70, Width = 70 };

                myMap.Children.Add(start);
                MapLayer.SetPosition(start,
                    new Bing.Maps.Location(route.RouteLegs[0].ActualStart.Coordinates[0],
                        route.RouteLegs[0].ActualStart.Coordinates[1]));

                BitmapImage srcEnd = new BitmapImage();
                srcEnd.UriSource = staticObjects.FriendProfilePicture;
                ImageBrush imgEnd = new ImageBrush();
                imgEnd.ImageSource = srcEnd;
                Ellipse end = new Ellipse() { Fill = imgEnd, Height = 70, Width = 70 };

                myMap.Children.Add(end);
                MapLayer.SetPosition(end,
                    new Bing.Maps.Location(route.RouteLegs[0].ActualEnd.Coordinates[0],
                    route.RouteLegs[0].ActualEnd.Coordinates[1]));

                myMap.SetView(new LocationRect(locations));
                RouteResults.DataContext = route;
            }
        }
Exemplo n.º 42
0
        async void MapView_userPosChanged(object sender, Bing.Maps.Location l)
        {
            UpdateUserRadius("0.1", l);
            userLoc = l;
            MapShapeLayer layer = new MapShapeLayer();
            if (pathLocations != null)
            {
                foreach (Bing.Maps.Location loc in pathLocations)
                {
                    if (inRadius(loc, l, 0.05))
                    {
                        insideRoute = true;
                        showWarn = false;
                        break;
                    }
                    else
                        if (!inRadius(loc, l, 0.05))
                        {

                            insideRoute = false;
                        }

                }
            }
            if(insideRoute == false && showWarn == false)
            {
                ResourceLoader rl = new ResourceLoader();
                mapView.popup = new Windows.UI.Popups.MessageDialog(rl.GetString("OffRoutePopup"), "Route");
                mapView.popup.Commands.Add(new UICommand(rl.GetString("Ok"), new UICommandInvokedHandler(this.CommandInvokedHandler)));
                showWarn = true;
                await mapView.popup.ShowAsync();
            }           
            
            //if (Route != null)
            //{
            //    if (userRadius.Intersects(Route.Bounds) && Route != null)
            //    {
            //        insideRoute = true;
            //    }
            //    else
            //        if (!userRadius.Intersects(Route.Bounds))
            //        {
            //            ResourceLoader rl = new ResourceLoader();
            //            mapView.popup = new Windows.UI.Popups.MessageDialog(rl.GetString("OffRoutePopup"), "Route");

            //            await mapView.popup.ShowAsync();
            //            insideRoute = false;
            //        }
            //}
        }
Exemplo n.º 43
0
 private void AppBarButton_getNearest(object sender, RoutedEventArgs e)
 {
     ClearMap();
     routeLayer = new MapShapeLayer();
     myMap.ShapeLayers.Add(routeLayer);
     getTheNear();
 }
Exemplo n.º 44
0
        private void MyMap_OnLoaded(object sender, RoutedEventArgs e)
        {
            var map = (Bing.Maps.Map) sender;
            var mapShapeLayer = new MapShapeLayer();
            var polyLine = new MapPolyline();

            var activities = map.Tag as List<Activity>;
            if (activities == null)
                return;

            var pinNumber = 0;
            foreach (var activity in activities
                .GroupBy(x => x.Latitude + x.Longitude) //ignore dupe coordinates
                .Select(g => g.First())
                .OrderBy(x => x.Timestamp))
            {
                // ReSharper disable CompareOfFloatsByEqualityOperator
                if (activity.Latitude != 0 && activity.Longitude != 0)
                {
                    polyLine.Locations.Add(new Location(activity.Latitude, activity.Longitude));

                    pinNumber++;
                    var pin = new Pushpin();
                    pin.Text = pinNumber.ToString();
                    pin.FontSize = 13; //this size works good for single or double digits
                    
                    MapLayer.SetPosition(pin, new Location(activity.Latitude, activity.Longitude));
                    map.Children.Add(pin);
                }
                // ReSharper restore CompareOfFloatsByEqualityOperator
            }
            
            polyLine.Width = 3;
            mapShapeLayer.Shapes.Add(polyLine);
            map.ShapeLayers.Add(mapShapeLayer);

            //Calculate a bounding box for the route
            var t = activities.Where(x => x.Latitude != 0).Max(x => x.Latitude);
            var b = activities.Where(x => x.Latitude != 0).Min(x => x.Latitude);
            var l = activities.Where(x => x.Longitude != 0).Min(x => x.Longitude);
            var r = activities.Where(x => x.Longitude != 0).Max(x => x.Longitude);

            //Pad the box
            var latPad = (t - b)*.3;
            var longPad = (r - l)*.3;
            
            map.SetView(new LocationRect(new Location(t + latPad,l-longPad), new Location(b - latPad,r + longPad)), MapAnimationDuration.None);
        }
Exemplo n.º 45
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="points"></param>
        private void DrawRoute(List<Location> points)
        {
            MapShapeLayer shapeLayer = new MapShapeLayer();
            MapPolyline polyline = new MapPolyline();

            LocationCollection lc = new LocationCollection();

            foreach (Location p in points)
            {
                lc.Add(p);
            }

            polyline.Locations = lc;
            polyline.Color = Color.FromArgb(255, 102, 0, 0);
            polyline.Width = 5;
            shapeLayer.Shapes.Add(polyline);
            Map.ShapeLayers.Clear();
            Map.ShapeLayers.Add(shapeLayer);

            Location midpoint = new Location(lc.FirstOrDefault().Latitude + ((lc.LastOrDefault().Latitude - lc.FirstOrDefault().Latitude) / 2.0),
                                             lc.FirstOrDefault().Longitude + ((lc.LastOrDefault().Longitude - lc.FirstOrDefault().Longitude) / 2.0));

            Map.SetView(midpoint, 15.5F);
        }
Exemplo n.º 46
0
        private void updateVisitedLine()
        {
            Map.ShapeLayers.Remove(shapeLayerVisited);
            shapeLayerVisited = new MapShapeLayer();
            MapPolyline polyLine = new MapPolyline();
            polyLine.Color = Windows.UI.Colors.Green;
            polyLine.Width = 5;

            foreach(WeBreda.Model.Waypoint wp in this.control.currentRoute.Waypoints)
            {
                if(wp.IsVisited)
                {
                    polyLine.Locations.Add(new Location() { Latitude = wp.Latitude, Longitude = wp.Longitude });
                }
            }
            shapeLayerVisited.Shapes.Add(polyLine);
            Map.ShapeLayers.Add(shapeLayerVisited);

        }
Exemplo n.º 47
0
 private void DrawRoute(LocationCollection wayPoints)
 {
     MapShapeLayer shapeLayer = new MapShapeLayer();
     MapPolyline polyline = new MapPolyline();
     polyline.Locations = wayPoints;
     polyline.Color = Windows.UI.Colors.Red;
     polyline.Width = 5;
     shapeLayer.Shapes.Add(polyline);
     LocationRect mapRectangle = new LocationRect(wayPoints);
     this.map.SetView(mapRectangle);
     this.map.ShapeLayers.Add(shapeLayer);
 }
Exemplo n.º 48
0
        /// <summary>
        /// Change the polylines on the map.
        /// </summary>
        private static void ShapesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            MapControl mapControl = (MapControl)d;

            if (e.OldValue != null)
            {
                // remove all old polylines from the map:
                mapControl.map.ShapeLayers.Clear();
            }

            if (e.NewValue != null)
            {
                MapShapeLayer routeLayer = new MapShapeLayer();

                List<Shape> shapes = (List<Shape>)e.NewValue;
                foreach (var shape in shapes)
                {
                    MapPolyline polyline = new MapPolyline();
                    polyline.Color = Color.FromArgb(255, 0x4f, 0x64, 0xba);
                    polyline.Width = 6;

                    LocationCollection locations = new LocationCollection();
                    foreach (var point in shape.Points)
                    {
                        locations.Add(new Location(point.Latitude, point.Longitude));
                    }

                    polyline.Locations = locations;
                    routeLayer.Shapes.Add(polyline);
                }

                mapControl.map.ShapeLayers.Add(routeLayer);
            }
        }
Exemplo n.º 49
0
        public void drawRouteLine(List<WeBreda.Model.Waypoint> wpList)
        {
            Map.ShapeLayers.Remove(shapeLayer);
            shapeLayer = new MapShapeLayer();
            MapPolyline polyLine = new MapPolyline();
            polyLine.Color = Windows.UI.Colors.Red;
            polyLine.Width = 5;

            foreach (WeBreda.Model.Waypoint wp in wpList)
            {
                polyLine.Locations.Add(new Location()
                {
                    Latitude = wp.Latitude,
                    Longitude = wp.Longitude
                });
            }
            shapeLayer.Shapes.Add(polyLine);
            Map.ShapeLayers.Add(shapeLayer);
        }
Exemplo n.º 50
0
        private async void btnGiveDirections_Click(object sender, RoutedEventArgs e)
        {

          tbError.Text = string.Empty;
            if (rdCoord.IsChecked == true)
                URL = "http://dev.virtualearth.net/REST/V1/Routes/Driving?o=json&wp.0=" + txtFromCoord.Text + "&wp.1=" + txtToCoord.Text + "&optmz=distance&rpo=Points&key=" + NavMaps.Credentials;
            else
                URL = "http://dev.virtualearth.net/REST/V1/Routes/Driving?o=json&wp.0=" + txtFromLocation.Text + "&wp.1=" + txtToLocation.Text + "&optmz=distance&rpo=Points&key=" + NavMaps.Credentials;
            Uri geocodeRequest = new Uri(URL);
            BingMapsRESTService.Response r = await GetResponse(geocodeRequest);

            geolocator = new Geolocator();
            MyPushPin = new Pushpin();

            FromLatitude = ((BingMapsRESTService.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates[0][0];
            FromLongitude = ((BingMapsRESTService.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates[0][1];

            location = new Location(FromLatitude, FromLongitude);
            MapLayer.SetPosition(MyPushPin, location);
            NavMaps.Children.Add(MyPushPin);
            NavMaps.SetView(location, 15.0f);

            MapPolyline routeLine = new MapPolyline();
            routeLine.Locations = new LocationCollection();
            routeLine.Color = Windows.UI.Colors.Blue;
            routeLine.Width = 5.0;
            // Retrieve the route points that define the shape of the route.
            int bound = ((BingMapsRESTService.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates.GetUpperBound(0);
            for (int i = 0; i < bound; i++)
            {
                routeLine.Locations.Add(new Location
                {
                    Latitude = ((BingMapsRESTService.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates[i][0],
                    Longitude = ((BingMapsRESTService.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates[i][1]
                });
            }
            MapShapeLayer shapeLayer = new MapShapeLayer();
            shapeLayer.Shapes.Add(routeLine);
            NavMaps.ShapeLayers.Add(shapeLayer);
        }
Exemplo n.º 51
0
        private async void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var shapeLayer = MainMap.ShapeLayers.FirstOrDefault();
            if (shapeLayer == null)
            {
                shapeLayer = new MapShapeLayer();
                MainMap.ShapeLayers.Add(shapeLayer);
            }

            foreach (var routeViewModel in e.RemovedItems.Cast<RouteViewModel>())
            {
                var item = routes[routeViewModel];
                if (item != null)
                {
                    shapeLayer.Shapes.Remove(item.Item2);
                    MainMap.Children.Remove(item.Item1);
                    MainMap.Children.Remove(item.Item3);
                }

            }

            foreach (var routeViewModel in e.AddedItems.Cast<RouteViewModel>())
            {
                var pushpin1 = new Pushpin
                {
                    Background = new SolidColorBrush(Colors.White)
                };
                MapLayer.SetPosition(pushpin1, routeViewModel.Locations.First());
                var routeLine = new MapPolyline();
                routeLine.Color = routeViewModel.Invoiced ? Color.FromArgb(255, 255, 127, 101) : Color.FromArgb(255, 67, 82, 102);
                routeLine.Width = 5;
                routeLine.Locations = new LocationCollection();
                var pushpin2 = new Pushpin
                {
                    Background = new SolidColorBrush(Colors.White)
                };
                MapLayer.SetPosition(pushpin2, routeViewModel.Locations.Last());

                routes[routeViewModel] = new Tuple<Pushpin, MapPolyline, Pushpin>(pushpin1, routeLine, pushpin2);


                MainMap.Children.Add(pushpin1);
                shapeLayer.Shapes.Add(routeLine);
                foreach (var routeLocation in routeViewModel.Locations)
                {
                    await Task.Delay(100);
                    routeLine.Locations.Add(routeLocation);
                }
                if (routes.ContainsKey(routeViewModel))
                {
                    MainMap.Children.Add(pushpin2);
                }
            }
            Debug.WriteLine("End");
        }
Exemplo n.º 52
0
 public async void DrawRoute(double lat, double lon, string falg)
 {
     //try
     //{
     string point2 = "";
     Geolocator myGeolocator = new Geolocator();
     Geoposition myGeoposition = await myGeolocator.GetGeopositionAsync();
     string point1 = myGeoposition.Coordinate.Latitude + "," + myGeoposition.Coordinate.Longitude;
     GetCurrentLocation();
     point2 = lat + "," + lon;
     string reqURL = "http://dev.virtualearth.net/REST/V1/Routes?wp.0=" + point1 + "&wp.1=" + point2 + "&key=AgGh6rnsoa0ho6TQLJ2Sm-gVwIRzUmxnB2MkNdEiglFsJsfXxqBFZkKdetZFyY7q";
     HttpClient client = new HttpClient();
     HttpResponseMessage response = await client.GetAsync(new Uri(reqURL));
     var jsonResponse = await response.Content.ReadAsStringAsync();
     var rootObject = JsonConvert.DeserializeObject<RootObject>(jsonResponse);
     foreach (ResourceSet set in rootObject.resourceSets)
     {
         resourceSet.Add(set);
     }
     loc.Clear();
     resource = resourceSet[0].resources[0];
     items = resource.routeLegs[0].itineraryItems;
     // Colleting location points to draw route got in response. 
     foreach (ItineraryItem item in items)
     {
         loc.Add(new Location() { Latitude = item.maneuverPoint.coordinates[0], Longitude = item.maneuverPoint.coordinates[1] });
     }
     // Declaring Object of MapPolyline to Draw Route
     MapPolyline line;
     line = new MapPolyline();
     // Defining color to Polyline that is Red you can give any color to it. 
     if (falg == "0")
         line.Color = Colors.Red;
     else if (falg == "1")
         line.Color = Colors.Black;
     // Defining width of Polyline so it can easily be visible to naked eye. 
     line.Width = 5;
     // Giving Collection of location points to Map Polyline     
     foreach (Location l in loc)
     {
         line.Locations.Add(l);
     }
     // Defining Map Shape layer Object to add Polyline shape to it. 
     shapeLayer = new MapShapeLayer();
     // Adding line to Shape Layer 
     shapeLayer.Shapes.Add(line);
     // Adding Shape Layer to Map
     MyMap.ShapeLayers.Add(shapeLayer);
     // Calculating Mid between both location to set center of Map
     int mid;
     if (loc.Count % 2 == 0)
     {
         mid = loc.Count / 2;
     }
     else
     {
         mid = (loc.Count + 1) / 2;
     }
     // Setting center of Map to Middle of Both Locations
     MyMap.Center = loc[mid];
     // Setting ZoomLevel of Map
     MyMap.ZoomLevel = 14;
     //}
     //catch (Exception ex)
     //{
     //    Debug.WriteLine(ex.ToString());
     //}
     //finally
     //{
     //  //  drawroute.IsEnabled = true;
     //   // progress.Visibility = Visibility.Collapsed;
     //}
 }
Exemplo n.º 53
0
        private async void OnMapTapped(object sender, TappedRoutedEventArgs e)
        {
            if (txtFromCoord.Text == "")
            {
                String loc = txtFromCoord.Text;
                var pos = e.GetPosition(NavMaps);
                Location location;
                NavMaps.TryPixelToLocation(pos, out location);

                MapLayer.SetPosition(Push, location);
                NavMaps.SetView(location);
                txtFromCoord.Text = Convert.ToString(location.Latitude) + "," + location.Longitude;
              
          



            }
            else
            {
            
                var pos = e.GetPosition(NavMaps);
                Location location;
                NavMaps.TryPixelToLocation(pos, out location);

                MapLayer.SetPosition(Push2, location);
                NavMaps.SetView(location);
                txtToCoord.Text = Convert.ToString(location.Latitude) + "," + location.Longitude;
                URL = "http://dev.virtualearth.net/REST/V1/Routes/Driving?o=json&wp.0=" + txtFromCoord.Text + "&wp.1=" + txtToCoord.Text + "&optmz=distance&rpo=Points&key=" + NavMaps.Credentials;
                Uri geocodeRequest = new Uri(URL);
                BingMapsRESTService.Response r = await GetResponse(geocodeRequest);

                geolocator = new Geolocator();
                MyPushPin = new Pushpin();

                FromLatitude = ((BingMapsRESTService.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates[0][0];
                FromLongitude = ((BingMapsRESTService.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates[0][1];

                location = new Location(FromLatitude, FromLongitude);
                MapLayer.SetPosition(MyPushPin, location);
                NavMaps.Children.Add(MyPushPin);
                NavMaps.SetView(location, 15.0f);

                MapPolyline routeLine = new MapPolyline();
                routeLine.Locations = new LocationCollection();
                routeLine.Color = Windows.UI.Colors.Blue;
                routeLine.Width = 5.0;
                // Retrieve the route points that define the shape of the route.
                int bound = ((BingMapsRESTService.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates.GetUpperBound(0);
                for (int i = 0; i < bound; i++)
                {
                    routeLine.Locations.Add(new Location
                    {
                        Latitude = ((BingMapsRESTService.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates[i][0],
                        Longitude = ((BingMapsRESTService.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates[i][1]
                    });
                }
                MapShapeLayer shapeLayer = new MapShapeLayer();
                shapeLayer.Shapes.Add(routeLine);
                NavMaps.ShapeLayers.Add(shapeLayer);
                txtFromCoord.Text = "";
                txtToCoord.Text = "";
            }
       
        }
        private void ChooseButton_Click(object sender, RoutedEventArgs e)
        {
            //inCreatePolygonMode = true;

            // Clears any objects added to the polygon layer.
            //if (TockeShapeLayer.Shapes.Count > 0)
            //    TockeShapeLayer.Shapes.Clear();

            MapShapeLayer shapeLayer = new MapShapeLayer();
            

            newPolygon = new MapPolygon();
            // Defines the polygon fill details
            //newPolygon.Locations = new LocationCollection() { new Bing.Maps.Location(44, -107), new Location(44, -110), new Location(46, -110), new Location(46, -107) };
            newPolygon.FillColor = Windows.UI.Colors.Red;
            //newPolygon.Fill = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Red);
            //newPolygon.StrokeThickness = 3;
            //newPolygon.Opacity = 0.8;
            shapeLayer.Shapes.Add(newPolygon);
            MyMap.ShapeLayers.Add(shapeLayer);
        }
Exemplo n.º 55
0
        public async void createRouteToVVV(Bing.Maps.Location curLoc,Bing.Maps.Location vvvLoc)
        {
            try
            {
                foreach (MapShapeLayer layer in Map.ShapeLayers)
                {
                    if (layer.Equals(RouteLayer))
                    {
                        layer.Shapes.Clear();
                        RouteLayer.Shapes.Clear();
                    }
                }
                Map.ShapeLayers.Clear();

                WaypointCollection routePoints = new WaypointCollection { new Waypoint(curLoc), new Waypoint(vvvLoc) };
                DirectionsManager manager = Map.DirectionsManager;
                manager.Waypoints.Clear();
                manager.RequestOptions.RouteMode = RouteModeOption.Walking;
                manager.Waypoints = routePoints;
                manager.RenderOptions.WalkingPolylineOptions.Visible = true;

                RouteResponse resp = await manager.CalculateDirectionsAsync();
                resp.Routes[0].RoutePath.LineWidth = 10.0;
                resp.Routes[0].RoutePath.LineColor = new Windows.UI.Color { A = 200, R = 200, B = 0, G = 2 };
                MapShapeLayer layer10 = new MapShapeLayer();
                
                

                LocationCollection locs = new LocationCollection();
                foreach(Bing.Maps.Location l in resp.Routes[0].RoutePath.PathPoints)
                {
                    Pushpin p = new Pushpin();
                    p.Text = "Pin";
                    MapLayer.SetPosition(p, l);
                    Map.Children.Add(p);
                    locs.Add(l);
                }
                MapPolyline line = new MapPolyline { Locations = locs };
                line.Color = new Windows.UI.Color { A = 100, G = 0, B = 200, R = 0 };
                line.Visible = true;
                line.Width = 10.0;
                layer10.Shapes.Add(line);
                Map.ShapeLayers.Add(layer10);

                manager.ShowRoutePath(resp.Routes[0]);
            }
            catch(Exception d)
            {
                System.Diagnostics.Debug.WriteLine(d);
                showInternetPopup();
            }
        }