ThinkGeo.com    |     Documentation    |     Premium Support

TileCache

Hello,


I'm trying to figure out how does the tile caching system work, but I cannot find any documentation about it other than a very basic howto sample.


In order to use it effectively, one must understand the way the cache works, its various properties and methods and the related ovelay properties and methods.


Thanks,


Ofer



Ofer, 
  
 I agree with you.  Currently that feature is very new and the product overall is in pre-release.  This means the documentation is not always instnc with the release.  We thought it better to get the major bugs released first.  In the very near future we will be releasing a video to go over all of the caching options and cover new features.  At the same time we are updating the documentation.  For now if you can explain a little about your requiremets we can point you towards the right class and API. 
  
 David

David,


I've enabled a FileBitmapTileCache as per the howto sample. Initially nothing was written to the cache until i realized i need to change the ReadOnly property to false.


I was expecting to see that tiles are beong added to the  cache when i pan/zoom   but i also noticed that some are being deleted. In addition, When I close my app and restart it , the cache isbeing  cleared . can you explain that.


can you explain what triggers the creation of tiles and what is the name convention for the created folders.


Is it possible to generate the whole cache of a specific area and specific  zoomlevels programatically upon program startup?


What is the purpose of the following  MapOvelay properties:   LocalCache, PreviewTileCache, ScreenBitmapTile


Thanks,


Ofer


 



Ofer,


I will give you my understandings on those questions, hope it helps. And if possible, hope David can give you much better and clearer explanations.


Basically, when you create a FileBitmapTileCache and set it to the property of TileCache of Overlay, it will be used to keep its tiles when you pan or zoom. The property CacheDirectory and CacheId will determine its created folders.
 
For example, if I create a FileBitmapTileCache and set its CacheDirectory as @”C:\temp\ “and its cacheId as “WorldOverlayCache”, then the final created folder will be:
C:\temp\WorldOverlayCache . If you just set the CacheDirecory and ignore specifying its CacheId, then it will have a random GUID as its CacheId, so every time you close your app and restart it, it seems you clear it.
 
About the generation of the whole cache of a specific zoom levels, following post can give you some guide, just have a quick look if you are interested.

gis.thinkgeo.com/Support/Dis...fault.aspx
gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/12/aft/6274/afv/topic/afpgj/1/Default.aspx#11328
 
About the properties in the Overlay: The LocalCache is kept just for compatibility with previous versions, so please just ignore it. The PreviewTileCache is used only when it is MultiThreaded mode and the TileCache is turned on. The ScreenBitmapTile is used when OnPaint without Refresh.
 
If I am not clear just feel free to let me know.
 
Thanks.
 
Yale


Yale,


Thanks for your help.


I'm trying to generate the whole cache according to the samples you pointed out above.


I have a 12000x12000 pixel image covering aprox. 8x8 miles. everything works fine from zoomlevel 1 to zoomlevel 15.  in zoom level 16, when i call  mapEngine.DrawStaticLayers an exception is thrown  (System.Runtime.InteropServices.ExternalException) with a "A generic error occurred in GDI+." message.


If i run my app with  bitmapTileCache.ReadOnly = false, The cache seems to be built ok as i move around the map in different zoom levels.


Any thoughts about the exception?


 


Ofer



Ofer,


It is strange that this exception will happens. It is obvious that it will take a long time to generate Zoomlevel16 or ZoomLevel17 and probably take forever:) to generate ZoomLevel20.


We used this tool to generate the WorldMapKit tiles for US area for ZoomLevel16 and ZoomLevel17 and it works fine. So I guess this problem is probably related with your data. Would you mind to send us your data to recreate the problem?


Your any more information would be appreciated.


Thanks.


Yale

 



Yale,




I created a simple ecw and eww files to show the problem.

You can download from telem.org/test/testMap.zip

You can use the sample program you mentioned above (gis.thinkgeo.com/Support/Dis...fault.aspx)

Please modify to GeographyUnit.Meter 

It works for me in zoomlevels 1-16 and then fail in level 17

 


Thanks,


Ofer





Ofer,


Thanks for your data and reminder!


We can recreate your problem according your guide easily, I have added this item to working track system and try to figure it out and let you know as soon as possible.


Thanks.


Yale

 



Yale,


I have another question regarding the cache.


I noticed that when i start my application and my cache is set  to readonly, the cache is being deleted the first time i refresh the map. This prevents me from building a cache once and then use it in the following program runs.


When do you expect the cache generation problem to be fixed?


Thanks,


Ofer



Ofer,


Thanks for your post!


We did made some mistake (which still will delete or clear even thought we set it to ReadOnly) in the ReadOnly property on last public release (3.0.415) and it has been fixed in latest release (4.0.426), you can get it from following link or contact our support.

gis.thinkgeo.com/Products/Ma...fault.aspx


The generation problem is caused by the generation sample code, hope the updated sample in attachment can give your help.


Let me know if any more problem.


Thanks.


Yale

 



1244-TestGenerateTilingImages_Update.zip (11.5 KB)

Yale,


Ok, thanks to the updated sample and new release i've made some progress.


Still have a few questions/issues:


1.The code you sent me in TestGenerateTilingImages_update has a small bug. The 2 inner "for" loops should have "<=" and not "<". This bug is casing the program not to generate the last column and last row.


2. I'm trying to have my app use the generated code. I'm not sure how can i tell programatically if the cache is used, but i changed one of the images in the cache and it does not show in my app. I'm guessing this means that the cache is not used. (there is also no change in the time it takes to move from one zoom level to the other when compared to a non cache using system).


