예제 #1
0
        private void Mapview1_ExtentChanged(object sender, EventArgs e)
        {
            Esri.ArcGISRuntime.Geometry.Geometry ext = GeometryEngine.NormalizeCentralMeridian(Mapview1.Extent);
            var vp = new Esri.ArcGISRuntime.Controls.Viewpoint(ext);

            SceneView1.SetViewAsync(vp);
        }
예제 #2
0
        /// <summary>
        /// 点击地图上 显示信息  如地震信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MyMapView_OnMapViewTapped(object sender, MapViewInputEventArgs e)
        {
            List <EarthquakeMsg> list = earthquake.EarthquakeMsgs;

            if (list == null)
            {
                return;
            }
            for (int i = 0; i < list.Count; i++)
            {
                var normalizedPoint = GeometryEngine.NormalizeCentralMeridian(e.Location);
                var projectedCenter = GeometryEngine.Project(normalizedPoint, SpatialReferences.Wgs84) as MapPoint;
                float.Parse(projectedCenter.X.ToString("0.00"));
                if (float.Parse(projectedCenter.X.ToString("0.00")) == list[i].longitude && float.Parse(projectedCenter.Y.ToString("0.00")) == list[i].latitude)
                {
                    double margin_left   = e.Position.X - this.earthquakeMsgDetailBorder.ActualWidth;
                    double margin_top    = e.Position.Y - this.earthquakeMsgDetailBorder.ActualHeight * 0.5;
                    double margin_right  = this.MyMapView.ActualWidth - margin_left - this.earthquakeMsgDetailBorder.ActualWidth;
                    double margin_bottom = this.MyMapView.ActualHeight - margin_top - this.earthquakeMsgDetailBorder.ActualHeight;
                    this.earthquakeMsgDetailBorder.Margin      = new Thickness(margin_left, margin_top, margin_right, margin_bottom);
                    this.earthquakeMsgDetailBorder.Visibility  = Visibility.Visible;
                    this.earthquakeMsgDetailBorder.DataContext = list[i];
                    return;
                }
            }
        }
예제 #3
0
        // Intersects feature geometries with a user defined polygon.
        private async void IntersectButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                _resultGraphics.Graphics.Clear();

                // wait for user to draw a polygon
                Polygon userpoly = await MyMapView.Editor.RequestShapeAsync(DrawShape.Polygon) as Polygon;

                Polygon poly = GeometryEngine.NormalizeCentralMeridian(userpoly) as Polygon;

                // get intersecting features from the feature layer
                SpatialQueryFilter filter = new SpatialQueryFilter();
                filter.Geometry            = GeometryEngine.Project(poly, _statesLayer.FeatureTable.SpatialReference);
                filter.SpatialRelationship = SpatialRelationship.Intersects;
                filter.MaximumRows         = 52;
                var stateFeatures = await _statesLayer.FeatureTable.QueryAsync(filter);

                // Intersect the feature geometries and add to graphics layer
                var states            = stateFeatures.Select(feature => feature.Geometry);
                var intersectGraphics = states
                                        .Select(state => GeometryEngine.Intersection(state, poly))
                                        .Select(geo => new Graphic(geo, _fillSymbol));

                _resultGraphics.Graphics.AddRange(intersectGraphics);
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog("Intersection Error: " + ex.Message, "Sample Error").ShowAsync();
            }
        }
