private void mapView_MapViewTapped(object sender, MapViewInputEventArgs e)
        {
            try
            {
                _graphicsLayer.Graphics.Clear();

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

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

                var bufferGraphic = new Graphic {
                    Geometry = buffer, Symbol = _bufferSymbol
                };
                _graphicsLayer.Graphics.Add(bufferGraphic);
            }
            catch (Exception ex)
            {
                var _ = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
            }
        }
        private void mapView_MouseMove(object sender, MouseEventArgs e)
        {
            try {
                // Convert screen point to map point
                var point = mapView.ScreenToLocation(e.GetPosition(mapView));
                if (point == null)
                {
                    return;
                }

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

                Graphic bufferGraphic = null;
                //show geometries on map
                if (graphicsLayer.Graphics.Count == 0)
                {
                    bufferGraphic = new Graphic {
                        Geometry = buffer, Symbol = _bufferSymbol
                    };
                    graphicsLayer.Graphics.Add(bufferGraphic);
                }
                else
                {
                    bufferGraphic = graphicsLayer.Graphics[0];
                }
                bufferGraphic.Geometry = buffer;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Geometry Engine Failed!");
            }
        }
        private void MapView_ExtentChanged(object sender, EventArgs e)
        {
            Envelope newExtent = null;

            if (mapView.WrapAround)
            {
                Geometry normalizedExtent = GeometryEngine.NormalizeCentralMeridianOfGeometry(mapView.Extent);
                if (normalizedExtent is Polygon)
                {
                    var normalizedPolygon = (Polygon)normalizedExtent;

                    if (normalizedPolygon.Rings.Count == 1)
                    {
                        newExtent = normalizedPolygon.Extent;
                    }
                    else
                    {
                        newExtent = new Envelope();

                        foreach (var p in normalizedPolygon.Rings[0])
                        {
                            if (p.X < newExtent.XMin || double.IsNaN(newExtent.XMin))
                            {
                                newExtent.XMin = p.X;
                            }
                            if (p.Y < newExtent.YMin || double.IsNaN(newExtent.YMin))
                            {
                                newExtent.YMin = p.Y;
                            }
                        }

                        foreach (var p in normalizedPolygon.Rings[1])
                        {
                            if (p.X > newExtent.XMax || double.IsNaN(newExtent.XMax))
                            {
                                newExtent.XMax = p.X;
                            }
                            if (p.Y > newExtent.YMax || double.IsNaN(newExtent.YMax))
                            {
                                newExtent.YMax = p.Y;
                            }
                        }
                    }
                }
                else if (normalizedExtent is Envelope)
                {
                    newExtent = normalizedExtent as Envelope;
                }
            }
            else
            {
                newExtent = mapView.Extent;
            }

            MinXNormalized.Text = newExtent.XMin.ToString("0.000");
            MinYNormalized.Text = newExtent.YMin.ToString("0.000");
            MaxXNormalized.Text = newExtent.XMax.ToString("0.000");
            MaxYNormalized.Text = newExtent.YMax.ToString("0.000");
        }
        private void UpdateDisplayPoints(Point position, MapPoint location)
        {
            txtScreenCoords.Text = string.Format("Screen Coords: {0:0}, {1:0}", position.X, position.Y);

            if (location != null)
            {
                MapPoint mapPoint = location;
                if (mapView.WrapAround)
                {
                    mapPoint = GeometryEngine.NormalizeCentralMeridianOfGeometry(mapPoint) as MapPoint;
                }
                txtMapCoords.Text = string.Format("Map Coords: {0:0.000}, {1:0.000}", mapPoint.X, mapPoint.Y);
            }
        }
