private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs e) { // 既にフィーチャが選択状態の場合は、選択を解除する foreach (EncLayer layer in _mainMapView.Map.OperationalLayers.OfType <EncLayer>()) { layer.ClearSelection(); } // コールアウトを非表示にする _mainMapView.DismissCallout(); // マップ上をクリックした地点にあるフィーチャを取得する IReadOnlyList <IdentifyLayerResult> results = await _mainMapView.IdentifyLayersAsync(e.Position, 10, false); // 該当するフィーチャが無い場合 if (results.Count < 1) { return; } // 取得されたフィーチャが含まれるレイヤーのリストが返されるので、ENCレイヤーのみを取得する IEnumerable <IdentifyLayerResult> encResults = results.Where(result => result.LayerContent is EncLayer); IEnumerable <IdentifyLayerResult> encResultsWithFeatures = encResults.Where(result => result.GeoElements.Count > 0); // ENCレイヤーのリストから最上位のレイヤーを取得する IdentifyLayerResult firstResult = encResultsWithFeatures.First(); EncLayer containingLayer = firstResult.LayerContent as EncLayer; // レイヤーに含まれるフィーチャ リストから最後のフィーチャを取得する EncFeature firstFeature = firstResult.GeoElements.Last() as EncFeature; // 取得したフィーチャを選択(ハイライト表示)する containingLayer.SelectFeature(firstFeature); // フィーチャの関連情報を取得を文字列に変換する var attributes = new System.Text.StringBuilder(); attributes.AppendLine(firstFeature.Description); if (firstFeature.Attributes.Count > 0) { // フィーチャの属性(key:属性のフィールド名、value:属性のフィールド値のペア)を取得する foreach (var attribute in firstFeature.Attributes) { var fieldName = attribute.Key; var fieldValue = attribute.Value; attributes.AppendLine(fieldName + ": " + fieldValue); } attributes.AppendLine(); } // ENCフィーチャの頭文字と関連情報を指定してコールアウトを作成する CalloutDefinition definition = new CalloutDefinition(firstFeature.Acronym, attributes.ToString()); // コールアウトをマップ上でクリックした場所に表示する _mainMapView.ShowCalloutAt(e.Location, definition); }
private async void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e) { // First clear any existing selections. ClearAllSelections(); try { // Perform the identify operation. IReadOnlyList <IdentifyLayerResult> results = await _myMapView.IdentifyLayersAsync(e.Position, 5, false); // Return if there are no results. if (results.Count < 1) { return; } // Get the results that are from ENC layers. IEnumerable <IdentifyLayerResult> encResults = results.Where(result => result.LayerContent is EncLayer); // Get the ENC results that have features. IEnumerable <IdentifyLayerResult> encResultsWithFeatures = encResults.Where(result => result.GeoElements.Count > 0); // Get the first result with ENC features. IdentifyLayerResult firstResult = encResultsWithFeatures.First(); // Get the layer associated with this set of results. EncLayer containingLayer = (EncLayer)firstResult.LayerContent; // Get the first identified ENC feature. EncFeature smallestFeature = (EncFeature)firstResult.GeoElements.OrderBy(f => GeometryEngine.Area(f.Geometry)).First(); // Select the feature. containingLayer.SelectFeature(smallestFeature); // Create the callout definition. CalloutDefinition definition = new CalloutDefinition(smallestFeature.Acronym, smallestFeature.Description); // Show the callout. _myMapView.ShowCalloutAt(e.Location, definition); } catch (Exception ex) { new UIAlertView("Error", ex.ToString(), (IUIAlertViewDelegate)null, "OK", null).Show(); } }
private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e) { // First clear any existing selections ClearAllSelections(); try { // Perform the identify operation. IReadOnlyList <IdentifyLayerResult> results = await MyMapView.IdentifyLayersAsync(e.Position, 10, false); // Return if there are no results. if (results.Count < 1) { return; } // Get the results that are from ENC layers. IEnumerable <IdentifyLayerResult> encResults = results.Where(result => result.LayerContent is EncLayer); // Get the first result with ENC features. (Depending on the data, there may be more than one IdentifyLayerResult that contains ENC features.) IdentifyLayerResult firstResult = encResults.First(); // Get the layer associated with this set of results. EncLayer containingLayer = (EncLayer)firstResult.LayerContent; // Get the GeoElement identified in this layer. EncFeature encFeature = (EncFeature)firstResult.GeoElements.First(); // Select the feature. containingLayer.SelectFeature(encFeature); // Create the callout definition. CalloutDefinition definition = new CalloutDefinition(encFeature.Acronym, encFeature.Description); // Show the callout. MyMapView.ShowCalloutAt(e.Location, definition); } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert("Error", ex.ToString(), "OK"); } }
private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e) { // First clear any existing selections ClearAllSelections(); // Perform the identify operation IReadOnlyList <IdentifyLayerResult> results = await MyMapView.IdentifyLayersAsync(e.Position, 5, false); // Return if there are no results if (results.Count < 1) { return; } // Get the results that are from ENC layers IEnumerable <IdentifyLayerResult> encResults = results.Where(result => result.LayerContent is EncLayer); // Get the ENC results that have features IEnumerable <IdentifyLayerResult> encResultsWithFeatures = encResults.Where(result => result.GeoElements.Count > 0); // Get the first result with ENC features IdentifyLayerResult firstResult = encResultsWithFeatures.First(); // Get the layer associated with this set of results EncLayer containingLayer = firstResult.LayerContent as EncLayer; // Select the smallest (area) feature in the layer. EncFeature smallestFeature = (EncFeature)firstResult.GeoElements.OrderBy(f => GeometryEngine.Area(f.Geometry)).First(); // Select the feature. containingLayer.SelectFeature(smallestFeature); // Create the callout definition. CalloutDefinition definition = new CalloutDefinition(smallestFeature.Acronym, smallestFeature.Description); // Show the callout MyMapView.ShowCalloutAt(e.Location, definition); }
private async void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e) { // First clear any existing selections ClearAllSelections(); // Perform the identify operation IReadOnlyList <IdentifyLayerResult> results = await _myMapView.IdentifyLayersAsync(e.Position, 5, false); // Return if there are no results if (results.Count < 1) { return; } // Get the results that are from ENC layers IEnumerable <IdentifyLayerResult> encResults = results.Where(result => result.LayerContent is EncLayer); // Get the ENC results that have features IEnumerable <IdentifyLayerResult> encResultsWithFeatures = encResults.Where(result => result.GeoElements.Count > 0); // Get the first result with ENC features IdentifyLayerResult firstResult = encResultsWithFeatures.First(); // Get the layer associated with this set of results EncLayer containingLayer = firstResult.LayerContent as EncLayer; // Get the first identified ENC feature EncFeature firstFeature = firstResult.GeoElements.First() as EncFeature; // Select the feature containingLayer.SelectFeature(firstFeature); // Create the callout definition CalloutDefinition definition = new CalloutDefinition(firstFeature.Acronym, firstFeature.Description); // Show the callout _myMapView.ShowCalloutAt(e.Location, definition); }