Exemple #1
0
        /// <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"].ToString();

            // Get the address; manually added to the point's attributes in UpdateSearch.
            string address = matchingGraphic.Attributes["Match_Address"].ToString();

            // 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 MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e)
        {
            // Search for the graphics underneath the user's tap
            IReadOnlyList <IdentifyGraphicsOverlayResult> results = await MyMapView.IdentifyGraphicsOverlaysAsync(e.Position, 12, false);

            // Return gracefully if there was no result
            //if (results.Count < 1 || results.First().Graphics.Count < 1) { return; }

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

            // Get the first result
            GeocodeResult address = addresses.First();
            // Use the city and region for the Callout Title
            //String calloutTitle = address.Attributes["City"] + ", " + address.Attributes["Region"];

            String calloutTitle = "日本住所";

            // Use the metro area for the Callout Detail
            String calloutDetail = address.Attributes["Address"].ToString();

            // Use the MapView to convert from the on-screen location to the on-map location
            MapPoint point = MyMapView.ScreenToLocation(e.Position);

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

            // Show the callout on the map at the tapped location
            MyMapView.ShowCalloutAt(point, calloutBody);
        }
Exemple #3
0
        /// <summary>
        /// Handle tap event on the map; displays callouts showing the address for a tapped search result
        /// </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);

            // Return gracefully if there was no result
            if (results.Count < 1 || results.First().Graphics.Count < 1)
            {
                return;
            }

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

            // Get the first result
            GeocodeResult address = addresses.First();
            // Use the city and region for the Callout Title
            string calloutTitle = address.Attributes["City"] + ", " + address.Attributes["Region"];
            // Use the metro area for the Callout Detail
            string calloutDetail = address.Attributes["MetroArea"].ToString();

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

            // Show the callout on the map at the tapped location
            MyMapView.ShowCalloutAt(e.Location, calloutBody);
        }
Exemple #4
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;

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

                // Create and show the callout.
                MyMapView.ShowCalloutAt(e.Location, browser);
            }
            catch (Exception ex)
            {
                await new MessageDialog(ex.ToString(), "Error").ShowAsync();
            }
        }
        private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs e)
        {
            //var CemLot = new Uri("http://apexgis:6080/arcgis/rest/services/CemeteryHost/CEMTESTSERV/FeatureServer/0");
            // FeatureLayer LotLayer = new FeatureLayer(CemLot);

            //await LotLayer.LoadAsync();

            // NEED TO ACCESS LAYERS AND ADD TO OPERATION MAPPP!!!!!!!!!


            // Perform the identify operation
            MapPoint tapScreenPoint = e.Location;

            var layer            = MyMapView.Map.OperationalLayers[1];
            var pixelTolerance   = 10;
            var returnPopupsOnly = false;
            var maxResults       = 200;

            MyMapView.DismissCallout();
            //IdentifyLayerResult myIdentifyResult = await MyMapView.IdentifyLayerAsync(layer, e.Position, pixelTolerance, returnPopupsOnly, maxResults);

            IdentifyLayerResult myIdentifyResult = await MyMapView.IdentifyLayerAsync(layer, e.Position, pixelTolerance, returnPopupsOnly, maxResults);

            //IReadOnlyList<IdentifyLayerResult> myIdentifyResult = await MyMapView.IdentifyLayersAsync(e.Position, pixelTolerance, returnPopupsOnly, maxResults);

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

            FeatureLayer idLayer = myIdentifyResult.LayerContent as FeatureLayer;

            // Retrieve the identified feature, which is always a WmsFeature for WMS layers

            Feature idFeature = (Feature)myIdentifyResult.GeoElements[0];

            //foreach (GeoElement idElement in myIdentifyResult.GeoElements)
            // {
            // cast the result GeoElement to Feature
            //   Feature idFeature = idElement as Feature;

            try
            {
                string content = string.Format("{0}   {1}    {2}    {3}  {4}", idFeature.Attributes["name_FIRST"].ToString(), idFeature.Attributes["name_LAST"].ToString(), idFeature.Attributes["plot"].ToString(), idFeature.Attributes["lot"].ToString(), idFeature.Attributes["PLOT_ID"].ToString());



                CalloutDefinition myCalloutDefinition = new CalloutDefinition("Plot Attributes", content);

                MyMapView.ShowCalloutAt(tapScreenPoint, myCalloutDefinition);
            }

            catch
            {
                MessageBox.Show("Not an Identifeable Layer");
            }
        }
 private void MyMapView_OnGeoViewTapped(object sender, GeoViewInputEventArgs e)
 {
     MyMapView.ShowCalloutAt(new CalloutDefinition
     {
         Location = e.Location,
         Title    = "Test",
         Message  = "只不过测试一下"
     });
 }
