private async void OnMapViewTapped(object sender, GeoViewInputEventArgs e)
        {
            var tolerance = 10d; // Use larger tolerance for touch
            var maximumResults = 1; // Only return one graphic  
            var onlyReturnPopups = false; // Don't only return 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)
            {
                // Make sure that the UI changes are done in the UI thread
                RunOnUiThread(() =>
                {
                    var alert = new AlertDialog.Builder(this);
                    alert.SetMessage("Tapped on graphic");
                    alert.Show();
                });
            }
        }
        private async void OnMapViewTapped(object sender, GeoViewInputEventArgs e)
        {
            try
            {
                // Define the selection tolerance
                double tolerance = 5;

                // Convert the tolerance to map units
                double mapTolerance = tolerance * MyMapView.UnitsPerPixel;

                // Define the envelope around the tap location for selecting features
                var selectionEnvelope = new Envelope(e.Location.X - mapTolerance, e.Location.Y - mapTolerance, e.Location.X + mapTolerance,
                    e.Location.Y + mapTolerance, MyMapView.Map.SpatialReference);

                // Define the query parameters for selecting features
                var queryParams = new QueryParameters();

                // Set the geometry to selection envelope for selection by geometry
                queryParams.Geometry = selectionEnvelope;

                // Select the features based on query parameters defined above
                await _featureLayer.SelectFeaturesAsync(queryParams, SelectionMode.New);
            }
            catch (Exception ex)
            {
                var message = new MessageDialog(ex.ToString(), "An error occured").ShowAsync();
            }
        }
        private async void OnMapViewTapped(object sender, GeoViewInputEventArgs e)
        {
            try
            {
                // Define the selection tolerance (half the marker symbol size so that any click on the symbol will select the feature)
                double tolerance = 14;

                // Convert the tolerance to map units
                double mapTolerance = tolerance * MyMapView.UnitsPerPixel;

                // Define the envelope around the tap location for selecting features
                var selectionEnvelope = new Envelope(e.Location.X - mapTolerance, e.Location.Y - mapTolerance, e.Location.X + mapTolerance,
                    e.Location.Y + mapTolerance, MyMapView.Map.SpatialReference);

                // Define the query parameters for selecting features
                var queryParams = new QueryParameters();

                // Set the geometry to selection envelope for selection by geometry
                queryParams.Geometry = selectionEnvelope;

                // Select the features based on query parameters defined above
                await _featureLayer.SelectFeaturesAsync(queryParams, Esri.ArcGISRuntime.Mapping.SelectionMode.New);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Sample error", ex.ToString());
            }
        }
        private async void _myMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            try
            {
                // Clear the existing graphics & callouts.
                _myMapView.DismissCallout();
                _myMapView.GraphicsOverlays[0].Graphics.Clear();

                // Add a graphic for the tapped point.
                Graphic pinGraphic = await GraphicForPoint(e.Location);

                _myMapView.GraphicsOverlays[0].Graphics.Add(pinGraphic);

                // Normalize the geometry - needed if the user crosses the international date line.
                MapPoint normalizedPoint = (MapPoint)GeometryEngine.NormalizeCentralMeridian(e.Location);

                // Reverse geocode to get addresses.
                IReadOnlyList <GeocodeResult> addresses = await _geocoder.ReverseGeocodeAsync(normalizedPoint);

                // Get the first result.
                GeocodeResult address = addresses.First();

                // Use the city and region for the Callout Title.
                string calloutTitle = address.Attributes["Address"].ToString();

                // Use the metro area for the Callout Detail.
                string calloutDetail = address.Attributes["City"] +
                                       " " + address.Attributes["Region"] +
                                       " " + address.Attributes["CountryCode"];

                // Define the callout.
                CalloutDefinition calloutBody = new CalloutDefinition(calloutTitle, calloutDetail);

                // Show the callout on the map at the tapped location.
                _myMapView.ShowCalloutForGeoElement(pinGraphic, e.Position, calloutBody);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
                new AlertDialog.Builder(this).SetMessage("No results found.").SetTitle("No results").Show();
            }
        }
