private void MyMapView_MouseMove(object sender, MouseEventArgs e)
        {
            try
            {
                // Convert screen point to map point
                var point = MyMapView.ScreenToLocation(e.GetPosition(MyMapView));
                if (point == null)
                {
                    return;
                }

                var buffer = GeometryEngine.GeodesicBuffer(
                    GeometryEngine.NormalizeCentralMeridian(point),                     //Normalize in case we we're too far west/east of the world bounds
                    500, LinearUnits.Miles);

                Graphic bufferGraphic = null;
                if (_graphicsOverlay.Graphics.Count == 0)
                {
                    bufferGraphic = new Graphic {
                        Geometry = buffer, Symbol = _bufferSymbol
                    };
                    _graphicsOverlay.Graphics.Add(bufferGraphic);
                }
                else
                {
                    bufferGraphic = _graphicsOverlay.Graphics[0];
                }
                bufferGraphic.Geometry = buffer;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Geometry Engine Failed!");
            }
        }
        private void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e)
        {
            try
            {
                _graphicsOverlay.Graphics.Clear();

                var point  = e.Location;
                var buffer = GeometryEngine.GeodesicBuffer(
                    GeometryEngine.NormalizeCentralMeridian(point),                     //Normalize in case we we're too far west/east of the world bounds
                    500, LinearUnits.Miles);

                var pointGraphic = new Graphic {
                    Geometry = point, Symbol = _pinSymbol
                };
                _graphicsOverlay.Graphics.Add(pointGraphic);

                var bufferGraphic = new Graphic {
                    Geometry = buffer, Symbol = _bufferSymbol
                };
                _graphicsOverlay.Graphics.Add(bufferGraphic);
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
            }
        }
Пример #3
0
 //When location changes, push this location to the route datasource
 private void LocationDisplay_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     if (e.PropertyName == "CurrentLocation")
     {
         if (LocationDisplay.CurrentLocation != null && !LocationDisplay.CurrentLocation.Location.IsEmpty)
         {
             if (Route != null)
             {
                 Route.SetCurrentLocation(LocationDisplay.CurrentLocation.Location);
             }
             if (firstLocation)
             {
                 var accuracy = double.IsNaN(LocationDisplay.CurrentLocation.HorizontalAccuracy) ? 0 :
                                LocationDisplay.CurrentLocation.HorizontalAccuracy;
                 ExtentRequested = GeometryEngine.GeodesicBuffer(LocationDisplay.CurrentLocation.Location,
                                                                 accuracy + 500, LinearUnits.Meters).Extent;
                 firstLocation = false;
                 if (Route == null && m_routeTaskCancellationToken == null && !string.IsNullOrWhiteSpace(RouteToAddress))                         //calculate route now
                 //Calculate a route from the address
                 {
                     GenerateRoute(RouteToAddress);
                 }
             }
         }
     }
 }
        private async void GenerateGeodesicBuffer_Click(object sender, RoutedEventArgs e)
        {
            string message = null;

            try
            {
                GraphicsLayer inputGraphicsLayer = null;
                var           drawShape          = (DrawShape)DrawShapes.SelectedItem;
                inputGraphicsLayer = drawShape == DrawShape.Point ? mapView1.Map.Layers["PointInputLayer"] as GraphicsLayer :
                                     ((drawShape == DrawShape.Polyline) ? mapView1.Map.Layers["LineInputLayer"] as GraphicsLayer : mapView1.Map.Layers["PolygonInputLayer"] as GraphicsLayer);

                if (inputGraphicsLayer.Graphics.Count == 0)
                {
                    throw new Exception("No input shape. Please draw shape to generate buffer");
                }
                Esri.ArcGISRuntime.Geometry.Geometry geom = inputGraphicsLayer.Graphics.FirstOrDefault().Geometry;

                if (geom != null)
                {
                    string json   = geom.ToJson();
                    var    buffer = GeometryEngine.GeodesicBuffer(geom, 10, LinearUnits.Meters);
                    if (buffer != null)
                    {
                        GraphicsLayer resultGraphicsLayer = mapView1.Map.Layers["GeometryResultGraphicsLayer"] as GraphicsLayer;
                        resultGraphicsLayer.Graphics.Add(new Graphic()
                        {
                            Geometry = buffer
                        });
                        mapView1.SetView(resultGraphicsLayer.Graphics.First().Geometry.Extent);
                    }
                }
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            if (message != null)
            {
                await new MessageDialog(message).ShowAsync();
            }
        }
Пример #5
0
        private void LocationButton_Checked(object sender, RoutedEventArgs e)
        {
            _myLocationOverlay.Graphics.Clear();
            var point  = MyMapView.LocationDisplay.CurrentLocation.Location;
            var buffer = GeometryEngine.GeodesicBuffer(point, 300, LinearUnits.Meters);

            MyMapView.SetView(buffer.Extent);

            var symbol = new PictureMarkerSymbol()
            {
                Width = 48, Height = 48, YOffset = 24
            };

            symbol.SetSourceAsync(new Uri("ms-appx:///Assets/CollPin.png"));
            var graphic = new Graphic()
            {
                Geometry = point,
                Symbol   = symbol
            };

            _myLocationOverlay.Graphics.Add(graphic);
        }