2

I am working on an extension to OpenLayers to pre-cache tiles in a local Web SQL datastore to support mapping on mobile device when connectivity is dead.

I would like to pre-seed my cache with a set of tiles. Currently this has to be done by visiting the area in question and using the cacheWrite control.

This would be done by fetching the tiles in question from my MapServer WMS and storing them locally in the Web SQL database. These would then be available for the cacheRead control to use on tileerror.

So, my question is: given a bounding box, is there an easy way for me to construct these calls using OpenLayers and hence populate the cache with the required tiles for a required zoom level?

A sample single tile call is:-

"http://mymapserver/pub/mapcache/mytheme?LAYERS=my_layer&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&SRS=EPSG%3A27700&BBOX=533371.66,169851.66,534011.66,170491.66&WIDTH=256&HEIGHT=256"

I can do this by panning the map about automatically, but the user experience is terrible ;-)

  • Further investigation shows that the key to this will be the Openlayers grid object which contains the tiles. Each tile has a method to return its url for a given zoom level. I am unclear as to whether the grid covers the current viewport or the whole map at the moment – user1331131 Jul 29 '13 at 8:21
  • Why don't you a preached WMTS service instead? The URL for the tiles in that case is far more easier to work with. – Devdatta Tengshe Jul 30 '13 at 9:54
1

I think you need to go over your interested zoom level range, and for every zoom level go over tile x and y ranges for your bounding area. Then calculate WMS request for each tile. Here is some code to do the last step - calculating WMS request parameters for given tile: https://github.com/CartoDB/mobile-android-samples/blob/master/AdvancedMapAndroid/app/src/main/java/com/carto/advancedmap/sections/overlaydatasources/WmsMapActivity.java#L86 . This code is specific to CARTO mobile SDK on Android Java, but it is easily changeable to any other language or framework.

This works for tile-compatible suitable coordinate systems like spherical mercator or wgs84 only.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.