Stephane,
I have modified our HowDoI sample to apply your method, it works for me, the cache images didn’t be deleted when I laugh application next time, you can see my sample code below.
private void DisplayMap_Load(object sender, EventArgs e)
{
winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);
ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(@"..\..\SampleData\Data\Countries02.shp");
worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;
worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
LayerOverlay staticOverlay = new LayerOverlay();
staticOverlay.Layers.Add("WorldLayer", worldLayer);
winformsMap1.Overlays.Add(staticOverlay);
ApplyCacheOverlay(staticOverlay);
winformsMap1.CurrentExtent = new RectangleShape(-143.4, 109.3, 116.7, -76.3);
winformsMap1.Refresh();
}
And the code for calculate scale is below which is ExtentHelper.GetScale method:
public static double GetScale(RectangleShape worldExtent, float screenWidth, GeographyUnit worldExtentUnit, float dpi)
{
double scale = 0;
if (worldExtentUnit == GeographyUnit.DecimalDegree)
{
scale = worldExtent.Width * inchPerDecimalDegree * dpi / screenWidth;
}
else
{
DistanceUnit distanceUnit = Conversion.ConvertGeographyUnitToDistanceUnit(worldExtentUnit);
double distance = Conversion.ConvertMeasureUnits(worldExtent.Width, distanceUnit, DistanceUnit.Meter);
double screenWidthInMeter = screenWidth * inchToMeter / dpi;
scale = distance / screenWidthInMeter;
}
return scale;
}
Thanks,
James