Example #5
0
        private async void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            // First clear any existing selections.
            ClearAllSelections();

            try
            {
                // Perform the identify operation.
                IReadOnlyList <IdentifyLayerResult> results = await _myMapView.IdentifyLayersAsync(e.Position, 10, false);

                // Return if there are no results.
                if (results.Count < 1)
                {
                    return;
                }

                // Get the results that are from ENC layers.
                IEnumerable <IdentifyLayerResult> encResults = results.Where(result => result.LayerContent is EncLayer);

                // Get the first result with ENC features. (Depending on the data, there may be more than one IdentifyLayerResult that contains ENC features.)
                IdentifyLayerResult firstResult = encResults.First();

                // Get the layer associated with this set of results.
                EncLayer containingLayer = (EncLayer)firstResult.LayerContent;

                // Get the GeoElement identified in this layer.
                EncFeature encFeature = (EncFeature)firstResult.GeoElements.First();

                // Select the feature.
                containingLayer.SelectFeature(encFeature);

                // Create the callout definition.
                CalloutDefinition definition = new CalloutDefinition(encFeature.Acronym, encFeature.Description);

                // Show the callout.
                _myMapView.ShowCalloutAt(e.Location, definition);
            }
            catch (Exception ex)
            {
                new UIAlertView("Error", ex.ToString(), (IUIAlertViewDelegate)null, "OK", null).Show();
            }
        }
Example #6
0
        private void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            try
            {
                // Project the tapped location to WGS 84.
                var projectedPoint = (MapPoint)GeometryEngine.Project(e.Location, SpatialReferences.Wgs84);

                // Add the map point to the list that will be used by the GeometryEngine.ConvexHull operation.
                _inputPointCollection.Add(projectedPoint);

                // Check if there are at least three points.
                if (_inputPointCollection.Count > 2)
                {
                    // Enable the button for creating hulls.
                    ConvexHullButton.IsEnabled = true;
                }

                // Create a simple marker symbol to display where the user tapped/clicked on the map. The marker symbol
                // will be a solid, red circle.
                SimpleMarkerSymbol userTappedSimpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, Color.Red, 10);

                // Create a new graphic for the spot where the user clicked on the map using the simple marker symbol.
                Graphic userTappedGraphic = new Graphic(e.Location, new Dictionary <string, object>()
                {
                    { "Type", "Point" }
                }, userTappedSimpleMarkerSymbol)
                {
                    ZIndex = 0
                };

                // Set the Z index for the user tapped graphic so that it appears above the convex hull graphic(s) added later.
                userTappedGraphic.ZIndex = 1;

                // Add the user tapped/clicked map point graphic to the graphic overlay.
                _graphicsOverlay.Graphics.Add(userTappedGraphic);
            }
            catch (System.Exception ex)
            {
                // Display an error message if there is a problem adding user tapped graphics.
                Application.Current.MainPage.DisplayAlert("Error", "Can't add user tapped graphic: " + ex.Message, "OK");
            }
        }
        private async void OnMapViewTapped(object sender, GeoViewInputEventArgs e)
        {
            // The geoprocessing task is still executing, don't do anything else (i.e. respond to
            // more user taps) until the processing is complete.
            if (_isExecutingGeoprocessing)
            {
                return;
            }

            // Indicate that the geoprocessing is running
            SetBusy();

            // Clear previous user click location and the viewshed geoprocessing task results
            _inputOverlay.Graphics.Clear();
            _resultOverlay.Graphics.Clear();

            // Get the tapped point
            MapPoint geometry = e.Location;

            // Create a marker graphic where the user clicked on the map and add it to the existing graphics overlay
            Graphic myInputGraphic = new Graphic(geometry);

            _inputOverlay.Graphics.Add(myInputGraphic);

            // Normalize the geometry if wrap-around is enabled
            //    This is necessary because of how wrapped-around map coordinates are handled by Runtime
            //    Without this step, the task may fail because wrapped-around coordinates are out of bounds.
            if (MyMapView.IsWrapAroundEnabled)
            {
                geometry = (MapPoint)GeometryEngine.NormalizeCentralMeridian(geometry);
            }

            try
            {
                // Execute the geoprocessing task using the user click location
                await CalculateViewshed(geometry);
            }
            catch (Exception ex)
            {
                await new MessageDialog(ex.ToString(), "Error").ShowAsync();
            }
        }
        private MapPoint getGeoPoint(GeoViewInputEventArgs point)
        {
            MapPoint geoPoint    = null;
            Point    screenPoint = new Point(point.Position.X, point.Position.Y);

            if (threeD)
            {
                geoPoint = sceneView.ScreenToBaseSurface(screenPoint);
                if (geoPoint.HasZ)
                {
                    geoPoint = new MapPoint(geoPoint.X, geoPoint.Y, geoPoint.SpatialReference);
                }
            }
            else
            {
                geoPoint = mapView.ScreenToLocation(screenPoint);
            }

            return(geoPoint);
        }
        private void MapView_Tapped(object sender, GeoViewInputEventArgs e)
        {
            // Skip if the sample isn't ready.
            if (_damageLayer == null)
            {
                return;
            }

            // Select the feature if none selected, move the feature otherwise.
            if (_selectedFeature == null)
            {
                // Select the feature.
                TrySelectFeature(e);
            }
            else
            {
                // Move the feature.
                MoveSelectedFeature(e);
            }
        }
        private async void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            // Clear any existing popups.
            _myMapView.DismissCallout();

            // Perform identify on the KML layer and get the results.
            IdentifyLayerResult identifyResult = await _myMapView.IdentifyLayerAsync(_forecastLayer, e.Position, 2, false);

            // Return if there are no results that are KML placemarks.
            if (!identifyResult.GeoElements.OfType <KmlGeoElement>().Any())
            {
                return;
            }

            // Get the first identified feature that is a KML placemark
            KmlNode firstIdentifiedPlacemark = identifyResult.GeoElements.OfType <KmlGeoElement>().First().KmlNode;

            // Show a preview with the HTML content.
            _webView.LoadHtmlString(new NSString(firstIdentifiedPlacemark.BalloonContent), new NSUrl(""));
        }
