Hi,
What I'm trying to figure out is a way to add graphics to the map, at specific distances along a selected line. See my example below. The user selects a line segment, then a database is queried that shows all of the sanitary sewer connection lines along that line. What I want to do is to put a point on the screen at each specified distance (starting at the start or end of the line) to show where each connection is.
I've never messed with graphics in ArcGIS Pro SDK before, so any guidance is appreciated.
Thanks!
Solved! Go to Solution.
Hi Brain,
At 2.5 and previous versions, you can use Map overlays to create graphic elements on your map. GeometryEngine provides methods to calculate the sewer connection points along the line. You can create your graphic elements at these points. MapOverlay samples
New at 2.6: GraphicsLayer API will be available and you can alternatively also use that to create the elements.
Thanks
Uma
Hi Brain,
At 2.5 and previous versions, you can use Map overlays to create graphic elements on your map. GeometryEngine provides methods to calculate the sewer connection points along the line. You can create your graphic elements at these points. MapOverlay samples
New at 2.6: GraphicsLayer API will be available and you can alternatively also use that to create the elements.
Thanks
Uma
Hi Uma Harano,
I've pretty much got this working, but the one thing that is causing me problems is the removal of the graphics when I select a new row in my table to add new points. Only the most recently added overlay point gets removed. I'm basically using the same code as from the Geocode sample to do this. Here is my OverlayUtils code:
namespace SAWS_Sewer_Connections
{
class OverlayUtils
{
private static System.IDisposable _overlayObject = null;
public static void RemoveFromMapOverlay(MapView mapView)
{
if (_overlayObject != null)
{
_overlayObject.Dispose();
_overlayObject = null;
}
}
public static void UpdateMapOverlay(ArcGIS.Core.Geometry.MapPoint point, MapView mapView)
{
//if (_overlayObject != null)
//{
// _overlayObject.Dispose();
// _overlayObject = null;
// AddToMapOverlay(point, mapView);
//}
//else
//{
// //first time
// AddToMapOverlay(point, mapView);
//}
AddToMapOverlay(point, mapView);
}
public static async void AddToMapOverlay(ArcGIS.Core.Geometry.MapPoint point, MapView mapView)
{
ArcGIS.Core.CIM.CIMPointSymbol symbol = null;
await QueuedTask.Run(() =>
{
// Construct point symbol
symbol = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.RedRGB, 5, SimpleMarkerStyle.Square);
});
//Get symbol reference from the symbol
CIMSymbolReference symbolReference = symbol.MakeSymbolReference();
await QueuedTask.Run(() =>
{
_overlayObject = mapView.AddOverlay(point, symbolReference);
});
}
}
}
And here is the code I run when the selection in my ListView changes:
foreach (var oid in selectedOIDs)
{
var insp = new ArcGIS.Desktop.Editing.Attributes.Inspector();
insp.Load(gsFLayer, oid);
//Get the To and From point of the currently selected feature
var pointCollection = ((ArcGIS.Core.Geometry.Multipart)insp.Shape).Points;
if (currentSurvey.direction == "U")
{
fromPoint = pointCollection[pointCollection.Count - 1];
}
else
{
fromPoint = pointCollection[0];
}
//MessageBox.Show(insp["FACILITYID"].ToString() + " - " + fromPoint.X.ToString() + ", " + fromPoint.Y.ToString());
MapView mapview = MapView.Active;
OverlayUtils.RemoveFromMapOverlay(mapview);
ArcGIS.Core.Geometry.MapPoint connPoint = null;
double theLength = ((ArcGIS.Core.Geometry.Multipart)insp.Shape).Length;
foreach (var currentDetail in lstDetails.Items.OfType<detailItems>())
{
if (currentSurvey.direction == "U")
{
connPoint = ArcGIS.Core.Geometry.GeometryEngine.Instance.QueryPoint((ArcGIS.Core.Geometry.Multipart)insp.Shape, ArcGIS.Core.Geometry.SegmentExtension.NoExtension, theLength - (double)currentDetail.distance, ArcGIS.Core.Geometry.AsRatioOrLength.AsLength);
}
else
{
connPoint = ArcGIS.Core.Geometry.GeometryEngine.Instance.QueryPoint((ArcGIS.Core.Geometry.Multipart)insp.Shape, ArcGIS.Core.Geometry.SegmentExtension.NoExtension, (double)currentDetail.distance, ArcGIS.Core.Geometry.AsRatioOrLength.AsLength);
}
OverlayUtils.UpdateMapOverlay(connPoint, mapview);
}
//OverlayUtils.UpdateMapOverlay(fromPoint, mapview);
}
I guess they are all individual objecsts, but is there a way to get RemoveFromMapOverlay to remove everything, not just the last one created??
I think I figured it out! Adding all of the added overlays in a collection seems to work.
namespace SAWS_Sewer_Connections
{
class OverlayUtils
{
private static System.IDisposable _overlayObject = null;
private static IList<System.IDisposable> _allOverlays = new List<System.IDisposable>();
public static void RemoveFromMapOverlay(MapView mapView)
{
if (_overlayObject != null)
{
foreach (var overlay in _allOverlays) overlay.Dispose();
_overlayObject.Dispose();
_overlayObject = null;
}
}
public static void UpdateMapOverlay(ArcGIS.Core.Geometry.MapPoint point, MapView mapView)
{
//if (_overlayObject != null)
//{
// _overlayObject.Dispose();
// _overlayObject = null;
// AddToMapOverlay(point, mapView);
//}
//else
//{
// //first time
// AddToMapOverlay(point, mapView);
//}
AddToMapOverlay(point, mapView);
}
public static async void AddToMapOverlay(ArcGIS.Core.Geometry.MapPoint point, MapView mapView)
{
ArcGIS.Core.CIM.CIMPointSymbol symbol = null;
await QueuedTask.Run(() =>
{
// Construct point symbol
symbol = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.RedRGB, 5, SimpleMarkerStyle.Square);
});
//Get symbol reference from the symbol
CIMSymbolReference symbolReference = symbol.MakeSymbolReference();
await QueuedTask.Run(() =>
{
_overlayObject = mapView.AddOverlay(point, symbolReference);
_allOverlays.Add(_overlayObject);
});
}
}
}
Thanks Uma Harano!!
Very helpful! Thank you!