Hey,
I am working on an add-in which searches in a series of on-line datasources.
I'd like to visualize the results in a view on top of any map.
In the old days (ArcMap 10.x) I would have done it like this:
pMap = pMxDoc.FocusMap;
activeView = pMap as IActiveView;
var point = makePoint(SrI.lon, SrI.lat, EPSG);
ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = activeView.ScreenDisplay;
screenDisplay.StartDrawing(screenDisplay.hDC, (System.Int16)ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache);
ESRI.ArcGIS.Display.ISimpleMarkerSymbol simpleMarkerSymbol = new ESRI.ArcGIS.Display.SimpleMarkerSymbol();
ESRI.ArcGIS.Display.ISymbol symbol = simpleMarkerSymbol as ESRI.ArcGIS.Display.ISymbol; // Dynamic cast.
screenDisplay.SetSymbol(symbol);
screenDisplay.DrawPoint(point);
screenDisplay.FinishDrawing();
I can see that there is something similar in the Runtime SDK : Add graphics and text—ArcGIS Runtime SDK for .NET | ArcGIS for Developers
Is there anything alike in the Add-In SDK ?
Thanx
/Bernhard
Try MapView.Active.AddOverlay
ArcGIS Pro 1.2 API Reference Guide
See the sample arcgis-pro-sdk-community-samples/GeocodeUtils.cs at 321754c2cf3e808bd58d311d44e18cadc6ad85fd · Esri/...
In Pro, you need to use something called the "Overlay". If you look at the MapView class you will see methods to manipulate the overlay. MapTools have an extension method called "AddOverlayAsync" so that you can add a sketch to the overlay as a convenience rather than getting the MapView.Active.
Here is some code - I copy-pasted it out of a sample we will be providing (amongst others) to show how to work with the Overlay. The easiest way to use it is to run the MapTool template in the SDK, delete out the entire contents of the code behind generated by the maptool template, copy this code into the code behind file. Change the class name back to the default (probably MapTool1 or something like that. Please let me know if you have questions.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ArcGIS.Core.CIM;
using ArcGIS.Core.Geometry;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Mapping;
namespace OverlayExamples {
/// <summary>
/// Show how to add a graphic to the overlay in either 2D or 3D.
/// </summary>
/// <remarks>Sketch a geometry. When the sketch is completed it is added to the
/// overlay. When you begin sketching again or deactivate the tool the previous
/// sketch is deleted</remarks>
class AddOverlayTool : MapTool {
private IDisposable _graphic = null;
private CIMLineSymbol _lineSymbol = null;
public AddOverlayTool() {
IsSketchTool = true;
SketchType = SketchGeometryType.Line; //Sketch a line geometry
SketchOutputMode = SketchOutputMode.Map;
}
protected override Task OnToolDeactivateAsync(bool hasMapViewChanged) {
if (_graphic != null)
_graphic.Dispose();//Clear out the old overlay
_graphic = null;
return base.OnToolDeactivateAsync(hasMapViewChanged);
}
/// <summary>
/// Occurs when the tool is activated.
/// </summary>
/// <param name="hasMapViewChanged">A value indicating if the active <see cref="T:ArcGIS.Desktop.Mapping.MapView"/> has changed.</param>
/// <returns>
/// A Task that represents a tool activation event.
/// </returns>
protected async override Task OnToolActivateAsync(bool hasMapViewChanged) {
if (_lineSymbol == null) {
_lineSymbol = await Module1.CreateLineSymbolAsync();
}
this.SketchSymbol = _lineSymbol.MakeSymbolReference();
}
protected override void OnToolMouseDown(MapViewMouseButtonEventArgs e) {
if (_graphic != null) {
_graphic.Dispose();//Clear out the old overlay
_graphic = null;
}
base.OnToolMouseDown(e);
}
protected async override Task<bool> OnSketchCompleteAsync(Geometry geometry) {
_graphic = await this.AddOverlayAsync(geometry, _lineSymbol.MakeSymbolReference());
return true;
}
}
}
Are there examples of how to add a CIMTextSymbol with a balloon callout?
Oh, you need this guy too in your Module:
/// <summary>Create a linesymbol with circle markers on the ends</summary>
internal static Task<CIMLineSymbol> CreateLineSymbolAsync() {
return QueuedTask.Run(() => {
var lineStroke = SymbolFactory.ConstructStroke(ColorFactory.RedRGB, 4.0);
var marker = SymbolFactory.ConstructMarker(ColorFactory.RedRGB, 12, SimpleMarkerStyle.Circle);
marker.MarkerPlacement = new CIMMarkerPlacementOnVertices() {
AngleToLine = true,
PlaceOnEndPoints = true,
Offset = 0
};
return new CIMLineSymbol() {
SymbolLayers = new CIMSymbolLayer[2] { marker, lineStroke }
};
});
}