예제 #4
0
        //맵뷰 클릭이벤트 핸들러 -  이동처리(ServiceFeature)
        public async void handlerGeoViewTappedMoveFeature_org(object sender, GeoViewInputEventArgs e)
        {
            //이동처리
            if (_selectedFeature != null)
            {
                try
                {
                    // Get the MapPoint from the EventArgs for the tap.
                    MapPoint destinationPoint = e.Location;

                    // Normalize the point - needed when the tapped location is over the international date line.
                    destinationPoint = (MapPoint)GeometryEngine.NormalizeCentralMeridian(destinationPoint);

                    // Load the feature.
                    //await _selectedFeature.LoadAsync();

                    // Update the geometry of the selected feature.
                    _selectedFeature.Geometry = destinationPoint;

                    // Apply the edit to the feature table.
                    await _selectedFeature.FeatureTable.UpdateFeatureAsync(_selectedFeature);

                    _selectedFeature.Refresh();

                    // Push the update to the service. - Save버튼에서 최종저장
                    //ServiceFeatureTable serviceTable = (ServiceFeatureTable)_selectedFeature.FeatureTable;
                    //await serviceTable.ApplyEditsAsync();
                    //MessageBox.Show("Moved feature " + _selectedFeature.Attributes["objectid"], "Success!");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Error when moving feature.");
                }
            }
        }
        private void MapView_ExtentChanged(object sender, EventArgs e)
        {
            Envelope newExtent = null;

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

                    if (normalizedPolygon.Parts.Count == 1)
                    {
                        newExtent = normalizedPolygon.Extent;
                    }
                    else
                    {
                        var newExtentBuilder = new EnvelopeBuilder(MyMapView.SpatialReference);

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

                        foreach (var p in normalizedPolygon.Parts[1].GetPoints())
                        {
                            if (p.X > newExtentBuilder.XMax || double.IsNaN(newExtentBuilder.XMax))
                            {
                                newExtentBuilder.XMax = p.X;
                            }
                            if (p.Y > newExtentBuilder.YMax || double.IsNaN(newExtentBuilder.YMax))
                            {
                                newExtentBuilder.YMax = p.Y;
                            }
                        }
                        newExtent = newExtentBuilder.ToGeometry();
                    }
                }
                else if (normalizedExtent is Envelope)
                {
                    newExtent = normalizedExtent as Envelope;
                }
            }
            else
            {
                newExtent = MyMapView.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");
        }
예제 #6
0
        // Cuts feature geometries with a user defined cut polyline.
        private async void CutButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                _resultGraphicsOverlay.Graphics.Clear();

                // wait for user to draw cut line
                var cutLine = await MyMapView.Editor.RequestShapeAsync(DrawShape.Polyline, _cutLineSymbol) as Polyline;

                Polyline polyline = GeometryEngine.NormalizeCentralMeridian(cutLine) as Polyline;

                // get intersecting features from the feature layer
                SpatialQueryFilter filter = new SpatialQueryFilter();
                filter.Geometry            = GeometryEngine.Project(polyline, _statesLayer.FeatureTable.SpatialReference);
                filter.SpatialRelationship = SpatialRelationship.Crosses;
                filter.MaximumRows         = 52;
                var stateFeatures = await _statesLayer.FeatureTable.QueryAsync(filter);

                // Cut the feature geometries and add to graphics layer
                var states      = stateFeatures.Select(feature => feature.Geometry);
                var cutGraphics = states
                                  .Where(geo => !GeometryEngine.Within(polyline, geo))
                                  .SelectMany(state => GeometryEngine.Cut(state, polyline))
                                  .Select(geo => new Graphic(geo, _cutFillSymbol));

                _resultGraphicsOverlay.Graphics.AddRange(cutGraphics);
            }
            catch (TaskCanceledException) { }
            catch (Exception ex)
            {
                var _x = new MessageDialog("Cut Error: " + ex.Message, "Sample Error").ShowAsync();
            }
        }
        private void AnimateGraphic()
        {
            MapPoint userStartPoint  = _userInteractionLayer.Graphics[0].Geometry as MapPoint;
            MapPoint userFinishPoint = _userInteractionLayer.Graphics[1].Geometry as MapPoint;

            MapPoint startPoint  = GeometryEngine.NormalizeCentralMeridian(userStartPoint) as MapPoint;
            MapPoint finishPoint = GeometryEngine.NormalizeCentralMeridian(userFinishPoint) as MapPoint;

            var animatingGraphic = new Graphic(new MapPoint(startPoint.X, startPoint.Y));

            _animatingLayer.Graphics.Add(animatingGraphic);

            // Framework easing objects may be used to calculate progressive values
            // - i.e. QuinticEase, BackEase, BounceEase, ElasticEase, etc.
            var easing = new QuinticEase()
            {
                EasingMode = EasingMode.EaseInOut
            };

            var animateStartTime = DateTime.Now;
            var animationTimer   = new DispatcherTimer();

            animationTimer.Interval = TimeSpan.FromMilliseconds(33);
            animationTimer.Tick    += (s, ex) =>
            {
                double fraction = easing.Ease((DateTime.Now - animateStartTime).TotalMilliseconds / AnimationDuration);
                var    x        = (finishPoint.X - startPoint.X) * fraction + startPoint.X;
                var    y        = (finishPoint.Y - startPoint.Y) * fraction + startPoint.Y;
                animatingGraphic.Geometry = new MapPoint(x, y);
            };

            animationTimer.Start();
        }
