End goal: Allow user to move points on a ILineElement using the selection handles from ISelectionTracker.
Issue: Using my code below I am able to get the handles to appear on the line element, but it appears to be using an EnvelopeTracker and not a LineTracker. Also I am unable to drag the displayed handles to reshape the line.
Code:
public void TrackSelection()
{
IGraphicsContainerSelect graphicsContainer = (IGraphicsContainerSelect)GetGraphicsContainer();
ILineElement outline = GetLine();
// Selecting the element adds the tracker handles.
graphicsContainer.SelectElement((IElement)outline);
RefreshView();
}
private ILineElement GetLine()
{
//For simplicity only 1 line is created so just grab it.
ILineElement line = null;
IGraphicsContainer graphicsContainer = GetGraphicsContainer();
if (graphicsContainer != null)
{
graphicsContainer.Reset();
IElement element = graphicsContainer.Next();
while (element != null)
{
if (element is ILineElement)
{
line = (ILineElement)element;
}
element = graphicsContainer.Next();
}
}
return line;
}
public void RandomLineElementCreator()
{
// Random line creator. Replacing.
IGraphicsContainer graphicsContainer = GetGraphicsContainer();
if (graphicsContainer != null)
{
graphicsContainer.DeleteAllElements();
IColor color = EsriConversionUtility.ConvertToRgbColor(Colors.Red);
ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass();
simpleLineSymbol.Color = color;
simpleLineSymbol.Width = 3;
IPointCollection path = new PathClass();
var line = new PolylineClass();
Random rnd = new Random();
for (int i = 0; i < 4; i++)
{
int randomX = rnd.Next(1, 8);
int randomY = rnd.Next(1, 16);
var point = new Point();
point.X = -12831100.742200622 - (randomX * 1000);
point.Y = 7674669.7012844728 - (randomY * 1000);
path.AddPoint(point);
}
line.IPointCollection4_AddPointCollection(path);
IGeometry geometry = line;
ILineElement lineElement = new LineElementClass();
lineElement.Symbol = simpleLineSymbol;
IElement elementToAdd = lineElement as IElement;
elementToAdd.Geometry = geometry;
graphicsContainer.AddElement(elementToAdd, 0);
RefreshView();
}
}
private IGraphicsContainer GetGraphicsContainer()
{
ICompositeGraphicsLayer compositeGraphicsLayer = (ICompositeGraphicsLayer)(MapController.Map.BasicGraphicsLayer);
try
{
_graphicsLayer = compositeGraphicsLayer.FindLayer(EditContourGraphicsLayerName);
}
catch
{
_graphicsLayer = compositeGraphicsLayer.AddLayer(EditContourGraphicsLayerName, null);
}
return _graphicsLayer as IGraphicsContainer;
}
private void RefreshView()
{
MapController.PartialRefreshMap();
if (ActiveMap.Instance.IsInitialized)
{
ActiveMap.Instance.Map.IsDirty = true;
}
}
What I have:
What I want:
IElement.Geometry
is anIGeometryCollection
with only oneIPath
in it?