I
just picked up a piece of code from the openlayers3 examples see
HERE,
now everytime you click the "geolocate me" button the tiles
of the map are reloaded , now is there anyway for the tiles of the map
to be stored locally ? I.E. when i click on the "geolocate
me!" button the 2nd time around the tiles sould be loaded from
the users browser locally, rather than being fetched from the internet.
The
code for generating the map is as following:
-
var
map = new ol.Map({
-
layers: [
-
new ol.layer.Tile({
-
source: new ol.source.OSM()
-
})
-
],
-
target: 'map',
-
controls: ol.control.defaults({
-
attributionOptions: /** @type
{olx.control.AttributionOptions} */ ({
-
collapsible: false
-
})
-
}),
-
view: view
-
});
I
tried the following using localstorage:
- if(localStorage.layer) {
-
localStorage.setItem('layer' , JSON.stringify(new
ol.layer.Tile({ source: new ol.source.OSM()}) )); console.log(localStorage.layer);
- }
-
- var
map = new ol.Map({
-
layers: localStorage.layer ?
[JSON.parse(localStorage.getItem('layer'))] : [
-
new ol.layer.Tile({
-
source: new ol.source.OSM()
-
})
-
],
-
target: 'map',
-
controls: ol.control.defaults({
-
attributionOptions: * @type {olx.control.AttributionOptions} ({
-
collapsible: false
-
})
-
}),
-
view: view
- });
But this does't seem to work, what can i do so that the
tiles of the map are stored locally instead of being loaded from
over the internet ?
a example i have seen using the DOJO library is
HERE.