Пример #1
0
        private async void MapViewTapped(object sender, GeoViewInputEventArgs geoViewInputEventArgs)
        {
            // Identify the tapped graphics
            IdentifyGraphicsOverlayResult result = null;

            try
            {
                result = await MyMapView.IdentifyGraphicsOverlayAsync(_graphicsOverlay, geoViewInputEventArgs.Position, 1, false);
            }
            catch (Exception e)
            {
                await new MessageDialog(e.ToString(), "Error").ShowAsync();
            }

            // Return if there are no results
            if (result == null || result.Graphics.Count < 1)
            {
                return;
            }

            // Get the first identified graphic
            Graphic identifiedGraphic = result.Graphics.First();

            // Clear any existing selection, then select the tapped graphic
            _graphicsOverlay.ClearSelection();
            identifiedGraphic.IsSelected = true;

            // Get the selected graphic's geometry
            Geometry selectedGeometry = identifiedGraphic.Geometry;

            // Perform the calculation and show the results
            ResultTextbox.Text = GetOutputText(selectedGeometry);
        }
Пример #2
0
        private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e)
        {
            // Identify the tapped graphics
            IdentifyGraphicsOverlayResult result = null;

            try
            {
                result = await MyMapView.IdentifyGraphicsOverlayAsync(_graphicsOverlay, e.Position, 1, false);
            }
            catch (Exception ex)
            {
                await((Page)Parent).DisplayAlert("Error", ex.ToString(), "OK");
            }

            // Return if there are no results
            if (result == null || result.Graphics.Count < 1)
            {
                return;
            }

            // Get the first identified graphic
            Graphic identifiedGraphic = result.Graphics.First();

            // Clear any existing selection, then select the tapped graphic
            _graphicsOverlay.ClearSelection();
            identifiedGraphic.IsSelected = true;

            // Get the selected graphic's geometry
            Geometry selectedGeometry = identifiedGraphic.Geometry;

            // Perform the calculation and show the results
            ResultTextbox.Text = GetOutputText(selectedGeometry);
        }
Пример #3
0
        private async void OnMapViewTapped(object sender, GeoViewInputEventArgs e)
        {
            double tolerance        = 10d;   // Use larger tolerance for touch
            int    maximumResults   = 1;     // Only return one graphic
            bool   onlyReturnPopups = false; // Don't return only popups

            try
            {
                // Use the following method to identify graphics in a specific graphics overlay
                IdentifyGraphicsOverlayResult identifyResults = await MyMapView.IdentifyGraphicsOverlayAsync(
                    _polygonOverlay,
                    e.Position,
                    tolerance,
                    onlyReturnPopups,
                    maximumResults);

                // Check if we got results
                if (identifyResults.Graphics.Count > 0)
                {
                    //  Display to the user the identify worked.
                    await new MessageDialog("Tapped on graphic", "").ShowAsync();
                }
            }
            catch (Exception ex)
            {
                await new MessageDialog(ex.ToString(), "Error").ShowAsync();
            }
        }
        private async void OnMapViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e)
        {
            double tolerance        = 10d;   // Use larger tolerance for touch
            int    maximumResults   = 1;     // Only return one graphic
            bool   onlyReturnPopups = false; // Don't return only popups

            try
            {
                // Use the following method to identify graphics in a specific graphics overlay
                IdentifyGraphicsOverlayResult identifyResults = await MyMapView.IdentifyGraphicsOverlayAsync(
                    _polygonOverlay,
                    e.Position,
                    tolerance,
                    onlyReturnPopups,
                    maximumResults);

                // Check if we got results
                if (identifyResults.Graphics.Count > 0)
                {
                    // Make sure that the UI changes are done in the UI thread
                    Device.BeginInvokeOnMainThread(async() => {
                        await((Page)Parent).DisplayAlert("", "Tapped on graphic", "OK");
                    });
                }
            }
            catch (Exception ex)
            {
                await((Page)Parent).DisplayAlert("Error", ex.ToString(), "OK");
            }
        }
Пример #5
0
        private async void OnMapViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e)
        {
            var tolerance        = 10d;   // Use larger tolerance for touch
            var maximumResults   = 1;     // Only return one graphic
            var onlyReturnPopups = false; // Don't return only popups

            // Use the following method to identify graphics in a specific graphics overlay
            IdentifyGraphicsOverlayResult identifyResults = await MyMapView.IdentifyGraphicsOverlayAsync(
                overlay,
                e.Position,
                tolerance,
                onlyReturnPopups,
                maximumResults
                );

            // Check if we got results
            if (identifyResults.Graphics.Count > 0)
            {
                // Make sure that the UI changes are done in the UI thread
                Device.BeginInvokeOnMainThread(async() => {
                    var json = JsonConvert.SerializeObject(identifyResults.Graphics[0].Attributes, Formatting.Indented);
                    await DisplayAlert("", json, "OK");
                });
            }
        }
