I have a MapTool where when the tool is activated, and also during mouse down events with the tool, the active map spatial reference is changed using MapView.Active.Map.SetSpatialReference(mySpatialReference);
In Pro 2.9 and earlier this worked fine, but now in Pro 3.0 the SetSpatialReference line of code deactivates my tool and the map Explore tool (i.e., the pointing hand cursor) is activated. Note that the spatial reference DOES change correctly. The problem is the tool being deactivated. This seems like a bug in Pro 3.0. Has anyone else encountered this or know if a work around?
Solved! Go to Solution.
Hi Karen,
If you have access to the tool code, can you see whether the following works for you as a possible workaround to the tool deactivating?
private bool ignoreToolDeactivation = false;
protected override async Task OnToolActivateAsync(bool active)
{
var map = MapView.Active.Map;
var wkid = map.SpatialReference.Wkid;
// wkid 102038 = world from space
if (wkid != 102038)
{
await QueuedTask.Run(() =>
{
ignoreToolDeactivation = true;
var sr = SpatialReferenceBuilder.CreateSpatialReference(102038);
map.SetSpatialReference(sr);
});
}
else
ignoreToolDeactivation = false;
await base.OnToolActivateAsync(active);
}
protected override Task OnToolDeactivateAsync(bool hasMapViewChanged)
{
if (ignoreToolDeactivation)
{
// dont let the tool deactivate
FrameworkApplication.SetCurrentToolAsync(this.ID);
}
return Task.CompletedTask;
}
Thanks
Narelle
Hi Karen,
I have taken a look at this, and can duplicate the behavior that you're seeing. Namely that modifying some map properties - either via some of the API calls or by modifying the CIMMap properties directly - can cause the sketch to be cancelled. In your scenario because you haven't yet started a sketch this will cause the tool to become deactivated.
Unfortunately, I don't have a workaround at this time. But can I ask you to explain your workflow as to why you are changing the map's spatial reference in the tool activation. If I understand your workflow, perhaps I can make a suggestion which will avoid the problem.
thanks
Narelle
Hi Narelle,
Thanks for your response. I'm glad that you can duplicate what I'm seeing.
In my workflow, when the tool button is clicked, the map changes to a "World from Space" (i.e., globe) projection. And then if the user clicks on the globe, the clicked point rotates to the center of the view, which also changes the map's spatial reference and therefore also deactivates the tool.
Regards,
Karen
Hi Karen,
If you have access to the tool code, can you see whether the following works for you as a possible workaround to the tool deactivating?
private bool ignoreToolDeactivation = false;
protected override async Task OnToolActivateAsync(bool active)
{
var map = MapView.Active.Map;
var wkid = map.SpatialReference.Wkid;
// wkid 102038 = world from space
if (wkid != 102038)
{
await QueuedTask.Run(() =>
{
ignoreToolDeactivation = true;
var sr = SpatialReferenceBuilder.CreateSpatialReference(102038);
map.SetSpatialReference(sr);
});
}
else
ignoreToolDeactivation = false;
await base.OnToolActivateAsync(active);
}
protected override Task OnToolDeactivateAsync(bool hasMapViewChanged)
{
if (ignoreToolDeactivation)
{
// dont let the tool deactivate
FrameworkApplication.SetCurrentToolAsync(this.ID);
}
return Task.CompletedTask;
}
Thanks
Narelle
Hi Narelle,
Thanks so much! That worked!