예제 #8
0
        public async void MyMapView_OnMapViewTapped(object sender, MapViewInputEventArgs e)
        {
            try
            {
                var normalizedPoint = GeometryEngine.NormalizeCentralMeridian(e.Location);
                var point           = GeometryEngine.Project(normalizedPoint, SpatialReferences.Wgs84) as MapPoint;

                if (isDelete)
                {
                    await DeleteScenic(e.Position);

                    //return;
                }
                if (isAdd)
                {
                    await AddScenic(point);

                    //return;
                }
                if (isAlter)
                {
                    await AlterScenic(e.Position);

                    //return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("HitTest Error: " + ex.Message, "Graphics Layer Hit Testing");
            }
        }
예제 #9
0
 private async void MapView_GeoViewTappedAsync(object sender, GeoViewInputEventArgs e)
 {
     try
     {
         double   tolerance    = 10;
         double   mapTolerance = tolerance * mapView.UnitsPerPixel;
         MapPoint geometry     = e.Location;
         if (mapView.IsWrapAroundEnabled)
         {
             geometry = GeometryEngine.NormalizeCentralMeridian(geometry) as MapPoint;
         }
         var selectionEnvelope = new Envelope(geometry.X - mapTolerance, geometry.Y - mapTolerance, geometry.X + mapTolerance,
                                              geometry.Y + mapTolerance, mapView.Map.SpatialReference);
         var queryParams = new QueryParameters();
         queryParams.Geometry = selectionEnvelope;
         SelectTagByTypoAsync(_featureLayer, "TAP", queryParams);
         SelectTagByTypoAsync(featureLayerNAP, "NAP", queryParams);
         SelectTagByTypoAsync(featureLayerMDU, "MDU", queryParams);
         await featureLayerCableCoaxial.SelectFeaturesAsync(queryParams, SelectionMode.New);
     }
     catch (Exception ex)
     {
         Log.Info("Error", ex.Message);
         GenerateAlertError("Error buscando el tap");
     }
 }
        private void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e)
        {
            try
            {
                _graphicsOverlay.Graphics.Clear();

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

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

                var bufferGraphic = new Graphic {
                    Geometry = buffer, Symbol = _bufferSymbol
                };
                _graphicsOverlay.Graphics.Add(bufferGraphic);
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
            }
        }
예제 #11
0
        // 피처추가
        public void handlerGeoViewTappedAddFeature(object sender, GeoViewInputEventArgs e)
        {
            try
            {
                // Get the MapPoint from the EventArgs for the tap.
                MapPoint destinationPoint = e.Location;
                // Normalize the point - needed when the tapped location is over the international date line.
                destinationPoint = (MapPoint)GeometryEngine.NormalizeCentralMeridian(destinationPoint);


                // 1.레이어에 위치추가
                AddFeatureToLayer(destinationPoint);


                //MessageBox.Show("Added feature ", "Success!");

                //이벤트핸들러원복
                mapView.GeoViewTapped -= handlerGeoViewTappedMoveFeature;
                mapView.GeoViewTapped -= handlerGeoViewTappedAddFeature;
                mapView.GeoViewTapped -= handlerGeoViewTapped;
                mapView.GeoViewTapped += handlerGeoViewTapped;

                /*
                 * 시설물DB 저장
                 */
                Messages.ShowInfoMsgBox("위치정보가 추가되었습니다. 해당시설물의 상세정보를 저장하세요");
            }
            catch (Exception ex)
            {
                Messages.ShowErrMsgBox(ex.ToString());
            }
        }