Пример #6
0
        private async void MapViewTapped(object sender, GeoViewInputEventArgs geoViewInputEventArgs)
        {
            IdentifyGraphicsOverlayResult result = null;

            try
            {
                // Identify the tapped graphics
                result = await MyMapView.IdentifyGraphicsOverlayAsync(_graphicsOverlay, geoViewInputEventArgs.Position, 1, false);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Error");
            }

            // Return if there are no results
            if (result == null || result.Graphics.Count < 1)
            {
                return;
            }

            // Get the first identified graphic
            Graphic identifiedGraphic = result.Graphics.First();

            // Clear any existing selection, then select the tapped graphic
            _graphicsOverlay.ClearSelection();
            identifiedGraphic.IsSelected = true;

            // Get the selected graphic's geometry
            Geometry selectedGeometry = identifiedGraphic.Geometry;

            // Update the spatial relationship display
            switch (selectedGeometry.GeometryType)
            {
            case GeometryType.Point:
                PointTreeEntry.ItemsSource    = null;
                PolygonTreeEntry.ItemsSource  = GetSpatialRelationships(selectedGeometry, _polygonGraphic.Geometry);
                PolylineTreeEntry.ItemsSource = GetSpatialRelationships(selectedGeometry, _polylineGraphic.Geometry);
                break;

            case GeometryType.Polygon:
                PolygonTreeEntry.ItemsSource  = null;
                PointTreeEntry.ItemsSource    = GetSpatialRelationships(selectedGeometry, _pointGraphic.Geometry);
                PolylineTreeEntry.ItemsSource = GetSpatialRelationships(selectedGeometry, _polylineGraphic.Geometry);
                break;

            case GeometryType.Polyline:
                PolylineTreeEntry.ItemsSource = null;
                PointTreeEntry.ItemsSource    = GetSpatialRelationships(selectedGeometry, _pointGraphic.Geometry);
                PolygonTreeEntry.ItemsSource  = GetSpatialRelationships(selectedGeometry, _polygonGraphic.Geometry);
                break;
            }

            // Expand the tree view
            PolylineTreeEntry.IsExpanded = true;
            PolygonTreeEntry.IsExpanded  = true;
            PointTreeEntry.IsExpanded    = true;
        }
        async void MyMapView_GeoViewTapped(System.Object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e)
        {
            // Clear any currently visible callouts, route graphics, or selections
            MyMapView.DismissCallout();
            _routeGraphicsOverlay.Graphics.Clear();
            _placesGraphicsOverlay.ClearSelection();

            // Get the place under the tap
            IdentifyGraphicsOverlayResult idResult = await MyMapView.IdentifyGraphicsOverlayAsync(_placesGraphicsOverlay, e.Position, 12, false);

            Graphic clickedElement = idResult.Graphics.FirstOrDefault();

            if (clickedElement != null)
            {
                // Select the place to highlight it; get name and address
                clickedElement.IsSelected = true;
                string name    = clickedElement.Attributes["Name"].ToString();
                string address = clickedElement.Attributes["Address"].ToString();

                // Create a callout definition that shows the name and address for the place; set the element as a tag
                CalloutDefinition definition = new CalloutDefinition(name, address);
                definition.Tag = clickedElement;

                // Handle button clicks for the button on the callout
                // This event receives the value assigned as the CalloutDefinition.Tag
                // ** Fix API ref for this!
                // https://developers.arcgis.com/net/latest/wpf/api-reference/html/P_Esri_ArcGISRuntime_UI_CalloutDefinition_OnButtonClick.htm
                definition.OnButtonClick = new Action <object>(async(tag) =>
                {
                    // Get the geoelement that represents the place
                    GeoElement poiElement = tag as GeoElement;
                    if (poiElement == null)
                    {
                        return;
                    }

                    // Call a function in the viewmodel that will route to this location
                    var routeGraphic = await _viewModel.RouteToPoiAsync(_deviceLocation, poiElement.Geometry as MapPoint, MyMapView.SpatialReference);

                    // Add the route graphic to the map view and zoom to its extent
                    _routeGraphicsOverlay.Graphics.Add(routeGraphic);
                    await MyMapView.SetViewpointGeometryAsync(routeGraphic.Geometry, 30);
                });

                // Set the button icon and show the callout at the click location
                definition.ButtonImage = WalkIcon;
                MyMapView.ShowCalloutAt(e.Location, definition);
            }
        }
        private async void OnMapViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.UI.GeoViewInputEventArgs e)
        {
            var tolerance      = 10d; // Use larger tolerance for touch
            var maximumResults = 1;   // Only return one graphic

            // Use the following method to identify graphics in a specific graphics overlay
            IReadOnlyList <Graphic> identifyResults = await MyMapView.IdentifyGraphicsOverlayAsync(
                _polygonOverlay,
                e.Position,
                tolerance, maximumResults);

            // Check if we got results
            if (identifyResults.Count > 0)
            {
                // Make sure that the UI changes are done in the UI thread
                Device.BeginInvokeOnMainThread(async() => {
                    await DisplayAlert("", "Tapped on graphic", "OK");
                });
            }
        }
Пример #9
0
        private async void OnMapViewTapped(object sender, GeoViewInputEventArgs e)
        {
            double tolerance        = 10d;   // Use larger tolerance for touch
            int    maximumResults   = 1;     // Only return one graphic
            bool   onlyReturnPopups = false; // Return more than popups

            // Use the following method to identify graphics in a specific graphics overlay
            IdentifyGraphicsOverlayResult identifyResults = await MyMapView.IdentifyGraphicsOverlayAsync(
                _polygonOverlay,
                e.Position,
                tolerance,
                onlyReturnPopups,
                maximumResults);

            // Check if we got results
            if (identifyResults.Graphics.Count > 0)
            {
                //  Display to the user the identify worked.
                MessageBox.Show("Tapped on graphic", "");
            }
        }