Hi
Are popups available in the ArcGIS Runtime SDK for .NET 100.0?
If popups are available, how we can use them?
Thank you
We haven't gotten around to using the new parts of the API. But we have the control that is shown above and display using the Overlays collection and call SetAnchorPoint to locate the pin. Our users want a popup that displays more than just a couple attributes, and this seems to be working. I do plan to try to integrate it into the Callout API stuff, but it is a low priority
Hello Joe,
How did you ended up showing all the attribute information.
Coming from Javascript API world, I am finding out working with runtime sdk very challenging.I would love to display more than just one line of attribute info. I would like to display attributes in tabular format like yours.
Can you please share your code?
thanks
Don
On a side note I'd really recommend against this pattern of creating huge popups with lots and lots of contents, as they block the view of the map. A better design approach is to keep the popup small with just a title and an 'edit' or 'info' button. Clicking that brings out a side-panel with the full information. That way part of the map you're looking stays mostly unblocked, and the detailed data you get to work with next to, instead of over the map.
Hi,
Can you please share the whole code, to get similar kind of output, I also want to create a callout with Table like GUI and close button at the top of the callout.
Thanks.
You can override the Callout style like this:
<SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"><</SPAN><SPAN class="namespace token">esri:</SPAN>MapView</SPAN><SPAN class="punctuation token">></SPAN></SPAN> <esri:MapView.Resources> <SPAN class="language-css style token"><SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"><</SPAN>Style</SPAN> <SPAN class="attr-name token">TargetType</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>esri:Callout<SPAN class="punctuation token">"</SPAN></SPAN><SPAN class="punctuation token">></SPAN></SPAN> <Setter Property=<SPAN class="string token">"BorderBrush"</SPAN> Value=<SPAN class="string token">"Red"</SPAN> /> <Setter Property=<SPAN class="string token">"BorderThickness"</SPAN> Value=<SPAN class="string token">"5"</SPAN> /> <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"></</SPAN>Style</SPAN><SPAN class="punctuation token">></SPAN></SPAN></SPAN> </esri:MapView.Resources> <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"></</SPAN><SPAN class="namespace token">esri:</SPAN>MapView</SPAN><SPAN class="punctuation token">></SPAN></SPAN> <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
There's a lot of properties to override, but you might have to adapt your layout to the callout's style (ie make the background the same blue color, and remove your own border, reduce padding/margins etc.
For reference here's the full callout style defined:
<SPAN class="language-css style token"><SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"><</SPAN>Style</SPAN> <SPAN class="attr-name token">TargetType</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>{x:Type local:Callout}<SPAN class="punctuation token">"</SPAN></SPAN><SPAN class="punctuation token">></SPAN></SPAN> <SPAN class="selector token"><Setter Property="MinWidth" Value="75" /> <Setter Property="Padding" Value="10" /> <Setter Property="Background" Value="#E6FFFFFF" /> <Setter Property="Foreground" Value="Black" /> <Setter Property="BorderBrush" Value="LightGray" /> <Setter Property="BorderThickness" Value="1" /> <Setter Property="HorizontalContentAlignment" Value="Center" /> <Setter Property="VerticalContentAlignment" Value="Center" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="</SPAN><SPAN class="punctuation token">{</SPAN><SPAN class="property token">x</SPAN><SPAN class="punctuation token">:</SPAN>Type <SPAN class="property token">local</SPAN><SPAN class="punctuation token">:</SPAN>Callout<SPAN class="punctuation token">}</SPAN><SPAN class="selector token">"> <Grid x:Name="RootElement"> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="EntranceTransitions"> <VisualState x:Name="Show"> <Storyboard> <DoubleAnimation Duration="0:0:0.1" From="0" To="1" Storyboard.TargetName="RootElement" Storyboard.TargetProperty="Opacity" > <DoubleAnimation.EasingFunction> <CubicEase /> </DoubleAnimation.EasingFunction> </DoubleAnimation> </Storyboard> </VisualState> <VisualState x:Name="Hide"> <Storyboard> <DoubleAnimation Duration="0:0:0" To="0" Storyboard.TargetName="RootElement" Storyboard.TargetProperty="Opacity" /> </Storyboard> </VisualState> </VisualStateGroup> <VisualStateGroup x:Name="Visibility"> <VisualState x:Name="Visible"> <Storyboard> <DoubleAnimation Duration="0:0:0.25" To="1" Storyboard.TargetName="RootElement" Storyboard.TargetProperty="Opacity" /> </Storyboard> </VisualState> <VisualState x:Name="HiddenByElevation"> <Storyboard> <DoubleAnimation Duration="0:0:0.25" To=".3" Storyboard.TargetName="RootElement" Storyboard.TargetProperty="Opacity" /> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Path x:Name="PART_Border" Fill="</SPAN><SPAN class="punctuation token">{</SPAN>TemplateBinding Background<SPAN class="punctuation token">}</SPAN><SPAN class="selector token">" Stretch="None" Stroke="</SPAN><SPAN class="punctuation token">{</SPAN>TemplateBinding BorderBrush<SPAN class="punctuation token">}</SPAN><SPAN class="selector token">" DataContext="</SPAN><SPAN class="punctuation token">{</SPAN>TemplateBinding BorderThickness<SPAN class="punctuation token">}</SPAN><SPAN class="selector token">" StrokeThickness="</SPAN><SPAN class="punctuation token">{</SPAN>Binding Left<SPAN class="punctuation token">}</SPAN><SPAN class="selector token">" HorizontalAlignment="Center" VerticalAlignment="Center" /> <Grid x:Name="PART_ContentArea" HorizontalAlignment="Left" VerticalAlignment="Top"> <ContentPresenter Margin="</SPAN><SPAN class="punctuation token">{</SPAN>TemplateBinding Padding<SPAN class="punctuation token">}</SPAN><SPAN class="selector token">" HorizontalAlignment="</SPAN><SPAN class="punctuation token">{</SPAN>TemplateBinding HorizontalContentAlignment<SPAN class="punctuation token">}</SPAN><SPAN class="selector token">" VerticalAlignment="</SPAN><SPAN class="punctuation token">{</SPAN>TemplateBinding VerticalContentAlignment<SPAN class="punctuation token">}</SPAN>" /> </Grid> </Grid> </ControlTemplate> </Setter.Value> </Setter> <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"></</SPAN>Style</SPAN><SPAN class="punctuation token">></SPAN></SPAN></SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
mnielsen-esristaff the new callout behavior of having the callout move if it goes out of the visible area (which we were not able to do) is really nice. Also not needing the whole SetAnchorPoint. The problem I am having is that there is the white edge of the default Callout around our custom Popup UI. I would like to use this because of the move behavior, but the outline makes it a no-go. Any way to get rid of that, I don't see any properties that would take care of it?
Thanks
-Joe
It might be worth mentioning that with v100.1, we greatly simplified this common workflow. The above method is great if you want full control of every pixel that's presented. If not, try the new callout api:
mapView.ShowCalloutAt( new MapPoint(0, 0, SpatialReferences.Wgs84), new UI.CalloutDefinition("Center of the world"));
Could you post the entire solution? If you have it for WPF, that would be great. Thanks!
It seems that this got answered in https://community.esri.com/thread/197650-popups-in-xamarin-android topic.
Hey Antti
Any input on how to do this within Xamarin? I've implemented this idea within our UWP and am now attempting the droid side and not sure how to proceed.
Was a solution for Xamarin ever identified for creating a control? The MapView on the droid side only has an Overlay property where the windows side has a Overlays property and it is specific to ESRI.
This example works with Xamarin.Forms???
Nice, will give a try! Thanks for sharing!
Ming
I was just writing a simple popup today so here is what I did.
<SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"><</SPAN><SPAN class="namespace token">esri:</SPAN>MapView</SPAN> <SPAN class="attr-name token"><SPAN class="namespace token">x:</SPAN>Name</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>MyMapView<SPAN class="punctuation token">"</SPAN></SPAN><SPAN class="punctuation token">></SPAN></SPAN> <esri:MapView.Overlays> <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"><</SPAN><SPAN class="namespace token">esri:</SPAN>OverlayItemsControl</SPAN><SPAN class="punctuation token">></SPAN></SPAN> <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"><</SPAN>Grid</SPAN> <SPAN class="attr-name token"><SPAN class="namespace token">x:</SPAN>Name</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>popup<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token"><SPAN class="namespace token">esri:</SPAN>MapView.ViewOverlayAnchor</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>{Binding Geometry}<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">IsHitTestVisible</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>False<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">HorizontalAlignment</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>Right<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">VerticalAlignment</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>Top<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">MaxWidth</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>200<SPAN class="punctuation token">"</SPAN></SPAN><SPAN class="punctuation token">></SPAN></SPAN> <Grid.RowDefinitions> <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"><</SPAN>RowDefinition</SPAN> <SPAN class="attr-name token">Height</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>*<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="punctuation token">/></SPAN></SPAN> <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"><</SPAN>RowDefinition</SPAN> <SPAN class="attr-name token">Height</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>20<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="punctuation token">/></SPAN></SPAN> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"><</SPAN>ColumnDefinition</SPAN> <SPAN class="attr-name token">Width</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>20<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="punctuation token">/></SPAN></SPAN> <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"><</SPAN>ColumnDefinition</SPAN> <SPAN class="attr-name token">Width</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>*<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="punctuation token">/></SPAN></SPAN> </Grid.ColumnDefinitions> <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"><</SPAN>Border</SPAN> <SPAN class="attr-name token">Background</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>#CC000000<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">BorderThickness</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>1,1,1,0<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">Margin</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>0,0,0,-1<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">BorderBrush</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>White<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">Grid.ColumnSpan</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>2<SPAN class="punctuation token">"</SPAN></SPAN><SPAN class="punctuation token">></SPAN></SPAN> <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"><</SPAN>StackPanel</SPAN> <SPAN class="attr-name token">Margin</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>20<SPAN class="punctuation token">"</SPAN></SPAN><SPAN class="punctuation token">></SPAN></SPAN> <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"><</SPAN>TextBlock</SPAN> <SPAN class="attr-name token">FontWeight</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>Bold<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">Foreground</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>White<SPAN class="punctuation token">"</SPAN></SPAN><SPAN class="punctuation token">></SPAN></SPAN> <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"><</SPAN>Run</SPAN> <SPAN class="attr-name token">Text</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>ObjectId <SPAN class="punctuation token">=</SPAN> <SPAN class="punctuation token">"</SPAN></SPAN><SPAN class="punctuation token">></SPAN></SPAN><SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"></</SPAN>Run</SPAN><SPAN class="punctuation token">></SPAN></SPAN> <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"><</SPAN>Run</SPAN> <SPAN class="attr-name token">Text</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>{Binding Attributes[objectid]}<SPAN class="punctuation token">"</SPAN></SPAN><SPAN class="punctuation token">></SPAN></SPAN><SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"></</SPAN>Run</SPAN><SPAN class="punctuation token">></SPAN></SPAN> <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"></</SPAN>TextBlock</SPAN><SPAN class="punctuation token">></SPAN></SPAN> <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"></</SPAN>StackPanel</SPAN><SPAN class="punctuation token">></SPAN></SPAN> <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"></</SPAN>Border</SPAN><SPAN class="punctuation token">></SPAN></SPAN> <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"><</SPAN>Path</SPAN> <SPAN class="attr-name token">StrokeThickness</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>1<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">Fill</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>#CC000000<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">Stroke</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>White<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">Stretch</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>Fill<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">HorizontalAlignment</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>Left<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">Data</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>M0,0 L0,1 1,0<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">Grid.Row</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>1<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="punctuation token">/></SPAN></SPAN> <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"><</SPAN>Path</SPAN> <SPAN class="attr-name token">StrokeThickness</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>1<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">Fill</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>#CC000000<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">Stroke</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>White<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">Stretch</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>Fill<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">VerticalAlignment</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>Top<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">Data</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>M0,0 L1,0<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">Grid.Row</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>1<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">Grid.Column</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>1<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="punctuation token">/></SPAN></SPAN> <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"></</SPAN>Grid</SPAN><SPAN class="punctuation token">></SPAN></SPAN> <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"></</SPAN><SPAN class="namespace token">esri:</SPAN>OverlayItemsControl</SPAN><SPAN class="punctuation token">></SPAN></SPAN> </esri:MapView.Overlays> <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"></</SPAN><SPAN class="namespace token">esri:</SPAN>MapView</SPAN><SPAN class="punctuation token">></SPAN></SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
And in your code you can do following
<SPAN class="keyword token">private</SPAN> ArcGISFeature _selectedFeature<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">async</SPAN> <SPAN class="keyword token">void</SPAN> <SPAN class="token function">OnGeoviewTapped</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">object</SPAN> sender<SPAN class="punctuation token">,</SPAN> GeoViewInputEventArgs e<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">try</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">// Clear all selected features</SPAN> <SPAN class="keyword token">foreach</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">var</SPAN> featureLayer <SPAN class="keyword token">in</SPAN> MyMapView<SPAN class="punctuation token">.</SPAN>Map<SPAN class="punctuation token">.</SPAN>OperationalLayers<SPAN class="punctuation token">.</SPAN>OfType<SPAN class="operator token"><</SPAN>FeatureLayer<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> featureLayer<SPAN class="punctuation token">.</SPAN><SPAN class="token function">ClearSelection</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="comment token">// Identify all features</SPAN> <SPAN class="keyword token">var</SPAN> results <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">await</SPAN> MyMapView<SPAN class="punctuation token">.</SPAN><SPAN class="token function">IdentifyLayersAsync</SPAN><SPAN class="punctuation token">(</SPAN>e<SPAN class="punctuation token">.</SPAN>Position<SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">false</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>results<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Any</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">// Get first result and get feature and layer from it</SPAN> <SPAN class="keyword token">var</SPAN> result <SPAN class="operator token">=</SPAN> results<SPAN class="punctuation token">.</SPAN><SPAN class="token function">First</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> feature <SPAN class="operator token">=</SPAN> result<SPAN class="punctuation token">.</SPAN>GeoElements<SPAN class="punctuation token">.</SPAN><SPAN class="token function">First</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> ArcGISFeature<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">await</SPAN> feature<SPAN class="punctuation token">.</SPAN><SPAN class="token function">LoadAsync</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// Load feature to get all attributes</SPAN> <SPAN class="keyword token">var</SPAN> layer <SPAN class="operator token">=</SPAN> result<SPAN class="punctuation token">.</SPAN>LayerContent <SPAN class="keyword token">as</SPAN> FeatureLayer<SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// Check if we already have clicked this feature </SPAN> <SPAN class="comment token">// if yes, then close popup</SPAN> <SPAN class="comment token">// if no, show the popup</SPAN> <SPAN class="keyword token">var</SPAN> objectIdField <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>layer<SPAN class="punctuation token">.</SPAN>FeatureTable <SPAN class="keyword token">as</SPAN> ArcGISFeatureTable<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>ObjectIdField<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>_selectedFeature<SPAN class="operator token">?</SPAN><SPAN class="punctuation token">.</SPAN>Attributes<SPAN class="punctuation token">[</SPAN>objectIdField<SPAN class="punctuation token">]</SPAN><SPAN class="operator token">?</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">ToString</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">==</SPAN> feature<SPAN class="punctuation token">.</SPAN>Attributes<SPAN class="punctuation token">[</SPAN>objectIdField<SPAN class="punctuation token">]</SPAN><SPAN class="operator token">?</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">ToString</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> popup<SPAN class="punctuation token">.</SPAN>Visibility <SPAN class="operator token">=</SPAN> Visibility<SPAN class="punctuation token">.</SPAN>Collapsed<SPAN class="punctuation token">;</SPAN> popup<SPAN class="punctuation token">.</SPAN>DataContext <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">;</SPAN> _selectedFeature <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">else</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">// Select feature</SPAN> layer<SPAN class="punctuation token">.</SPAN><SPAN class="token function">SelectFeature</SPAN><SPAN class="punctuation token">(</SPAN>feature<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// Set selected feature to the popups datacontext</SPAN> popup<SPAN class="punctuation token">.</SPAN>DataContext <SPAN class="operator token">=</SPAN> feature<SPAN class="punctuation token">;</SPAN> popup<SPAN class="punctuation token">.</SPAN>Visibility <SPAN class="operator token">=</SPAN> Visibility<SPAN class="punctuation token">.</SPAN>Visible<SPAN class="punctuation token">;</SPAN> _selectedFeature <SPAN class="operator token">=</SPAN> feature<SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">else</SPAN> <SPAN class="punctuation token">{</SPAN> popup<SPAN class="punctuation token">.</SPAN>Visibility <SPAN class="operator token">=</SPAN> Visibility<SPAN class="punctuation token">.</SPAN>Collapsed<SPAN class="punctuation token">;</SPAN> popup<SPAN class="punctuation token">.</SPAN>DataContext <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">catch</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="token class-name">Exception</SPAN> ex<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> MessageBox<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Show</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"An error occurred. "</SPAN> <SPAN class="operator token">+</SPAN> ex<SPAN class="punctuation token">.</SPAN><SPAN class="token function">ToString</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Sample error"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Note that the implementation might differ depending what you want to do. In my case I want to show a callout when clicking a feature isn't currently selected. If the feature is currently selected, then I want to hide the callout and if nothing is located where I click, I want to reset the map.
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.