Ejemplo n.º 1
0
        // buffer the click point, query the map service with the buffer geometry as the filter and add graphics to the map
        private async void mapView_MapViewTapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
        {
            try
            {
                graphicsLayer.Graphics.Add(new Graphic(e.Location));

                var bufferResult = GeometryEngine.Buffer(e.Location, 100);
                bufferLayer.Graphics.Add(new Graphic(bufferResult));

                var queryTask = new QueryTask(
                    new Uri("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/BloomfieldHillsMichigan/Parcels/MapServer/2"));
                var query = new Query("1=1")
                {
                    ReturnGeometry      = true,
                    OutSpatialReference = mapView.SpatialReference,
                    Geometry            = bufferResult
                };
                query.OutFields.Add("OWNERNME1");

                var queryResult = await queryTask.ExecuteAsync(query);

                if (queryResult != null && queryResult.FeatureSet != null)
                {
                    parcelLayer.Graphics.AddRange(queryResult.FeatureSet.Features);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Spatial Query Sample");
            }
        }
Ejemplo n.º 2
0
        private async void mapView1_Tapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
        {
            var     mp   = e.Location;
            Graphic stop = new Graphic()
            {
                Geometry = mp
            };
            var stopsGraphicsLayer = mapView1.Map.Layers["MyStopsGraphicsLayer"] as GraphicsLayer;

            stopsGraphicsLayer.Graphics.Add(stop);

            if (stopsGraphicsLayer.Graphics.Count > 1)
            {
                try
                {
                    var routeTask   = new OnlineRouteTask(new Uri("http://tasks.arcgisonline.com/ArcGIS/rest/services/NetworkAnalysis/ESRI_Route_NA/NAServer/Route"));
                    var routeParams = await routeTask.GetDefaultParametersAsync();

                    FeaturesAsFeature stopsFeatures = new FeaturesAsFeature();
                    stopsFeatures.Features           = stopsGraphicsLayer.Graphics;
                    routeParams.Stops                = stopsFeatures;
                    routeParams.UseTimeWindows       = false;
                    routeParams.OutSpatialReference  = mapView1.SpatialReference;
                    routeParams.DirectionsLengthUnit = LinearUnits.Miles;
                    var result = await routeTask.SolveAsync(routeParams);

                    if (result != null)
                    {
                        if (result.Routes != null && result.Routes.Count > 0)
                        {
                            var firstRoute = result.Routes.FirstOrDefault();
                            var direction  = firstRoute.RouteDirections.FirstOrDefault();

                            if (direction != null)
                            {
                                int totalMins = 0;
                                foreach (RouteDirection dir in firstRoute.RouteDirections)
                                {
                                    totalMins = totalMins + dir.Time.Minutes;
                                }

                                await new MessageDialog(string.Format("{0:N2} minutes", totalMins)).ShowAsync();
                            }

                            var routeLayer = mapView1.Map.Layers["MyRouteGraphicsLayer"] as GraphicsLayer;
                            routeLayer.Graphics.Add(firstRoute.RouteGraphic);
                        }
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                }
            }
        }
        // buffer the click point, query the map service with the buffer geometry as the filter and add graphics to the map
        private async void MyMapView_Tapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
        {
            try
            {
                var graphicsOverlay = MyMapView.GraphicsOverlays["graphicsOverlay"];
                if (!(graphicsOverlay.Graphics.Count == 0))
                {
                    graphicsOverlay.Graphics.Clear();
                }

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

                var bufferOverlay = MyMapView.GraphicsOverlays["bufferOverlay"];
                if (!(bufferOverlay.Graphics.Count == 0))
                {
                    bufferOverlay.Graphics.Clear();
                }

                var bufferResult = GeometryEngine.Buffer(e.Location, 100);
                bufferOverlay.Graphics.Add(new Graphic()
                {
                    Geometry = bufferResult
                });

                var queryTask = new QueryTask(
                    new Uri("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/BloomfieldHillsMichigan/Parcels/MapServer/2"));
                var query = new Query("1=1")
                {
                    ReturnGeometry      = true,
                    OutSpatialReference = MyMapView.SpatialReference,
                    Geometry            = bufferResult
                };
                query.OutFields.Add("OWNERNME1");

                var queryResult = await queryTask.ExecuteAsync(query);

                if (queryResult != null && queryResult.FeatureSet != null)
                {
                    var resultOverlay = MyMapView.GraphicsOverlays["parcelOverlay"];
                    if (!(resultOverlay.Graphics.Count == 0))
                    {
                        resultOverlay.Graphics.Clear();
                    }

                    resultOverlay.Graphics.AddRange(queryResult.FeatureSet.Features.OfType <Graphic>());
                }
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
            }
        }
        private async void mapView1_Tapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
        {
            // Convert screen point to map point
            var mapPoint = mapView1.ScreenToLocation(e.Position);
            var l        = mapView1.Map.Layers["InputLayer"] as GraphicsLayer;

            l.Graphics.Clear();
            l.Graphics.Add(new Graphic()
            {
                Geometry = mapPoint
            });

            string       error = null;
            Geoprocessor task  = new Geoprocessor(new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Network/ESRI_DriveTime_US/GPServer/CreateDriveTimePolygons"));

            var parameter = new GPInputParameter();

            parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Location", mapPoint));
            parameter.GPParameters.Add(new GPString("Drive_Times", "1 2 3"));

            try
            {
                var result = await task.ExecuteAsync(parameter);

                var r = mapView1.Map.Layers["ResultLayer"] as GraphicsLayer;
                r.Graphics.Clear();
                foreach (GPParameter gpParameter in result.OutParameters)
                {
                    if (gpParameter is GPFeatureRecordSetLayer)
                    {
                        GPFeatureRecordSetLayer gpLayer = gpParameter as GPFeatureRecordSetLayer;
                        List <Esri.ArcGISRuntime.Symbology.Symbol> bufferSymbols = new List <Esri.ArcGISRuntime.Symbology.Symbol>(
                            new Esri.ArcGISRuntime.Symbology.Symbol[] { LayoutRoot.Resources["FillSymbol1"] as Esri.ArcGISRuntime.Symbology.Symbol, LayoutRoot.Resources["FillSymbol2"] as Esri.ArcGISRuntime.Symbology.Symbol, LayoutRoot.Resources["FillSymbol3"] as Esri.ArcGISRuntime.Symbology.Symbol });

                        int count = 0;
                        foreach (Graphic graphic in gpLayer.FeatureSet.Features)
                        {
                            graphic.Symbol = bufferSymbols[count];
                            graphic.Attributes.Add("Info", String.Format("{0} minute buffer ", 3 - count));
                            r.Graphics.Add(graphic);
                            count++;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                error = "Geoprocessor service failed: " + ex.Message;
            }
            if (error != null)
            {
                await new MessageDialog(error).ShowAsync();
            }
        }
        private async void MyMapView_MapViewTapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
        {
            try
            {
                if (MyDataForm.ResetCommand.CanExecute(null))
                {
                    MyDataForm.ResetCommand.Execute(null);
                }

                MyDataForm.GeodatabaseFeature = null;

                if (_editedLayer != null)
                {
                    _editedLayer.ClearSelection();
                }

                foreach (var layer in MyMapView.Map.Layers.OfType <FeatureLayer>().Reverse())
                {
                    // Get possible features and if none found, move to next layer
                    var foundFeatures = await layer.HitTestAsync(MyMapView, new Rect(e.Position, new Size(10, 10)), 1);

                    if (foundFeatures.Count() == 0)
                    {
                        continue;
                    }

                    // Get feature from table
                    var feature = await layer.FeatureTable.QueryAsync(foundFeatures[0]);

                    // Change UI
                    DescriptionTextArea.Visibility = Visibility.Collapsed;
                    DataFormArea.Visibility        = Visibility.Visible;

                    _editedFeature = feature as GeodatabaseFeature;
                    _editedLayer   = layer;
                    _editedLayer.SelectFeatures(new long[] { foundFeatures[0] });

                    // Set feature that is being edited to data form
                    MyDataForm.GeodatabaseFeature = _editedFeature;
                    return;
                }

                // No features found
                DescriptionTextArea.Visibility = Visibility.Visible;
                DataFormArea.Visibility        = Visibility.Collapsed;
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Error occured : {0}", ex.ToString()), "Sample error");
            }
        }
Ejemplo n.º 6
0
        private void mapView1_MapViewTapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
        {
            // Convert screen point to map point
            var mapPoint = mapView1.ScreenToLocation(e.Position);

            // Create graphic
            Graphic g = new Graphic()
            {
                Geometry = mapPoint
            };

            // Get layer and add point to it
            var graphicsLayer = mapView1.Map.Layers["MyGraphicsLayer"] as GraphicsLayer;

            graphicsLayer.Graphics.Add(g);
        }
        private async void mapView1_Tapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
        {
            var mapPoint = e.Location;
            var l        = mapView1.Map.Layers["InputLayer"] as GraphicsLayer;

            l.Graphics.Clear();
            l.Graphics.Add(new Graphic()
            {
                Geometry = mapPoint
            });
            string       error            = null;
            Geoprocessor geoprocessorTask = new Geoprocessor(new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_Currents_World/GPServer/MessageInABottle"));

            var parameter = new GPInputParameter()
            {
                OutSpatialReference = mapView1.SpatialReference
            };
            var toGeographic = GeometryEngine.Project(mapPoint, new SpatialReference(4326)) as MapPoint;

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

            try
            {
                var result = await geoprocessorTask.ExecuteAsync(parameter);

                var r = mapView1.Map.Layers["ResultLayer"] as GraphicsLayer;
                r.Graphics.Clear();
                foreach (GPParameter gpParameter in result.OutParameters)
                {
                    if (gpParameter is GPFeatureRecordSetLayer)
                    {
                        GPFeatureRecordSetLayer gpLayer = gpParameter as GPFeatureRecordSetLayer;
                        r.Graphics.AddRange(gpLayer.FeatureSet.Features.OfType <Graphic>());
                    }
                }
            }
            catch (Exception ex)
            {
                error = "Geoprocessor service failed: " + ex.Message;
            }
            if (error != null)
            {
                await new MessageDialog(error).ShowAsync();
            }
        }
Ejemplo n.º 8
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;
            }
        }
        private async void mapView1_Tapped_1(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
        {
            var     mp = e.Location;
            Graphic g  = new Graphic()
            {
                Geometry = mp
            };
            var graphicsLayer = mapView1.Map.Layers["MyGraphicsLayer"] as GraphicsLayer;

            graphicsLayer.Graphics.Add(g);

            var bufferResult = GeometryEngine.Buffer(mp, 100);
            var bufferLayer  = mapView1.Map.Layers["BufferLayer"] as GraphicsLayer;

            bufferLayer.Graphics.Add(new Graphic()
            {
                Geometry = bufferResult
            });


            var queryTask = new QueryTask(new Uri("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/BloomfieldHillsMichigan/Parcels/MapServer/2"));
            var query     = new Query("1=1")
            {
                ReturnGeometry      = true,
                OutSpatialReference = mapView1.SpatialReference,
                Geometry            = bufferResult
            };

            query.OutFields.Add("OWNERNME1");

            try
            {
                var queryResult = await queryTask.ExecuteAsync(query);

                if (queryResult != null && queryResult.FeatureSet != null)
                {
                    var resultLayer = mapView1.Map.Layers["MyResultsGraphicsLayer"] as GraphicsLayer;
                    resultLayer.Graphics.AddRange(queryResult.FeatureSet.Features);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 10
0
        private void MyMapView_MapViewTapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
        {
            var viewModel = DataContext as MainWindowViewModel;

            if (viewModel != null)
            {
                if (viewModel.IsMovingStartPoint)
                {
                    StartPointGraphic       = UpdatePoint(e.Location, StartPointGraphic, true);
                    viewModel.StartLocation = e.Location;
                }
                else
                {
                    EndPointGraphic       = UpdatePoint(e.Location, EndPointGraphic);
                    viewModel.EndLocation = e.Location;
                }
            }
        }
Ejemplo n.º 11
0
        private void mapView1_Tapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
        {
            var     mp = mapView1.ScreenToLocation(e.Position);
            Graphic g  = new Graphic()
            {
                Geometry = mp
            };
            var stopsLayer    = mapView1.Map.Layers["MyStopsGraphicsLayer"] as GraphicsLayer;
            var barriersLayer = mapView1.Map.Layers["MyBarriersGraphicsLayer"] as GraphicsLayer;

            if (StopsRadioButton.IsChecked.Value)
            {
                stopsLayer.Graphics.Add(g);
            }
            else if (BarriersRadioButton.IsChecked.Value)
            {
                barriersLayer.Graphics.Add(g);
            }
        }
Ejemplo n.º 12
0
        private async void mapView1_MapViewTapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
        {
            var hitGraphic = await _candidateGraphicsLayer.HitTestAsync(mapView1, e.Position);

            if (hitGraphic != null)
            {
                if (mapView1tip.Visibility == Windows.UI.Xaml.Visibility.Collapsed)
                {
                    _mapTipGraphic = hitGraphic;
                    RenderMapTip();
                }
                else
                {
                    mapView1tip.Visibility  = Windows.UI.Xaml.Visibility.Collapsed;
                    mapView1tip.DataContext = null;
                    _mapTipGraphic          = null;
                }
            }
        }
        /// <summary>
        /// On each mouse click:
        /// - HitTest the feature layer
        /// - Query the feature table for the returned row
        /// - Set the result feature for the UI
        /// </summary>
        private async void mapView_MapViewTapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
        {
            try
            {
                var rows = await cities.HitTestAsync(mapView, e.Position);

                if (rows != null && rows.Length > 0)
                {
                    var features = await cities.FeatureTable.QueryAsync(rows);

                    ResultFeature = features.FirstOrDefault();
                }
                else
                {
                    ResultFeature = null;
                }
            }
            catch (Exception ex)
            {
                ResultFeature = null;
                MessageBox.Show("HitTest Error: " + ex.Message, "Feature Layer Hit Testing Sample");
            }
        }
Ejemplo n.º 14
0
        private async void mapView_Tapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
        {
            try
            {
                progress.Visibility     = Visibility.Visible;
                resultsGrid.DataContext = null;

                GraphicsLayer graphicsLayer = mapView.Map.Layers["GraphicsLayer"] as GraphicsLayer;
                graphicsLayer.Graphics.Clear();
                graphicsLayer.Graphics.Add(new Graphic(e.Location));

                IdentifyParameter identifyParams = new IdentifyParameter(e.Location, mapView.Extent, 2, (int)mapView.ActualHeight, (int)mapView.ActualWidth)
                {
                    LayerOption      = LayerOption.Visible,
                    SpatialReference = mapView.SpatialReference,
                };

                IdentifyTask identifyTask = new IdentifyTask(
                    new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer"));

                var result = await identifyTask.ExecuteAsync(identifyParams);

                resultsGrid.DataContext = result.Results;
                if (result != null && result.Results != null && result.Results.Count > 0)
                {
                    titleComboBox.SelectedIndex = 0;
                }
            }
            catch (Exception ex)
            {
                var _ = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
            }
            finally
            {
                progress.Visibility = Visibility.Collapsed;
            }
        }
Ejemplo n.º 15
0
 /// <summary>
 /// 地图单击事件,行为大多在此生效
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void MapView_MapViewTapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
 {
     if (_behaviors == null)
     {
         string xml = "<Document TaskGuid = \"FF17D1B3-85C7-40F4-8CDC-73DC57CD29BC\" DataGuid = \"004\" DataType = \"ClearGraphic\">"
                      + "<Target Type = \"TEXT\">Drawing</Target>"
                      + "</Document>";
         SetData("TEST", "FF17D1B3-85C7-40F4-8CDC-73DC57CD29BC", "", "ClearGraphic", xml);
         return;
     }
     foreach (var b in _behaviors)
     {
         if (b is GetMapPointBehavior)
         {
             b.Work(e);
             continue;
         }
         if (b is IdentifyBehavior)
         {
             b.Work(e);
             continue;
         }
         if (b is HitTestBehavior)
         {
             b.Work(e);
         }
     }
     //清空已经过时的行为
     for (var i = _behaviors.Count - 1; i >= 0; i--)
     {
         if (((BaseBehavior)_behaviors[i]).IsObsolete)
         {
             _behaviors.RemoveAt(i);
         }
     }
 }
        private async void mapView_Tapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
        {
            var hitGraphic = await _locationGraphicsLayer.HitTestAsync(mapView1, e.Position);

            if (hitGraphic != null)
            {
                if (maptip.Visibility == Windows.UI.Xaml.Visibility.Collapsed)
                {
                    MapTipGraphic = hitGraphic;
                    RenderMapTip();
                }
                else
                {
                    maptip.Visibility  = Windows.UI.Xaml.Visibility.Collapsed;
                    maptip.DataContext = null;
                    MapTipGraphic      = null;
                }
            }
            else
            {
                maptip.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                var mp = mapView1.ScreenToLocation(e.Position);

                Graphic g = new Graphic()
                {
                    Geometry = mp
                };

                var layer = mapView1.Map.Layers.OfType <GraphicsLayer>().First();
                layer.Graphics.Add(g);

                var token       = "";
                var locatorTask =
                    new OnlineLocatorTask(new Uri("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer", UriKind.Absolute), token);

                try
                {
                    var result = await locatorTask.ReverseGeocodeAsync(mp, 30, mapView1.SpatialReference, CancellationToken.None);

                    Graphic graphic = new Graphic()
                    {
                        Geometry = mp
                    };

                    string latlon   = String.Format("{0}, {1}", result.Location.X, result.Location.Y);
                    string address1 = result.AddressFields["Address"].ToString();
                    string address2 = String.Format("{0}, {1} {2}", result.AddressFields["City"], result.AddressFields["Region"], result.AddressFields["Postal"]);

                    graphic.Attributes.Add("LatLon", latlon);
                    graphic.Attributes.Add("Address1", address1);
                    graphic.Attributes.Add("Address2", address2);

                    _locationGraphicsLayer.Graphics.Add(graphic);
                    MapTipGraphic = graphic;
                    RenderMapTip();
                }
                catch (Exception)
                {
                }
            }
        }
 private void mapView1_MapViewTapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
 {
 }
 private async void mapView1_Tapped_1(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
 {
     await RunIdentify(e.Location);
 }
 private async void mapView1_Tapped_1(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
 {
     await RunQuery(Expand(mapView1.Extent, e.Location, 0.01));
 }