Our application has to display various different map background layers. We use both MercatorProjection and EPSG900913Projection depending on which map we are displaying. Furthermore we use EPSG900913Projection to display data from an image file, using a custom provider derived from UriImageProvider. For this scenario we need to be able to set a maximum zoom level of 30. When switching between different map backgrounds we try to reset the state of the map control. These are the steps we take to try and do this:
//Workaround for modern client crash when disposing telerik control (switching between maps)
if (RadMap?.Items?.Count > 0)
{
foreach (var radMapItem in RadMap.Items)
{
var visualizationLayer = radMapItem as VisualizationLayer;
visualizationLayer?.Items?.Clear();
}
}
DetachRadMapHandlers();
DetachViewModelHandlers(_viewModel);
DisposeMapLayers();
// Reset state of RadMap
RadMap.ItemsSource = null;
foreach (var provider in RadMap.Providers)
{
provider.Dispose();
}
RadMap.Provider = null;
RadMap.Providers.RemoveAll();;
// if we're re-using this control we must change the min/max zoom before changing spatial reference
RadMap.MinZoomLevel = MapConstants.DefaultMapMinZoomLevel;
RadMap.MaxZoomLevel = MapConstants.DefaultMapMaxZoomLevel;
_defaultMinZoomLevel = MapConstants.DefaultMapMinZoomLevel;
_defaultMaxZoomLevel = MapConstants.DefaultMapMaxZoomLevel;
// we need to set the zoom level to a value in the allowable zoom range
// before assigning another background
RadMap.ZoomLevel = MapConstants.DefaultMapMinZoomLevel;
RadMap.SpatialReference = new MercatorProjection();
MiniMap.SpatialReference = new MercatorProjection();
RadMap.GeoBounds = new LocationRect();
RadMap.Center = new Location();
RadMap.GeoBoundsNW = Location.Empty;
RadMap.GeoBoundsSE = Location.Empty;
Unfortunately this doesn't always seem to work. In particular I notice that this does not set the GeographicalBounds back the the initial state (I don't know if this is significant). It won't be easy to create a sample app to try and isolate this problem but if you have any suggestions on how better to restore the map control to it's initial state I'd appreciate it.
Thanks
Pete