Skip to content

Commit

Permalink
PopupViewer sample: check all results for popups before building new …
Browse files Browse the repository at this point in the history
…one (#511)
  • Loading branch information
mstefarov committed Jul 11, 2023
1 parent f720225 commit 5db7706
Showing 1 changed file with 36 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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<IdentifyLayerResult> 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);
Expand All @@ -71,35 +99,24 @@ private Popup GetPopup(IdentifyLayerResult result)

return Popup.FromGeoElement(geoElement);
}

return null;
return BuildPopupFromGeoElement(result.SublayerResults);
}

private Popup GetPopup(IEnumerable<IdentifyLayerResult> results)
private Popup BuildPopupFromGeoElement(IEnumerable<IdentifyLayerResult> results)
{
if (results == null)
{
return null;
}
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)
Expand Down

0 comments on commit 5db7706

Please sign in to comment.