MapView.ZoomTo unreliable when changing viewport

06-29-2020 12:49 PM
New Contributor II

I've noticed the following issue with ZoomTo. Assume you've created a new camera object with a different viewport(height and width) and location (X, Y, Z) than the current maps' camera. Then I would expect this to never throw.

MapView view = GetMapView();

Camera newCamera = GetCameraWithUpdatedViewportAndLocation();


Assert.Equals(view.Camera.ViewportHeight, newCamera.ViewportHeight); // this will throw sometimes

Assert.Equals(view.Camera.X, newCamera.X); // this never throws

This happens irregularly but seems to happen more often when my machine is under performance stress or when the debugger is attached or when I'm setting the camera for a mapframe inside a layout. It happens with or without the duration parameter (TimeSpan) and also when using ZoomToAsync.

This is not a case where I just have to wait to the camera to change, because I've noticed the XYZ values update already with the new values and just the viewport value stay stale. I've even added code to wait until the viewpoer changes to what the newCamera is set to and that results in a thread waiting forever.

I use the viewport on the CameraUpdated event to perform some calculations in my add in. When I observe the camera in the map itself it seems like the viewport is correct but the calculations are wrong and when I step into the application I can notice the viewport is not changed.

Are there any known reasons why the ZoomTo function would not set the viewport while still setting the XYZ?

0 Kudos
0 Replies