예제 #12
0
        private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e)
        {
            // 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((Page)Parent).DisplayAlert("Error", ex.ToString(), "OK");
            }
        }
        private async Task DoCutPolygons()
        {
            if (statesOverlay != null && resultsOverlay != null)
            {
                resultsOverlay.Graphics.Clear();

                // Get the user's input
                var cutPolyLine = (await mapView1.Editor.RequestShapeAsync(DrawShape.Polyline)) as Polyline;

                // Normalize for WrapAround
                Polyline polyline = GeometryEngine.NormalizeCentralMeridian(cutPolyLine) as Polyline;

                // Iterate over the graphics in the GraphicsOverlay. If the graphic intersects with the polyline we will cut it
                // and create Graphic objects from the results. Next we add those Graphics resulting to a List<Graphic>.
                List <Graphic> cutGraphics = new List <Graphic>();
                foreach (var g in statesOverlay.Graphics)
                {
                    if (GeometryEngine.Intersects(g.Geometry, polyline))
                    {
                        var cutPolygonGeometries = GeometryEngine.Cut(g.Geometry, polyline);
                        var cutPolygonGraphics   = cutPolygonGeometries.Select(x => new Graphic {
                            Geometry = x
                        });
                        cutGraphics.AddRange(cutPolygonGraphics);
                    }
                }
                // Add the results to the GraphicsOverlay
                resultsOverlay.Graphics.AddRange(cutGraphics);
            }
        }
예제 #14
0
        private async void OnMapViewTapped(object sender, GeoViewInputEventArgs e)
        {
            _inputOverlay.Graphics.Clear();
            _resultOverlay.Graphics.Clear();

            // Get the tapped point

            MapPoint geometry = new MapPoint(e.Location.X, e.Location.Y, e.Location.SpatialReference);


            Console.WriteLine(geometry.ToString());
            // 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 (MainWindow.View.Map2D.IsWrapAroundEnabled)
            {
                geometry = (MapPoint)GeometryEngine.NormalizeCentralMeridian(geometry);
            }

            try
            {
                // Execute the geoprocessing task using the user click location
                await CalculateViewshed(geometry);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error");
            }
        }
        // Process elevation data requests by the user
        private async Task ProcessUserRequests()
        {
            try
            {
                // Get user rectangle
                var userEnvelope = await MyMapView.Editor.RequestShapeAsync(DrawShape.Envelope) as Envelope;

                if (userEnvelope.Height == 0 || userEnvelope.Width == 0)
                {
                    throw new ArgumentNullException("Please click and drag a box to define an extent.");
                }

                // Display the graphics
                _graphicsLayer.Graphics.Add(new Graphic(userEnvelope));


                // Take account of WrapAround
                var      polygon  = GeometryEngine.NormalizeCentralMeridian(userEnvelope) as Polygon;
                Envelope envelope = polygon.Extent;

                // Retrieve elevation data from the service
                ElevationData elevationData = await GetElevationData(envelope);

                // Create the image for the display
                WriteableBitmap writeableBitmapElevation = await CreateElevationImageAsync(elevationData);

                ElevationImage.Source    = writeableBitmapElevation;
                ElevationView.Visibility = Visibility.Visible;
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
            }
        }
        private async void MapView_Tapped(object sender, GeoViewInputEventArgs e)
        {
            try
            {
                // Create the feature.
                ArcGISFeature feature = (ArcGISFeature)_damageFeatureTable.CreateFeature();

                // Get the normalized geometry for the tapped location and use it as the feature's geometry.
                MapPoint tappedPoint = (MapPoint)GeometryEngine.NormalizeCentralMeridian(e.Location);
                feature.Geometry = tappedPoint;

                // Set feature attributes.
                feature.SetAttributeValue("typdamage", "Minor");
                feature.SetAttributeValue("primcause", "Earthquake");

                // Add the feature to the table.
                await _damageFeatureTable.AddFeatureAsync(feature);

                // Apply the edits to the service.
                await _damageFeatureTable.ApplyEditsAsync();

                // Update the feature to get the updated objectid - a temporary ID is used before the feature is added.
                feature.Refresh();

                // Confirm feature addition.
                MessageBox.Show("Created feature " + feature.Attributes["objectid"], "Success!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error adding feature");
            }
        }
예제 #17
0
        private void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e)
        {
            var normalizedPoint = GeometryEngine.NormalizeCentralMeridian(e.Location);
            var projectedCenter = GeometryEngine.Project(normalizedPoint, SpatialReferences.Wgs84) as MapPoint;

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

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

                Graphic bufferGraphic = null;
                if (_graphicsOverlay.Graphics.Count == 0)
                {
                    bufferGraphic = new Graphic {
                        Geometry = buffer, Symbol = _bufferSymbol
                    };
                    _graphicsOverlay.Graphics.Add(bufferGraphic);
                }
                else
                {
                    bufferGraphic = _graphicsOverlay.Graphics[0];
                }
                bufferGraphic.Geometry = buffer;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Geometry Engine Failed!");
            }
        }
