Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

189
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda