Exemplo n.º 1
0
 private async void mapView1_Tapped_1(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
 {
     await RunQuery(Expand(mapView1.Extent, e.Location, 0.01));
 }
Exemplo n.º 2
0
        // Calculate the route
        private async void MyMapView_MapViewDoubleTapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
        {
            if (_stopsOverlay.Graphics.Count() < 2)
            {
                return;
            }

            try
            {
                e.Handled = true;

                panelResults.Visibility = Visibility.Collapsed;
                progress.Visibility     = Visibility.Visible;

                RouteParameters routeParams = await _routeTask.GetDefaultParametersAsync();

                routeParams.OutSpatialReference  = MyMapView.SpatialReference;
                routeParams.ReturnDirections     = true;
                routeParams.DirectionsLengthUnit = LinearUnits.Miles;
                routeParams.DirectionsLanguage   = new CultureInfo("en-Us");               // CultureInfo.CurrentCulture;
                routeParams.SetStops(_stopsOverlay.Graphics);

                var routeResult = await _routeTask.SolveAsync(routeParams);

                if (routeResult == null || routeResult.Routes == null || routeResult.Routes.Count() == 0)
                {
                    throw new Exception("No route could be calculated");
                }

                var route = routeResult.Routes.First();
                _routesOverlay.Graphics.Add(new Graphic(route.RouteFeature.Geometry));

                _directionsOverlay.GraphicsSource = route.RouteDirections.Select(rd => GraphicFromRouteDirection(rd));

                var totalTime   = route.RouteDirections.Select(rd => rd.Time).Aggregate(TimeSpan.Zero, (p, v) => p.Add(v));
                var totalLength = route.RouteDirections.Select(rd => rd.GetLength(LinearUnits.Miles)).Sum();
                txtRouteTotals.Text = string.Format("Time: {0:h':'mm':'ss} / Length: {1:0.00} mi", totalTime, totalLength);

                await MyMapView.SetViewAsync(route.RouteFeature.Geometry.Extent.Expand(1.25));
            }
            catch (AggregateException ex)
            {
                var message             = ex.Message;
                var innermostExceptions = ex.Flatten().InnerExceptions;
                if (innermostExceptions != null && innermostExceptions.Count > 0)
                {
                    message = innermostExceptions[0].Message;
                }

                var _x = new MessageDialog(message, "Sample Error").ShowAsync();
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
            }
            finally
            {
                progress.Visibility = Visibility.Collapsed;
                if (_directionsOverlay.Graphics.Count() > 0)
                {
                    panelResults.Visibility = Visibility.Visible;
                }
            }
        }
 private async void mapView1_Tapped_1(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
 {
     await RunIdentify(e.Location);
 }
Exemplo n.º 4
0
        private async void mapView1_MapViewTapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
        {
            if (MyMapView.Editor.IsActive || _layer == null)
            {
                return;
            }
            _layer.ClearSelection();

            Graphic hitGraphic = await _stopsOverlay.HitTestAsync(MyMapView, e.Position);

            var features = await _layer.HitTestAsync(MyMapView, e.Position);

            if (hitGraphic != null)
            {
                FlyoutBase.ShowAttachedFlyout((FrameworkElement)sender);
                return;
            }

            if (features != null)
            {
                string message = null;

                MyMapView.Overlays.Items.Clear();
                try
                {
                    if (!features.Any())
                    {
                        return;
                    }


                    var featureID = features.FirstOrDefault();
                    _layer.SelectFeatures(new long[] { featureID });
                    var feature = (GeodatabaseFeature)await _layer.FeatureTable.QueryAsync(featureID);

                    message = _layer.DisplayName;
                    for (int i = 0; i < feature.Attributes.Values.Count(); i++)
                    {
                        if (feature.Attributes.Keys.ToArray()[i].ToString() != "OBJECTID")
                        {
                            message += "\n" + feature.Attributes.Keys.ToArray()[i] + ": " + feature.Attributes.Values.ToArray()[i];
                        }
                    }
                }
                catch (Exception ex)
                {
                    message = ex.Message;
                }
                if (!string.IsNullOrWhiteSpace(message))
                {
                    var result  = message;
                    var overlay = new ContentControl()
                    {
                        HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Top
                    };
                    overlay.Template    = LayoutRoot.Resources["PopUpTipTemplate"] as ControlTemplate;
                    overlay.DataContext = result;
                    MapView.SetViewOverlayAnchor(overlay, e.Location);
                    MyMapView.Overlays.Items.Add(overlay);
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// マップビュータップ時の処理
        /// </summary>
        private async void mainMapView_MapViewTapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
        {
            //解析手順のメッセージを非表示
            analyzeTextBox.Visibility = System.Windows.Visibility.Collapsed;

            //プログレスバーを表示
            analyzeProgressBar.Visibility = System.Windows.Visibility.Visible;

            //マップビュータップ時のイベントハンドラを解除
            mainMapView.MapViewTapped -= mainMapView_MapViewTapped;

            //カーソルを矢印に変更
            mainMapView.Cursor = Cursors.Arrow;

            //クリックした位置からグラフィックを作成
            Graphic clickPoint = new Graphic(e.Location)
            {
                Symbol = layoutRoot.Resources["greenMarkerSymbol"] as SimpleMarkerSymbol,
                ZIndex = 2
            };

            //到達圏解析結果表示用のグラフィックスレイヤにクリック位置のグラフィックを追加
            serviceAreaResultLayer.Graphics.Add(clickPoint);

            try
            {
                //到達圏解析用パラメーターの作成
                GPInputParameter parameter = new GPInputParameter();
                parameter.GPParameters.Add(new GPFeatureRecordSetLayer("facilities", e.Location));  //解析の中心点
                parameter.GPParameters.Add(new GPString("break_values", "10"));                     //到達圏の範囲(10分)
                parameter.GPParameters.Add(new GPString("env:outSR", "102100"));                    //結果の空間参照(Web メルカトル)
                parameter.GPParameters.Add(new GPString("travel_mode", "Walking"));                 //"徒歩"で到達できる範囲を解析

                //到達圏の解析を開始
                GPJobInfo result = await serviceAreaGp.SubmitJobAsync(parameter);

                //到達圏の解析結果が"成功"、"失敗"、"時間切れ"、"キャンセル"のいずれかになるまで
                //2秒ごとに ArcGIS Online にステータスを確認
                while (result.JobStatus != GPJobStatus.Succeeded &&
                       result.JobStatus != GPJobStatus.Failed &&
                       result.JobStatus != GPJobStatus.TimedOut &&
                       result.JobStatus != GPJobStatus.Cancelled)
                {
                    result = await serviceAreaGp.CheckJobStatusAsync(result.JobID);

                    await Task.Delay(2000);
                }


                //到達圏解析の結果が成功した場合は結果を表示
                if (result.JobStatus == GPJobStatus.Succeeded)
                {
                    //到達圏解析の結果を取得
                    GPParameter resultData = await serviceAreaGp.GetResultDataAsync(result.JobID, "Service_Areas");

                    //到達圏解析結果レイヤのグラフィックを結果グラフィックとして取得
                    GPFeatureRecordSetLayer gpLayer = resultData as GPFeatureRecordSetLayer;
                    serviceAreaGraphic = gpLayer.FeatureSet.Features[0] as Graphic;

                    //グラフィックにシンボルを設定
                    serviceAreaGraphic.Symbol = layoutRoot.Resources["greenFillSymbol"] as SimpleFillSymbol;

                    //結果グラフィックが解析の中心点のグラフィックより下に表示されるように表示順序を設定
                    serviceAreaGraphic.ZIndex = 1;

                    //到達圏解析結果表示用のグラフィックスレイヤにグラフィックを追加
                    serviceAreaResultLayer.Graphics.Add(serviceAreaGraphic);
                }
            }
            //エラーが発生した場合の処理
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("到達圏解析:{0}", ex.Message));

                //到達圏解析の結果をクリア
                ClearAnalysisResult();
            }
            finally
            {
                //プログレスバーを非表示
                analyzeProgressBar.Visibility = System.Windows.Visibility.Collapsed;

                //到達圏解析ボタンを表示
                analyzePanel.Visibility = System.Windows.Visibility.Visible;
            }
        }