Hi,
is there any way to move the selected feature by dragging the mouse? I know this is normal editing in ArcGIS Pro, but I also want to incorporate an element selection that I already have set up.
internal class PresunAnotaciPodelRamu : MapTool
{
public PresunAnotaciPodelRamu()
{
IsSketchTool = true;
SketchType = SketchGeometryType.Point;
SketchOutputMode = SketchOutputMode.Map;
}
protected override Task<bool> OnSketchCompleteAsync(Geometry geometry)
{
return QueuedTask.Run(() => Selection(geometry));
}
protected async Task<bool> Selection(Geometry geometry)
{
await QueuedTask.Run(() =>
{
MapView mapView = MapView.Active;
const string bodyAnno = "BodyAnno";
const string body = "Body";
const string ramyPresahu25 = "ramyPresahu_25";
var insp = new Inspector();
AnnotationLayer alBodyAnno = mapView.Map.FindLayers(bodyAnno).FirstOrDefault() as AnnotationLayer;
FeatureLayer flBody = mapView.Map.FindLayers(body).FirstOrDefault() as FeatureLayer;
FeatureLayer flRamyPresahu25 = mapView.Map.FindLayers(ramyPresahu25).FirstOrDefault() as FeatureLayer;
List<FeatureLayer> seznamVrstev = new List<FeatureLayer>()
{flBody, flRamyPresahu25};
if (alBodyAnno == null)
{
MessageBox.Show(@"Neexistuje.");
return;
}
foreach (var vrstva in seznamVrstev)
{
if (vrstva == null)
{
MessageBox.Show(@"Neexistuje.");
return;
}
}
var editace = new EditOperation
{
Name = "Posun anotace",
SelectNewFeatures = false
};
var features = mapView.GetFeatures(geometry);
if (features.ContainsKey(alBodyAnno))
{
var thisTag = features.FirstOrDefault(t => t.Key == alBodyAnno);
var oidSeznam = thisTag.Value;
long oid = 0;
string strana = null;
foreach (var longOid in oidSeznam)
{
oid = longOid;
}
var filter = new QueryFilter
{
WhereClause = " OBJECTID = " + oid
};
var anotaceHledana = alBodyAnno.Search(filter);
while (anotaceHledana.MoveNext())
{
var aktual = anotaceHledana.Current;
strana = aktual["STRANA"].ToString();
}
var anotaceZvolena = alBodyAnno.Select(filter);
insp.Load(alBodyAnno, oid);
AnnotationProperties annoProperties = insp.GetAnnotationProperties();
var shape = annoProperties.Shape;
var envelope = shape.Extent;
var mapPointCentroid = GeometryEngine.Instance.Centroid(envelope);
double souradniceStrduX = mapPointCentroid.X;
double souradniceStreduY = mapPointCentroid.Y;
if (strana == "horni" || strana == "dolni")
{
if (shape.GeometryType != GeometryType.GeometryBag)
{
HandleMouseUp(e);
var dictionary = GetMousePositionWindowsForms();
var souradniceY = dictionary.FirstOrDefault(x => x.Key == "Y").Value;
var posun = GeometryEngine.Instance.Move(shape, souradniceStrduX, souradniceY);
annoProperties.Shape = posun;
}
}
else
{
if (shape.GeometryType != GeometryType.GeometryBag)
{
HandleMouseUp(e);
var dictionary = GetMousePositionWindowsForms();
var souradniceX = dictionary.FirstOrDefault(x => x.Key == "X").Value;
var posun = GeometryEngine.Instance.Move(shape, souradniceX, souradniceStreduY);
annoProperties.Shape = posun;
}
}
insp.SetAnnotationProperties(annoProperties);
editace.Modify(insp);
}
else
{
MessageBox.Show("Nebyla zvolena anotace!");
return;
}
MouseButtonEventArgs e;//I don't know how to set it up
OnMouseDoubleClick(editace, e);
});
return true;
}
void OnMouseDoubleClick(EditOperation editace, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
{
editace.Execute();
}
}
void HandleMouseUp(MapViewMouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
{
GetMousePositionWindowsForms();
}
}
public static Dictionary<string,double> GetMousePositionWindowsForms()
{
Dictionary<string,double> list = new Dictionary<string, double>();
var point = Control.MousePosition;
list.Add("X",point.X);
list.Add("Y",point.Y);
return list;
}
}
Finally, I would like to end the method by double-clicking the mouse. Is it possible to do that?
Thank you
David