예제 #1
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());
            }
        }
        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_GeoViewTapped(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs e)
        {
            // Clear any prior incident and routes from the graphics.
            _incidentGraphicsOverlay.Graphics.Clear();

            // Get the tapped point.
            _incidentPoint = e.Location;

            // Populate the facility parameters than solve using the task.
            PopulateParametersAndSolveRouteAsync();
        }
        private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs e)
        {
            var point = e.Position;
            var watch = new Stopwatch();

            if (_allLayers == false)
            {
                //IReadOnlyList<IdentifyLayerResult> idLayersResult = await MyMapView.IdentifyLayersAsync(point, 20, false, 5);
                IReadOnlyList <Layer> layers = MyMapView.Map.AllLayers;

                watch.Start();

                int count = 0;
                foreach (var layer in layers)
                {
                    System.Threading.Thread.Sleep(500);
                    System.Diagnostics.Debug.WriteLine(layer.Name);

                    if (layer is FeatureLayer)
                    {
                        System.Diagnostics.Debug.WriteLine("Feature layer: " + layer.Name);

                        //Determine the feature layer that the tapPoint was on when clicked
                        var idLayerResults = await MyMapView.IdentifyLayerAsync(layer, point, 0, false);
                    }
                    count++;
                }
                watch.Stop();
                MessageBox.Show("It took " + watch.Elapsed.Seconds.ToString("N2") + " seconds to go through " + count.ToString() + " layers.");
            }
            else
            {
                watch.Start();
                System.Threading.Thread.Sleep(1500);
                var idLayerResults = await MyMapView.IdentifyLayersAsync(point, 0, false);

                var x = idLayerResults.ToList();
                watch.Stop();
                MessageBox.Show("It took " + watch.Elapsed.Seconds.ToString() + " seconds to go through all layers.");
            }
        }
        private async void SceneViewTapped(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs e)
        {
            try
            {
                // Remove this method from the event handler to prevent concurrent calls.
                _mySceneView.GeoViewTapped -= SceneViewTapped;

                // Check that the point is on the surface.
                if (e.Location != null)
                {
                    // Clear any existing graphics from the graphics overlay.
                    _overlay.Graphics.Clear();

                    // Get the elevation value.
                    double elevation = await _baseSurface.GetElevationAsync(e.Location);

                    // Set the text displaying the elevation.
                    _elevationTextSymbol.Text      = $"{Math.Round(elevation)} m";
                    _elevationTextGraphic.Geometry = new MapPoint(e.Location.X, e.Location.Y, e.Location.Z + 850);

                    // Add the text to the graphics overlay.
                    _overlay.Graphics.Add(_elevationTextGraphic);

                    // Add the marker indicating where the user tapped.
                    _overlay.Graphics.Add(new Graphic(e.Location, _elevationMarker));
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                CreateErrorDialog(ex.Message);
            }
            finally
            {
                // Re-add to the event handler.
                _mySceneView.GeoViewTapped += SceneViewTapped;
            }
        }
예제 #6
0
        // 点选
        private async void myMapViewGetAttributeValue(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs e)
        {
            StackPanel stackPanel = (StackPanel)w.FindName("cykGeometryCalcuEdit");

            if (layersComboBox.SelectedIndex >= 0 && stackPanel.Visibility == Visibility.Visible)
            {
                myShapeFileResult = await myMapView.IdentifyLayerAsync(featureLayer, e.Position, 15, false);

                //if(myShapeFileResult != null)  MessageBox.Show("" + 12 + " " + myShapeFileResult);

                // 要素选择高亮
                try
                {
                    string          numberFID   = ((Feature)(myShapeFileResult.GeoElements[0])).GetAttributeValue("FID") + "";
                    QueryParameters queryParams = new QueryParameters
                    {
                        //WhereClause = "upper(FID) = " + numberFID
                        Geometry = e.Location
                    };
                    FeatureQueryResult queryResult = await featureLayer.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);
                    }

                    // 每一次"选择"都需要点击一次"选择"按钮
                    myMapView.GeoViewTapped -= myMapViewGetAttributeValue;
                    //t1.Text = numberFID + " ID;" + features.Count + "个;  " + e.Location.X + ", " + e.Location.Y + "  //  投影" + myMapView.Map.SpatialReference + "," + myMapView.UnitsPerPixel;
                }
                catch (Exception ex)
                {
                }
                //t1.Text += featureLayer.Description + table.DisplayName + "...";
            }
        }