예제 #19
0
        // Clips feature geometries with a user defined clipping rectangle.
        private async void ClipButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                _clippedGraphicsOverlay.Graphics.Clear();

                // wait for user to draw clip rect
                var rect = await MyMapView.Editor.RequestShapeAsync(DrawShape.Rectangle);

                Polygon polygon = GeometryEngine.NormalizeCentralMeridian(rect) as Polygon;

                // get intersecting features from the feature layer
                SpatialQueryFilter filter = new SpatialQueryFilter();
                filter.Geometry            = GeometryEngine.Project(polygon, _statesLayer.FeatureTable.SpatialReference);
                filter.SpatialRelationship = SpatialRelationship.Intersects;
                filter.MaximumRows         = 52;
                var stateFeatures = await _statesLayer.FeatureTable.QueryAsync(filter);

                // Clip the feature geometries and add to graphics layer
                var states       = stateFeatures.Select(feature => feature.Geometry);
                var clipGraphics = states
                                   .Select(state => GeometryEngine.Clip(state, polygon.Extent))
                                   .Select(geo => new Graphic(geo, _clipSymbol));

                _clippedGraphicsOverlay.Graphics.AddRange(clipGraphics);
            }
            catch (TaskCanceledException) { }
            catch (Exception ex)
            {
                var _x = new MessageDialog("Clip Error: " + ex.Message, "Clip Geometry").ShowAsync();
            }
        }
        private async void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            // 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();
            }
        }
예제 #21
0
        private async void OnMapViewTapped(object sender, GeoViewInputEventArgs e)
        {
            // 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, SelectionMode.New);
        }
예제 #22
0
        private void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs geoViewInputEventArgs)
        {
            // Get the tapped location.
            MapPoint tappedLocation = (MapPoint)GeometryEngine.NormalizeCentralMeridian(geoViewInputEventArgs.Location);

            // Show the tapped location.
            _tappedLocationGraphic.Geometry = tappedLocation;

            // Get the nearest vertex in the polygon.
            ProximityResult nearestVertexResult = GeometryEngine.NearestVertex(_polygonGraphic.Geometry, tappedLocation);

            // Get the nearest coordinate in the polygon.
            ProximityResult nearestCoordinateResult =
                GeometryEngine.NearestCoordinate(_polygonGraphic.Geometry, tappedLocation);

            // Get the distance to the nearest vertex in the polygon.
            int distanceVertex = (int)(nearestVertexResult.Distance / 1000);

            // Get the distance to the nearest coordinate in the polygon.
            int distanceCoordinate = (int)(nearestCoordinateResult.Distance / 1000);

            // Show the nearest vertex in blue.
            _nearestVertexGraphic.Geometry = nearestVertexResult.Coordinate;

            // Show the nearest coordinate in red.
            _nearestCoordinateGraphic.Geometry = nearestCoordinateResult.Coordinate;

            // Show the distances in the UI.
            _distanceLabel.Text = $"Vertex dist: {distanceVertex} km, Point dist: {distanceCoordinate} km";
        }
        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 = GeometryEngine.NormalizeCentralMeridian(geometry) as MapPoint;
            }

            // Execute the geoprocessing task using the user click location
            await CalculateViewshed(geometry);
        }
예제 #24
0
        private void MapViewTapped(object sender, GeoViewInputEventArgs geoViewInputEventArgs)
        {
            // Get the tapped location
            MapPoint tappedLocation = (MapPoint)GeometryEngine.NormalizeCentralMeridian(geoViewInputEventArgs.Location);

            // Show the tapped location
            _tappedLocationGraphic.Geometry = tappedLocation;

            // Get the nearest vertex in the polygon
            ProximityResult nearestVertexResult = GeometryEngine.NearestVertex(_polygonGraphic.Geometry, tappedLocation);

            // Get the nearest coordinate in the polygon
            ProximityResult nearestCoordinateResult =
                GeometryEngine.NearestCoordinate(_polygonGraphic.Geometry, tappedLocation);

            // Get the distance to the nearest vertex in the polygon
            int distanceVertex = (int)(nearestVertexResult.Distance / 1000);

            // Get the distance to the nearest coordinate in the polygon
            int distanceCoordinate = (int)(nearestCoordinateResult.Distance / 1000);

            // Show the nearest vertex in blue
            _nearestVertexGraphic.Geometry = nearestVertexResult.Coordinate;

            // Show the nearest coordinate in red
            _nearestCoordinateGraphic.Geometry = nearestCoordinateResult.Coordinate;

            // Show the distances in the UI
            ResultsLabel.Content =
                string.Format("Vertex dist: {0} km, Point dist: {1} km", distanceVertex, distanceCoordinate);
        }
