private Location PinIt(string url, string person) { var request = WebRequest.Create(url.ToString()) as HttpWebRequest; using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { if (response.StatusCode == HttpStatusCode.OK) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(response.GetResponseStream()); var node = xmlDoc.DocumentElement.LastChild.LastChild.LastChild.FirstChild.LastChild; string latitude = node["Latitude"].InnerText; double latitudeD = Double.Parse(latitude.Replace('.', ',')); string longitude = node["Longitude"].InnerText; double longitudeD = Double.Parse(longitude.Replace('.', ',')); var location = new Location() { Latitude = latitudeD, Longitude = longitudeD }; ParcelMap.PinPushpinWithName(location, person); ParcelMap.Center = location; ParcelMap.ZoomLevel = 14; return(location); } return(null); } }
private void FindResultControl_SelectionChanged(object sender, SelectionChangedEventArgs e) { // User selected a result, zoom to feature. ObservableCollection <FindResultValue> findResults = FindResultControl.ItemsSource as ObservableCollection <FindResultValue>; int index = FindResultControl.SelectedIndex; if ((index < 0) || (index >= findResults.Count())) { return; } if (findResults[index].Geometry != null) { if (ParcelMap.SpatialReference.Equals(findResults[index].Geometry.SpatialReference)) { ParcelMap.ZoomTo(findResults[index].Geometry.Extent.Expand(1.5)); // If we zoom into far, the parcel might fall below the min resolution. // ParcelMap_ExtentChanged will correct this. } else { MessageBox.Show((string)Application.Current.FindResource("strQueryServiceSRNotEqual"), (string)Application.Current.FindResource("strNavigationFailed")); } } }
private void SendParcel_Click(object sender, RoutedEventArgs e) { var parcelAddViewModel = (ParcelAddViewModel)DataContext; InfoWindow info = new InfoWindow(); if (!CalculateCost()) { return; } DataModel.Region senderRegion = null; if (parcelAddViewModel.ParcelSendMethodSelected.id == 2) { senderRegion = ParcelMap.GetCurrentRegion(From, companyEntities); if (senderRegion == null) { info.ShowInfo("Lokalizacja nadania przesyłki znajduje się w nieobsługiwanym regionie!", "Nadanie przesyłki", "Ok"); return; } } DataModel.Region receiverRegion = null; receiverRegion = ParcelMap.GetCurrentRegion(To, companyEntities); if (receiverRegion == null) { info.ShowInfo("Lokalizacja odbioru przesyłki znajduje się w nieobsługiwanym regionie!", "Nadanie przesyłki", "Ok"); return; } if (parcelAddViewModel.ParcelTypeSelected.id == (int)EnumTypeOfParcel.CashOnDelivery) { info.ShowInfo($"Przesyłka została wyceniona na kwotę {parcelAddViewModel.MyTariff.cost + 10} zł. Chcesz nadać przesyłkę?", "Nadanie przeyłki", "Nie", "Tak"); } else { info.ShowInfo($"Przesyłka została wyceniona na kwotę {parcelAddViewModel.MyTariff.cost} zł. Chcesz nadać przesyłkę?", "Nadanie przeyłki", "Nie", "Tak"); } if (!info.Answer) { return; } if (parcelAddViewModel.SendParcel(senderRegion, receiverRegion, From, To, (bool)generateLabel.IsChecked, (bool)generateConfirmate.IsChecked)) { info.ShowInfo("Przesyłka została nadana!", "Nadanie przesyłki", "Ok"); ParcelMap.ClearAllMap(); Worth.Text = "0,00 zł"; generateLabel.IsChecked = false; generateConfirmate.IsChecked = false; parcelAddViewModel.VisibilityOption = Visibility.Hidden; } else { info.ShowInfo("Nie udało się nadać przesyłki!", "Nadanie przesyłki", "Ok"); } }
private void ParcelMap_ExtentChanged(object sender, ExtentEventArgs e) { if (System.Diagnostics.Debugger.IsAttached) { ShowProjectedExtent(sender as Map); } // If we have zoomed less than the min resolution, zoom out a slight amount of the min to ensure display is drawn double minRes = ParcelMap.MinimumResolution * 1.0001; if (ParcelMap.Resolution <= minRes) { ParcelMap.ZoomToResolution(minRes); } }
private void ParcelMap_MouseRightButtonDown(object sender, MouseButtonEventArgs e) { ContextMenu context = new ContextMenu(); context.IsOpen = true; if (_noOfErrorsOnScreen == 0 && !Lock) { var setPushpins = new MenuItem() { Header = "Wyznacz pinezki na podstawie adresów" }; setPushpins.Click += (se, e) => { ParcelMap.ClearAllMap(); SetPushpins(); }; context.Items.Add(setPushpins); var setManualPushpins = new MenuItem() { Header = "Dodaj pinezki samodzielnie" }; setManualPushpins.Click += (se, e) => { ParcelMap.ClearAllMap(); if (From != null) { ParcelMap.PinPushpinWithName(From, "Nadawca"); } if (To != null) { ParcelMap.PinPushpinWithName(To, "Odbiorca"); } SetManualPushpinsAsync(); }; context.Items.Add(setManualPushpins); } }
private void Route(BingMapsRESTService.Common.JSON.Response r) { if (r != null && r.ResourceSets != null && r.ResourceSets.Length > 0 && r.ResourceSets[0].Resources != null && r.ResourceSets[0].Resources.Length > 0) { BingMapsRESTService.Common.JSON.Route route = r.ResourceSets[0].Resources[0] as BingMapsRESTService.Common.JSON.Route; double[][] routePath = route.RoutePath.Line.Coordinates; LocationCollection locs = new LocationCollection(); for (int i = 0; i < routePath.Length; i++) { if (routePath[i].Length >= 2) { locs.Add(new Microsoft.Maps.MapControl.WPF.Location(routePath[i][0], routePath[i][1])); } } MapPolyline routeLine = new MapPolyline() { Locations = locs, Stroke = new SolidColorBrush(Colors.Blue), StrokeThickness = 5 }; ParcelMap.Children.Add(routeLine); ParcelMap.SetView(locs, new Thickness(30), 0); var parcelAddViewModel = (ParcelAddViewModel)DataContext; parcelAddViewModel.ParcelDistance = route.TravelDistance; parcelAddViewModel.ParcelDuration = route.TravelDuration; } }
private async void SetManualPushpinsAsync() { Lock = true; InfoWindow info = new InfoWindow(); string sender = "Nadawca"; string receiver = "Odbiorca"; if (From != null) { info.ShowInfo("Czy chcesz zmienić lokalizacje nadawcy?", "Zmiana lokalizacji", "Nie", "Tak"); if (info.Answer) { info.ShowInfo("Dodaj lokalizację nadawcy poprzez dwukrotne kliknięcie na mapie!", "Dodaj pinezkę", "Ok"); await ParcelMap.PinPushpinWhenClicked(true, sender); } } else { info.ShowInfo("Dodaj lokalizację nadawcy poprzez dwukrotne kliknięcie na mapie!", "Dodaj pinezkę", "Ok"); await ParcelMap.PinPushpinWhenClicked(false, sender); } if (To != null) { info.ShowInfo("Czy chcesz zmienić lokalizacje odbiorcy?", "Zmiana lokalizacji", "Nie", "Tak"); if (info.Answer) { info.ShowInfo("Dodaj lokalizację odbiorcy poprzez dwukrotne kliknięcie na mapie!", "Dodaj pinezkę", "Ok"); await ParcelMap.PinPushpinWhenClicked(true, receiver); } } else { info.ShowInfo("Dodaj lokalizację odbiorcy poprzez dwukrotne kliknięcie na mapie!", "Dodaj pinezkę", "Ok"); await ParcelMap.PinPushpinWhenClicked(false, receiver); } var pushpins = ParcelMap.GetPushpins(); From = pushpins.FirstOrDefault(p => p.Content.Equals(sender)).Location; To = pushpins.FirstOrDefault(p => p.Content.Equals(receiver)).Location; if (From == null || To == null) { info.ShowInfo("Ze względu na brak jednej z lokalizacji nie można wyznaczyć trasy.\nProszę powtórz procedurę dodawania pinezek.", "Błąd wyznaczania trasy", "Ok"); info.Close(); Lock = false; return; } string uri = $"http://dev.virtualearth.net/REST/V1/Routes/Driving?wp.0={From.Latitude},{From.Longitude}&wp.1={To.Latitude},{To.Longitude}&rpo=Points&key={MAP_KEY}"; var response = DriveRoute(uri); if (response != null) { Route(response); SetDistanceAndDuration(); } else { info.ShowInfo("Nie można wyznaczyć trasy. Proszę spróbować jeszcze raz.", "Błąd wyznaczania trasy", "Ok"); } info.Close(); Lock = false; }
private void ScaleRotate(Point srcPoint) { if (!PDE_Tools.IsExpanded) { return; } ParcelData parcelData = ParcelGridContainer.DataContext as ParcelData; _moveScale = _oldScale = parcelData.ScaleValue; _moveRotation = _oldRotation = parcelData.RotationValue; _srPoint = ParcelMap.ScreenToMap(srcPoint); _srSnapPoint = null; double spX = _srPoint.X; double spY = _srPoint.Y; // Find _startPoint in list of points. If "close" snap to that point. // Otherwise user can free form scale or rotate parcel lines. double shortestDistance = double.MaxValue; Int32 shortestId = -1; ESRI.ArcGIS.Client.Geometry.MapPoint foundPoint = null; foreach (KeyValuePair <Int32, ESRI.ArcGIS.Client.Geometry.MapPoint> kvp in _calculatedPoints) { double x = kvp.Value.X; double y = kvp.Value.Y; double distance = GeometryUtil.LineLength(spX, spY, x, y); if ((distance < shortestDistance) && (distance < _xmlConfiguation.SnapTolerance)) { shortestDistance = distance; shortestId = kvp.Key; foundPoint = new ESRI.ArcGIS.Client.Geometry.MapPoint(x, y); } } if (BearingDistanceToPoint(shortestId, out _srBearingToPoint, out _srDistanceToPoint, out _srSnapPoint)) { // BearingDistanceToPoint will fail if shortestId == -1 _srSnapPointId = shortestId; if (RotationButton.IsChecked == true) { double radialSearch = _srDistanceToPoint * parcelData.ScaleValue; // We seem to be getting some numerical precision error when rotating... this does not // really matter here; we only need to re-buffer if the changes are > 0.1. // if the user re-rotate with the same rotate point, try to avoid re-caching. if ((_originPoint == null) || (_lastGeometryCP == null) || (Math.Abs(_lastSearchDistance - radialSearch) > 0.1) || !_lastBufferBasedOnCurve || (_lastGeometryCP.X != _originPoint.X) || (_lastGeometryCP.Y != _originPoint.Y)) { ESRI.ArcGIS.Client.Geometry.MapPoint offsetOriginPoint = new ESRI.ArcGIS.Client.Geometry.MapPoint(_originPoint.X - radialSearch, _originPoint.Y); // Create a geometry circle from the anchor/rotating point to the snap point. // We will create create a cache of all these points within the buffer distance // of this circle. ESRI.ArcGIS.Client.Geometry.MapPoint endPoint; ESRI.ArcGIS.Client.Geometry.Polyline circle = GeometryUtil.ConstructArcSegment(offsetOriginPoint, 0.0, 0.001, radialSearch, false, SweepDirection.Counterclockwise, out endPoint); _lastGeometryCP = _originPoint; _lastSearchDistance = radialSearch; _lastBufferBasedOnCurve = true; CacheSnapObjects(circle, radialSearch); } } else if (ScaleButton.IsChecked == true) { double mapDistanceBuffer = _srDistanceToPoint * 1.5 * parcelData.ScaleValue; // if the user re-scales with the same scale point, try to avoid re-caching. if ((_originPoint == null) || (_lastGeometryCP == null) || (_lastSearchDistance < mapDistanceBuffer) || _lastBufferBasedOnCurve || (_lastGeometryCP.X != _originPoint.X) || (_lastGeometryCP.Y != _originPoint.Y)) { // Create a line from the anchor/rotating point to the snap point * 1.5 of the distance. // We will create create a cache of all these points within the buffer distance // of this line. ESRI.ArcGIS.Client.Geometry.MapPoint endPoint; ESRI.ArcGIS.Client.Geometry.Polyline snapLine = GeometryUtil.Line(_originPoint, _srBearingToPoint - parcelData.RotationValue, mapDistanceBuffer, out endPoint); if (snapLine != null) { _lastGeometryCP = _originPoint; _lastSearchDistance = mapDistanceBuffer; _lastBufferBasedOnCurve = false; CacheSnapObjects(snapLine, mapDistanceBuffer); } } } // else no snapping. CalculateAndAddLineGraphics(); // Redraw so we have snap graphic shown } else // BearingDistanceToPoint returns false if id = -1 { _srSnapPointId = -1; } }
private void ParcelMap_MouseMove(object sender, MouseEventArgs e) { if (ParcelLineInfoWindow.IsOpen == true && ParcelLineInfoWindow.Visibility == System.Windows.Visibility.Visible) { const double hideDistance = 25; double width = ParcelLineInfoWindow.ActualWidth; double height = ParcelLineInfoWindow.ActualHeight; var anchorScreenPoint = ParcelMap.MapToScreen(ParcelLineInfoWindow.Anchor); double x1 = anchorScreenPoint.X - width / 2 - hideDistance; double y1 = anchorScreenPoint.Y - height - hideDistance - 10; // -ve for info indicator double x2 = anchorScreenPoint.X + width / 2 + hideDistance; double y2 = anchorScreenPoint.Y + hideDistance; var envelope = new ESRI.ArcGIS.Client.Geometry.Envelope(x1, y1, x2, y2); Point pointLoc = e.GetPosition(this); if (!envelope.Intersects(new ESRI.ArcGIS.Client.Geometry.Envelope(pointLoc.X, pointLoc.Y, pointLoc.X, pointLoc.Y))) { ParcelLineInfoWindow.IsOpen = false; ParcelMap.Focus(); // Cause any non-committed cell in the popup window to lose its focus. This will commit the cell. } } if ((_srPoint == null) || !PDE_Tools.IsExpanded) { return; } ParcelData parcelData = ParcelGridContainer.DataContext as ParcelData; ESRI.ArcGIS.Client.Geometry.MapPoint currentPoint = ParcelMap.ScreenToMap(e.GetPosition(this)); if (RotationButton.IsChecked == true) { double rotation = GeometryUtil.Angle(_srPoint, currentPoint, _originPoint) + _oldRotation; while (rotation < -Math.PI) { rotation += Math.PI * 2; } while (rotation > Math.PI) { rotation -= Math.PI * 2; } parcelData.RotationValue = rotation; } else if (ScaleButton.IsChecked == true) { parcelData.ScaleValue = GeometryUtil.Scale(_srPoint, currentPoint, _originPoint) * _oldScale; } // If we have a snap point, adjust scale/rotation if we can snap point. if (_srSnapPointId != -1) { bool isRotating = RotationButton.IsChecked.GetValueOrDefault(false); bool isScaling = ScaleButton.IsChecked.GetValueOrDefault(false); double distanceToPoint = _srDistanceToPoint * parcelData.ScaleValue; double bearingToPoint = _srBearingToPoint - parcelData.RotationValue; if (bearingToPoint >= 2 * Math.PI) { bearingToPoint -= 2 * Math.PI; } ESRI.ArcGIS.Client.Geometry.MapPoint snapPointSR = GeometryUtil.ConstructPoint(_originPoint, bearingToPoint, distanceToPoint); if (snapPointSR != null) { ESRI.ArcGIS.Client.Geometry.Polyline snapLine; SnapPointToCacheObjects(snapPointSR, isScaling, out snapLine); // if scaling, skip zero distance so if (snapLine != null) // we don't snap to origin point. { bool ok = false; ESRI.ArcGIS.Client.Geometry.MapPoint intersectPoint = null; if (isRotating) { ok = GeometryUtil.ConstructPointLineCurveIntersection(snapLine, _originPoint, bearingToPoint, distanceToPoint, out intersectPoint); // distanceToPoint is radius here if (ok) // Only snap if the mouse location is within snap solution { ok = GeometryUtil.LineLength(intersectPoint, currentPoint) <= _xmlConfiguation.SnapTolerance; } if (ok) { parcelData.RotationValue = GeometryUtil.Angle(_srSnapPoint, intersectPoint, _originPoint); } } else if (isScaling) { ESRI.ArcGIS.Client.Geometry.MapPoint endPoint = GeometryUtil.ConstructPoint(_originPoint, bearingToPoint, distanceToPoint + _xmlConfiguation.SnapTolerance); ESRI.ArcGIS.Client.Geometry.Polyline sourceLine = GeometryUtil.Line(_originPoint, endPoint); ok = GeometryUtil.ConstructPointLineLineIntersection(snapLine, sourceLine, out intersectPoint); if (ok) // Only snap if the mouse location is within snap solution { ok = GeometryUtil.LineLength(intersectPoint, currentPoint) <= _xmlConfiguation.SnapTolerance; } if (ok) { double scale = GeometryUtil.Scale(_srSnapPoint, intersectPoint, _originPoint); if (scale > 0.0) { parcelData.ScaleValue = scale; } } } // Test code for debugging. // //GraphicsLayer testGraphicsLayer = ParcelMap.Layers["TestGraphicLayer"] as GraphicsLayer; //testGraphicsLayer.ClearGraphics(); //if (intersectPoint != null) //{ // ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic() // { // Geometry = intersectPoint, // Symbol = LayoutRoot.Resources["TestMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol // }; // testGraphicsLayer.Graphics.Add(graphic); //} } } } // Only redraw if there have been an update; // Otherwise runtime does not process mouse up and over flashes. if ((parcelData.ScaleValue != _moveScale) || (parcelData.RotationValue != _moveRotation)) { CalculateAndAddLineGraphics(); _moveScale = parcelData.ScaleValue; _moveRotation = parcelData.RotationValue; } }
private void QueryLayer_ExecuteCompleted(object sender, QueryEventArgs args) { ObservableCollection <FindResultValue> findResults = FindResultControl.ItemsSource as ObservableCollection <FindResultValue>; if (!_foundParcel) { findResults.Clear(); } LayerDefinition layerDefn = (LayerDefinition)args.UserState; // display search results for this layers query. if (args.FeatureSet.Features.Count > 0) { // Show search window if (!_foundParcel) { FindResultControl.Visibility = System.Windows.Visibility.Visible; } foreach (Graphic feature in args.FeatureSet.Features) { _foundParcel = true; string name = ""; foreach (string fieldName in layerDefn.DisplayFields) { if (name != "") { name += ", "; } // Since accessing the dictionary via the [] operator is case sensitive, // ie, name += (string)feature.Attributes[fieldName]; // we need to enum thru all the values. foreach (var att in feature.Attributes) { if (att.Key.ToLower() == fieldName.ToLower()) { if (att.Value != null) { name += att.Value.ToString(); } break; } } } if (!_foundParcel) { ParcelMap.PanTo(feature.Geometry); // Pan to the first result } _foundParcel = true; FindResultValue resultValue = new FindResultValue() { Layer = layerDefn.Name, Item = name, ItemTooltip = layerDefn.Tooltip }; resultValue.Geometry = feature.Geometry; // "Zoom to" geometry findResults.Add(resultValue); // display result values } } else { System.Console.WriteLine("No features returned from {0}", layerDefn.Name); } // when we have received the same number of replies as we issued, then hide the spinning arrow System.Threading.Interlocked.Increment(ref _queryAttributeComplete); if (_queryAttributeCount == _queryAttributeComplete) { Loading.Visibility = System.Windows.Visibility.Collapsed; // spinning arrow CalculateAndAddLineGraphics(); } }