Example #11
0
        private void _myMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            // Get the user-tapped location
            MapPoint mapLocation = e.Location;

            // Project the user-tapped map point location to a geometry
            Geometry myGeometry = GeometryEngine.Project(mapLocation, SpatialReferences.Wgs84);

            // Convert to geometry to a traditional Lat/Long map point
            MapPoint projectedLocation = (MapPoint)myGeometry;

            // Format the display callout string based upon the projected map point (example: "Lat: 100.123, Long: 100.234")
            string mapLocationDescription = $"Lat: {projectedLocation.Y:F3} Long:{projectedLocation.X:F3}";

            // Create a new callout definition using the formatted string
            CalloutDefinition myCalloutDefinition = new CalloutDefinition("Location:", mapLocationDescription);

            // Display the callout
            _myMapView.ShowCalloutAt(mapLocation, myCalloutDefinition);
        }
Example #12
0
        private async void MySceneView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            try
            {
                // Get the geographic location for the current mouse position.
                MapPoint geoPoint = await MySceneView.ScreenToLocationAsync(e.Position);

                if (geoPoint == null)
                {
                    return;
                }

                // Update the location distance measurement.
                _distanceMeasurement.EndLocation = geoPoint;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
        }
Example #13
0
        private async void mapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            Exception error = null;

            try
            {
                var result = await mapView.IdentifyLayersAsync(e.Position, 3, false);

                // Retrieves or builds Popup from IdentifyLayerResult
                var popup = GetPopup(result);

                // Displays callout and updates visibility of PopupViewer
                if (popup != null)
                {
                    var callout = new CalloutDefinition(popup.GeoElement);
                    callout.Tag           = popup;
                    callout.ButtonImage   = InfoIcon;
                    callout.OnButtonClick = new Action <object>((s) =>
                    {
                        popupViewer.Hidden       = false;
                        popupViewer.PopupManager = new PopupManager(popup);
                    });
                    mapView.ShowCalloutForGeoElement(popup.GeoElement, e.Position, callout);
                }
                else
                {
                    popupViewer.PopupManager = null;
                    popupViewer.Hidden       = true;
                }
            }
            catch (Exception ex)
            {
                error = ex;
            }
            if (error != null)
            {
                var alert = UIAlertController.Create(error.GetType().Name, error.Message, UIAlertControllerStyle.Alert);
                alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
                this.PresentViewController(alert, true, null);
            }
        }