3.When in readonly mode, the cache does not get deleted anymore. but if i set readonly to false, the cache is regenerated evry time i change a zoomlevel. I thought that in this mode, the cached is being used if the right tile exists, and if not the missing tiles are generated. Is this a bug or do i missunderstand the purpose of this mode.


Thanks,


Ofer



Ofer,


Thanks for your post and hope my following answer can give you some help.
 
1)      Thanks for your sharing of the bug fix in the updated sample.
2)      Following code shows which bitmap tiles are being used in current extent.

   LayerOverlay staticOverlay = (LayerOverlay)winformsMap1.Overlays["WorldOverlay"];
            FileBitmapTileCache bitmapTileCache = (FileBitmapTileCache)staticOverlay.TileCache;
            string directory =bitmapTileCache.CacheDirectory;
            string cacheId = bitmapTileCache.CacheId;
            double scale = staticOverlay.TileCache.TileMatrix.Scale;
            string format = bitmapTileCache.ImageFormat.ToString();

            Collection<TileMatrixCell> currentCells = staticOverlay.TileCache.TileMatrix.GetIntersectingCells(winformsMap1.CurrentExtent);
            foreach (TileMatrixCell tileCell in currentCells)
            {
                string row = tileCell.Row.ToString();
                string column = tileCell.Column.ToString();
                string fileName = string.Format("{0}\\{1}\\{2}\\{3}\\{4}.{5}", directory, cacheId, scale, row, column, format);
                System.Diagnostics.Debug.WriteLine(fileName);
            }

 
3)When it is in ReadOnly mode, the cache will not be generated or deleted, this is expected in our design structure. Also when the tiles not exist, it would be generated when needed when you pan around the map control.
 
Following post also talk about the ReadOnly property, just take a look if you are interested.
gis.thinkgeo.com/Support/Dis...fault.aspx

 
Any more questions just feel free to let me know.
 
Thanks.
 
Yale


Yale, your item 3) says "… Also when the tiles not exist, it would be generated when needed when you pan around the map control". 
  
 In a prior post to me yesterday, you said:  "The ReadOnly property means that tiles will never be added or deleted and only the already existing tiles can be used…" 
  
 This is very inconsistent. 
  
 What I have found, in my own testing with 426 is that when I start with an empty cache, I get tiles added, but the tiles are blank.   They do not contain any imagery, and as I pan around the map, the map behaves as if there were never any tiles added. 
  
 I am sorry, but I do not understand these contradictions in the ReadOnly property descriptions, and it is because of these kinds of inconsistent statements that I asked for the clear review of exactly how to create a persistent cache.

Ted, 
  
 Sorry to make you make some misunderstanding. 
  
 I think what I am talking about with item 3 in Ofer’ post is assuming the ReadOnly is set to false (in his post). While I told you in your post is referring the ReadOnly is set to true which will make the result different. 
  
 Any more questions please just let me know. 
  
 Thanks. 
  
 Yale 


Yale,


Regarding section 2 of your answer above:


I used the code you provided to identify the path of where the  cache is expected. I found that it is not consistent.


The scale part  changes for the same zoomlevel. for example, for zoomlevel 14 i get the following different pathes:


<directory></directory><cacheid></cacheid>directory\cacheID\72093,7243652342\101403\102477.Png


<directory></directory><cacheid></cacheid>directory\cacheID\72093,6854346442\101403\102477.Png


In Addition, the path that was generated by the program that generates the cache was


<directory></directory><cacheid></cacheid>directory\cacheID\72093,7243652344\101403\102477.Png


It looks to me like a bug caused by a math rounding problem.


 


Regarding section 3,  I understand the "readOnly=true" mode. My problem is with "readOnly=false" mode because in this mode every time i go back to a zoomlevel for which a cache was allready generated, the cache is deleted and regenerated.


Maybe it has something to do with the problem above...



Yale,


I tried to bypass the problem above  (scale rounding problem) by changing the default zoom level scales to round numbers so the scale for  zoom level 14 changes from 72093.724365234375  to 72093.0.


Yet, the path expected by the system is  directory\cacheID\72093,0000000002\101406\102478.Png


 





Ofer,


We also find this precision issue in the TileCache when the map unit is set to meter recently and have added it to our working track system for later fix.


Currently, We have provided a class for you called SnappedFileBitmapTileCache which is inherited from FileBitmapTileCache to work around this problem. The code and a simple sample is in the attachment, you can take a look if you are interested.


When using this sample the other two directories in your above example (‘directory\cacheID\72093,7243652342’ and ‘directory\cacheID\72093,6854346442’) will not be generated if the ReadOnly property is set to false. It will just use the folder ‘directory\cacheID\72093,7243652344’ which has been generated by the application TestGenerateTilingImages_update.


Any more questions please let us know.


Thanks,


Yale

 



1256-Issue5659.zip (11.3 KB)

Hi


I have not used the cache generation program for a while , but now there are again problems as described above, but this time these problems also happen when using  the SnappedFileBitmapTileCache.


It seems that  when using Metric maps the cache is not consistent in generating the directories names so sometime it will try to access "directory\cacheID\72093,6854346442" and sometime  "directory\cacheID\72093,6854346443"


Thanks,


Ofer


 



Ofer,  
  
 Thanks for your post.  
  
 I am curious this problem is still happening. This problem was expected to be fixed before last public release. 
  
 Which version are you trying to use now? So when you use the sample in attachment Issue5659, this problem will be happening? 
  
 Sorry for the delay for this problem. 
  
 Thanks. 
  
 Yale 


Hi,


Can anyone from ThinkGeo support responde to the cache issue?