Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
React Leaflet - get Tiles Offline

I use leaflet.offline which allows to save the tiles in indexedDB. The backup is done by a click on a button 'L.control'. I would like this backup to be automatic each time you start a map (without button). How to do it with leaflet.offline or do you know another way, please?

Layer creation - works fine

const tileLayerOffline = L.tileLayer.offline(
  "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
  {
    attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors',
    subdomains: "abc",
    crossOrigin: true,
    minZoom: 13,
    maxZoom: 16,
  }
)

Launch button

const controlSaveTiles = L.control.savetiles(tileLayerOffline, {
  zoomlevels: [13, 16], // optional zoomlevels to save, default current zoomlevel
});
controlSaveTiles.addTo(map);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Looking at the source code, the savetiles control button triggers the _saveTiles() method. You can call this method directly on the controlSaveTiles variable which contains a reference to the savetiles control.

const controlSaveTiles = L.control.savetiles(tileLayerOffline, {
  zoomlevels: [13, 16]
});
controlSaveTiles._saveTiles(); // no need to addTo(map), just save

Code that creates the control buttons: https://github.com/allartk/leaflet.offline/blob/master/src/ControlSaveTiles.js#L123

Method that saves the tiles: https://github.com/allartk/leaflet.offline/blob/master/src/ControlSaveTiles.js#L144

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!