React version of Leaflet.TileLayer.PouchDBCached
npm i react-leaflet-pouchdb-tilelayer --save
OR
npm i react-leaflet-pouchdb-tilelayer@3.2.2-beta --save
https://codesandbox.io/p/sandbox/strange-field-t7l4ly
This plugin is compatible with version 2 of React-Leaflet
import { Map, TileLayer, LayersControl } from "react-leaflet";
import PouchDBTileLayer from "react-leaflet-pouchdb-tilelayer";
<Map center={[22.287, 114.1694]} zoom={15}>
<LayersControl position="topleft">
<LayersControl.BaseLayer checked name="PouchDBTileLayer">
<PouchDBTileLayer
useCache={true}
crossOrigin={true}
attribution='© <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
</LayersControl.BaseLayer>
<LayersControl.BaseLayer name="TileLayer">
<TileLayer
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
/>
</LayersControl.BaseLayer>
</LayersControl>
</Map>;
{ useCache: true }
Enable the cache logic
{ saveToCache: true }
Save the map tile to PouchDB
{ useOnlyCache: false }
Load from PouchDB cache and do not download from web
{ cacheFormat: 'image/png' }
The mine type
{ cacheMaxAge: 3600000 }
cache age in millisecond unit
{ cacheNextZoomLevel: true }
pre-load and cache the next level tile
- Clone the project
- Run
npm install
- Run
npm run build
- Start coding