private void DisplayMap_Load(object sender, EventArgs e) { winformsMap1.MapUnit = GeographyUnit.DecimalDegree; winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean); ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(Samples.RootDirectory + @"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); FileBitmapTileCache bitmapTileCache = new FileBitmapTileCache(); bitmapTileCache.CacheDirectory = Samples.RootDirectory + @"Data\SampleCacheTiles"; bitmapTileCache.CacheId = "World02CachedTiles"; bitmapTileCache.TileAccessMode = TileAccessMode.ReadOnly; bitmapTileCache.ImageFormat = TileImageFormat.Png; staticOverlay.TileCache = bitmapTileCache; winformsMap1.CurrentExtent = new RectangleShape(-143.4, 109.3, 116.7, -76.3); winformsMap1.Refresh(); }
private void WpfMap_Loaded(object sender, RoutedEventArgs e) { wpfMap1.MapUnit = GeographyUnit.DecimalDegree; wpfMap1.CurrentExtent = new RectangleShape(-155.733, 95.60, 104.42, -81.9); LayerOverlay worldOverlay = new LayerOverlay(); wpfMap1.Overlays.Add("WorldOverlay", worldOverlay); BackgroundLayer backgroundLayer = new BackgroundLayer(new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean)); worldOverlay.Layers.Add(backgroundLayer); ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(@"..\..\SampleData\Data\Countries02.shp"); worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1; worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; worldOverlay.Layers.Add("WorldLayer", worldLayer); // If you want to use file cache which saves images to the disk; // When loading back the same tile, we'll find from the disk first. // Turn the cache on enhance the performance a lot; // if your map image is static, we recommend to turn the cache on. // It's off by default. FileBitmapTileCache bitmapTileCache = new FileBitmapTileCache(); bitmapTileCache.CacheDirectory = @"..\..\SampleData\Data\SampleCacheTiles"; bitmapTileCache.CacheId = "World02CachedTiles"; bitmapTileCache.TileAccessMode = TileAccessMode.ReadOnly; bitmapTileCache.ImageFormat = TileImageFormat.Png; worldOverlay.TileCache = bitmapTileCache; worldOverlay.TransitionEffect = TransitionEffect.None; wpfMap1.Refresh(); }
public static void RefreshCache(this TileOverlay overlay, bool enabled, string cacheId, string cacheDirectory) { BitmapTileCache tempTileCache = overlay.TileCache as BitmapTileCache; FileBitmapTileCache newCache = null; if (enabled) { newCache = new FileBitmapTileCache(cacheDirectory, cacheId); if (overlay.MapArguments != null) { newCache.TileMatrix.BoundingBoxUnit = overlay.MapArguments.MapUnit; } } if (newCache != null) { newCache.TileMatrix.TileHeight = overlay.TileHeight; newCache.TileMatrix.TileWidth = overlay.TileWidth; } overlay.TileCache = newCache; if (!overlay.IsBase && tempTileCache != null) { Task.Factory.StartNew(cache => { BitmapTileCache removingCache = (BitmapTileCache)cache; lock (removingCache) { try { removingCache.ClearCache(); } catch { } } }, tempTileCache); } }
public static RectangleShape GetDefaultMaxExtent(GeographyUnit mapUnit) { RectangleShape maxExtent = new RectangleShape(); switch (mapUnit) { case GeographyUnit.DecimalDegree: maxExtent = new RectangleShape(-180, 90, 180, -90); break; case GeographyUnit.Meter: BitmapTileCache meterCache = new FileBitmapTileCache(); meterCache.TileMatrix.BoundingBoxUnit = GeographyUnit.Meter; meterCache.TileMatrix.BoundingBox = new RectangleShape(-1000000000, 1000000000, 1000000000, -1000000000); maxExtent = meterCache.TileMatrix.BoundingBox; break; case GeographyUnit.Feet: BitmapTileCache feetCache = new FileBitmapTileCache(); feetCache.TileMatrix.BoundingBoxUnit = GeographyUnit.Feet; feetCache.TileMatrix.BoundingBox = new RectangleShape(-1000000000, 1000000000, 1000000000, -1000000000); maxExtent = feetCache.TileMatrix.BoundingBox; break; default: break; } return(maxExtent); }
public static void OpenCacheDirectory(this TileOverlay overlay) { FileBitmapTileCache tileCache = overlay.TileCache as FileBitmapTileCache; if (tileCache != null) { if (Directory.Exists(tileCache.CacheDirectory)) { ProcessUtils.OpenPath(tileCache.CacheDirectory); } } }
public static bool CacheDirectoryExist(FileBitmapTileCache tileCache) { bool isExist = false; if (tileCache != null) { if (Directory.Exists(tileCache.CacheDirectory)) { isExist = true; } } return(isExist); }
/// <summary> /// Constructor of WorldMapKitMapOverlay class. /// </summary> /// <param name="webProxy">Proxy to use for the WMS Server.</param> /// <param name="clientId">The clientId for the WMS Server.</param> /// <param name="privateKey">The privateKey for the WMS Server.</param> public WorldMapKitMapOverlay(WebProxy webProxy, string clientId, string privateKey) : base() { wktLayer = new FastWorldMapKitRasterLayer(clientId, privateKey); wktLayer.SendingWebRequest += new EventHandler <SendingWebRequestEventArgs>(osmLayer_SendingWebRequest); wktLayer.SentWebRequest += new EventHandler <SentWebRequestEventArgs>(osmLayer_SentWebRequest); wktLayer.TimeoutInSecond = 10; wktLayer.TileCache = null; TileCache = new FileBitmapTileCache(GetTemporaryFolder(), GetDefaultCacheId()); TileWidth = defaultTileWidth; TileHeight = defaultTileHeight; DrawingExceptionMode = DrawingExceptionMode.DrawException; IsBase = true; Attribution = "© ThinkGeo © OpenStreetMap contributors"; }
private static FileBitmapTileCache GetTileCache(TileOverlay overlay, string cacheDirectory, string cacheId) { FileBitmapTileCache newCache = new FileBitmapTileCache(cacheDirectory, cacheId); if (overlay.MapArguments != null) { newCache.TileMatrix.BoundingBoxUnit = overlay.MapArguments.MapUnit; } if (newCache != null) { newCache.TileMatrix.TileHeight = overlay.TileHeight; newCache.TileMatrix.TileWidth = overlay.TileWidth; } return(newCache); }
public static void RefreshCache(this TileOverlay overlay, bool enabled) { BingMapsOverlay bingOverlay = overlay as BingMapsOverlay; WorldMapKitMapOverlay wmkOverlay = overlay as WorldMapKitMapOverlay; OpenStreetMapOverlay osmOverlay = overlay as OpenStreetMapOverlay; string cacheId = string.Empty; string cacheFolder = string.Empty; bool needRefresh = overlay.TileCache == null; FileBitmapTileCache tileCache = null; if (bingOverlay != null) { cacheId = bingOverlay.MapType.ToString(); cacheFolder = Path.Combine(TemporaryPath, "BingMap"); bingOverlay.TileCache = null; needRefresh = true; if (enabled) { tileCache = GetTileCache(overlay, cacheFolder, cacheId); } bingOverlay.TileCache = tileCache; overlay.TileCache = tileCache; } else if (wmkOverlay != null) { //cacheId = wmkOverlay.Projection.ToString(); cacheId = GetDefaultCacheId(wmkOverlay.LayerType, wmkOverlay.Projection, wmkOverlay.MapType); string layerType = wmkOverlay.LayerType.ToString(); if (layerType == Layers.WorldMapKitLayerType.Default.ToString()) { layerType = Layers.WorldMapKitLayerType.OSMWorldMapKitLayer.ToString(); } cacheFolder = Path.Combine(TemporaryPath, layerType); needRefresh = true; if (enabled) { tileCache = GetTileCache(overlay, cacheFolder, cacheId); } overlay.TileCache = tileCache; } else if (osmOverlay != null) { cacheId = "SphereMercator"; cacheFolder = Path.Combine(TemporaryPath, "OpenStreetMap"); osmOverlay.TileCache = null; if (enabled) { tileCache = GetTileCache(overlay, cacheFolder, cacheId); } osmOverlay.TileCache = tileCache; overlay.TileCache = tileCache; } else { cacheId = Guid.NewGuid().ToString(); cacheFolder = TemporaryPath; if (enabled) { tileCache = GetTileCache(overlay, cacheFolder, cacheId); } overlay.TileCache = tileCache; needRefresh = true; } if (needRefresh) { BitmapTileCache tempTileCache = overlay.TileCache as BitmapTileCache; if (!overlay.IsBase && tempTileCache != null) { Task.Factory.StartNew(cache => { BitmapTileCache removingCache = (BitmapTileCache)cache; lock (removingCache) { try { removingCache.ClearCache(); } catch { } } }, tempTileCache); } } }