Пример #5
0
        // Begin geoprocessing with a user tap on the map
        private async void mapView_MapViewTapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
        {
            try
            {
                Progress.Visibility = Visibility.Visible;

                InputLayer.Graphics.Clear();
                InputLayer.Graphics.Add(new Graphic()
                {
                    Geometry = e.Location
                });

                Geoprocessor geoprocessorTask = new Geoprocessor(
                    new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_Currents_World/GPServer/MessageInABottle"));

                var parameter = new GPInputParameter()
                {
                    OutSpatialReference = mapView.SpatialReference
                };
                var ptNorm       = GeometryEngine.NormalizeCentralMeridianOfGeometry(e.Location);
                var ptGeographic = GeometryEngine.Project(ptNorm, SpatialReferences.Wgs84) as MapPoint;

                parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Point", ptGeographic));
                parameter.GPParameters.Add(new GPDouble("Days", Convert.ToDouble(DaysTextBox.Text)));

                var result = await geoprocessorTask.ExecuteAsync(parameter);

                ResultLayer.Graphics.Clear();
                foreach (GPParameter gpParameter in result.OutParameters)
                {
                    if (gpParameter is GPFeatureRecordSetLayer)
                    {
                        GPFeatureRecordSetLayer gpLayer = gpParameter as GPFeatureRecordSetLayer;
                        ResultLayer.Graphics.AddRange(gpLayer.FeatureSet.Features);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Geoprocessor service failed: " + ex.Message, "Sample Error");
            }
            finally
            {
                Progress.Visibility = Visibility.Collapsed;
            }
        }
Пример #6
0
        private void mapView_MouseMove(object sender, MouseEventArgs e)
        {
            if (mapView.Extent == null)
            {
                return;
            }

            System.Windows.Point screenPoint = e.GetPosition(mapView);
            ScreenCoordsTextBlock.Text = string.Format("Screen Coords: X = {0}, Y = {1}",
                                                       screenPoint.X, screenPoint.Y);

            MapPoint mapPoint = mapView.ScreenToLocation(screenPoint);

            if (mapView.WrapAround)
            {
                mapPoint = GeometryEngine.NormalizeCentralMeridianOfGeometry(mapPoint) as MapPoint;
            }
            MapCoordsTextBlock.Text = string.Format("Map Coords: X = {0}, Y = {1}",
                                                    Math.Round(mapPoint.X, 4), Math.Round(mapPoint.Y, 4));
        }
        public async Task Query(string text)
        {
            try
            {
                if (Controller == null)
                {
                    return;
                }

                IsLoadingSearchResults = true;
                text = text.Trim();

                if (_searchCancellationTokenSource != null)
                {
                    if (_currentSearchString != null && _currentSearchString == text)
                    {
                        return;
                    }
                    _searchCancellationTokenSource.Cancel();
                }
                _searchCancellationTokenSource = new CancellationTokenSource();
                var      cancellationToken = _searchCancellationTokenSource.Token;
                Envelope boundingBox       = Controller.Extent;
                if (string.IsNullOrWhiteSpace(text))
                {
                    return;
                }
                if (_currentSearchString != null && _currentSearchString != text)
                {
                    if (!cancellationToken.IsCancellationRequested)
                    {
                        _searchCancellationTokenSource.Cancel();
                    }
                }
                _searchResultLayer.Graphics.Clear();
                var geo = new OnlineLocatorTask(new Uri("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer", UriKind.Absolute), "");

                boundingBox = boundingBox.Expand(1.2);

                _currentSearchString = text;
                SearchResultStatus   = string.Format("Searching for '{0}'...", text.Trim());
                var result = await geo.FindAsync(new OnlineLocatorFindParameters(text)
                {
                    MaxLocations        = 50,
                    OutSpatialReference = WebMapVM.SpatialReference,
                    Location            = (MapPoint)GeometryEngine.NormalizeCentralMeridianOfGeometry(boundingBox.GetCenter()),
                    Distance            = GetDistance(boundingBox),
                }, cancellationToken);

                int retries = 3;
                while (result.Count == 0 && --retries > 0) //Try again with larger and larger extent
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        return;
                    }
                    boundingBox = boundingBox.Expand(2);
                    result      = await geo.FindAsync(new OnlineLocatorFindParameters(text)
                    {
                        MaxLocations        = 50,
                        OutSpatialReference = WebMapVM.SpatialReference,
                        Location            = (MapPoint)GeometryEngine.NormalizeCentralMeridianOfGeometry(boundingBox.GetCenter()),
                        Distance            = GetDistance(boundingBox),
                    }, cancellationToken);
                }
                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }
                if (result.Count == 0) //Try again unbounded
                {
                    result = await geo.FindAsync(new OnlineLocatorFindParameters(text)
                    {
                        MaxLocations        = 50,
                        OutSpatialReference = WebMapVM.SpatialReference
                    }, cancellationToken);
                }

                if (result.Count == 0)
                {
                    SearchResultStatus = string.Format("No results for '{0}' found", text);
                    if (Locations != null)
                    {
                        Locations.Clear();
                    }
                    //await new Windows.UI.Popups.MessageDialog(string.Format("No results for '{0}' found", text)).ShowAsync();
                }
                else
                {
                    SearchResultStatus = string.Format("Found {0} results for '{1}'", result.Count.ToString(), text);
                    Envelope           extent = null;
                    var                color  = (App.Current.Resources["AppAccentBrush"] as SolidColorBrush).Color;
                    var                color2 = (App.Current.Resources["AppAccentForegroundBrush"] as SolidColorBrush).Color;
                    SimpleMarkerSymbol symbol = new SimpleMarkerSymbol()
                    {
                        Color   = Colors.Black,
                        Outline = new SimpleLineSymbol()
                        {
                            Color = Colors.Black, Width = 2
                        },
                        Size  = 16,
                        Style = SimpleMarkerStyle.Square
                    };

                    // set the picture marker symbol used in the search result composite symbol.
                    var imageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/Icons/SearchResult.png"));

                    var imageSource = await imageFile.OpenReadAsync();

                    var pictureMarkerSymbol = new PictureMarkerSymbol();
                    await pictureMarkerSymbol.SetSourceAsync(imageSource);

                    // apply an x and y offsets so that the tip of of the pin points to the correct location.
                    pictureMarkerSymbol.XOffset = SearchResultPinXOffset;
                    pictureMarkerSymbol.YOffset = SearchResultPinYOffset;

                    int ID = 1;
                    foreach (var r in result)
                    {
                        if (extent == null)
                        {
                            extent = r.Extent;
                        }
                        else if (r.Extent != null)
                        {
                            extent = extent.Union(r.Extent);
                        }

                        var textSymbol = new TextSymbol()
                        {
                            Text = ID.ToString(),
                            Font = new SymbolFont()
                            {
                                FontFamily = "Verdena", FontSize = 10, FontWeight = SymbolFontWeight.Bold
                            },
                            Color                   = color2,
                            BorderLineColor         = color2,
                            HorizontalTextAlignment = Esri.ArcGISRuntime.Symbology.HorizontalTextAlignment.Center,
                            VerticalTextAlignment   = Esri.ArcGISRuntime.Symbology.VerticalTextAlignment.Bottom,
                            XOffset                 = SearchResultPinXOffset,
                            YOffset                 = SearchResultPinYOffset
                        }; //Looks like Top and Bottom are switched - potential CR

                        // a compsite symbol for both the PictureMarkerSymbol and the TextSymbol could be used, but we
                        // wanted to higlight the pin without the text; therefore, we will add them separately.

                        // add the PictureMarkerSymbol to _searchResultLayer
                        Graphic pin = new Graphic()
                        {
                            Geometry = r.Extent.GetCenter(),
                            Symbol   = pictureMarkerSymbol,
                        };
                        pin.Attributes["ID"]   = ID;
                        pin.Attributes["Name"] = r.Name;
                        _searchResultLayer.Graphics.Add(pin);

                        // add the text to _searchResultLayer
                        Graphic pinText = new Graphic()
                        {
                            Geometry = r.Extent.GetCenter(),
                            Symbol   = textSymbol,
                        };
                        pinText.Attributes["ID"]   = ID;
                        pinText.Attributes["Name"] = r.Name;
                        _searchResultLayer.Graphics.Add(pinText);

                        ID++;
                    }

                    SetResult(result);
                    base.RaisePropertyChanged("IsClearGraphicsVisible");
                    if (extent != null)
                    {
                        var _ = SetViewAsync(extent, 50);
                    }
                }
            }
            finally
            {
                IsLoadingSearchResults         = false;
                _searchCancellationTokenSource = null;
                _currentSearchString           = null;
            }
        }