I have simple ArcObjects extension I'm porting over to Pro as an Add-In. I have it almost working, but my MapView is always coming back as null when I'm trying to zoom down to a section.
General idea of the tool: user enters in a section, township, and range or a parcel id(PID) number. It loads the parcel fabric from a mapx file I have sitting on a network drive(I am also testing loading the mapx file from Portal). The tool then zooms to the section or PID based on the user input.
Currently, it'll load the mapx file, select the section, but then tell me the MapView is null and will not zoom.
Here is a snippet of my code:
await QueuedTask.Run(() =>
{
map = MapFactory.Instance.CreateMap(new Uri(mapxPath));
ProApp.Panes.CreateMapPaneAsync(map);
});
await QueuedTask.Run(() =>
{
FeatureLayer mapLayer = GetMapLayer(map, "PLSS Section");
QueryFilter queryFilter = new QueryFilter { WhereClause = $"Name = '{sectionNumber}-{townshipNumber}-{rangeNumber}'" };
using (Selection sectionSelection = mapLayer.Select(queryFilter, SelectionCombinationMethod.New))
{
ZoomToSelected();
}
});
The GetMapLayer is a separate function I have and does the obvious, gets the Map Layer called PLSS Section, so I can query it for the correct section.
Any help would be greatly appreciated. I'm guessing I'm overlooking something very simple. If I can't get it to work, then I'll create a separate Add-in to do the zooming down to the section or PID once the map is loaded but I'm hopeful I can get it to work with a little help from the community.
Thanks,
Matt