예제 #7
0
        private async void MainWindow_Click(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs e)
        {
            if (count == 0)
            {
                count      = 1;
                _downPoint = e.Location;
                //_downPointP = e.Position;
                //dragSelectRectangle.Margin = new Thickness(0, 0, 0, 0);
                //dragSelectRectangle.Width = 0;
                //dragSelectRectangle.Height = 0;
            }
            else
            {
                count = 0;
                var _endpoint = e.Location;

                try
                {
                    double   tolerance    = 0.0001;
                    double   mapTolerance = tolerance /** myMapView.UnitsPerPixel*/;
                    MapPoint geometry     = new MapPoint((_downPoint.X + _endpoint.X) / 2, (_downPoint.Y + _endpoint.Y) / 2, myMapView.SpatialReference);
                    if (myMapView.IsWrapAroundEnabled)
                    {
                        geometry = (MapPoint)GeometryEngine.NormalizeCentralMeridian(geometry);
                    }
                    Envelope        selectionEnvelope = new Envelope(geometry, Math.Abs(_downPoint.X - _endpoint.X), Math.Abs(_downPoint.Y - _endpoint.Y) /*geometry.X - mapTolerance, geometry.Y - mapTolerance, geometry.X + mapTolerance, geometry.Y + mapTolerance,*/ /*myMapView.Map.SpatialReference*/);
                    QueryParameters queryParams       = new QueryParameters()
                    {
                        Geometry = selectionEnvelope
                    };

                    FeatureLayer       tempLayer = (FeatureLayer)(myMapView.Map.OperationalLayers[0]);
                    FeatureQueryResult fr        = await tempLayer.SelectFeaturesAsync(queryParams, Esri.ArcGISRuntime.Mapping.SelectionMode.New);

                    IEnumerator <Feature> frr      = fr.GetEnumerator();
                    List <Feature>        features = new List <Feature>();
                    while (frr.MoveNext())
                    {
                        features.Add(frr.Current);
                    }

                    // 查看属性
                    Esri.ArcGISRuntime.Data.FeatureTable tempTable = (Esri.ArcGISRuntime.Data.FeatureTable)tempLayer.FeatureTable;
                    long          row        = tempTable.NumberOfFeatures;
                    int           col        = tempTable.Fields.Count;
                    List <String> fieldNames = new List <string>();
                    for (int i = 0; i < col; i++)
                    {
                        fieldNames.Add(tempTable.Fields[i] + "");
                    }

                    StackPanel  stackPanel = new StackPanel();
                    WrapPanel[] wrapPanels = new WrapPanel[row];

                    // 字段名
                    WrapPanel wrapPanelField = new WrapPanel()
                    {
                        Margin = new Thickness()
                        {
                            Left   = 10,
                            Top    = 1,
                            Right  = 10,
                            Bottom = 1
                        }
                    };
                    for (int i = 0; i < col; i++)
                    {
                        Button button = new Button()
                        {
                            Content    = fieldNames[i],
                            ToolTip    = fieldNames[i],
                            Width      = 60,
                            Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 100, 183, 134))
                        };
                        wrapPanelField.Children.Add(button);
                    }
                    stackPanel.Children.Add(wrapPanelField);

                    // 记录
                    for (int i = 0; i < row; i++)
                    {
                        wrapPanels[i] = new WrapPanel()
                        {
                            Margin = new Thickness()
                            {
                                Left   = 10,
                                Top    = 1,
                                Right  = 10,
                                Bottom = 1
                            }
                        };
                        for (int j = 0; j < col; j++)
                        {
                            Button button = new Button()
                            {
                                Width   = 60,
                                Content = features[i].GetAttributeValue(fieldNames[j]),
                                ToolTip = features[i].GetAttributeValue(fieldNames[j])
                            };
                            wrapPanels[i].Children.Add(button);
                        }
                        stackPanel.Children.Add(wrapPanels[i]);
                    }

                    ScrollViewer scrollViewer = new ScrollViewer();
                    scrollViewer.VerticalScrollBarVisibility   = ScrollBarVisibility.Visible;
                    scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
                    scrollViewer.Content = stackPanel;

                    var window = new Window();
                    window.Content               = scrollViewer;
                    window.SizeToContent         = SizeToContent.WidthAndHeight;
                    window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                    window.MaxHeight             = 700;
                    window.MaxWidth              = 1000;

                    window.Title = "要素多选属性表";
                    window.Show();
                }
                catch
                {
                    t1.Text = "要素多选发生错误";
                }
            }
        }