# FileBitmapTileCache caching or using bad tiles

**URL:** <https://community.thinkgeo.com/t/filebitmaptilecache-caching-or-using-bad-tiles/2886>\
**Category:** WPF\
**Created:** [November 26, 2010, 4:12pm UTC](https://community.thinkgeo.com/t/filebitmaptilecache-caching-or-using-bad-tiles/2886 "2010-11-26T16:12:30Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Klaus3](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/k/e5b9ba/32.png) [@Klaus3](https://community.thinkgeo.com/u/Klaus3)\
**Post date:** [November 26, 2010, 4:12pm UTC](https://community.thinkgeo.com/t/filebitmaptilecache-caching-or-using-bad-tiles/2886/1 "2010-11-26T16:12:30Z")

</div>

Couple&nbsp;of&nbsp;questions,&nbsp;which&nbsp;I&nbsp;need&nbsp;answers&nbsp;as&nbsp;soon&nbsp;as&nbsp;possible,&nbsp;please.

1.&nbsp;What&nbsp;happens&nbsp;if&nbsp;TileOverlay&nbsp;is&nbsp;unable&nbsp;to&nbsp;write&nbsp;to&nbsp;its&nbsp;cache.&nbsp;&nbsp;Does&nbsp;it&nbsp;run&nbsp;into&nbsp;a&nbsp;problem&nbsp;rendering&nbsp;rest&nbsp;of&nbsp;the&nbsp;layer?&nbsp;&nbsp;In&nbsp;other&nbsp;words,&nbsp;what&nbsp;will&nbsp;prevent&nbsp;DrawCore&nbsp;of&nbsp;a&nbsp;layer&nbsp;from&nbsp;being&nbsp;called?

2.&nbsp;Is&nbsp;it&nbsp;possible&nbsp;to&nbsp;prevent&nbsp;FileBitmapTileCache&nbsp;from&nbsp;caching&nbsp;bad&nbsp;tiles&nbsp;i.e&nbsp;tiles&nbsp;with&nbsp;a&nbsp;size&nbsp;less&nbsp;than&nbsp;a&nbsp;certain&nbsp;threshold,&nbsp;say&nbsp;2K,&nbsp;and&nbsp;for&nbsp;LayerOverlay&nbsp;not&nbsp;to&nbsp;use&nbsp;such&nbsp;bad&nbsp;tiles?

&nbsp;TIA.

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [November 28, 2010, 10:56pm UTC](https://community.thinkgeo.com/t/filebitmaptilecache-caching-or-using-bad-tiles/2886/2 "2010-11-28T22:56:20Z")

</div>

Hi&nbsp;Klaus,

&nbsp;

1.&nbsp;When&nbsp;FileBitmapTileCache&nbsp;is&nbsp;unable&nbsp;to&nbsp;save&nbsp;image&nbsp;files&nbsp;(like&nbsp;when&nbsp;its&nbsp;CacheDirectory

is&nbsp;set&nbsp;to&nbsp;an&nbsp;unauthorized&nbsp;folder),&nbsp;the&nbsp;following&nbsp;drawing&nbsp;procedure&nbsp;will&nbsp;fail&nbsp;too.

This&nbsp;is&nbsp;because&nbsp;when&nbsp;we&nbsp;are&nbsp;using&nbsp;caches&nbsp;in&nbsp;a&nbsp;TileOverlay,&nbsp;the&nbsp;TileOverlay&nbsp;saves&nbsp;the&nbsp;drawing&nbsp;result&nbsp;to&nbsp;image&nbsp;files,&nbsp;then&nbsp;it&nbsp;loads&nbsp;the&nbsp;image&nbsp;files.&nbsp;So&nbsp;if&nbsp;the&nbsp;file&nbsp;saving&nbsp;fails,&nbsp;then&nbsp;the&nbsp;upcoming&nbsp;drawing&nbsp;will&nbsp;fail&nbsp;too.

&nbsp;

2.&nbsp;Currently&nbsp;we&nbsp;don’t&nbsp;have&nbsp;an&nbsp;existing&nbsp;solution&nbsp;for&nbsp;this,&nbsp;but&nbsp;we&nbsp;can&nbsp;accomplish&nbsp;this&nbsp;by&nbsp;inheriting&nbsp;FileBitmapTileCache&nbsp;and&nbsp;overriding&nbsp;the&nbsp;SaveTileCore&nbsp;method.&nbsp;Here&nbsp;is&nbsp;a&nbsp;sample&nbsp;that&nbsp;may&nbsp;be&nbsp;usable:

&nbsp;`public class MyFileCache : FileBitmapTileCache{    public MyFileCache(string folder)        : base(folder)    { }    protected override void SaveTileCore(ThinkGeo.MapSuite.Core.Tile tile)    {        BitmapTile bitmapTile = tile as BitmapTile;        if (bitmapTile != null)        {            using (MemoryStream stream = new MemoryStream())            {                bitmapTile.Bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);                long sizeInKB = stream.Length / 1024;                if (sizeInKB > 2)                {                    base.SaveTileCore(tile);                }            }        }    }}`

Hope&nbsp;this&nbsp;can&nbsp;be&nbsp;of&nbsp;help.

&nbsp;

Regards,

Tsui

---

<div class="post-metadata">

**Author:** ![Klaus3](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/k/e5b9ba/32.png) [@Klaus3](https://community.thinkgeo.com/u/Klaus3)\
**Post date:** [November 29, 2010, 8:19am UTC](https://community.thinkgeo.com/t/filebitmaptilecache-caching-or-using-bad-tiles/2886/3 "2010-11-29T08:19:51Z")

</div>

Tsui,&nbsp;&nbsp;  
  
  
  
On&nbsp;2,&nbsp;will&nbsp;try&nbsp;proposed&nbsp;solution,&nbsp;thanks.&nbsp;  
  
  
  
On&nbsp;1,&nbsp;you&nbsp;guys&nbsp;should&nbsp;look&nbsp;into&nbsp;the&nbsp;draw&nbsp;sequence&nbsp;after&nbsp;creating&nbsp;the&nbsp;tile&nbsp;bitmap.&nbsp;&nbsp;Why&nbsp;not&nbsp;use&nbsp;created&nbsp;bitmap&nbsp;to&nbsp;render&nbsp;to&nbsp;screen&nbsp;then&nbsp;save&nbsp;to&nbsp;disk&nbsp;after.&nbsp;&nbsp;Sounds&nbsp;like&nbsp;drawing&nbsp;first,&nbsp;then&nbsp;saving&nbsp;later&nbsp;will&nbsp;improve&nbsp;perceived&nbsp;performance&nbsp;a&nbsp;bit&nbsp;as&nbsp;IO&nbsp;access&nbsp;has&nbsp;some&nbsp;small&nbsp;cost.

Also,&nbsp;on&nbsp;a&nbsp;related&nbsp;note,&nbsp;&nbsp;TileOverlay&nbsp;perceived&nbsp;performance&nbsp;can&nbsp;be&nbsp;further&nbsp;improved&nbsp;by&nbsp;creating&nbsp;and&nbsp;loading&nbsp;tiles&nbsp;that&nbsp;are&nbsp;within&nbsp;visible&nbsp;extent&nbsp;before&nbsp;creating&nbsp;and&nbsp;loading&nbsp;tiles&nbsp;for&nbsp;buffer&nbsp;zone.&nbsp;

Thanks&nbsp;again.

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [November 29, 2010, 8:22pm UTC](https://community.thinkgeo.com/t/filebitmaptilecache-caching-or-using-bad-tiles/2886/4 "2010-11-29T20:22:31Z")

</div>

Hi&nbsp;Klaus,&nbsp;  
&nbsp;&nbsp;  
&nbsp;We&nbsp;made&nbsp;a&nbsp;little&nbsp;change&nbsp;in&nbsp;the&nbsp;Tile&nbsp;class,&nbsp;now&nbsp;it&nbsp;draws&nbsp;itself&nbsp;even&nbsp;if&nbsp;the&nbsp;TileCache&nbsp;fails&nbsp;to&nbsp;save&nbsp;images.&nbsp;  
&nbsp;Now,&nbsp;if&nbsp;the&nbsp;TileCache&nbsp;property&nbsp;of&nbsp;a&nbsp;TileOverlay&nbsp;is&nbsp;set&nbsp;to&nbsp;an&nbsp;unauthorized&nbsp;path,&nbsp;the&nbsp;behavior&nbsp;of&nbsp;a&nbsp;tile&nbsp;will&nbsp;be&nbsp;like&nbsp;this:&nbsp;  
&nbsp;It&nbsp;tries&nbsp;to&nbsp;use&nbsp;the&nbsp;TileCache&nbsp;to&nbsp;get&nbsp;saved&nbsp;image&nbsp;file,&nbsp;this&nbsp;fails.&nbsp;  
&nbsp;Then&nbsp;it&nbsp;draws&nbsp;itself&nbsp;and&nbsp;tries&nbsp;to&nbsp;save&nbsp;the&nbsp;drawing&nbsp;result&nbsp;to&nbsp;disk,&nbsp;the&nbsp;saving&nbsp;part&nbsp;fails,&nbsp;but&nbsp;we&nbsp;handled&nbsp;the&nbsp;exception&nbsp;here.&nbsp;  
&nbsp;Please&nbsp;download&nbsp;the&nbsp;next&nbsp;package&nbsp;(any&nbsp;version&nbsp;after&nbsp;4.5.29.0)&nbsp;from&nbsp;help&nbsp;desk&nbsp;and&nbsp;try&nbsp;again.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards,&nbsp;  
&nbsp;Tsui

---

<div class="post-metadata">

**Author:** ![Klaus3](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/k/e5b9ba/32.png) [@Klaus3](https://community.thinkgeo.com/u/Klaus3)\
**Post date:** [November 30, 2010, 10:40am UTC](https://community.thinkgeo.com/t/filebitmaptilecache-caching-or-using-bad-tiles/2886/5 "2010-11-30T10:40:31Z")

</div>

Good&nbsp;stuff&nbsp;Tsui,&nbsp;thanks&nbsp;but&nbsp;I&nbsp;am&nbsp;not&nbsp;observing&nbsp;expected&nbsp;behavior.&nbsp;&nbsp;I&nbsp;tried&nbsp;setting&nbsp;cache&nbsp;directory&nbsp;to&nbsp;one&nbsp;that&nbsp;has&nbsp;no&nbsp;read/write&nbsp;permissions&nbsp;and&nbsp;I&nbsp;do&nbsp;not&nbsp;see&nbsp;tiles.&nbsp;&nbsp;If&nbsp;I&nbsp;do&nbsp;not&nbsp;turn&nbsp;on&nbsp;cache,&nbsp;tiles&nbsp;are&nbsp;drawn.

DLL&nbsp;versions&nbsp;I&nbsp;am&nbsp;using&nbsp;is&nbsp;4.5.30.0&nbsp;downloaded&nbsp;today.  
  
  
  
One&nbsp;more&nbsp;request&nbsp;on&nbsp;this&nbsp;subject&nbsp;of&nbsp;tile&nbsp;creation&nbsp;and&nbsp;caching:&nbsp;&nbsp;would&nbsp;it&nbsp;be&nbsp;relatively&nbsp;easy&nbsp;to&nbsp;first&nbsp;create&nbsp;tiles&nbsp;within&nbsp;the&nbsp;visible&nbsp;extent&nbsp;of&nbsp;the&nbsp;map&nbsp;before&nbsp;those&nbsp;in&nbsp;the&nbsp;buffer&nbsp;zone?&nbsp;&nbsp;&nbsp;This&nbsp;should&nbsp;also&nbsp;improve&nbsp;on&nbsp;perceived&nbsp;performance&nbsp;especially&nbsp;if&nbsp;the&nbsp;TileBuffer&nbsp;property&nbsp;is&nbsp;set&nbsp;to&nbsp;a&nbsp;value&nbsp;greater&nbsp;than&nbsp;0.&nbsp;&nbsp;&nbsp;  
  
  
  
My&nbsp;status&nbsp;bar&nbsp;tracks&nbsp;tile&nbsp;drawing&nbsp;progress&nbsp;and&nbsp;what&nbsp;I&nbsp;am&nbsp;noticing&nbsp;is&nbsp;that&nbsp;there&nbsp;is&nbsp;progress,&nbsp;probably&nbsp;from&nbsp;the&nbsp;buffer&nbsp;tiles&nbsp;being&nbsp;created,&nbsp;even&nbsp;though&nbsp;I&nbsp;do&nbsp;not&nbsp;see&nbsp;new&nbsp;tiles&nbsp;coming&nbsp;in&nbsp;on&nbsp;the&nbsp;screen.&nbsp;&nbsp;&nbsp;

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [November 30, 2010, 9:34pm UTC](https://community.thinkgeo.com/t/filebitmaptilecache-caching-or-using-bad-tiles/2886/6 "2010-11-30T21:34:02Z")

</div>

Hi&nbsp;Klaus,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Were&nbsp;you&nbsp;using&nbsp;single&nbsp;tile&nbsp;mode&nbsp;when&nbsp;you&nbsp;observed&nbsp;the&nbsp;unexpected&nbsp;behavior?&nbsp;If&nbsp;that&nbsp;is&nbsp;the&nbsp;case,&nbsp;then&nbsp;it’s&nbsp;our&nbsp;fault.&nbsp;We&nbsp;missed&nbsp;the&nbsp;code&nbsp;that&nbsp;saves&nbsp;cache&nbsp;in&nbsp;single&nbsp;tile&nbsp;mode.&nbsp;Please&nbsp;try&nbsp;the&nbsp;next&nbsp;package&nbsp;and&nbsp;try&nbsp;again.&nbsp;  
&nbsp;&nbsp;  
&nbsp;We’ll&nbsp;get&nbsp;back&nbsp;to&nbsp;you&nbsp;later&nbsp;on&nbsp;the&nbsp;buffer&nbsp;zone&nbsp;issue.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards,&nbsp;  
&nbsp;Tsui

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [December 1, 2010, 12:24am UTC](https://community.thinkgeo.com/t/filebitmaptilecache-caching-or-using-bad-tiles/2886/7 "2010-12-01T00:24:35Z")

</div>

&nbsp;Hi&nbsp;Klaus,

&nbsp;

About&nbsp;the&nbsp;buffer:

What&nbsp;you&nbsp;described&nbsp;is&nbsp;just&nbsp;what&nbsp;we&nbsp;are&nbsp;doing.&nbsp;When&nbsp;the&nbsp;TileBuffer&nbsp;is&nbsp;greater&nbsp;than&nbsp;0,&nbsp;we&nbsp;do&nbsp;draw&nbsp;the&nbsp;visible&nbsp;tiles&nbsp;first&nbsp;and&nbsp;draw&nbsp;the&nbsp;buffer&nbsp;zone&nbsp;later.

&nbsp;

About&nbsp;the&nbsp;drawing&nbsp;progress:

The&nbsp;tiles&nbsp;in&nbsp;buffer&nbsp;zone&nbsp;are&nbsp;counted&nbsp;when&nbsp;we&nbsp;calculate&nbsp;the&nbsp;percentage.&nbsp;If&nbsp;you&nbsp;don’t&nbsp;want&nbsp;the&nbsp;buffer&nbsp;tiles&nbsp;to&nbsp;affect&nbsp;the&nbsp;percentage,&nbsp;there&nbsp;is&nbsp;a&nbsp;little&nbsp;work-around&nbsp;that&nbsp;may&nbsp;help:

&nbsp;`int previousPercentage = 0;private void tileOverlay_DrawTilesProgressChanged(object sender, DrawTilesProgressChangedTileOverlayEventArgs e){    if (Math.Abs(e.ProgressPercentage - previousPercentage) >= 5 || e.ProgressPercentage == 100 && previousPercentage != 100)    {        previousPercentage = e.ProgressPercentage;        TileOverlay tileOverlay = (TileOverlay)sender;        Canvas drawingCanvas = (Canvas)tileOverlay.OverlayCanvas.Children[0];        var tilesInVisibleExtent = drawingCanvas.Children                                                .OfType<ThinkGeo.MapSuite.WpfDesktopEdition.Tile>()                                                .Where(tile => tileOverlay.MapArguments.CurrentExtent.Contains(tile.TargetExtent));        var tilesLoaded = tilesInVisibleExtent.Where(tile => tile.IsOpened);        double percentage = tilesLoaded.Count() * 100 / tilesInVisibleExtent.Count();        //update the progress bar    }}`

Just&nbsp;hook&nbsp;the&nbsp;code&nbsp;above&nbsp;to&nbsp;the&nbsp;DrawTilesProgressChanged&nbsp;event.&nbsp;The&nbsp;conditional&nbsp;check&nbsp;at&nbsp;the&nbsp;beginning&nbsp;is&nbsp;added&nbsp;because&nbsp;sometimes&nbsp;this&nbsp;event&nbsp;happens&nbsp;too&nbsp;frequently&nbsp;that&nbsp;the&nbsp;UI&nbsp;thread&nbsp;may&nbsp;get&nbsp;blocked.

&nbsp;

Regards,

Tsui

---

<div class="post-metadata">

**Author:** ![Klaus3](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/k/e5b9ba/32.png) [@Klaus3](https://community.thinkgeo.com/u/Klaus3)\
**Post date:** [December 1, 2010, 10:41am UTC](https://community.thinkgeo.com/t/filebitmaptilecache-caching-or-using-bad-tiles/2886/8 "2010-12-01T10:41:39Z")

</div>

&nbsp;Tsui,

Suggested&nbsp;solution&nbsp;for&nbsp;draw&nbsp;draw&nbsp;progress&nbsp;works&nbsp;great,&nbsp;thank&nbsp;you.&nbsp;&nbsp;&nbsp;As&nbsp;for&nbsp;buffer&nbsp;zone,&nbsp;it&nbsp;this&nbsp;is&nbsp;what&nbsp;you&nbsp;guys&nbsp;are&nbsp;currently&nbsp;doing,&nbsp;that&nbsp;is&nbsp;fine.&nbsp;I&nbsp;have&nbsp;a&nbsp;related&nbsp;question&nbsp;based&nbsp;on&nbsp;a&nbsp;quick&nbsp;test&nbsp;I&nbsp;performed&nbsp;with&nbsp;TileBuffer&nbsp;set&nbsp;to&nbsp;0&nbsp;and&nbsp;TileType&nbsp;set&nbsp;to&nbsp;Multiple.&nbsp;&nbsp;This&nbsp;test&nbsp;is&nbsp;captured&nbsp;in&nbsp;attached&nbsp;sample:

If&nbsp;TileBuffer&nbsp;on&nbsp;LayerOverlay&nbsp;is&nbsp;set&nbsp;to&nbsp;0&nbsp;there&nbsp;is&nbsp;usually&nbsp;many&nbsp;more&nbsp;tiles&nbsp;that&nbsp;what&nbsp;is&nbsp;required&nbsp;for&nbsp;visible&nbsp;extent&nbsp;regardless&nbsp;of&nbsp;TransitionEffect&nbsp;setting?&nbsp;&nbsp;&nbsp;For&nbsp;example,&nbsp;at&nbsp;zoom&nbsp;level&nbsp;0,&nbsp;we&nbsp;require&nbsp;6&nbsp;tiles&nbsp;for&nbsp;visible&nbsp;extent&nbsp;but&nbsp;total&nbsp;number&nbsp;of&nbsp;tiles&nbsp;in&nbsp;overlay&nbsp;is&nbsp;8.&nbsp;&nbsp;At&nbsp;zoom&nbsp;level&nbsp;1,&nbsp;we&nbsp;require&nbsp;6&nbsp;tiles&nbsp;for&nbsp;display&nbsp;but&nbsp;total&nbsp;number&nbsp;is&nbsp;20,&nbsp;etc.&nbsp;&nbsp;This&nbsp;does&nbsp;not&nbsp;seem&nbsp;to&nbsp;affect&nbsp;progress&nbsp;percentage&nbsp;based&nbsp;on&nbsp;logic&nbsp;your&nbsp;proposed&nbsp;but&nbsp;just&nbsp;out&nbsp;of&nbsp;curiosity&nbsp;what&nbsp;these&nbsp;additional&nbsp;tiles&nbsp;for?&nbsp;&nbsp;

Back&nbsp;to&nbsp;original&nbsp;problem:&nbsp;&nbsp;&nbsp;This&nbsp;is&nbsp;still&nbsp;an&nbsp;issue.&nbsp;&nbsp;Maybe&nbsp;it&nbsp;is&nbsp;specific&nbsp;to&nbsp;the&nbsp;WorldMapKitRenderLayer.&nbsp;&nbsp;Run&nbsp;attached&nbsp;sample&nbsp;with&nbsp;your&nbsp;windows&nbsp;user&nbsp;denied&nbsp;read&nbsp;or&nbsp;write&nbsp;permission&nbsp;to&nbsp;cache&nbsp;directory&nbsp;and&nbsp;you&nbsp;will&nbsp;see&nbsp;that&nbsp;layer&nbsp;does&nbsp;not&nbsp;draw.

Please&nbsp;let&nbsp;me&nbsp;know,&nbsp;thanks.

K

---

<div class="post-metadata">

**Author:** ![Klaus3](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/k/e5b9ba/32.png) [@Klaus3](https://community.thinkgeo.com/u/Klaus3)\
**Post date:** [December 1, 2010, 11:04am UTC](https://community.thinkgeo.com/t/filebitmaptilecache-caching-or-using-bad-tiles/2886/9 "2010-12-01T11:04:10Z")

</div>

Tsui,&nbsp;I&nbsp;cannot&nbsp;upload&nbsp;zipped&nbsp;sample&nbsp;which&nbsp;is&nbsp;31Kb&nbsp;in&nbsp;size!

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [December 1, 2010, 11:08pm UTC](https://community.thinkgeo.com/t/filebitmaptilecache-caching-or-using-bad-tiles/2886/10 "2010-12-01T23:08:14Z")

</div>

&nbsp;Hi&nbsp;Klaus,

&nbsp;

Please&nbsp;refer&nbsp;the&nbsp;attachment&nbsp;instruction&nbsp;

([gis.thinkgeo.com/Support/Dis...fault.aspx](http://gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/39/aft/7657/afv/topic/Default.aspx))&nbsp;and&nbsp;try&nbsp;again.

If&nbsp;it&nbsp;still&nbsp;won’t&nbsp;work,&nbsp;please&nbsp;send&nbsp;the&nbsp;sample&nbsp;to&nbsp;[forumsupport@thinkgeo.com](mailto:forumsupport@thinkgeo.com)

&nbsp;

Looking&nbsp;forward&nbsp;to&nbsp;your&nbsp;sample.

&nbsp;

Regards,

Tsui

---

<div class="post-metadata">

**Author:** ![Klaus3](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/k/e5b9ba/32.png) [@Klaus3](https://community.thinkgeo.com/u/Klaus3)\
**Post date:** [December 2, 2010, 9:04am UTC](https://community.thinkgeo.com/t/filebitmaptilecache-caching-or-using-bad-tiles/2886/11 "2010-12-02T09:04:27Z")

</div>

Oops,&nbsp;my&nbsp;mistake.&nbsp;&nbsp;I&nbsp;was&nbsp;uploading&nbsp;wrong&nbsp;zip&nbsp;file.&nbsp;&nbsp;&nbsp;&nbsp;Run&nbsp;sample&nbsp;with&nbsp;security&nbsp;permissions&nbsp;on&nbsp;your&nbsp;cache&nbsp;directory&nbsp;set&nbsp;to&nbsp;deny&nbsp;all&nbsp;and&nbsp;layer&nbsp;will&nbsp;not&nbsp;draw.

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [December 2, 2010, 7:59pm UTC](https://community.thinkgeo.com/t/filebitmaptilecache-caching-or-using-bad-tiles/2886/12 "2010-12-02T19:59:18Z")

</div>

&nbsp;Hi&nbsp;Klaus,

&nbsp;  
I&nbsp;Copied&nbsp;all&nbsp;the&nbsp;world&nbsp;map&nbsp;kit&nbsp;data&nbsp;to&nbsp;my&nbsp;local&nbsp;machine,&nbsp;then&nbsp;modified&nbsp;the&nbsp;CreateWMKOverlayFromLocal&nbsp;method&nbsp;in&nbsp;the&nbsp;sample&nbsp;a&nbsp;little&nbsp;bit&nbsp;like&nbsp;this:  
&nbsp;  
`LayerOverlay CreateWMKOverlayFromLocal(){    var worldMapKitRenderLayer = new WorldMapKitRenderLayer(@"C:\WorldMapKitData");    var layers = GetBaseMapSymbolLayers();    worldMapKitRenderLayer.LoadLayers(layers);    var overlay = new LayerOverlay();    overlay.Name = "WMK";    overlay.RenderMode = RenderMode.GdiPlus;    overlay.TileType = TileType.MultipleTile;    overlay.TileBuffer = 0;    overlay.TransitionEffect = TransitionEffect.Stretch;    // Set security permissions to your cache directory to deny everything and layer will not draw    overlay.TileCache = new FileBitmapTileCache(@"Z:\GIS\caches", "WMK") { TileAccessMode = TileAccessMode.ReadAdd };    overlay.Layers.Add(worldMapKitRenderLayer);    return overlay;}`  
&nbsp;  
The&nbsp;path&nbsp;“Z:\GIS\caches”&nbsp;doesn’t&nbsp;exist&nbsp;on&nbsp;my&nbsp;local&nbsp;machine.  
The&nbsp;sample&nbsp;worked.&nbsp;Even&nbsp;though&nbsp;no&nbsp;cache&nbsp;image&nbsp;files&nbsp;are&nbsp;saved,&nbsp;but&nbsp;the&nbsp;tiles&nbsp;are&nbsp;drawn.  
Please&nbsp;download&nbsp;the&nbsp;latest&nbsp;package&nbsp;and&nbsp;try&nbsp;again&nbsp;and&nbsp;please&nbsp;make&nbsp;sure&nbsp;the&nbsp;version&nbsp;is&nbsp;4.5.32.0&nbsp;or&nbsp;higher.  
&nbsp;  
Regards,  
Tsui

---

<div class="post-metadata">

**Author:** ![Klaus3](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/k/e5b9ba/32.png) [@Klaus3](https://community.thinkgeo.com/u/Klaus3)\
**Post date:** [December 2, 2010, 8:46pm UTC](https://community.thinkgeo.com/t/filebitmaptilecache-caching-or-using-bad-tiles/2886/13 "2010-12-02T20:46:55Z")

</div>

Tsui,&nbsp;to&nbsp;duplicate,&nbsp;try&nbsp;this:

1.&nbsp;Set&nbsp;cached&nbsp;directory&nbsp;to&nbsp;say&nbsp;c:\gis\caches&nbsp;and&nbsp;make&nbsp;sure&nbsp;this&nbsp;folder&nbsp;and&nbsp;subfolder&nbsp;"wmk"&nbsp;exists.

2.&nbsp;From&nbsp;Windows&nbsp;Explorer,&nbsp;right&nbsp;click&nbsp;on&nbsp;c:\gis\caches\wmk&nbsp;folder&nbsp;,&nbsp;select&nbsp;Properties&nbsp;|&nbsp;Security,&nbsp;then&nbsp;set&nbsp;option&nbsp;for&nbsp;Deny&nbsp;on&nbsp;Full&nbsp;control&nbsp;for&nbsp;your&nbsp;windows&nbsp;userid.&nbsp;&nbsp;&nbsp;&nbsp;In&nbsp;other&nbsp;words,&nbsp;remove&nbsp;any&nbsp;read/write&nbsp;permission&nbsp;on&nbsp;this&nbsp;folder&nbsp;for&nbsp;your&nbsp;userid.

3.&nbsp;Run&nbsp;sample&nbsp;again&nbsp;and&nbsp;observe&nbsp;that&nbsp;layer&nbsp;does&nbsp;not&nbsp;draw.&nbsp;&nbsp;I&nbsp;am&nbsp;running&nbsp;v&nbsp;4.5.32.0.

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [December 3, 2010, 4:08am UTC](https://community.thinkgeo.com/t/filebitmaptilecache-caching-or-using-bad-tiles/2886/14 "2010-12-03T04:08:56Z")

</div>

Hi&nbsp;Klaus,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;for&nbsp;your&nbsp;information,&nbsp;we&nbsp;found&nbsp;the&nbsp;bug.&nbsp;  
&nbsp;We&nbsp;only&nbsp;dealt&nbsp;with&nbsp;conditions&nbsp;that&nbsp;a&nbsp;path&nbsp;doesn’t&nbsp;exist,&nbsp;but&nbsp;did&nbsp;not&nbsp;deal&nbsp;with&nbsp;conditions&nbsp;that&nbsp;a&nbsp;path&nbsp;is&nbsp;not&nbsp;allowed&nbsp;to&nbsp;access.&nbsp;We&nbsp;fixed&nbsp;this&nbsp;issue.&nbsp;  
&nbsp;We&nbsp;are&nbsp;correcting&nbsp;this&nbsp;error&nbsp;we&nbsp;made;&nbsp;we’ll&nbsp;let&nbsp;you&nbsp;when&nbsp;it’s&nbsp;taken&nbsp;care&nbsp;of.&nbsp;  
&nbsp;Sorry&nbsp;for&nbsp;all&nbsp;the&nbsp;inconvenience.&nbsp;  
&nbsp;&nbsp;  
&nbsp;And&nbsp;about&nbsp;the&nbsp;earlier&nbsp;question,&nbsp;you&nbsp;mentioned&nbsp;that&nbsp;there&nbsp;are&nbsp;20&nbsp;tiles&nbsp;when&nbsp;only&nbsp;6&nbsp;tiles&nbsp;are&nbsp;required.&nbsp;Would&nbsp;you&nbsp;please&nbsp;let&nbsp;us&nbsp;know&nbsp;how&nbsp;you&nbsp;got&nbsp;this&nbsp;observation,&nbsp;so&nbsp;we&nbsp;can&nbsp;reproduce&nbsp;it?&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards,&nbsp;  
&nbsp;Tsui

---

<div class="post-metadata">

**Author:** ![Klaus3](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/k/e5b9ba/32.png) [@Klaus3](https://community.thinkgeo.com/u/Klaus3)\
**Post date:** [December 3, 2010, 6:19am UTC](https://community.thinkgeo.com/t/filebitmaptilecache-caching-or-using-bad-tiles/2886/15 "2010-12-03T06:19:53Z")

</div>

Glad&nbsp;to&nbsp;know&nbsp;you&nbsp;found&nbsp;bug.&nbsp;&nbsp;We&nbsp;ran&nbsp;into&nbsp;this&nbsp;issue&nbsp;by&nbsp;accident.

In&nbsp;regards&nbsp;to&nbsp;second&nbsp;issue&nbsp;when&nbsp;tile&nbsp;count&nbsp;is&nbsp;greater&nbsp;than&nbsp;expected,&nbsp;please&nbsp;run&nbsp;modified&nbsp;sample&nbsp;and&nbsp;look&nbsp;at&nbsp;your&nbsp;Visual&nbsp;Studio's&nbsp;output&nbsp;window.&nbsp;&nbsp;&nbsp;At&nbsp;zoom&nbsp;level&nbsp;4,&nbsp;for&nbsp;example,&nbsp;we&nbsp;have&nbsp;6&nbsp;tiles&nbsp;visible&nbsp;and&nbsp;20&nbsp;tiles&nbsp;in&nbsp;total.&nbsp;&nbsp;This&nbsp;is&nbsp;with&nbsp;Overlay.Transition&nbsp;effect&nbsp;set&nbsp;to&nbsp;None&nbsp;and&nbsp;Overlay.TileBuffer&nbsp;set&nbsp;to&nbsp;0.

Thanks&nbsp;again.

[001\_WmkRenderLayer.zip](https://community.thinkgeo.com/uploads/default/original/2X/1/1d62a50486cf79b68371dbdd5557a93ddbf88b9f.zip) (32.1 KB)

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [December 5, 2010, 8:49pm UTC](https://community.thinkgeo.com/t/filebitmaptilecache-caching-or-using-bad-tiles/2886/16 "2010-12-05T20:49:23Z")

</div>

&nbsp;Hi&nbsp;Klaus,

&nbsp;

The&nbsp;drawn&nbsp;percentage&nbsp;method&nbsp;we&nbsp;suggested&nbsp;in&nbsp;another&nbsp;post&nbsp;is&nbsp;a&nbsp;little&nbsp;misleading,&nbsp;we&nbsp;are&nbsp;sorry&nbsp;about&nbsp;that.

 ![](https://community.thinkgeo.com/uploads/default/original/2X/f/f16070ed0a6e306e17d09625be2dce0f74e40b3e.PNG)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

In&nbsp;that&nbsp;method,&nbsp;only&nbsp;the&nbsp;tiles&nbsp;marked&nbsp;as&nbsp;“In&nbsp;Extent”&nbsp;in&nbsp;the&nbsp;screen&nbsp;shot&nbsp;above&nbsp;are&nbsp;counted&nbsp;as&nbsp;visible&nbsp;tiles,&nbsp;because&nbsp;we&nbsp;used&nbsp;the&nbsp;Contains&nbsp;method&nbsp;to&nbsp;filter&nbsp;tiles.

But&nbsp;actually&nbsp;all&nbsp;the&nbsp;tiles&nbsp;shown&nbsp;in&nbsp;the&nbsp;screen&nbsp;shot&nbsp;above&nbsp;should&nbsp;be&nbsp;counted&nbsp;as&nbsp;visible,&nbsp;even&nbsp;though&nbsp;some&nbsp;of&nbsp;them&nbsp;are&nbsp;only&nbsp;partially&nbsp;visible.

To&nbsp;correct&nbsp;this&nbsp;error,&nbsp;replace&nbsp;the&nbsp;Contains&nbsp;method&nbsp;with&nbsp;Intersects&nbsp;method.

&nbsp;

Sorry&nbsp;for&nbsp;the&nbsp;confusion&nbsp;and&nbsp;hope&nbsp;this&nbsp;will&nbsp;be&nbsp;of&nbsp;help.

&nbsp;

Regards,

Tsui

---

<div class="post-metadata">

**Author:** ![Klaus3](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/k/e5b9ba/32.png) [@Klaus3](https://community.thinkgeo.com/u/Klaus3)\
**Post date:** [December 6, 2010, 7:07am UTC](https://community.thinkgeo.com/t/filebitmaptilecache-caching-or-using-bad-tiles/2886/17 "2010-12-06T07:07:44Z")

</div>

.....pictures&nbsp;do&nbsp;speak&nbsp;a&nbsp;thousand&nbsp;words&nbsp;indeed.&nbsp;&nbsp;It&nbsp;is&nbsp;very&nbsp;comforting&nbsp;to&nbsp;be&nbsp;able&nbsp;to&nbsp;explain&nbsp;what&nbsp;one&nbsp;is&nbsp;observing.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
  
  
  
Also,&nbsp;I&nbsp;just&nbsp;confirmed&nbsp;that&nbsp;tiles&nbsp;are&nbsp;now&nbsp;being&nbsp;drawn&nbsp;regardless&nbsp;of&nbsp;security&nbsp;permissions&nbsp;of&nbsp;cache&nbsp;directory.&nbsp;&nbsp;&nbsp;  
  
  
  
Great&nbsp;stuff&nbsp;and&nbsp;thanks&nbsp;again&nbsp;Tsui.

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [December 6, 2010, 7:14pm UTC](https://community.thinkgeo.com/t/filebitmaptilecache-caching-or-using-bad-tiles/2886/18 "2010-12-06T19:14:27Z")

</div>

Hi&nbsp;Klaus,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Glad&nbsp;to&nbsp;be&nbsp;of&nbsp;help.&nbsp;And&nbsp;thanks&nbsp;for&nbsp;reporting&nbsp;these&nbsp;valuable&nbsp;information&nbsp;which&nbsp;helped&nbsp;us&nbsp;to&nbsp;fix&nbsp;the&nbsp;bug.&nbsp;  
&nbsp;Please&nbsp;let&nbsp;us&nbsp;know&nbsp;if&nbsp;you&nbsp;have&nbsp;any&nbsp;other&nbsp;questions.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards,&nbsp;  
&nbsp;Tsui