Example #14
0
        private void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            try
            {
                // Get the buffer size (in miles) from the entry.
                double bufferDistanceInMiles = Convert.ToDouble(_bufferDistanceMilesEditText.Text);

                // Create a variable to be the buffer size in meters. There are 1609.34 meters in one mile.
                double bufferDistanceInMeters = bufferDistanceInMiles * 1609.34;

                // Add the map point to the list that will be used by the GeometryEngine.Buffer operation.
                _bufferPointsList.Add(e.Location);

                // Add the buffer distance to the list that will be used by the GeometryEngine.Buffer operation.
                _bufferDistancesList.Add(bufferDistanceInMeters);

                // Create a simple marker symbol to display where the user tapped/clicked on the map. The marker symbol will be a
                // solid, red circle.
                SimpleMarkerSymbol userTappedSimpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, System.Drawing.Color.Red, 10);

                // Create a new graphic for the spot where the user clicked on the map using the simple marker symbol.
                Graphic userTappedGraphic = new Graphic(e.Location, userTappedSimpleMarkerSymbol)
                {
                    // Specify a ZIndex value on the user input map point graphic to assist with the drawing order of mixed geometry types
                    // being added to a single GraphicCollection. The lower the ZIndex value, the lower in the visual stack the graphic is
                    // drawn. Typically, Polygons would have the lowest ZIndex value (ex: 0), then Polylines (ex: 1), and finally MapPoints (ex: 2).
                    ZIndex = 2
                };

                // Add the user tapped/clicked map point graphic to the graphic overlay.
                _graphicsOverlay.Graphics.Add(userTappedGraphic);
            }
            catch (Exception ex)
            {
                // Display an error message if there is a problem generating the buffer polygon.
                AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
                alertBuilder.SetTitle("There was a problem generating buffers.");
                alertBuilder.SetMessage(ex.ToString());
                alertBuilder.Show();
            }
        }
Example #15
0
        private void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            try
            {
                // Normalize the tapped point.
                var centralizedPoint = (MapPoint)GeometryEngine.NormalizeCentralMeridian(e.Location);

                // Add the map point to the list that will be used by the GeometryEngine.ConvexHull operation.
                _inputPointCollection.Add(centralizedPoint);

                // Check if there are at least three points.
                if (_inputPointCollection.Count > 2)
                {
                    // Enable the button for creating hulls.
                    _createHullButton.Enabled = true;
                }

                // Create a simple marker symbol to display where the user tapped/clicked on the map. The marker symbol
                // will be a solid, red circle.
                SimpleMarkerSymbol userTappedSimpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, System.Drawing.Color.Red, 10);

                // Create a new graphic for the spot where the user clicked on the map using the simple marker symbol.
                Graphic userTappedGraphic = new Graphic(e.Location, new Dictionary <string, object> {
                    { "Type", "Point" }
                }, userTappedSimpleMarkerSymbol)
                {
                    // Set the Z index for the user tapped graphic so that it appears above the convex hull graphic(s) added later.
                    ZIndex = 1
                };

                // Add the user tapped/clicked map point graphic to the graphic overlay.
                _graphicsOverlay.Graphics.Add(userTappedGraphic);
            }
            catch (Exception ex)
            {
                // Display an error message if there is a problem adding user tapped graphics.
                UIAlertController alertController = UIAlertController.Create("Can't add user-tapped graphic.", ex.Message, UIAlertControllerStyle.Alert);
                alertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
                PresentViewController(alertController, true, null);
            }
        }
Example #16
0
        private void GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            if (_readyForEdits == EditState.NotReady)
            {
                return;
            }

            // 新しいポイントデータを作成
            var mapClickPoint = e.Location;

            MapPoint wgs84Point = (MapPoint)GeometryEngine.Project(mapClickPoint, SpatialReferences.Wgs84);

            // 新しいポイントデータを追加する
            addFeature(wgs84Point);

            // 編集状態を更新する
            _readyForEdits = EditState.Ready;

            // 同期ボタンを有効にする
            mySyncButton.IsEnabled = true;
        }
        /// <summary>
        /// Reverse geocode au clic sur la carte
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        async void mapView1_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            // on set les paramètres du reverse geocode
            ReverseGeocodeParameters geocodeParams = new ReverseGeocodeParameters();

            geocodeParams.MaxDistance = 800;
            geocodeParams.MaxResults  = 10;
            // on effectue le reverse geocode sur l'emplacement cliqué
            IReadOnlyList <GeocodeResult> resultList = await myLocator.ReverseGeocodeAsync(e.Location, geocodeParams);

            // si il y a un résultat, on affiche le premier
            if (resultList.Count > 0)
            {
                reverseGeocodeLabel.Visibility = Visibility.Visible;
                reverseGeocodeLabel.Content    = "Magasin : " + resultList[0].Label;
            }
            else
            {
                reverseGeocodeLabel.Visibility = Visibility.Hidden;
            }
        }
        private async void OnMapViewTapped(object sender, GeoViewInputEventArgs e)
        {
            var tolerance = 10d; // Use larger tolerance for touch
            var maximumResults = 1; // Only return one graphic  
            var 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", "");
            }
        }
