Select to view content in your preferred language

How to set overlay anchor point in ArcGISRuntime100.9.0

1093
2
10-19-2020 09:52 AM
KoryKarr
Emerging Contributor

I am migrating code from .net 10.2. to 100.9.0.  We use overlays to show details when the user hovers on a feature. However I can't find how to set the coordinates of the overlay in 100.9.0 (so it appears by the mouse cursor).

XAML:

 <esri:MapView x:Name="CenterlineHistoryMapView" WrapAround="True" MouseMove="CLHistMapView_OnMouseMove">
    ...
    <esri:MapView.Overlays>
       <esri:OverlayItemsControl>
       <Border x:Name="MapTooltip" 
          Background="White" 
          BorderBrush="Black" BorderThickness="2" 
          Padding="4" Margin="4" 
          HorizontalAlignment="Left" VerticalAlignment="Top" 
          Visibility="Collapsed">
      
          <StackPanel x:Name="ToolTipStackPanel">
             <TextBlock Text="{Binding Attributes[LINE_DESCRIPTION], StringFormat='Line Description: {0}'}" Foreground="Black" FontWeight="Bold" />
             <TextBlock Text="{Binding Attributes[ROUTE_ID], StringFormat='Route Id: {0}'}" Foreground="Black" />
             <TextBlock Text="{Binding Attributes[DESIGNATOR], StringFormat='Designator: {0}'}" Foreground="Black" />
          </StackPanel>
       </Border>
       </esri:OverlayItemsControl>
    </esri:MapView.Overlays>
 </esri:MapView>

Code behind:

// rectangle is derived from mouse event location

// I have migrated some of the code to the 100.9 API, like using IdentifyLayerAsync method 
long[] rows = await _centerlineFeatureLayer.HitTestAsync(CenterlineHistoryMapView, rectangle);
if (rows != null && rows.Length > 0)
{
 IEnumerable<Feature> features = await _centerlineFeatureLayer.FeatureTable.QueryAsync(rows);
 Feature feature = features.FirstOrDefault();
 if (feature != null)
 {
 _hoverOverlay.Graphics.Add(new Graphic(feature.Geometry, _hoverLineSymbol));
 MapTooltip.DataContext = feature;
 MapTooltip.Visibility = Visibility.Visible;
 
 //Looking for the equivalent of this call in 100.9.0
 Esri.ArcGISRuntime.Controls.ViewBase.SetViewOverlayAnchor(MapTooltip,
 CenterlineHistoryMapView.ScreenToLocation(screenPoint));
 }
 else
 {
 MapTooltip.Visibility = Visibility.Collapsed;
 }
}

On a side note, is would this be better suited as a popup? I'm not understanding the difference between a popup and an overlay. 

0 Kudos
2 Replies
JoeHershman
MVP Regular Contributor

Hi,

I don't have a sample readily available.  But I think the better approach in Runtime 100.9 would be to use a callout GeoView.ShowCalloutAt Method (MapPoint, CalloutDefinition).  This will allow you to setup the callout and then place in a location based on mouse location.

Thanks,
-Joe
0 Kudos
MichaelBranscomb
Esri Frequent Contributor

Callout is a good suggestion from Joe - here is some sample code showing how this can be implemented: arcgis-runtime-samples-dotnet/ShowCallout.xaml.cs at dbdc4452dfe816ad695719d947fb15a3d93d0891 · Esri... 

Regarding Callouts and Popups:

Callouts are simple UI types that can be added over the map and anchored to a coordinate with a leader/tail. Callouts have a configurable components including title, text, and symbol.

Popups are part of the ArcGIS information model and can be configured for individual layers (or sublayers) in a map via a popup definition. They can also be used with graphics from graphics overlays and pixels from rasters. Popups are intended to display the data of a feature, graphic or pixel (geo elements) in a way that is easier to understand than basic attributes in a row/column format. 

Popup sample code: arcgis-runtime-samples-dotnet/ShowPopup.xaml at master · Esri/arcgis-runtime-samples-dotnet · GitHub.

Note the PopupViewer is pulled in from the Toolkit (arcgis-toolkit-dotnet/src/Toolkit/Toolkit/UI/Controls/PopupViewer at main · Esri/arcgis-toolkit-dotn...). 

Thanks

Mike

0 Kudos