public void Calculate() { lc.Clear(); foreach (var item in locations) { if (locations.IndexOf(item) >= startIndex & locations.IndexOf(item) <= endIndex) { lc.Add(item); } else if (locations.IndexOf(item) >= endIndex & locations.IndexOf(item) <= startIndex) { lc.Add(item); } } MapPolyline path = new MapPolyline(); path.Stroke = new SolidColorBrush(Colors.Green); path.StrokeThickness = 10; path.Opacity = 1; path.Locations = lc; MainMap.Children.Remove(path); MainMap.Children.Add(path); }
private void PopulateValidLocations() { mPolyShapeLocations.Clear(); mPolyShapeLocations.Add(new Location(15, -15)); mPolyShapeLocations.Add(new Location(30, -90)); mPolyShapeLocations.Add(new Location(-45, -15)); mPolyShapeLocations.Add(new Location(30, 90)); mPolyShapeLocations.Add(new Location(60, 60)); }
public void Dispose() { Response.Dispose(); ContentCollection.Clear(); AdsCollection.Clear(); PricesCollection.Clear(); LocationCollection.Clear(); PublishingTimeCollection.Clear(); IndividualAdsUrlsCollection.Clear(); IndividualAdsNamesCollection.Clear(); }
private void GeoRangeToPolygon(SqlGeography geoRange, LocationCollection polygon) { int numPoints = geoRange.STNumPoints().Value; polygon.Clear(); for (int i = 1; i <= numPoints; i++) { SqlGeography point = geoRange.STPointN(i); polygon.Add(new Location(point.Lat.Value, point.Long.Value)); } }
/// <summary> /// load GPX /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void load_gpx_button_Click(object sender, RoutedEventArgs e) { if (GpxUtils.OpenGpxDlg(out string gpxFileName) == System.Windows.Forms.DialogResult.Cancel) { return; } if (gpxFileName == null || gpxFileName.Length == 0) { return; } var newRoute = GpxUtils.ReadGpxCoords(gpxFileName); route.Clear(); foreach (Location loc in newRoute) { route.Add(loc); } navigator.SetRoute(route); uiMgr.SetRoute(route); myMap.Center = route[0]; }
void rsc_GetRoutingCompleted(object sender, GetRoutingCompletedEventArgs e) { carloc.Clear(); cari = 0; MapLayer layer = (MapLayer)this.ctlMap.FindName("routing"); layer.Children.Clear(); 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[] { ',' }); if ((strArray2.Length == 1) && (strArray2[0].Length > 1)) { //Ellipse dependencyObject = new Ellipse(); //dependencyObject.Width=10.0; //dependencyObject.Height=(10.0); //dependencyObject.Fill=(new SolidColorBrush(color)); //dependencyObject.Opacity=(0.65); //Location location = new Location(double.Parse(strArray2[0].Split(new char[] { ' ' })[0]), double.Parse(strArray2[0].Split(new char[] { ' ' })[1])); //MapLayer.SetPosition(dependencyObject, location); //ToolTipService.SetToolTip(dependencyObject, builder.ToString()); //layer.Children.Add(dependencyObject); } else { LocationCollection locations; Location location2; Location locPoint; if (strArray2[0].Equals(strArray2[strArray2.Length - 1])) { var polygon = new MapPolygon { Stroke = new SolidColorBrush(color), StrokeThickness = 2.0, Fill = new SolidColorBrush(color), Opacity = 0.75 }; locations = new LocationCollection(); index = 0; while (index < strArray2.Length) { if (strArray2[index].IndexOf(" ") != -1) { location2 = new Location(double.Parse(strArray2[index].Split(new char[] { ' ' })[0]), double.Parse(strArray2[index].Split(new char[] { ' ' })[1])); locations.Add(location2); } index++; } polygon.Locations = locations; ToolTipService.SetToolTip(polygon, builder.ToString()); layer.Children.Add(polygon); } else { var polyline = new MapPolyline { Stroke = new SolidColorBrush(color), StrokeThickness = 6.0 }; var doubles = new DoubleCollection { 3.0, 3.0 }; polyline.StrokeDashArray = doubles; locations = new LocationCollection(); for (index = strArray2.Length - 1; index >= 0; index--) { location2 = new Location(double.Parse(strArray2[index].Split(new char[] { ' ' })[0]), double.Parse(strArray2[index].Split(new char[] { ' ' })[1])); locations.Add(location2); if (i == 0) { carloc.Add(location2); } } //添加坐标到小车轨迹 if (i > 0) { Location loc1 = new Location(double.Parse(strArrayPoints[0].Split(new char[] { ' ' })[0]), double.Parse(strArrayPoints[0].Split(new char[] { ' ' })[1])); Location loc2 = new Location(double.Parse(strArrayPoints[strArrayPoints.Length - 1].Split(new char[] { ' ' })[0]), double.Parse(strArrayPoints[strArrayPoints.Length - 1].Split(new char[] { ' ' })[1])); if (IsCloset(carloc.ElementAt(carloc.Count - 1), loc1, loc2)) { for (index = strArrayPoints.Length - 1; index >= 0; index--) { var tmoloc1 = new Location(double.Parse(strArrayPoints[index].Split(new char[] { ' ' })[0]), double.Parse(strArrayPoints[index].Split(new char[] { ' ' })[1])); carloc.Add(tmoloc1); } } else { for (index = 0; index < strArrayPoints.Length - 1; index++) { var tmoloc = new Location(double.Parse(strArrayPoints[index].Split(new char[] { ' ' })[0]), double.Parse(strArrayPoints[index].Split(new char[] { ' ' })[1])); carloc.Add(tmoloc); } } } polyline.Locations = locations; ToolTipService.SetToolTip(polyline, builder.ToString()); layer.Children.Add(polyline); } } } } CustomPushpin otmpcp = GetCarByMSID("car", carml); for (int i = 0; i < carloc.Count; i++) { var item = carloc.ElementAt(i); if (item.Latitude == otmpcp.Location.Latitude && item.Longitude == otmpcp.Location.Longitude) { for (int y = 0; y < i + 1; y++) { if (carloc.Count > y + 1) { carloc.RemoveAt(y); } } } } carloc.RemoveAt(0); isgetloc = false; timer.Begin(); //RouteLoadingPanel.Stop(); }
private void DrawAreas(XAMLResponse e) { CenterRectAreas = new LocationRect(); AllPointsInLayer = new LocationCollection(); int resultCnt = e.OutputFields.Count; if (resultCnt > 0) { if (resultCnt < recordLimit) { if (Layers.Count > 0) { MapLayer currentLayer = Layers[0]; MapLayer newLayer = (MapLayer)XamlReader.Load(e.XAML); currentLayer.Children.Clear(); Layers[2].Children.Clear(); currentLayer.Children.Add(newLayer); foreach (XAMLFields shp in e.OutputFields) { UIElement el = (UIElement)newLayer.FindName(shp.ID); if (el != null) { el.MouseLeftButtonUp += new MouseButtonEventHandler(el_MouseLeftButtonUp); el.MouseEnter += polygon_MouseEnter; el.MouseLeave += polygon_MouseLeave; Area newArea = new Area(); newArea.Name = shp.Fields["name"]; newArea.Country = shp.Fields["country"].ToString(); newArea.DesignationType = shp.Fields["desig_type"]; newArea.Designation = shp.Fields["desig_eng"]; newArea.RepArea = shp.Fields["rep_area"]; int year = 0; int.TryParse(shp.Fields["status_yr"], out year); if (year != 0) newArea.StatusYear = year; newArea.Wdpaid = int.Parse(shp.Fields["wdpaid"]); newArea.Iucncat = shp.Fields["iucncat"]; StringBuilder label = new StringBuilder("\n"); label.Append("Name :" + shp.Fields["name"] + "\n"); label.Append("Country :" + shp.Fields["country"] + "\n"); label.Append("Designation :" + shp.Fields["desig_eng"] + "\n"); label.Append("Type :" + shp.Fields["desig_type"] + "\n"); label.Append("Total Area :" + shp.Fields["rep_area"] + "\n"); label.Append("Iucncat :" + shp.Fields["iucncat"] + "\n"); label.Append("Continent :" + shp.Fields["continent"] + "\n"); (el as FrameworkElement).Tag = newArea; ToolTip tt = AddToolTip(label.ToString()); ToolTipService.SetToolTip(el, tt); if (el.GetType().Equals(typeof(Pushpin))) { Pushpin p = (Pushpin)el; AllPointsInLayer.Add(p.Location); Pin pin = new Pin { ShowCustomPin = true }; pin.MouseLeftButtonUp += new MouseButtonEventHandler(el_MouseLeftButtonUp); pin.Cursor = Cursors.Hand; newLayer.AddChild(pin, p.Location, PositionOrigin.BottomCenter); ToolTip tt1 = AddToolTip(label.ToString()); ToolTipService.SetToolTip(pin, tt1); newLayer.Children.Remove(p); } if (el.GetType().Equals(typeof(MapLayer))) { MapLayer p = (MapLayer)el; p.Cursor = Cursors.Hand; foreach (MapPolygon mp in p.Children) { for (int i = 0; i < mp.Locations.Count; i++) { AllPointsInLayer.Add(mp.Locations[i]); } mp.Fill = new SolidColorBrush(MiscFunctions.ColorFromInt(LayerStyle[Layers[0].Name].fill)); mp.Stroke = new SolidColorBrush(MiscFunctions.ColorFromInt(LayerStyle[Layers[0].Name].stroke)); mp.Opacity = LayerStyle[Layers[0].Name].opacity; LocationRect rect = new LocationRect(mp.Locations); Pin pin = new Pin { ShowCustomTree = true }; pin.Tag = (el as MapLayer); ToolTip tt1 = AddToolTip(label.ToString()); pin.Cursor = Cursors.Hand; ToolTipService.SetToolTip(pin, tt1); pin.MouseLeftButtonUp += new MouseButtonEventHandler(el_MouseLeftButtonUp); newLayer.AddChild(pin, rect.Center, PositionOrigin.BottomCenter); photoservices.GetFotos(rect, Layers[2], currentMap); } } if (el.GetType().Equals(typeof(MapPolyline))) { MapPolyline p = (MapPolyline)el; for (int i = 0; i < p.Locations.Count; i++) { AllPointsInLayer.Add(p.Locations[i]); } p.Stroke = new SolidColorBrush(MiscFunctions.ColorFromInt(LayerStyle[Layers[0].Name].stroke)); p.StrokeThickness = 2; p.StrokeMiterLimit = 0; } if (el.GetType().Equals(typeof(MapPolygon))) { MapPolygon p = (MapPolygon)el; for (int i = 0; i < p.Locations.Count; i++) { AllPointsInLayer.Add(p.Locations[i]); } LocationRect rect = new LocationRect(p.Locations); Pin pin = new Pin { ShowCustomTree = true }; ToolTip tt1 = AddToolTip(label.ToString()); ToolTipService.SetToolTip(pin, tt1); pin.Cursor = Cursors.Hand; pin.MouseLeftButtonUp += new MouseButtonEventHandler(el_MouseLeftButtonUp); newLayer.AddChild(pin, rect.Center, PositionOrigin.BottomCenter); p.Stroke = new SolidColorBrush(MiscFunctions.ColorFromInt(LayerStyle[Layers[0].Name].stroke)); p.Fill = new SolidColorBrush(MiscFunctions.ColorFromInt(LayerStyle[Layers[0].Name].fill)); p.Opacity = LayerStyle[Layers[0].Name].opacity; } } } } CenterRectAreas = new LocationRect(AllPointsInLayer); if(currentMap != null) currentMap.SetView(CenterRectAreas); if (AllPointsInLayer != null) AllPointsInLayer.Clear(); CenterRectAreas = null; } else { cw = new ChildWindow { Content = "Too many locations were found, try a smaller area" }; cw.Show(); } } else { cw = new ChildWindow { Content = string.Format("No locations were found, try a bigger area {0}",e.OutputMessage) }; cw.Show(); } Messenger.Default.Send<bool>(true, "draw"); }
private void MakePolylines(Dictionary <string, Tuple <string, string, List <LocationCollection> > > routeMap) { // ultimately is list of routes -> segments // split up route collections into route collections that include "shared routes" Dictionary <double, Tuple <LocationCollection, List <string> > > segmentToIdMap = new Dictionary <double, Tuple <LocationCollection, List <string> > >(); foreach (string routeId in routeMap.Keys) { Tuple <string, string, List <LocationCollection> > routeData = routeMap[routeId]; List <LocationCollection> locs = routeData.Item3; foreach (LocationCollection collection in locs) { double key = GetHash(collection); List <string> idList = new List <string>(); if (segmentToIdMap.ContainsKey(key)) { idList = segmentToIdMap[key].Item2; } idList.Add(routeId); segmentToIdMap[key] = Tuple.Create <LocationCollection, List <string> >(collection, idList); // clean up idList = null; } } foreach (double key in segmentToIdMap.Keys) { LocationCollection collection = segmentToIdMap[key].Item1; List <string> idList = segmentToIdMap[key].Item2; if (idList.Count == 1) { string routeId = idList[0]; string routeColor = routeMap[routeId].Item2; AddPolyline(routeColor, collection); } // there may be a segment shared by many routes else { int i = 0; int n = idList.Count; Location prevLoc = null; double totalDist = 0; double maxDist = 0.00025; foreach (Location loc in collection) { if (prevLoc != null) { double dist = Math.Sqrt(Math.Pow((prevLoc.Longitude - loc.Longitude), 2) + Math.Pow((prevLoc.Latitude - prevLoc.Latitude), 2)); // split up the segment pair into smaller segments if (dist > maxDist) { int numSteps = (int)Math.Ceiling(dist / maxDist); double latDiff = (loc.Latitude - prevLoc.Latitude) / numSteps; double lngDiff = (loc.Longitude - prevLoc.Longitude) / numSteps; for (int j = 0; j < numSteps; j++) { Location new_loc1 = new Location(prevLoc.Latitude + latDiff * j, prevLoc.Longitude + lngDiff * j); Location new_loc2 = new Location(prevLoc.Latitude + latDiff * (j + 1), prevLoc.Longitude + lngDiff * (j + 1)); LocationCollection newLocCollection = new LocationCollection(); newLocCollection.Add(new_loc1); newLocCollection.Add(new_loc2); string routeId = idList[i]; string routeColor = routeMap[routeId].Item2; AddPolyline(routeColor, newLocCollection); i = (i + 1) % n; // clean up new_loc1 = null; new_loc2 = null; newLocCollection.Clear(); newLocCollection = null; } } else { // add polyline between loc and prevLoc LocationCollection pair = new LocationCollection(); pair.Add(prevLoc); pair.Add(loc); string routeId = idList[i]; string routeColor = routeMap[routeId].Item2; AddPolyline(routeColor, pair); totalDist += dist; if (totalDist > maxDist) { totalDist = 0; i = (i + 1) % n; } pair = null; // clean up } } prevLoc = loc; } prevLoc = null; // clean up } } // clean up segmentToIdMap.Clear(); segmentToIdMap = null; }
public async void TraceRoot(List <Stop> stopList) { if (stopList.Count < 2) { return; } for (int i = 0; i < stopList.Count - 1; i++) { List <ResourceSet> resourceSet = new List <ResourceSet>(); Resource resource; List <ItineraryItem> items = new List <ItineraryItem>(); LocationCollection loc = new LocationCollection(); string point1 = stopList[i].Lat + "," + stopList[i].Lng; string point2 = stopList[i + 1].Lat + "," + stopList[i + 1].Lng; try { string reqURL = "http://dev.virtualearth.net/REST/V1/Routes?wp.0=" + point1 + "&wp.1=" + point2 + "&key=" + Global.mapKey; HttpClient client = new HttpClient(); HttpResponseMessage response = await client.GetAsync(reqURL); var jsonResponse = await response.Content.ReadAsStringAsync(); // Parsing JSON Response 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 = new MapPolyline(); // Defining color to Polyline line.Stroke = new SolidColorBrush(Colors.DodgerBlue); line.StrokeThickness = 5; line.Locations = loc; // Adding line to Map MyMap.Children.Add(line); // 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; } MyMap.Center = loc[mid]; } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } }