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:
This is after the search, with the selected feature highlighted.
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...
Solved! Go to Solution.
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);
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);
Thanks much, that seems to have done the trick. 🙂