Exemple #7
0
        private async Task ShowGeocodeResult(MapPoint tappedPoint)
        {
            // Reverse geocode to get an address.
            IReadOnlyList <GeocodeResult> results = await _packageLocator.ReverseGeocodeAsync(tappedPoint);

            // Process the address into usable strings.
            string address = results.First().Label;

            // Show the address in a callout.
            MyMapView.ShowCalloutAt(tappedPoint, new CalloutDefinition(address));
        }
        private void ShowHtmlCallout(string htmlContent, MapPoint position)
        {
            // Create the web browser control
            WebView htmlView = new WebView()
            {
                Height = 100, Width = 200
            };

            // Display the string content as an HTML document
            htmlView.NavigateToString(htmlContent);

            // Create the callout with the browser
            MyMapView.ShowCalloutAt(position, htmlView);
        }
Exemple #9
0
        private async void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            // 識別対象のレイヤーを取得
            var layer = MyMapView.Map.OperationalLayers[0] as FeatureLayer;

            // フィーチャのハイライトをクリア
            layer.ClearSelection();

            // コールアウトを非表示
            MyMapView.DismissCallout();

            // タップした地点のスクリーン ポイントを取得
            Point tapScreenPoint = e.Position;

            // タップした地点の許容範囲
            var pixelTolerance = 1;
            // ポップアップ オブジェクト作成の有無
            var returnPopupsOnly = false;

            // タップ地点に含まれるレイヤーを識別し、結果を取得
            IdentifyLayerResult idLayerResults = await MyMapView.IdentifyLayerAsync(layer, tapScreenPoint, pixelTolerance, returnPopupsOnly);

            if (idLayerResults.GeoElements.Count > 0)
            {
                // 選択したフィーチャをハイライト
                Feature idFeature = idLayerResults.GeoElements[0] as Feature;
                layer.SelectFeature(idFeature);

                // コールアウトのコンテンツを作成
                var layerName = layer.Name;

                var attributes = new System.Text.StringBuilder();
                if (idFeature.Attributes.Count > 0)
                {
                    foreach (var attribute in idFeature.Attributes)
                    {
                        // フィーチャの属性(key:属性のフィールド名、value:属性のフィールド値のペア)を取得
                        var fieldName  = attribute.Key;
                        var fieldValue = attribute.Value;
                        attributes.AppendLine(fieldName + ": " + fieldValue);
                    }
                    attributes.AppendLine();
                }

                // コールアウトのコンテンツを定義
                CalloutDefinition myCalloutDefinition = new CalloutDefinition(layerName, attributes.ToString());
                // コールアウトを表示
                MyMapView.ShowCalloutAt(e.Location, myCalloutDefinition);
            }
        }
        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 MapTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e)
        {
            try
            {
                // Get the result for where the user tapped on the raster layer.
                IdentifyLayerResult identifyResult = await MyMapView.IdentifyLayerAsync(_rasterLayer, e.Position, 1, false, 1);

                // If no cell was identified, dismiss the callout.
                if (!identifyResult.GeoElements.Any())
                {
                    MyMapView.DismissCallout();
                    return;
                }

                // Create a StringBuilder to display information to the user.
                var stringBuilder = new StringBuilder();

                // Get the identified raster cell.
                GeoElement cell = identifyResult.GeoElements.First();

                // Loop through the attributes (key/value pairs).
                foreach (KeyValuePair <string, object> keyValuePair in cell.Attributes)
                {
                    // Add the key/value pair to the string builder.
                    stringBuilder.AppendLine($"{keyValuePair.Key}: {keyValuePair.Value}");
                }

                // Get the x and y values of the cell.
                double x = cell.Geometry.Extent.XMin;
                double y = cell.Geometry.Extent.YMin;

                // Add the X & Y coordinates where the user clicked raster cell to the string builder.
                stringBuilder.AppendLine($"X: {Math.Round(x, 4)}\nY: {Math.Round(y, 4)}");

                // Create a callout using the string.
#if __IOS__
                var definition = new CalloutDefinition(string.Empty, stringBuilder.ToString().Replace("\n", " "));
#else
                var definition = new CalloutDefinition(string.Empty, stringBuilder.ToString());
#endif

                // Display the call out in the map view.
                MyMapView.ShowCalloutAt(e.Location, definition);
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert(ex.GetType().Name, ex.Message, "OK");
            }
        }