Example #19
0
        private async void OnMapViewTapped(object sender, GeoViewInputEventArgs e)
        {
            if (_isExecutingGeoprocessing)
            {
                return;
            }

            SetBusy();

            // Clear previous location and results
            _inputOverlay.Graphics.Clear();
            _resultOverlay.Graphics.Clear();

            // Add marker to indicate analysis location
            Graphic inputGraphic = new Graphic(e.Location);

            _inputOverlay.Graphics.Add(inputGraphic);

            // Execute geoprocessing task
            await CalculateViewshed(e.Location);
        }
Example #20
0
        private async void OnMapViewTapped(object sender, GeoViewInputEventArgs e)
        {
            // Define the selection tolerance
            double tolerance = 5;

            // Convert the tolerance to map units
            double mapTolerance = tolerance * _myMapView.UnitsPerPixel;

            // Define the envelope around the tap location for selecting features
            var selectionEnvelope = new Envelope(e.Location.X - mapTolerance, e.Location.Y - mapTolerance, e.Location.X + mapTolerance,
                                                 e.Location.Y + mapTolerance, _myMapView.Map.SpatialReference);

            // Define the query parameters for selecting features
            var queryParams = new QueryParameters();

            // Set the geometry to selection envelope for selection by geometry
            queryParams.Geometry = selectionEnvelope;

            // Select the features based on query parameters defined above
            await _featureLayer.SelectFeaturesAsync(queryParams, SelectionMode.New);
        }
Example #21
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", "");
            }
        }
Example #22
0
        private async void OnMapViewTapped(object sender, GeoViewInputEventArgs e)
        {
            try
            {
                // Define the selection tolerance.
                double tolerance = 15;

                // Convert the tolerance to map units.
                double mapTolerance = tolerance * MyMapView.UnitsPerPixel;

                // Get the tapped point.
                MapPoint geometry = e.Location;

                // Normalize the geometry if wrap-around is enabled.
                //    This is necessary because of how wrapped-around map coordinates are handled by Runtime.
                //    Without this step, querying may fail because wrapped-around coordinates are out of bounds.
                if (MyMapView.IsWrapAroundEnabled)
                {
                    geometry = (MapPoint)GeometryEngine.NormalizeCentralMeridian(geometry);
                }

                // Define the envelope around the tap location for selecting features.
                Envelope selectionEnvelope = new Envelope(geometry.X - mapTolerance, geometry.Y - mapTolerance, geometry.X + mapTolerance,
                                                          geometry.Y + mapTolerance, MyMapView.Map.SpatialReference);

                // Define the query parameters for selecting features.
                QueryParameters queryParams = new QueryParameters
                {
                    // Set the geometry to selection envelope for selection by geometry.
                    Geometry = selectionEnvelope
                };

                // Select the features based on query parameters defined above.
                await _featureLayer.SelectFeaturesAsync(queryParams, Esri.ArcGISRuntime.Mapping.SelectionMode.New);
            }
            catch (Exception ex)
            {
                await((Page)Parent).DisplayAlert("Error", ex.ToString(), "OK");
            }
        }
        private async void MapView_Tapped(object sender, GeoViewInputEventArgs e)
        {
            // Clear any existing selection.
            _damageLayer.ClearSelection();

            // Dismiss any existing callouts.
            _myMapView.DismissCallout();

            try
            {
                // Perform an identify to determine if a user tapped on a feature.
                IdentifyLayerResult identifyResult = await _myMapView.IdentifyLayerAsync(_damageLayer, e.Position, 8, false);

                // Do nothing if there are no results.
                if (!identifyResult.GeoElements.Any())
                {
                    return;
                }

                // Otherwise, get the ID of the first result.
                long featureId = (long)identifyResult.GeoElements.First().Attributes["objectid"];

                // Get the feature by constructing a query and running it.
                QueryParameters qp = new QueryParameters();
                qp.ObjectIds.Add(featureId);
                FeatureQueryResult queryResult = await _damageLayer.FeatureTable.QueryFeaturesAsync(qp);

                Feature tappedFeature = queryResult.First();

                // Select the feature.
                _damageLayer.SelectFeature(tappedFeature);

                // Show the callout.
                ShowDeletionCallout(tappedFeature);
            }
            catch (Exception ex)
            {
                ShowMessage(ex.ToString(), "There was a problem.");
            }
        }
