diff --git a/src/Samples/Toolkit.SampleApp.WPF/Samples/PopupViewer/PopupViewerSample.xaml.cs b/src/Samples/Toolkit.SampleApp.WPF/Samples/PopupViewer/PopupViewerSample.xaml.cs index 65b53eb91..54ac420df 100644 --- a/src/Samples/Toolkit.SampleApp.WPF/Samples/PopupViewer/PopupViewerSample.xaml.cs +++ b/src/Samples/Toolkit.SampleApp.WPF/Samples/PopupViewer/PopupViewerSample.xaml.cs @@ -1,5 +1,6 @@ -using Esri.ArcGISRuntime.Data; +using Esri.ArcGISRuntime.Data; using Esri.ArcGISRuntime.Mapping.Popups; +using Esri.ArcGISRuntime.RealTime; using Esri.ArcGISRuntime.UI; using Esri.ArcGISRuntime.UI.Controls; using System; @@ -31,7 +32,7 @@ private async void mapView_GeoViewTapped(object sender, GeoViewInputEventArgs e) var result = await mapView.IdentifyLayersAsync(e.Position, 3, false); // Retrieves or builds Popup from IdentifyLayerResult - var popup = GetPopup(result); + var popup = GetPopup(result) ?? BuildPopupFromGeoElement(result); if (popup != null) { PopupBackground.Visibility = Visibility.Visible; @@ -54,15 +55,42 @@ private Popup GetPopup(IdentifyLayerResult result) var popup = result.Popups.FirstOrDefault(); if (popup != null) { + if (popup.GeoElement is DynamicEntityObservation deo) + { + return new Popup(deo.GetDynamicEntity(), popup.PopupDefinition); + } return popup; } + return GetPopup(result.SublayerResults); + } + + private Popup GetPopup(IEnumerable results) + { + if (results == null) + return null; + foreach (var result in results) + { + var popup = GetPopup(result); + if (popup != null) + return popup; + } + + return null; + } + + private Popup BuildPopupFromGeoElement(IdentifyLayerResult result) + { + if (result == null) + return null; var geoElement = result.GeoElements.FirstOrDefault(); if (geoElement != null) { - if (result.LayerContent is IPopupSource) + if (geoElement is DynamicEntityObservation obs) + geoElement = obs.GetDynamicEntity(); + if (result.LayerContent is IPopupSource source) { - var popupDefinition = ((IPopupSource)result.LayerContent).PopupDefinition; + var popupDefinition = source.PopupDefinition; if (popupDefinition != null) { return new Popup(geoElement, popupDefinition); @@ -71,11 +99,10 @@ private Popup GetPopup(IdentifyLayerResult result) return Popup.FromGeoElement(geoElement); } - - return null; + return BuildPopupFromGeoElement(result.SublayerResults); } - private Popup GetPopup(IEnumerable results) + private Popup BuildPopupFromGeoElement(IEnumerable results) { if (results == null) { @@ -83,23 +110,13 @@ private Popup GetPopup(IEnumerable results) } foreach (var result in results) { - var popup = GetPopup(result); + var popup = BuildPopupFromGeoElement(result); if (popup != null) { return popup; } - - foreach (var subResult in result.SublayerResults) - { - popup = GetPopup(subResult); - if (popup != null) - { - return popup; - } - } } - - return null; + return null; } private void PopupBackground_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)