Select to view content in your preferred language

MapView.Active.Map not showing the actually active map?

347
2
Jump to solution
03-04-2025 12:20 PM
RogerAsbury
Frequent Contributor

I have a form that lets people select a feature, and the map zooms to that feature. The basic code behind that is:

 

// Make the selection the active PAN
PropertyInspectorDockPaneViewModel.Instance.PAN = selection;

// Knowing the PAN, clear all other highlights, highlight selected PAN and zoom in.
var layer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().Where(fl => fl.Name.Contains("Parcels")).FirstOrDefault();
QueuedTask.Run(layer.ClearSelection);
QueryFilter qf = new QueryFilter
{
    WhereClause = $@"PAN = {selection}"
};
QueuedTask.Run(() =>
{
    var mySelect = layer.Select(qf);
    MapView.Active.ZoomToSelected();
});

 

This works as expected, with the map in ArcGIS Pro zooming to and selecting that feature. However, once that is displayed, I have an option that creates a new view, and it should take that map and place it in the view. But it seems to be looking at some other section of the map. The code for creating that portion of the view is below:

 

// The map to add to this layout is the current map.
Map currMap = MapView.Active.Map;

// Build a map frame geometry and envelope
Coordinate2D ur = new Coordinate2D(8.0, 9.75);
Coordinate2D ll = new Coordinate2D(.5, 6);
Envelope mapEnv = EnvelopeBuilderEx.CreateEnvelope(ur, ll);

// Create the map frame and add it to the layout.
MapFrame newMapFrame = ElementFactory.Instance.CreateMapFrameElement(newLayout, mapEnv, currMap);
newMapFrame.SetName("Selected Area");
Camera camera = newMapFrame.Camera;
camera.Scale = 850;
newMapFrame.SetCamera(camera);

 

I'm not sure why that would happen. Below are images of the results:
aftersearcg.png

 

This is after the search, with the selected feature highlighted.

afternewview.png

 

This is after creating the new view, showing a different area of the map, with no feature highlighted. 

I suspect I've made some basic error, but I'm not sure what it is. Any help would be greatly appreciated.

Edit to add: If I click the Zoom To Map View button, as shown below, it knows what the view should be...
itknows.png

 

--
Roger Asbury
Analyst/Programmer - Fairbanks North Star Borough
Tags (3)
0 Kudos
1 Solution

Accepted Solutions
UmaHarano
Esri Regular Contributor

Try to link the MapFrame's camera to the active map view's camera -  Something like this:

Camera camera = MapView.Active.Camera;
newMapFrame.SetCamera(camera);

View solution in original post

2 Replies
UmaHarano
Esri Regular Contributor

Try to link the MapFrame's camera to the active map view's camera -  Something like this:

Camera camera = MapView.Active.Camera;
newMapFrame.SetCamera(camera);

RogerAsbury
Frequent Contributor

Thanks much, that seems to have done the trick. 🙂

--
Roger Asbury
Analyst/Programmer - Fairbanks North Star Borough
0 Kudos