[OpenLayers-Users] Cache maps with OSM

Stephen Woodbridge woodbri at swoodbridge.com
Fri Sep 21 18:24:13 PDT 2012


On 9/21/2012 8:53 PM, hz hanks wrote:
> Hey, All:
>
> I have created a simple web based map application using
> OpenLayers.Layer.OSM. Now I'm asked to cache part of the map in
> advance. ( Say, cache it when it's accessible to the Internet and then
> we may move the laptop to a place without the Internet. )
>
> My idea is to use setCenter( center, zoom ) function to change the
> zoom argument and let the OpenLayer to cache the data. I went through
> the example of offline-storage.js provided by OpenLayer and now how to
> add cache control. But how can I make sure that all data is cached
> before I change the zoom argument again? I tried to register event
> "loadend" ( change the zoom argument after "loadend" is triggered )
> but it didn't work. Did I choose a wrong event? Or is this idea not
> feasible ( caching every tile that has been displayed is not
> guaranteed? ). Is there any other way to do that (e.g. create a
> offline map of a desired area) and how?

This is not a function or capability of OpenLayers, but that said you 
might want to ask this question on the Mapserver.org list regarding 
mapcache.

The idea being to set up apache2 on your laptop with mapcache installed 
and configured to pull tiles from OSM, then configure your OpenLayers 
app to pull tiles from mapcache. Mapcache will pull and cache the tiles 
locally as they are requested or you can run a seeder that will 
pre-populate the tiles.

There are two problems that I see with this setup:

1. unless you have a huge disk you will need to write a script to clean 
tiles that you do not need.

2. you need to write a script to run the seeder and pull the area of 
interest that you are interested in, before you go offline.

Hope this helps,
   -Steve W



More information about the Users mailing list