Select to view content in your preferred language

display xy without creating a feature layer

367
2
05-19-2023 07:28 AM
Daniel4
Emerging Contributor

hi, is it possible to display a xy without creating a feature layer? From an api call I get the xy information, and I want to show where they are located on the map in AGP. But I don’t what to create a feature layer, because the user are going to use the function multiply times, and I don’t want the TOC to be flooded with feature layers. 

0 Kudos
2 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

You can look at this community sample:

arcgis-pro-sdk-community-samples/Map-Authoring/GraphicsLayers at 24c3224cc4566ab69c77b0bff40bff02562...

It contains code to create a graphics layer (see AddGraphicsLayer.cs) and the code to add a point to that graphic layer (see GraphicCreationTools/PointGraphic.cs).

The ProConcepts document for graphics layers is here:  ProConcepts GraphicsLayers · Esri/arcgis-pro-sdk Wiki (github.com)

Wolf
by Esri Regular Contributor
Esri Regular Contributor

You can also use an extension method on the MapView class: AddOverlay to add a Symbol (point, line, polygon) to a MapView's grphic overlay.   AddOverlay Method (MappingExtensions)—ArcGIS Pro

Here is the documentation on Graphic Overlays for MapView:

ProConcepts Map Exploration · Esri/arcgis-pro-sdk Wiki (github.com)

  private IDisposable _graphic = null; //defined elsewhere

  // Add point graphic to the overlay at the center of the mapView
  // Note: Run within QueuedTask.Run
  _graphic = mapView.AddOverlay(mapView.Extent.Center, 
               SymbolFactory.Instance.ConstructPointSymbol(
                 ColorFactory.Instance.RedRGB, 40.0, SimpleMarkerStyle.Star).MakeSymbolReference());

  // Note: Update graphic using UpdateOverlay
  // mapView.UpdateOverlay(_graphic,...);

  _graphic.Dispose(); //Removes the graphic