I am trying to display information from a feature layer using PopUp.
I am using the Esri.ArcGISRuntime.Xamarin.Forms nuget package.
I saw that you can specifiy a PopupDefinition on the FeatureLayer but how to display information on the MapView.
I'd like to open a popup when a user click on a feature but did not find any sample.
Any idea ?
Cheers
Did you end up finding a solution to this? I am having a similar issue.
Sorry did not find any solution for the moment. Not sure if pop up is supported for the moment
To get to the popup on all/any layers for a tapped location , you will have to call MapView.IdentifyLayersAsync(),or you can call MapView.IdentifyLayerAsync to get info for a specific layer. The result of Identify "IdentifyLayerResult" has Popups property that will return popup info on a layer(s).
Side note, if layer has sublayers then you would need to get the SublayerResults and then check for popups for that sublayer.
Just to give an idea I quickly typed following code to demonstrate how to get the popup from a featurelayer. This is not a functional code. Let me know if you still have problems and I will put together a quick sample.
IReadOnlyList<IdentifyLayerResult> results = await MyMapView.IdentifyLayersAsync(Position, tolerance, false,Features);
foreach (IdentifyLayerResult identifyLayerResult in results)
{
if (identifyLayerResult.Error != null)
{
//Display error
}
else if (identifyLayerResult.Popups?.Count > 0)
{
//Get the popup for geoelement
var ge=identifyLayerResult.Popups[0].GeoElement;
//get attributes
foreach (KeyValuePair<string, object> element in ge.Attributes)
{
// do something
}
}
else if (identifyLayerResult.SublayerResults?.Count > 0)
{
foreach (var sublayer in identifyLayerResult.SublayerResults)
{
if (sublayer.Popups?.Count > 0)
{
////Get the popup from sublayer
var sublayerGE=(sr.Popups[0].GeoElement);
}
....
}
}
Thanks, but how do I display the pop-up ? I don't need to get the pop-up to iterate through the attributes (I can just query the feature).
Displaying pop-up info is app logic and is left to app developer to decide and design how that info is displayed (e.g. custom UI control, a MapOverlay ). ArcGIS Runtime SDK for Dotnet API or Toolkit does not have any out-of-the-box UI control for displaying Pop-up control yet.
--Preeti
Thanks Preeti,
I understand that it was not a priority for the first release.
But it is confusing because we have access to this popup class but we can't do anything with it. Using target specific SDK (Android, iOS, old .Net), there are some `PopupContainer` or `PopUpManager` classes that can be used to display popups.
It would be great to update the release notes to explain this because I lost few hours to try to figure out how to display popup using the SDK.
Anyway, the SDK is great 😉
Cheers,
Thomas.
I also spent hours in search for sample code to display pop-up on the MapViewer. It seems to me this is a very fundamental and essential function of the MapViwer. Hopefully ESRI can quickly put up sample for how to display pop-up that already defined in a webmap and layer for a MapViewer.
Agree: the SDK is great!
Thanks,
Ming