Skip to content

Commit

Permalink
There is a new option "minZoomLevel" with a default value of 12.
Browse files Browse the repository at this point in the history
The OfflineLayer will report an error when trying to calculate the nb of tiles or to save tiles with a map zoomed out more than that limit.
  • Loading branch information
mbriau committed Jun 23, 2014
1 parent e3b5032 commit 4575267
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/OfflineLayer.coffee
Expand Up @@ -20,6 +20,9 @@ module.exports = class OfflineLayer extends L.TileLayer
dbOption = options["dbOption"]
storeName = options["storeName"] || 'OfflineLeafletTileImages'
@_tileImagesStore = null
@_minZoomLevel = 12
if options["minZoomLevel"]?
@_minZoomLevel = parseInt(options["minZoomLevel"])

if dbOption? and dbOption != "None"
try
Expand Down Expand Up @@ -123,6 +126,10 @@ module.exports = class OfflineLayer extends L.TileLayer

# calculateNbTiles includes potentially already saved tiles.
calculateNbTiles: (zoomLevelLimit) ->
if @_map.getZoom() < @_minZoomLevel
@_reportError("ZOOM_LEVEL_TOO_LOW")
return -1

count = 0
tileImagesToQuery = @_getTileImages(zoomLevelLimit)
for key of tileImagesToQuery
Expand Down Expand Up @@ -192,6 +199,11 @@ module.exports = class OfflineLayer extends L.TileLayer
onError("system is busy.")
return

if @_map.getZoom() < @_minZoomLevel
@_reportError("ZOOM_LEVEL_TOO_LOW")
onError("ZOOM_LEVEL_TOO_LOW")
return

#lock UI
tileImagesToQuery = @_getTileImages(zoomLevelLimit)
@_tileImagesStore.saveImages(tileImagesToQuery, onStarted, onSuccess, (error) =>
Expand Down
2 changes: 2 additions & 0 deletions src/demo.coffee
Expand Up @@ -52,6 +52,8 @@ class CacheBtnControl extends L.Control
# Might be a good idea to put a limit on the number of tiles that can would be saved
# calculateNbTiles includes potentially already saved tiles.
nbTiles = offlineLayer.calculateNbTiles();
if nbTiles == -1
return
if(nbTiles < 10000)
console.log("Will be saving: " + nbTiles + " tiles");

Expand Down

0 comments on commit 4575267

Please sign in to comment.