Exemple #12
0
        private void ShowDeletionCallout(Feature tappedFeature)
        {
            // Create a button for deleting the feature.
            Button deleteButton = new Button();

            deleteButton.Content = "Delete incident";
            deleteButton.Padding = new Thickness(5);
            deleteButton.Tag     = tappedFeature;

            // Handle button clicks.
            deleteButton.Click += DeleteButton_Click;

            // Show the callout.
            MyMapView.ShowCalloutAt((MapPoint)tappedFeature.Geometry, deleteButton);
        }
Exemple #13
0
        private async void MouseMoved(object sender, PointerRoutedEventArgs e)
        {
            try
            {
                // Get the curent mouse position.
                Point position = e.GetCurrentPoint(MyMapView).Position;

                // Get the result for where the user hovered on the raster layer.
                IdentifyLayerResult identifyResult = await MyMapView.IdentifyLayerAsync(_rasterLayer, position, 1, false, 1);

                // If no cell was identified, dismiss the callout.
                if (!identifyResult.GeoElements.Any())
                {
                    MyMapView.DismissCallout();
                    return;
                }

                // Create a StringBuilder to display information to the user.
                var stringBuilder = new StringBuilder();

                // Get the identified raster cell.
                GeoElement cell = identifyResult.GeoElements.First();

                // Loop through the attributes (key/value pairs).
                foreach (KeyValuePair <string, object> keyValuePair in cell.Attributes)
                {
                    // Add the key/value pair to the string builder.
                    stringBuilder.AppendLine($"{keyValuePair.Key}: {keyValuePair.Value}");
                }

                // Get the x and y values of the cell.
                double x = cell.Geometry.Extent.XMin;
                double y = cell.Geometry.Extent.YMin;

                // Add the X & Y coordinates where the user clicked raster cell to the string builder.
                stringBuilder.AppendLine($"X: {Math.Round(x, 4)}\nY: {Math.Round(y, 4)}");

                // Create a callout using the string.
                var definition = new CalloutDefinition(stringBuilder.ToString());

                // Display the call out in the map view.
                MyMapView.ShowCalloutAt(MyMapView.ScreenToLocation(position), definition);
            }
            catch (Exception ex)
            {
                await new MessageDialog(ex.Message, ex.GetType().Name).ShowAsync();
            }
        }
        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;

                // Populate the Description if empty.
                if (string.IsNullOrEmpty(firstIdentifiedPlacemark.Description))
                {
                    firstIdentifiedPlacemark.Description = "Weather condition";
                }

                // Create a browser to show the feature popup HTML.
                WebView2 browser = new WebView2
                {
                    Width  = 400,
                    Height = 100
                };

                // Ensure the CoreWebView2 has been created.
                await browser.EnsureCoreWebView2Async();

                // Initiate the navigation to the BalloonContent HTML.
                browser.NavigateToString(firstIdentifiedPlacemark.BalloonContent);

                // Create and show the callout.
                MyMapView.ShowCalloutAt(e.Location, browser);
            }
            catch (Exception ex)
            {
                await new MessageDialog2(ex.ToString(), "Error").ShowAsync();
            }
        }
Exemple #15
0
        private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e)
        {
            // First clear any existing selections
            ClearAllSelections();

            try
            {
                // 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);
            }
            catch (Exception ex)
            {
                await((Page)Parent).DisplayAlert("Error", ex.ToString(), "OK");
            }
        }
        private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.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)
            {
                await Application.Current.MainPage.DisplayAlert("Error", ex.ToString(), "OK");
            }
        }
        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 = string.Format("Lat: {0:F3} Long:{1:F3}", projectedLocation.Y, projectedLocation.X);

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

            // Display the callout
            MyMapView.ShowCalloutAt(mapLocation, myCalloutDefinition);
        }
        private void MapView_Tapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.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);
        }
        private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.UI.Controls.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 = firstResult.LayerContent as EncLayer;

            // Get the first identified ENC feature
            EncFeature firstFeature = firstResult.GeoElements.First() as EncFeature;

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

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

            // Show the callout
            MyMapView.ShowCalloutAt(e.Location, definition);
        }