Example #24
0
        private async void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            // Clear any existing popups.
            MyMapView.DismissCallout();

            try
            {
                // Perform identify on the KML layer and get the results.
                IdentifyLayerResult identifyResult = await MyMapView.IdentifyLayerAsync(_forecastLayer, e.Position, 2, false);

                // Return if there are no results that are KML placemarks.
                if (!identifyResult.GeoElements.OfType <KmlGeoElement>().Any())
                {
                    return;
                }

                // Get the first identified feature that is a KML placemark
                KmlNode firstIdentifiedPlacemark = identifyResult.GeoElements.OfType <KmlGeoElement>().First().KmlNode;

                if (string.IsNullOrEmpty(firstIdentifiedPlacemark.Description))
                {
                    firstIdentifiedPlacemark.Description = "Weather condition";
                }

                // Create a browser to show the feature popup HTML.
                WebBrowser browser = new WebBrowser
                {
                    Width  = 400,
                    Height = 100
                };
                browser.NavigateToString(firstIdentifiedPlacemark.BalloonContent);

                // Create and show the callout.
                MyMapView.ShowCalloutAt(e.Location, browser);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error");
            }
        }
        private async void OnMapViewTapped(object sender, GeoViewInputEventArgs e)
        {
            try
            {
                // Define the selection tolerance (half the marker symbol size so that any click on the symbol will select the feature)
                double tolerance = 14;

                // Convert the tolerance to map units
                double mapTolerance = tolerance * MyMapView.UnitsPerPixel;

                // Get the tapped point
                MapPoint geometry = e.Location;

                // Normalize the geometry if wrap-around is enabled
                //    This is necessary because of how wrapped-around map coordinates are handled by Runtime
                //    Without this step, querying may fail because wrapped-around coordinates are out of bounds.
                if (MyMapView.IsWrapAroundEnabled)
                {
                    geometry = GeometryEngine.NormalizeCentralMeridian(geometry) as MapPoint;
                }

                // Define the envelope around the tap location for selecting features
                var selectionEnvelope = new Envelope(geometry.X - mapTolerance, geometry.Y - mapTolerance, geometry.X + mapTolerance,
                                                     geometry.Y + mapTolerance, MyMapView.Map.SpatialReference);

                // Define the query parameters for selecting features
                var queryParams = new QueryParameters();

                // Set the geometry to selection envelope for selection by geometry
                queryParams.Geometry = selectionEnvelope;

                // Select the features based on query parameters defined above
                await _featureLayer.SelectFeaturesAsync(queryParams, Esri.ArcGISRuntime.Mapping.SelectionMode.New);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Sample error", ex.ToString());
            }
        }
        private async void mapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            Exception error = null;

            try
            {
                var result = await mapView.IdentifyLayersAsync(e.Position, 3, false);

                // Retrieves or builds Popup from IdentifyLayerResult
                var popup = GetPopup(result);

                // Displays callout and updates visibility of PopupViewer
                if (popup != null)
                {
                    var callout = new CalloutDefinition(popup.GeoElement);
                    callout.Tag           = popup;
                    callout.ButtonImage   = InfoIcon;
                    callout.OnButtonClick = new Action <object>((s) =>
                    {
                        popupViewer.IsVisible    = true;
                        popupViewer.PopupManager = new PopupManager(s as Popup);
                    });
                    mapView.ShowCalloutForGeoElement(popup.GeoElement, e.Position, callout);
                }
                else
                {
                    popupViewer.PopupManager = null;
                    popupViewer.IsVisible    = false;
                }
            }
            catch (Exception ex)
            {
                error = ex;
            }
            if (error != null)
            {
                await DisplayAlert(error.GetType().Name, error.Message, "OK");
            }
        }
        private void MapView_Tapped(object sender, GeoViewInputEventArgs e)
        {
            // Get the tapped point - this is in the map's spatial reference,
            // which in this case is WebMercator because that is the SR used by the included basemaps.
            MapPoint tappedPoint = e.Location;

            // Update the graphics.
            _myMapView.GraphicsOverlays[0].Graphics.Clear();
            _myMapView.GraphicsOverlays[0].Graphics.Add(new Graphic(tappedPoint));

            // Project the point to WGS84
            MapPoint projectedPoint = (MapPoint)GeometryEngine.Project(tappedPoint, SpatialReferences.Wgs84);

            // Format the results in strings.
            string originalCoords  = $"Original: {tappedPoint.X:F4}, {tappedPoint.Y:F4}";
            string projectedCoords = $"Projected: {projectedPoint.X:F4}, {projectedPoint.Y:F4}";

            // Define a callout and show it in the map view.
            CalloutDefinition calloutDef = new CalloutDefinition(projectedCoords, originalCoords);

            _myMapView.ShowCalloutAt(tappedPoint, calloutDef);
        }
