This is a migrated thread and some comments may be shown as answers.

How-to reset state of RadMap control?

1 Answer 143 Views
Map
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Veteran
Peter asked on 24 Jan 2020, 05:56 PM

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

 

 

1 Answer, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 29 Jan 2020, 07:47 AM

Hi Peter,

Can you tell me which are the properties that have unexpected values on load ? From your code I can see an empty locations for the geo-bounds-properties. Can you give me a picture of what happens on load ? Also you can try to isolate part of your code, for example try to reproduce the issue with a single layer that is remove and re-added to the map. This will generally help me get better understanding of the scenario.

Also I noticed a workaround for a fix we already included in our product in 2017. What is the version that you use now ? Can you try your scenario with our latest official version - R1 2020 ?

Regards,
Petar Mladenov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Map
Asked by
Peter
Top achievements
Rank 1
Veteran
Answers by
Petar Mladenov
Telerik team
Share this question
or