Skip to content

Commit

Permalink
- only one data parameter when reporting errors
Browse files Browse the repository at this point in the history
- setTimeout with 0 duration
- OfflineTileLayer runs in NO_DB mode if an error occurred while creating the DB
  • Loading branch information
mbriau committed Jul 8, 2014
1 parent 4575267 commit 0ab006a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
14 changes: 6 additions & 8 deletions README.md
Expand Up @@ -14,7 +14,7 @@ It is initialized the same way, using url and options but it has extra options:
* **onReady:** All db operations are asynch, onReady will be called when the DB is ready and tile images can be
retrieved.
* **dbOption:** Can choose storage by setting to "WebSQL" or "IndexedDB". "None" or null will not use any DB.
* onError(optional): Will be called if anything goes wrong with (errorType, errorData, ...), more details in Errors section.
* onError(optional): Will be called if anything goes wrong with (errorType, errorData), more details in Errors section.
* storeName(optional): If you ever need to change the default storeName: "OfflineLeafletTileImages".

**Methods:**
Expand Down Expand Up @@ -49,12 +49,12 @@ OfflineLayer fires the following events while saving tiles:

##Error callback:

When calling the onError callback, the parameters are (errorType, errorData1, errorData2)
When calling the onError callback, the parameters are (errorType, errorData)

**new OfflineLayer errors:**

* **"COULD\_NOT\_CREATE\_DB":** An error has been thrown when creating the DB (calling new IDBStore internally).
ErrorData1 is the error thrown by the IDBStore.
errorData is the error thrown by the IDBStore.
* **"NO\_DB":** Calling clearTiles() or saveTiles() will doing nothing but call the error callback if there is no DB.
This could happen if these functions are called before the onReady callback or if the DB could not be initialized
(previous error).
Expand All @@ -64,11 +64,9 @@ This could happen if these functions are called before the onReady callback or i
**saveTiles() errors:**
* **"SYSTEM\_BUSY":** System is busy.
* **"SAVING\_TILES":** An error occurred when calling saveTiles.
* **"DB\_GET":** An error occurred when calling get on ImageStore. ErrorData1 is the DB key of the tile.
* **"GET\_STATUS\_ERROR":** The XMLHttpRequest Get status is not equal to 200. ErrorData1 is the error from XMLHttpRequest.
ErrorData2 is the URL of the image.
* **"NETWORK\_ERROR":** The XMLHttpRequest used to get an image threw an error. ErrorData1 is the error from XMLHttpRequest.
ErrorData2 is the URL of the image.
* **"DB\_GET":** An error occurred when calling get on ImageStore. errorData is the DB key of the tile.
* **"GET\_STATUS\_ERROR":** The XMLHttpRequest Get status is not equal to 200. errorData contains the error from XMLHttpRequest and the URL of the image.
* **"NETWORK\_ERROR":** The XMLHttpRequest used to get an image threw an error. errorData contains the error from XMLHttpRequest and the URL of the image.

**clearTiles() errors:**
* **"SYSTEM\_BUSY":** System is busy.
Expand Down
2 changes: 1 addition & 1 deletion src/ImageStore.coffee
Expand Up @@ -148,7 +148,7 @@ module.exports = class ImageStore

errorGettingImage = (errorType, errorData) =>
@_decrementNbTilesLeftToSave()
@_eventEmitter._reportError(errorType, errorData, data.tileInfo)
@_eventEmitter._reportError(errorType, {data: errorData, tileInfo: data.tileInfo})
callback(errorType)

@_nbImagesCurrentlyBeingRetrieved++
Expand Down
14 changes: 10 additions & 4 deletions src/OfflineLayer.coffee
Expand Up @@ -41,19 +41,25 @@ module.exports = class OfflineLayer extends L.TileLayer
@_onReady()
,
(error) =>
@_tileImagesStore = null
@_reportError("COULD_NOT_CREATE_DB", error)
setTimeout(() =>
@_onReady()
, 0
)
, useWebSQL
)
catch err
@_tileImagesStore = null
@_reportError("COULD_NOT_CREATE_DB", err)
setTimeout(() =>
@_onReady()
, 1000
, 0
)
else
setTimeout(() =>
@_onReady()
, 1000
, 0
)

# look at the code from L.TileLayer for more details
Expand All @@ -66,9 +72,9 @@ module.exports = class OfflineLayer extends L.TileLayer
}
)

_reportError: (errorType, errorData1, errorData2) ->
_reportError: (errorType, errorData) ->
if @_onError
@_onError(errorType, errorData1, errorData2)
@_onError(errorType, errorData)

# look at the code from L.TileLayer for more details
_loadTile: (tile, tilePoint) ->
Expand Down

0 comments on commit 0ab006a

Please sign in to comment.