void FitToView() { LocationRectangle setRect = null; if (selected_shape == "Polygon" && (poly != null)) { Debug.WriteLine("Fitting polygon into the view"); setRect = LocationRectangle.CreateBoundingRectangle(poly.Path); } else if (selected_shape == "Polyline" && (polyline != null)) { double north = 0; double west = 0; double south = 0; double east = 0; north = south = polyline.Path[0].Latitude; west = east = polyline.Path[0].Longitude; foreach (var p in polyline.Path.Skip(1)) { if (north < p.Latitude) { north = p.Latitude; } if (west > p.Longitude) { west = p.Longitude; } if (south > p.Latitude) { south = p.Latitude; } if (east < p.Longitude) { east = p.Longitude; } } setRect = new LocationRectangle(north, west, south, east); } else if (selected_shape == "Markers" && (markerLayer != null)) { Debug.WriteLine("Fitting: " + markerLayer.Count() + " markers into the view"); GeoCoordinate[] geoArr = new GeoCoordinate[markerLayer.Count()]; for (var p = 0; p < markerLayer.Count(); p++) { geoArr[p] = markerLayer[p].GeoCoordinate; } setRect = LocationRectangle.CreateBoundingRectangle(geoArr); } if (setRect != null) { map1.SetView(setRect); } }
private void SetMapView(Map map, MapLayer mapLayer) { if (mapLayer.Count() == 1) { map.Center = mapLayer[0].GeoCoordinate; } else { bool gotRect = false; double north = 0; double west = 0; double south = 0; double east = 0; for (var p = 0; p < mapLayer.Count(); p++) { if (!gotRect) { gotRect = true; north = south = mapLayer[p].GeoCoordinate.Latitude; west = east = mapLayer[p].GeoCoordinate.Longitude; } else { if (north < mapLayer[p].GeoCoordinate.Latitude) { north = mapLayer[p].GeoCoordinate.Latitude; } if (west > mapLayer[p].GeoCoordinate.Longitude) { west = mapLayer[p].GeoCoordinate.Longitude; } if (south > mapLayer[p].GeoCoordinate.Latitude) { south = mapLayer[p].GeoCoordinate.Latitude; } if (east < mapLayer[p].GeoCoordinate.Longitude) { east = mapLayer[p].GeoCoordinate.Longitude; } } } if (gotRect) { map.SetView(new LocationRectangle(north, west, south, east)); } } }
void Circhegraphic_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { Ellipse clickedOne = sender as Ellipse; if (clickedOne != null && markerLayer != null) { Debug.WriteLine("Circhegraphic_MouseLeftButtonUp"); for (var i = 0; i < markerLayer.Count(); i++) { if (markerLayer[i].Content == clickedOne) { Debug.WriteLine("removing index: " + i); dynamicPolyline.Path.Remove(markerLayer[i].GeoCoordinate); // remove point from the polyline markerLayer.Remove(markerLayer[i]); // remove marker from the map } } } markerSelected = false; }
void ToggleVisibility() { if (selected_shape == "Rectangle") { if (Rectangle1 != null && (Rectangle1.Count() > 0)) { Rectangle rect = (Rectangle1[0].Content as Rectangle); if (rect.Visibility == System.Windows.Visibility.Visible) { Debug.WriteLine("Set Rectangle Visibility off "); rect.Visibility = System.Windows.Visibility.Collapsed; } else { Debug.WriteLine("Set Rectangle Visibility on "); rect.Visibility = System.Windows.Visibility.Visible; } } } else if (selected_shape == "Circle") { if (Circle != null && (Circle.Count() > 0)) { Ellipse circcle = (Circle[0].Content as Ellipse); if (circcle.Visibility == System.Windows.Visibility.Visible) { Debug.WriteLine("Set Circle Visibility off "); circcle.Visibility = System.Windows.Visibility.Collapsed; } else { Debug.WriteLine("Set Circle Visibility on "); circcle.Visibility = System.Windows.Visibility.Visible; } } } else if (selected_shape == "Polygons") { if (PolyCircle != null) { if (PolyCircle.StrokeColor == Color.FromArgb(0xFF, 0xFF, 0x00, 0xFF)) { Debug.WriteLine("Set Polygon Visibility off "); PolyCircle.FillColor = Color.FromArgb(0x00, 0xFF, 0xFF, 0x00); PolyCircle.StrokeColor = Color.FromArgb(0x00, 0xFF, 0x00, 0xFF); PolyRect.FillColor = Color.FromArgb(0x00, 0x00, 0x00, 0x00); PolyRect.StrokeColor = Color.FromArgb(0x00, 0xFF, 0xFF, 0xFF); } else { Debug.WriteLine("Set Polygon Visibility on "); PolyCircle.FillColor = Color.FromArgb(0x55, 0xFF, 0xFF, 0x00); PolyCircle.StrokeColor = Color.FromArgb(0xFF, 0xFF, 0x00, 0xFF); PolyRect.FillColor = Color.FromArgb(0x55, 0x00, 0x00, 0x00); PolyRect.StrokeColor = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF); } } } }
void geoQ_QueryCompleted(object sender, QueryCompletedEventArgs <IList <MapLocation> > e) { // The result is a GeocodeResponse object resList = e.Result; Debug.WriteLine("Geo query, error: " + e.Error); Debug.WriteLine("Geo query, cancelled: " + e.Cancelled); Debug.WriteLine("Geo query, cancelled: " + e.UserState.ToString()); Debug.WriteLine("Geo query, Result.Count(): " + resList.Count()); if (resList.Count() > 0) { for (int i = 0; i < resList.Count(); i++) { Debug.WriteLine("Result no.: " + i); Debug.WriteLine("Name: " + resList[i].Information.Name); Debug.WriteLine("Address.ToString: " + resList[i].Information.Address.ToString()); Debug.WriteLine("Address.District: " + resList[i].Information.Address.District); Debug.WriteLine("Address.Country: " + resList[i].Information.Address.CountryCode + ": " + resList[i].Information.Address.Country); Debug.WriteLine("Address.County: " + resList[i].Information.Address.County); Debug.WriteLine("Address.Neighborhood: " + resList[i].Information.Address.Neighborhood); Debug.WriteLine("Address.Street: " + resList[i].Information.Address.Street); Debug.WriteLine("Address.PostalCode: " + resList[i].Information.Address.PostalCode); Debug.WriteLine("Address.Continent: " + resList[i].Information.Address.Continent); Debug.WriteLine("GeoCoordinate.Latitude: " + resList[i].GeoCoordinate.Latitude.ToString()); Debug.WriteLine("GeoCoordinate.Longitude: " + resList[i].GeoCoordinate.Longitude.ToString()); string numNum = "0" + i; if (i > 9) { numNum = "" + i; } AddResultToMap(numNum, resList[i].GeoCoordinate); } } if ((markerLayer != null)) // fit all { if (markerLayer.Count() == 1) { map1.Center = markerLayer[0].GeoCoordinate; } else { bool gotRect = false; double north = 0; double west = 0; double south = 0; double east = 0; for (var p = 0; p < markerLayer.Count(); p++) { if (!gotRect) { gotRect = true; north = south = markerLayer[p].GeoCoordinate.Latitude; west = east = markerLayer[p].GeoCoordinate.Longitude; } else { if (north < markerLayer[p].GeoCoordinate.Latitude) { north = markerLayer[p].GeoCoordinate.Latitude; } if (west > markerLayer[p].GeoCoordinate.Longitude) { west = markerLayer[p].GeoCoordinate.Longitude; } if (south > markerLayer[p].GeoCoordinate.Latitude) { south = markerLayer[p].GeoCoordinate.Latitude; } if (east < markerLayer[p].GeoCoordinate.Longitude) { east = markerLayer[p].GeoCoordinate.Longitude; } } } if (gotRect) { map1.SetView(new LocationRectangle(north, west, south, east)); } } } }
void FitToView(bool all) { bool gotRect = false; double north = 0; double west = 0; double south = 0; double east = 0; if (all) // fit all { if ((oneMarker != null)) { gotRect = true; north = south = oneMarker.GeoCoordinate.Latitude; west = east = oneMarker.GeoCoordinate.Longitude; } if ((markerLayer != null)) // fit all { for (var p = 0; p < markerLayer.Count(); p++) { if (!gotRect) { gotRect = true; north = south = markerLayer[p].GeoCoordinate.Latitude; west = east = markerLayer[p].GeoCoordinate.Longitude; } else { if (north < markerLayer[p].GeoCoordinate.Latitude) { north = markerLayer[p].GeoCoordinate.Latitude; } if (west > markerLayer[p].GeoCoordinate.Longitude) { west = markerLayer[p].GeoCoordinate.Longitude; } if (south > markerLayer[p].GeoCoordinate.Latitude) { south = markerLayer[p].GeoCoordinate.Latitude; } if (east < markerLayer[p].GeoCoordinate.Longitude) { east = markerLayer[p].GeoCoordinate.Longitude; } } } } } else if (selected_shape == "5 Markers" && (markerLayer != null)) { for (var p = 0; p < markerLayer.Count(); p++) { if (!gotRect) { gotRect = true; north = south = markerLayer[p].GeoCoordinate.Latitude; west = east = markerLayer[p].GeoCoordinate.Longitude; } else { if (north < markerLayer[p].GeoCoordinate.Latitude) { north = markerLayer[p].GeoCoordinate.Latitude; } if (west > markerLayer[p].GeoCoordinate.Longitude) { west = markerLayer[p].GeoCoordinate.Longitude; } if (south > markerLayer[p].GeoCoordinate.Latitude) { south = markerLayer[p].GeoCoordinate.Latitude; } if (east < markerLayer[p].GeoCoordinate.Longitude) { east = markerLayer[p].GeoCoordinate.Longitude; } } } } else if (selected_shape == "One marker" && (oneMarker != null)) { gotRect = true; north = south = oneMarker.GeoCoordinate.Latitude; west = east = oneMarker.GeoCoordinate.Longitude; } if (gotRect) { map1.SetView(new LocationRectangle(north, west, south, east)); } }