Example #28
0
        private async void MapView_Tapped(object sender, GeoViewInputEventArgs e)
        {
            // Skip if the sample isn't ready yet.
            if (_damageLayer == null)
            {
                return;
            }

            // Clear any existing selection.
            _damageLayer.ClearSelection();

            // Dismiss any existing callouts.
            _myMapView.DismissCallout();

            try
            {
                // Perform an identify to determine if a user tapped on a feature.
                IdentifyLayerResult identifyResult = await _myMapView.IdentifyLayerAsync(_damageLayer, e.Position, 8, false);

                // Do nothing if there are no results.
                if (!identifyResult.GeoElements.Any())
                {
                    return;
                }

                // Get the tapped feature.
                _selectedFeature = (ArcGISFeature)identifyResult.GeoElements.First();

                // Select the feature.
                _damageLayer.SelectFeature(_selectedFeature);

                // Update the UI for the selection.
                ShowFeatureCallout();
            }
            catch (Exception ex)
            {
                ShowMessage("Error selecting feature.", ex.ToString());
            }
        }
Example #29
0
        private async void mapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            Exception error = null;

            try
            {
                var result = await mapView.IdentifyLayersAsync(e.Position, 3, false);

                // Retrieves or builds Popup from IdentifyLayerResult
                var popup = GetPopup(result);

                // Displays callout and updates visibility of PopupViewer
                if (popup != null)
                {
                    var callout = new CalloutDefinition(popup.GeoElement);
                    callout.Tag           = popup;
                    callout.ButtonImage   = InfoIcon;
                    callout.OnButtonClick = OnPopupInfoButtonClicked;
                    mapView.ShowCalloutForGeoElement(popup.GeoElement, e.Position, callout);
                }
                else
                {
                    popupViewer.PopupManager = null;
                    popupViewer.Visibility   = Android.Views.ViewStates.Gone;
                }
            }
            catch (Exception ex)
            {
                error = ex;
            }
            if (error != null)
            {
                var alert = new AlertDialog.Builder(this);
                alert.SetTitle(error.GetType().Name);
                alert.SetMessage(error.Message);
                alert.SetPositiveButton("OK", (a, b) => { });
                RunOnUiThread(() => alert.Show());
            }
        }
