Hi,
I'm trying to move the annotation, but every time I take its geometry, I only see how the line moves (it's the same length as the length of the annotation).
protected override async void OnToolMouseMove(MapViewMouseEventArgs e)
{
lock (_zamek)
{
if (_sledovaniTrasy == TrackingState.NotTracking)
return;
if (_pracovniPlocha.HasValue)
{
_posledniPozice = e.ClientPoint;
return;
}
_posledniPozice = e.ClientPoint;
_pracovniPlocha = e.ClientPoint;
_sledovaniTrasy = TrackingState.Tracking;
}
await QueuedTask.Run(() =>
{
var symbolReference = _symbol.MakeSymbolReference();
const string bodyAnno = "BodyAnno";
var alBodyAnno = AlBodyAnno(bodyAnno);
var insp = Insp();
insp.Load(alBodyAnno, oid);
AnnotationProperties annoVlastnosti = insp.GetAnnotationProperties();
while (true)
{
Point? bod;
Geometry geometrie = null;
IDisposable grafika;
lock (_zamek)
{
bod = _posledniPozice;
_posledniPozice = null;
_pracovniPlocha = bod;
if (bod == null || !bod.HasValue)
{
_pracovniPlocha = null;
break;
}
if (_geometrie == null || _grafika == null)
{
_sledovaniTrasy = TrackingState.NotTracking;
break;
}
grafika = _grafika;
}
var envelope = shape.Extent;
var mapovyBodCentroid = GeometryEngine.Instance.Centroid(envelope);
double souradniceStrduX = mapovyBodCentroid.X;
double souradniceStreduY = mapovyBodCentroid.Y;
if (strana == "horni" || strana == "dolni")
{
if (shape.GeometryType != GeometryType.GeometryBag)
{
var mapovyBod = ActiveMapView.ClientToMap(e.ClientPoint);
var souradniceX = mapovyBod.X;
var x = souradniceX - souradniceStrduX;
var posun = GeometryEngine.Instance.Move(shape, x, 0);
annoVlastnosti.Shape = posun;
UpdateOverlay(grafika,posun, symbolReference);
}
}
else
{
if (shape.GeometryType != GeometryType.GeometryBag)
{
var mapovyBod = ActiveMapView.ClientToMap(e.ClientPoint);
var souradniceY = mapovyBod.Y;
var y = souradniceY - souradniceStreduY;
var posun = GeometryEngine.Instance.Move(shape, 0, y);
annoVlastnosti.Shape = posun;
UpdateOverlay(grafika, posun, symbolReference);
}
}
}
});
}
Could it be that the Gemetry annotation is Polyline?
Thanks for the advice and tips.
David
If you need a custom map tool that allows you to select a single annotation feature and then allows you to move it you can use the following code:
internal class MoveAnnoTool : MapTool
{
public MoveAnnoTool()
{
IsSketchTool = true;
SketchType = SketchGeometryType.Point;
SketchOutputMode = SketchOutputMode.Map;
}
protected override Task OnToolActivateAsync(bool active)
{
return base.OnToolActivateAsync(active);
}
protected override Task<bool> OnSketchCompleteAsync(Geometry geometry)
{
{
// execute on the MCT
return QueuedTask.Run(() =>
{
// find features under the sketch
var features = MapView.Active.SelectFeatures(geometry);
// only one feature ...
if (features.Count != 1) return false;
// this works only if one annotation feature has been
// selected
var annoSelected = 0;
foreach (var annoLayer in features.ToDictionary().Keys.OfType<AnnotationLayer>())
{
// are there features?
var featOids = features[annoLayer];
annoSelected += featOids.Count;
}
if (annoSelected == 1)
RunOnUiThread(() =>
{
// or use ICommand.Execute
ICommand cmd = FrameworkApplication.GetPlugInWrapper("esri_editing_EditVerticesMove") as ICommand;
if ((cmd != null) && cmd.CanExecute(null))
cmd.Execute(null);
});
return true;
});
}
}
/// <summary>
/// utility function to enable an action to run on the UI thread (if not already)
/// </summary>
/// <param name="action">the action to execute</param>
/// <returns></returns>
internal static void RunOnUiThread(Action action)
{
try
{
if (IsOnUiThread)
action();
else
System.Windows.Application.Current.Dispatcher.BeginInvoke(action);
}
catch (Exception ex)
{
MessageBox.Show($@"Error in OpenAndActivateMap: {ex.Message}");
}
}
/// <summary>
/// Determines whether the calling thread is the thread associated with this
/// System.Windows.Threading.Dispatcher, the UI thread.
///
/// If called from a View model test it always returns true.
/// </summary>
public static bool IsOnUiThread => FrameworkApplication.TestMode || System.Windows.Application.Current.Dispatcher.CheckAccess();
}
Click the tool and then click on an annotation feature, to select a feature, next the Pro Move command will be activated, and you can now move (rotate, scale) the annotation. Once you moved a feature you can repeat. You can insert additional custom code as needed.
Thank you very much, I'm glad for the answer, but my idea is a little different.