Select to view content in your preferred language

MapView is null

686
2
Jump to solution
07-24-2023 08:33 AM
mhudson
Occasional Contributor

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

1 Solution

Accepted Solutions
GKmieliauskas
Esri Regular Contributor

Hi,

Try code below:

await QueuedTask.Run(() =>
{
    map = MapFactory.Instance.CreateMap(new Uri(mapxPath));
});

await ProApp.Panes.CreateMapPaneAsync(map);

or

await QueuedTask.Run(async() =>
{
    map = MapFactory.Instance.CreateMap(new Uri(mapxPath));
    await ProApp.Panes.CreateMapPaneAsync(map);
});

View solution in original post

0 Kudos
2 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

Try code below:

await QueuedTask.Run(() =>
{
    map = MapFactory.Instance.CreateMap(new Uri(mapxPath));
});

await ProApp.Panes.CreateMapPaneAsync(map);

or

await QueuedTask.Run(async() =>
{
    map = MapFactory.Instance.CreateMap(new Uri(mapxPath));
    await ProApp.Panes.CreateMapPaneAsync(map);
});
0 Kudos
mhudson
Occasional Contributor

I apologize for not getting back to this sooner. Busy week!

Your simple change to the code worked. Thank you!

So it looks like I just didn't have the await in front of the ProApp call? I'll have to play around with this a little more as I actually had the exact line of code commented out but it was during some other testing for bringing a mapx file from Portal instead of from our network drive. I was running into the same issue. 

At least I have a solution that will work.

Thank you again!

0 Kudos