Example #30
0
        private async void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            // Show the loading indicator.
            _activityIndicator.StartAnimating();

            // Clear previous user click location and the viewshed geoprocessing task results.
            _inputOverlay.Graphics.Clear();
            _resultOverlay.Graphics.Clear();

            // Get the tapped point.
            MapPoint geometry = e.Location;

            // Create a marker graphic where the user clicked on the map and add it to the existing graphics overlay.
            Graphic inputGraphic = new Graphic(geometry);

            _inputOverlay.Graphics.Add(inputGraphic);

            // Normalize the geometry if wrap-around is enabled.
            //    This is necessary because of how wrapped-around map coordinates are handled by Runtime.
            //    Without this step, the task may fail because wrapped-around coordinates are out of bounds.
            if (_myMapView.IsWrapAroundEnabled)
            {
                geometry = (MapPoint)GeometryEngine.NormalizeCentralMeridian(geometry);
            }

            try
            {
                // Execute the geoprocessing task using the user click location.
                await CalculateViewshed(geometry);
            }
            catch (Exception ex)
            {
                new UIAlertView("Error", ex.ToString(), (IUIAlertViewDelegate)null, "OK", null).Show();
            }
            finally
            {
                _activityIndicator.StopAnimating();
            }
        }
        private async void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            // First clear any existing selections
            ClearAllSelections();

            // Perform the identify operation
            IReadOnlyList <IdentifyLayerResult> results = await _myMapView.IdentifyLayersAsync(e.Position, 5, false);

            // Return if there are no results
            if (results.Count < 1)
            {
                return;
            }

            // Get the results that are from ENC layers
            IEnumerable <IdentifyLayerResult> encResults = results.Where(result => result.LayerContent is EncLayer);

            // Get the ENC results that have features
            IEnumerable <IdentifyLayerResult> encResultsWithFeatures = encResults.Where(result => result.GeoElements.Count > 0);

            // Get the first result with ENC features
            IdentifyLayerResult firstResult = encResultsWithFeatures.First();

            // Get the layer associated with this set of results
            EncLayer containingLayer = (EncLayer)firstResult.LayerContent;

            // Select the smallest (area) feature in the layer.
            EncFeature smallestFeature = (EncFeature)firstResult.GeoElements.OrderBy(f => GeometryEngine.Area(f.Geometry)).First();

            // Select the feature.
            containingLayer.SelectFeature(smallestFeature);

            // Create the callout definition.
            CalloutDefinition definition = new CalloutDefinition(smallestFeature.Acronym, smallestFeature.Description);

            // Show the callout
            _myMapView.ShowCalloutAt(e.Location, definition);
        }
        /// <summary>
        /// Shows a callout for any tapped graphics
        /// </summary>
        private async void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            // Search for the graphics underneath the user's tap
            IReadOnlyList<IdentifyGraphicsOverlayResult> results = await MyMapView.IdentifyGraphicsOverlaysAsync(e.Position, 12, false);

            // Clear callouts and return if there was no result
            if (results.Count < 1 || results.First().Graphics.Count < 1) { MyMapView.DismissCallout(); return; }

            // Get the first graphic from the first result
            Graphic matchingGraphic = results.First().Graphics.First();

            // Get the title; manually added to the point's attributes in UpdateSearch
            String title = matchingGraphic.Attributes["Match_Title"] as String;

            // Get the address; manually added to the point's attributes in UpdateSearch
            String address = matchingGraphic.Attributes["Match_Address"] as String;

            // Define the callout
            CalloutDefinition calloutBody = new CalloutDefinition(title, address);

            // Show the callout on the map at the tapped location
            MyMapView.ShowCalloutAt(e.Location, calloutBody);
        }
        private async void OnMapViewTapped(object sender, GeoViewInputEventArgs e)
        {
            // The geoprocessing task is still executing, don't do anything else (i.e. respond to 
            // more user taps) until the processing is complete.
            if (_isExecutingGeoprocessing)
            {
                return;
            }

            // Indicate that the geoprocessing is running
            SetBusy();

            // Clear previous user click location and the viewshed geoprocessing task results
            _inputOverlay.Graphics.Clear();
            _resultOverlay.Graphics.Clear();

            // Create a marker graphic where the user clicked on the map and add it to the existing graphics overlay 
            Graphic myInputGraphic = new Graphic(e.Location);
            _inputOverlay.Graphics.Add(myInputGraphic);

            // Execute the geoprocessing task using the user click location 
            await CalculateViewshed(e.Location);
        }
        private void SceneViewTapped(object sender, GeoViewInputEventArgs e)
        {
            // When the view is tapped, define the observer or target location with the tap point as appropriate.
            if (_observerLocation == null)
            {
                // Define the observer location (plus an offset for observer height) and set the target to the same point.
                _observerLocation = new MapPoint(e.Location.X, e.Location.Y, e.Location.Z + ZOffset);
                _lineOfSightAnalysis.ObserverLocation = _observerLocation;
                _lineOfSightAnalysis.TargetLocation   = _observerLocation;

                // Clear the target location (if any) so the next click will define the target.
                _targetLocation = null;
            }
            else if (_targetLocation == null)
            {
                // Define the target.
                _targetLocation = new MapPoint(e.Location.X, e.Location.Y, e.Location.Z + ZOffset);
                _lineOfSightAnalysis.TargetLocation = _targetLocation;

                // Clear the observer location so it can be defined again.
                _observerLocation = null;
            }
        }
        private async void _myMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            // Perform the identify operation
            IdentifyLayerResult myIdentifyResult = await _myMapView.IdentifyLayerAsync(_wmsLayer, e.Position, 20, false);

            // Return if there's nothing to show
            if (myIdentifyResult.GeoElements.Count < 1)
            {
                return;
            }

            // Retrieve the identified feature, which is always a WmsFeature for WMS layers
            WmsFeature identifiedFeature = (WmsFeature)myIdentifyResult.GeoElements[0];

            // Retrieve the WmsFeature's HTML content
            string htmlContent = identifiedFeature.Attributes["HTML"].ToString();

            // Note that the service returns a boilerplate HTML result if there is no feature found;
            //    here might be a good place to check for that and filter out spurious results

            // Show a preview with the HTML content
            ShowHtml(htmlContent, e.Location);
        }
        private async void OnMapViewTapped(object sender, 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
                InvokeOnMainThread(() =>
                {
                    var alert = new UIAlertView("", "Tapped on graphic", null, "OK", null);
                    alert.Show();
                });
            }
        }