예제 #25
0
        // Unions feature geometries with a user defined polygon.
        private async void UnionButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                _resultGraphics.Graphics.Clear();

                // wait for user to draw a polygon
                var poly = await MyMapView.Editor.RequestShapeAsync(DrawShape.Polygon);

                // Take account of WrapAround
                var normalizedPoly = GeometryEngine.NormalizeCentralMeridian(poly) as Polygon;

                // get intersecting features from the feature layer
                SpatialQueryFilter filter = new SpatialQueryFilter();
                filter.Geometry            = GeometryEngine.Project(normalizedPoly, _statesLayer.FeatureTable.SpatialReference);
                filter.SpatialRelationship = SpatialRelationship.Intersects;
                filter.MaximumRows         = 52;
                var stateFeatures = await _statesLayer.FeatureTable.QueryAsync(filter);

                // Union the geometries and add to graphics layer
                var states     = stateFeatures.Select(feature => feature.Geometry);
                var unionPolys = states.ToList();

                var unionPoly    = GeometryEngine.Union(unionPolys);
                var unionGraphic = new Graphic(unionPoly, _fillSymbol);

                _resultGraphics.Graphics.Add(unionGraphic);
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog("Union Error: " + ex.Message, "Sample Error").ShowAsync();
            }
        }
        public void MapView_MouseDown(object sender, MouseButtonEventArgs e)
        {
            System.Windows.Point screenPoint = e.GetPosition(mainMapView);
            MapPoint             mapPoint    = mainMapView.ScreenToLocation(screenPoint);

            if (mainMapView.WrapAround)
            {
                mapPoint = GeometryEngine.NormalizeCentralMeridian(mapPoint) as MapPoint;
            }
            switch (mapOperationType)
            {
            case MapOperationType.AddPerson:
                var personAddDialogViewModel = new PersonAddDialogViewModel(personService, imgService);
                personAddDialogViewModel.FamousPerson.BornX = mapPoint.X;
                personAddDialogViewModel.FamousPerson.BornY = mapPoint.Y;
                new PersonAddDialog(personAddDialogViewModel).ShowDialog();
                break;

            case MapOperationType.AddEvent:
                var eventAddDialogViewModel = new EventAddDialogViewModel(historyEventService, imgService);
                eventAddDialogViewModel.HistoryEvent.OccurX = mapPoint.X;
                eventAddDialogViewModel.HistoryEvent.OccurY = mapPoint.Y;
                new EventAddDialog(eventAddDialogViewModel).ShowDialog();
                break;

            default:
                break;
            }
        }
예제 #27
0
        private async void MySceneView_MouseLeftDown(object sender, MouseEventArgs e)
        {
            if (edit == true && (type == "line" || type == "area"))
            {
                if (MySceneView.GetCurrentViewpoint(ViewpointType.BoundingGeometry) == null)
                {
                    return;
                }
                _mapViewModel.Clear(type);
                System.Windows.Point screenPoint = e.GetPosition(MySceneView);
                MapPoint             mapPoint    = await MySceneView.ScreenToLocationAsync(screenPoint);

                if (mapPoint.X != 0 && mapPoint.Y != 0 && mapPoint.Z != 0)
                {
                    mapPoint = GeometryEngine.NormalizeCentralMeridian(mapPoint) as MapPoint;
                    mapPoint_list.Add(new MapPoint(mapPoint.X, mapPoint.Y));
                    if (mapPoint_list.Count > 1)
                    {
                        var boatPositions = new PolylineBuilder(SpatialReferences.Wgs84);
                        boatPositions.AddPoint(new MapPoint(mapPoint_list[mapPoint_list.Count - 2].X, mapPoint_list[mapPoint_list.Count - 2].Y));
                        boatPositions.AddPoint(new MapPoint(mapPoint_list[mapPoint_list.Count - 1].X, mapPoint_list[mapPoint_list.Count - 1].Y));
                        var boatRoute = boatPositions.ToGeometry();
                        _mapViewModel.Line(boatRoute, "temp");;
                    }
                }
            }
        }
