We are using the GetGeographicFromZoom(xamGeoMap.ActualWindowRect) to get the current geographic view and zoom and then persist this view.
When the user re-opens the Map, we need to Zoom back to the original view the user had.
To do this we use:
xamGeoMap.WindowRect = xamGeoMap.GetZoomFromGeographic(Settings.WindowRect); // Settings.WindowsRect being the rect we got from GetGeographicFromZoom as above.
This works to a certain extend, except that the Zoom is slightly zoomed out further than saved.
The map is center, but slightly zoomed out further than when we saved the current rect.
Are we approaching this incorrectly? Are we using the correct methods to persist and restore the viewport on the map?
Please advise urgently...
Thank you for following up. I would assume you are handling this as expected. However since the zoom is slightly different I would imagine the Rect also differs before and after persisting and loading. I would try using the GetZoomRectFromGeoRect method to identify the changes to the Rect and make adjustments accordingly. In addition you may want to try calling the map's UseFixAspectZoom property to see if it helps.
Please provide a sample that demonstrates the issue and I'll investigate this further with you.
Let me know if you a have any questions.
I have tried your suggestion, but when re-applying the saved rect using the above suggestion, then map is still zoomed out a little more than the rect I saved from using the GetGeographicFromZoom(xamGeoMap.ActualWindowRect) method.
UseFixedAspectZoom method had no affect.
I'm sure that someone must know how to persist and reload a certain area and zoom?? Has no one done this before?
Thank you for following up.
I very much would like to debug your application. Please provide your code or a sample that reproduces the behavior and I'll investigate this with my team.
I can also confirm that this is an issue. You can even see it happen in the IG samples application in the favorites example you describe. Zoom to a location and click add to favorite and then you'll see that the map immediately zooms out a bit due to the recently added favorite becoming selected in the list.
I am also facing this issue as I need to save the current windowRect and re-apply it when users re-enter this map view. I haven't found a great workaround yet so any help would be appreciated.
I attached sample app that saves and loads view parameters of the GeoMap using the ActualWindowRect property. Note that the Map automatically recalculates any value set to WindowRect property such that the center of saved map view is always displayed in plot area of the map. For example, if you zoom the map to such that all boarders of France are visible, save the map view, resize the map (or app window), load map view, then the map will adjust its internal WindowRect such that center of France is visible. This behavior cover most use cases for our customers. Please submit feature request if you would like to have other behaviors for resolving WindowRect of the GeoMap.
Now try the following: This works if your map control size does not change.
Save the settings, then resize your window to be smaller or larger than when you saved the setting.
NOW reload using the above approach and you will see the map does not center where you saved it.
Still no joy....
It's anticipated that resizing the component will cause a saved window rect to not display the correct position. A window rect is aspect ratio dependent, and if you have modified the aspect ratio in the interim, it wont restore the correct view, unless corrected for the aspect ratio change.
The simplest resolution is to store the geographic coordinates around the center point and restore those, but, as I see, you were having an issue with that. Looking into it, I believe this is actually due to a bug in converting back from geographic coordinates to window positioning whereby some additional coercion is being performed that doesn't look necessary to me, or warranted. We'll look into this further and likely write it up as a bug.
In the meantime, you should be able to use this workaround to avoid the extra coercion being performed on the provided geographic rectangle:
Hope this helps!