/// <summary> /// Displays current attribute values of related record. /// </summary> private async void RelatedRecords_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (RelatedRecords.SelectedItem == null) { return; } var graphic = (Graphic)RelatedRecords.SelectedItem; SetAttributeEditor(); string message = null; try { if (table == null) { table = await GetRelatedTableAsync(); } var featureID = Convert.ToInt64(graphic.Attributes[table.ObjectIDField], CultureInfo.InvariantCulture); var feature = await table.QueryAsync(featureID); SetAttributeEditor(feature); } catch (Exception ex) { message = ex.Message; } if (!string.IsNullOrWhiteSpace(message)) { await new MessageDialog(message).ShowAsync(); } }
/// <summary> /// Enables attribute editing, submits attribute edit back to the server and refreshes dynamic layer. /// </summary> private async void ChoiceList_SelectionChanged(object sender, SelectionChangedEventArgs e) { ChoiceList.SelectionChanged -= ChoiceList_SelectionChanged; var featureID = (Int64)AttributeEditor.Tag; var selected = (KeyValuePair <object, string>)ChoiceList.SelectedItem; var layer = MyMapView.Map.Layers["PoolPermit"] as ArcGISDynamicMapServiceLayer; var overlay = MyMapView.GraphicsOverlays["Highlighter"] as GraphicsOverlay; string message = null; try { if (table == null) { // Creates table based on visible layer of dynamic layer // using FeatureServer specifying has_pool field to enable editing. var id = layer.VisibleLayers[0]; var url = layer.ServiceUri.Replace("MapServer", "FeatureServer"); url = string.Format("{0}/{1}", url, id); table = await ServiceFeatureTable.OpenAsync(new Uri(url), null, MyMapView.SpatialReference); table.OutFields = new OutFields(new string[] { "has_pool" }); } // Retrieves feature identified by ID and updates its attributes. var feature = await table.QueryAsync(featureID); feature.Attributes["has_pool"] = selected.Key; await table.UpdateAsync(feature); if (table.HasEdits) { // Pushes attribute edits back to the server. var result = await table.ApplyEditsAsync(); if (result.UpdateResults == null || result.UpdateResults.Count < 1) { return; } var updateResult = result.UpdateResults[0]; if (updateResult.Error != null) { message = updateResult.Error.Message; } // Refreshes layer to reflect attribute edits. layer.Invalidate(); } } catch (Exception ex) { message = ex.Message; } finally { overlay.Graphics.Clear(); SetAttributeEditor(); } if (!string.IsNullOrWhiteSpace(message)) { MessageBox.Show(message); } }
/// <summary> /// 選択範囲内にある物件フィーチャを選択 /// </summary> /// <param name="g">選択範囲を示すグラフィック</param> private async Task SelectFeatureWithIn(Graphic g) { //空間検索用のフィルタを作成 SpatialQueryFilter spatialQueryFilter = new SpatialQueryFilter() { Geometry = g.Geometry, SpatialRelationship = SpatialRelationship.Within, }; try { //物件レイヤのフィーチャテーブルに対して空間検索を実行 ServiceFeatureTable serviceFeatureTable = buildingLayer.FeatureTable as ServiceFeatureTable; IEnumerable <Feature> features = await serviceFeatureTable.QueryAsync(spatialQueryFilter); //空間検索結果のフィーチャを選択フィーチャコレクションに追加 foreach (Feature f in features) { selectedFeatures.Add(f); } //物件リストボックスの選択変更時のイベントハンドラを設定 selectedBuildingListBox.SelectionChanged += selectedBuildingListBox_SelectionChanged; } //エラーが発生した場合の処理 catch (Exception ex) { MessageBox.Show(string.Format("空間検索:{0}", ex.Message)); } }
/// <summary> /// Enables geometry editing, submits geometry edit back to the server and refreshes dynamic layer. /// </summary> private async void EditButton_Click(object sender, RoutedEventArgs e) { var layer = MyMapView.Map.Layers["RecreationalArea"] as ArcGISDynamicMapServiceLayer; var overlay = MyMapView.GraphicsOverlays["Highlighter"] as GraphicsOverlay; var featureID = (long)EditButton.Tag; string message = null; try { // Hides graphic from overlay and dynamic layer while its geometry is being modified. overlay.Graphics.Clear(); // Negative IDs indicate they do not exist on server yet. if (featureID > 0) { if (layer.LayerDefinitions == null) { layer.LayerDefinitions = new ObservableCollection <LayerDefinition>(); } else { layer.LayerDefinitions.Clear(); } layer.LayerDefinitions.Add(new LayerDefinition() { LayerID = layer.VisibleLayers[0], Definition = string.Format("Objectid <> {0}", featureID) }); } if (table == null) { // Creates table based on visible layer of dynamic layer // using FeatureServer specifying shape field to enable editing. var id = layer.VisibleLayers[0]; var url = layer.ServiceUri.Replace("MapServer", "FeatureServer"); url = string.Format("{0}/{1}", url, id); table = await ServiceFeatureTable.OpenAsync(new Uri(url), null, MyMapView.SpatialReference); } // Retrieves feature identified by ID and updates its geometry // using GeometryEngine to correct ring orientation. var feature = await table.QueryAsync(featureID); var geometry = await MyMapView.Editor.EditGeometryAsync(feature.Geometry); feature.Geometry = GeometryEngine.Simplify(geometry); await table.UpdateAsync(feature); if (table.HasEdits) { // Pushes geometry edits back to the server. var result = await table.ApplyEditsAsync(); if (result.UpdateResults == null || result.UpdateResults.Count < 1) { return; } var updateResult = result.UpdateResults[0]; if (updateResult.Error != null) { message = updateResult.Error.Message; } } } catch (TaskCanceledException te) { // Handles canceling out of Editor. } catch (Exception ex) { message = ex.Message; } finally { SetGeometryEditor(); if (layer.LayerDefinitions != null) { layer.LayerDefinitions.Clear(); // Refreshes layer to reflect geometry edits. layer.Invalidate(); } } if (!string.IsNullOrWhiteSpace(message)) { MessageBox.Show(message); } }