In 2.3 something went wrong. TargetModel is null in DropInfo that passed to OnDrop method of a drop handler. It makes it impossible to determine where I drop my object. I should perform drop on MapView only. In 2.2 TargetModel contained that MapView when I dragging an object over it.
Is it a bug or there is API to specify where it is valid to drop an object?
Solved! Go to Solution.
Hi Max
If you drop into a pane in Pro that holds a MapView, it will be an IMapPane. From this, you can get the MapView.
This works even if you drop into a Pane that is not the active one (gray on the tab name).
Thanks
Uma
Hi Max,
There was an issue with the sequence of how custom drop handlers were being evaluated in Pro 2.2 on drag drop and that was fixed in 2.3. Because custom handlers are now evaluated first, the TargetModel property cannot always be guaranteed to be populated. Instead, please use this code snippet below: We will be updating the relevant samples for 2.4.
public override void OnDrop(DropInfo dropInfo)
{
#region Implement Your OnDrop Here
if (FrameworkApplication.Panes.ActivePane is IMapPane)
{
//a drag is being made on the active map
var view = ((IMapPane)FrameworkApplication.Panes.ActivePane).MapView;
// globe or local
if (view.ViewingMode == MapViewingMode.SceneGlobal ||
view.ViewingMode == MapViewingMode.SceneLocal)
{
//we are in 3D
OnDrop3D(dropInfo);
}
else
{
//we are in 2D
OnDrop2D(dropInfo);
}
}
#endregion
dropInfo.Handled = true;
}
Thanks
Uma
Hi Uma,
FrameworkApplication.Panes.ActivePane is the same thing as drop target? I think no. At now I use VisualTarget to determine where I'm dropping my object:
private static bool IsOverMapView(DropInfo dropInfo)
{
if (dropInfo == null)
return false;
if (dropInfo.TargetModel is MapView)
return true;
var visualTarget = dropInfo.VisualTarget;
if (visualTarget == null)
return false;
// TODO: seems there is a bug in ArcGIS Pro SDK 2.3 with TargetModel is null, so this is a workaround
return visualTarget.GetType().Name == "MapPaneView";
}
Hi Max
If you drop into a pane in Pro that holds a MapView, it will be an IMapPane. From this, you can get the MapView.
This works even if you drop into a Pane that is not the active one (gray on the tab name).
Thanks
Uma