예제 #28
0
        // 点选Popup属性
        private async void myMapViewGetAttributeValue(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs e)
        {
            IdentifyLayerResult myShapeFileResult = await myMapView.IdentifyLayerAsync(tempPopupLayer, e.Position, 20, false);

            try
            {
                Feature tempGeoElement = (Feature)myShapeFileResult.GeoElements[0];
                // 遍历全部属性
                List <ArcGISApp1.Utils.ShapefileAttribution> attrList = new List <ArcGISApp1.Utils.ShapefileAttribution>();
                foreach (KeyValuePair <string, object> keyValuePair in tempGeoElement.Attributes)
                {
                    ArcGISApp1.Utils.ShapefileAttribution temp = new ArcGISApp1.Utils.ShapefileAttribution(keyValuePair.Key, (keyValuePair.Value).ToString());
                    attrList.Add(temp);
                }
                Popup    myPopup    = (Popup)mainWindow.FindName("myPopup");
                DataGrid myDataGrid = (DataGrid)mainWindow.FindName("myDataGrid");
                myPopup.IsOpen = false;
                myPopup.IsOpen = true;
                myDataGrid.AutoGenerateColumns = false;
                myDataGrid.ItemsSource         = attrList;
            }
            catch
            {
                TextBlock myTest = (TextBlock)mainWindow.FindName("myTest");
                myTest.Text = "当前无要素被选中。";
            }

            // 要素选择高亮
            try
            {
                double   tolerance    = 0.0000001;
                double   mapTolerance = tolerance * myMapView.UnitsPerPixel;
                MapPoint geometry     = e.Location;

                if (myMapView.IsWrapAroundEnabled)
                {
                    geometry = (MapPoint)GeometryEngine.NormalizeCentralMeridian(geometry);
                }
                Envelope        selectionEnvelope = new Envelope(geometry.X - mapTolerance, geometry.Y - mapTolerance, geometry.X + mapTolerance, geometry.Y + mapTolerance, myMapView.Map.SpatialReference);
                QueryParameters queryParams       = new QueryParameters
                {
                    Geometry = selectionEnvelope
                               //Geometry = geometry
                };
                FeatureQueryResult queryResult = await tempPopupLayer.SelectFeaturesAsync(queryParams, Esri.ArcGISRuntime.Mapping.SelectionMode.New);

                //IEnumerator<Feature> resultFeatures = queryResult.GetEnumerator();
                //List<Feature> features = new List<Feature>();
                //while (resultFeatures.MoveNext())
                //{
                //    features.Add(resultFeatures.Current);
                //}
                //MessageBox.Show(geometry.X + "\n" + geometry.Y + "\n" + features.Count);
            }
            catch (Exception ex)
            {
                MessageBox.Show("要素选择错误: ", ex.ToString());
            }
        }
예제 #29
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Envelope ext     = GeometryEngine.NormalizeCentralMeridian(Mapview1.Extent).Extent;
            MapPoint ptnMin  = new MapPoint(ext.XMin, ext.YMin, Mapview1.SpatialReference);
            MapPoint nptnMin = GeometryEngine.Project(ptnMin, new SpatialReference(4326)) as MapPoint;
            MapPoint ptnMax  = new MapPoint(ext.XMax, ext.YMax, Mapview1.SpatialReference);
            MapPoint nptnMax = GeometryEngine.Project(ptnMax, new SpatialReference(4326)) as MapPoint;

            SetLocation(sender, string.Format("{0},{1},{2},{3}", nptnMin.X, nptnMin.Y, nptnMax.X, nptnMax.Y));
        }
예제 #30
0
        void AssociatedObject_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            MapView mapView = sender as MapView;

            System.Windows.Point screenPoint = e.GetPosition(mapView);
            MapPoint             mapPoint    = mapView.ScreenToLocation(screenPoint);

            if (mapView.WrapAround)
            {
                mapPoint = GeometryEngine.NormalizeCentralMeridian(mapPoint) as MapPoint;
            }
        }