/// <summary> /// Called when a sketch is completed. /// </summary> protected override async Task <bool> OnSketchCompleteAsync(ArcGIS.Core.Geometry.Geometry geometry) { var popupContent = await QueuedTask.Run(() => { //Get the features that intersect the sketch geometry. var result = ActiveMapView.GetFeatures(geometry); //For each feature in the result create a new instance of our custom pop-up content class. List <PopupContent> popups = new List <PopupContent>(); foreach (var kvp in result) { kvp.Value.ForEach(id => popups.Add(new DynamicPopupContent(kvp.Key, id))); } //Flash the features that intersected the sketch geometry. ActiveMapView.FlashFeature(result); //return the collection of pop-up content object. return(popups); }); //Show the custom pop-up with the custom commands and the default pop-up commands. ActiveMapView.ShowCustomPopup(popupContent, null, true); return(true); }
protected override async Task HandleMouseDownAsync(MapViewMouseButtonEventArgs e) { await QueuedTask.Run(() => { var mapPoint = MapPointBuilder.CreateMapPoint(e.ClientPoint.X, e.ClientPoint.Y); var result = ActiveMapView.GetFeatures(mapPoint); List <PopupContent> popups = new List <PopupContent>(); foreach (var kvp in result) { var layer = kvp.Key as BasicFeatureLayer; if (layer == null) { continue; } var fields = layer.GetFieldDescriptions().Where(f => f.Name == "DI_JI_HAO"); var tableDef = layer.GetTable().GetDefinition(); var oidField = tableDef.GetObjectIDField(); foreach (var id in kvp.Value) { //获取地级编号 //DI_JI_HAO var qf = new QueryFilter() { WhereClause = $"{oidField} = {id}", SubFields = string.Join(",", fields.Select(f => f.Name)) }; var rows = layer.Search(qf); if (!rows.MoveNext()) { continue; } using (var row = rows.Current) { foreach (var field in fields) { var val = row[field.Name]; if (field.Name == "DI_JI_HAO") { PopupContent pc = new PopupContent(new Uri("http://59.42.105.34:5001/client/?id=" + val), "林业"); popups.Add(pc); } } } } } //Flash the features that intersected the sketch geometry. MessageBox.Show(popups.ToString()); ActiveMapView.FlashFeature(result); var height = System.Windows.SystemParameters.WorkArea.Height / 2; var width = System.Windows.SystemParameters.WorkArea.Width / 2; var topLeftCornerPoint = new System.Windows.Point(0, 0); var popupDef = new PopupDefinition() { Append = true, // if true new record is appended to existing (if any) Dockable = true, // if true popup is dockable - if false Append is not applicable Position = topLeftCornerPoint, // Position of top left corner of the popup (in pixels) Size = new System.Windows.Size(width, height) // size of the popup (in pixels) }; //Show the custom pop-up with the custom commands and the default pop-up commands. try { ActiveMapView.ShowCustomPopup(popups, null, true, popupDef); } catch (System.Exception e1) { MessageBox.Show(string.Format("{0}", e1)); } //return the collection of pop-up content object. }); }
/// <summary> /// Called when a sketch is completed. /// </summary> protected override async Task <bool> OnSketchCompleteAsync(ArcGIS.Core.Geometry.Geometry geometry) { List <PopupContent> popupContent = await QueuedTask.Run(() => { //Get the features that intersect the sketch geometry. var mapPoint = geometry as MapPoint; var sb = new StringBuilder(); sb.AppendLine(string.Format("OnSketchCompleteAsync X: {0}", mapPoint.X)); sb.Append(string.Format("Y: {0}", mapPoint.Y)); if (mapPoint.HasZ) { sb.AppendLine(); sb.Append(string.Format("Z: {0}", mapPoint.Z)); } MessageBox.Show(sb.ToString()); var result = ActiveMapView.GetFeatures(geometry); //For each feature in the result create a new instance of our custom pop-up content class. List <PopupContent> popups = new List <PopupContent>(); foreach (var kvp in result) { //kvp.Value.ForEach(id => popups.Add(new DynamicPopupContent(kvp.Key, id))); //kvp.Value.ForEach(id => popups.Add(new PopupContent(new Uri("https://www.google.com/webhp?ie=UTF-8&rct=j"), "xxxx"))); //popups.Add(new PopupContent("<b>This text is bold.</b>", "Custom tooltip from HTML string")); var layer = kvp.Key as BasicFeatureLayer; if (layer == null) { continue; } var fields = layer.GetFieldDescriptions().Where(f => f.Name == "DI_JI_HAO"); var tableDef = layer.GetTable().GetDefinition(); var oidField = tableDef.GetObjectIDField(); foreach (var id in kvp.Value) { //获取地级编号 //DI_JI_HAO var qf = new QueryFilter() { WhereClause = $"{oidField} = {id}", SubFields = string.Join(",", fields.Select(f => f.Name)) }; var rows = layer.Search(qf); if (!rows.MoveNext()) { continue; } using (var row = rows.Current) { foreach (var field in fields) { var val = row[field.Name]; if (field.Name == "DI_JI_HAO") { PopupContent pc = new PopupContent(new Uri("http://59.42.105.34:5001/client/?id=" + val), "林业"); popups.Add(pc); } } } } } //Flash the features that intersected the sketch geometry. ActiveMapView.FlashFeature(result); //return the collection of pop-up content object. return(popups); }); var height = System.Windows.SystemParameters.WorkArea.Height / 2; var width = System.Windows.SystemParameters.WorkArea.Width / 2; var topLeftCornerPoint = new System.Windows.Point(0, 0); var popupDef = new PopupDefinition() { Append = true, // if true new record is appended to existing (if any) Dockable = true, // if true popup is dockable - if false Append is not applicable Position = topLeftCornerPoint, // Position of top left corner of the popup (in pixels) Size = new System.Windows.Size(width, height) // size of the popup (in pixels) }; //Show the custom pop-up with the custom commands and the default pop-up commands. ActiveMapView.ShowCustomPopup(popupContent, null, true, popupDef); return(true); }