Exemple #20
0
        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  = string.Format("Original: {0:F4}, {1:F4}", tappedPoint.X, tappedPoint.Y);
            string projectedCoords = string.Format("Projected: {0:F4}, {1:F4}", projectedPoint.X, projectedPoint.Y);
            string formattedString = string.Format("{0}\n{1}", originalCoords, projectedCoords);

            // Define a callout and show it in the map view.
            CalloutDefinition calloutDef = new CalloutDefinition("Coordinates:", formattedString);

            MyMapView.ShowCalloutAt(tappedPoint, calloutDef);
        }
Exemple #21
0
        //=======敏感区=====
        public void Createarea(double lon, double lat, double radius)
        {
            // Create the graphics overlay.
            GraphicsOverlay overlay1 = new GraphicsOverlay();
            GraphicsOverlay overlay2 = new GraphicsOverlay();
            // Create a green simple line symbol
            SimpleLineSymbol outlineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, System.Drawing.Color.FromArgb(0xFF, 0x00, 0x50, 0x00), 1);

            // Create a green mesh simple fill symbol
            SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Cross, System.Drawing.Color.Yellow, outlineSymbol);

            Esri.ArcGISRuntime.Geometry.PointCollection boatPositions = new Esri.ArcGISRuntime.Geometry.PointCollection(SpatialReferences.Wgs84);
            for (int i = 0; i < 36; i++)
            {
                double angle = (2 * Math.PI / 36) * i;
                // new MapPoint([lon + Math.sin(angle) * radius[0], lat[0] + Math.cos(angle) * radius[0]]);
                boatPositions.Add(new MapPoint(lon + Math.Sin(angle) * radius, lat + Math.Cos(angle) * radius));
            }
            ;

            // Create the polyline from the point collection
            Esri.ArcGISRuntime.Geometry.Polygon polygon = new Esri.ArcGISRuntime.Geometry.Polygon(boatPositions);

            // Create the graphic with polyline and symbol
            Graphic graphic  = new Graphic(polygon, fillSymbol);
            Graphic graphic1 = new Graphic(polygon, fillSymbol);

            // Add graphic to the graphics overlay
            overlay1.Graphics.Add(graphic);
            overlay2.Graphics.Add(graphic1);
            //MessageBox.Show(lon + "  "+ lat + "添加成功");
            // Show the graphics overlay in the scene.
            MyMapView.GraphicsOverlays.Add(overlay1);
            MySceneView.GraphicsOverlays.Add(overlay2);


            int de = -1;
            int mi = -1;

            if (Dector2D.Count > 0)
            {
                int count = Dector2D.Count;

                for (int i = 0; i < count; i++)
                {
                    List <MapPoint> _artificialMapPoints = new List <MapPoint>();


                    _artificialMapPoints = MapPointslist[i];

                    int index = Global.DectorIndexIdlist[i];

                    for (int j = index; j < index + 120; j++)
                    {
                        MapPoint selectedMapPoint = _artificialMapPoints[j % _artificialMapPoints.Count];
                        double   di = Distance(selectedMapPoint.X, selectedMapPoint.Y, selectedMapPoint.Z, lon, lat, 0);
                        if (di < radius * 100000)
                        {
                            de = i;
                            mi = j - index;
                            break;
                        }
                    }

                    // }
                    if (mi != -1)
                    {
                        break;
                    }
                }



                //double d = Distance(lon, lat, 0, lon1, lat1, radius1);
                StackPanel s  = new StackPanel();
                Label      l1 = new Label();
                Label      l2 = new Label();
                Label      l3 = new Label();
                s.Children.Add(l1);
                s.Children.Add(l2);
                s.Children.Add(l3);
                l1.Content = "longitude :" + lon;
                l2.Content = "latitude : " + lat;
                if (de != -1)
                {
                    l3.Content = "探空仪 " + Global.DectorNamelist[de] + " 将在" + mi + "分钟后到达敏感区";
                }
                else
                {
                    /*
                     *
                     * string[] strArr = new string[3];
                     * string sArguments = @"station.py"; //调用的python的文件名字
                     * strArr[0] = lon.ToString();
                     * strArr[1] = lat.ToString();
                     * strArr[2] = (radius*111).ToString();
                     * RunPythonScript(sArguments, "-u", strArr);
                     */



                    //int counter = 0;
                    //string line;
                    string   result = "Please wait";
                    string[] lines  = System.IO.File.ReadAllLines(@"E:\\VSProjects\\test\\data.txt", Encoding.GetEncoding("gb2312"));
                    //System.Console.WriteLine("Contents of WriteLines2.txt = ");

                    foreach (string line in lines)
                    {
                        result = line;
                    }


                    // System.IO.StreamReader file = new System.IO.StreamReader(@"E:\\VSProjects\\test\\data.txt");

                    // while ((line = file.ReadLine()) != null)
                    //{
                    //System.Console.WriteLine(line);
                    //   counter++;
                    // }
                    /// MessageBox.Show( result);
                    // file.Close();
                    l3.Content = result;
                }

                MyMapView.ShowCalloutAt(new MapPoint(lon, lat, SpatialReferences.Wgs84), s);
            }
            else
            {
                //double d = Distance(lon, lat, 0, lon1, lat1, radius1);
                StackPanel s  = new StackPanel();
                Label      l1 = new Label();
                Label      l2 = new Label();
                Label      l3 = new Label();
                s.Children.Add(l1);
                s.Children.Add(l2);
                s.Children.Add(l3);
                l1.Content = "longitude :" + lon;
                l2.Content = "latitude : " + lat;
                // l3.Content = "";

                /*
                 * string[] strArr = new string[3];
                 * string sArguments = @"station.py"; //调用的python的文件名字
                 * strArr[0] = lon.ToString();
                 * strArr[1] = lat.ToString();
                 * strArr[2] = (radius * 111).ToString();
                 * RunPythonScript(sArguments, "-u", strArr);
                 */

                string   result = "Please wait";
                string[] lines  = System.IO.File.ReadAllLines(@"E:\\VSProjects\\test\\data.txt", Encoding.GetEncoding("gb2312"));
                //System.Console.WriteLine("Contents of WriteLines2.txt = ");

                foreach (string line in lines)
                {
                    result = line;
                }


                // System.IO.StreamReader file = new System.IO.StreamReader(@"E:\\VSProjects\\test\\data.txt");

                // while ((line = file.ReadLine()) != null)
                //{
                //System.Console.WriteLine(line);
                //   counter++;
                // }
                // MessageBox.Show("c" + result);
                // file.Close();
                l3.Content = "可选放球站:" + result;
                // string text = System.IO.File.ReadAllText(@"E:\\VSProjects\\test\\data.txt");



                MyMapView.ShowCalloutAt(new MapPoint(lon, lat, SpatialReferences.Wgs84), s);
            }



            // MyMapView.ShowCalloutAt(new MapPoint(lon, lat, SpatialReferences.Wgs84), s);
        }
Exemple #22
0
        private async void IdentifyCell(Point position)
        {
            // Check if a cell is already being identified
            if (_isIdentifying)
            {
                _nextIdentifyAction = () => IdentifyCell(position);
                return;
            }

            // Set variable to true to prevent concurrent identify calls.
            _isIdentifying = true;

            try
            {
                // Get the result for where the user hovered on the raster layer.
                IdentifyLayerResult identifyResult = await MyMapView.IdentifyLayerAsync(_rasterLayer, position, 1, false, 1);

                // If no cell was identified, dismiss the callout.
                if (!identifyResult.GeoElements.Any())
                {
                    MyMapView.DismissCallout();
                    return;
                }

                // Create a StringBuilder to display information to the user.
                var stringBuilder = new StringBuilder();

                // Get the identified raster cell.
                GeoElement cell = identifyResult.GeoElements.First();

                // Loop through the attributes (key/value pairs).
                foreach (KeyValuePair <string, object> keyValuePair in cell.Attributes)
                {
                    // Add the key/value pair to the string builder.
                    stringBuilder.AppendLine($"{keyValuePair.Key}: {keyValuePair.Value}");
                }

                // Get the x and y values of the cell.
                double x = cell.Geometry.Extent.XMin;
                double y = cell.Geometry.Extent.YMin;

                // Add the X & Y coordinates where the user clicked raster cell to the string builder.
                stringBuilder.AppendLine($"X: {Math.Round(x, 4)}\nY: {Math.Round(y, 4)}");

                // Create a callout using the string.
                var definition = new CalloutDefinition(stringBuilder.ToString());

                // Display the call out in the map view.
                MyMapView.ShowCalloutAt(MyMapView.ScreenToLocation(position), definition);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }
            finally
            {
                _isIdentifying = false;
            }

            // Check if there is a new position to identify.
            if (_nextIdentifyAction != null)
            {
                Action action = _nextIdentifyAction;

                // Clear the queued identify action.
                _nextIdentifyAction = null;

                // Run the next action.
                action();
            }
        }