From f255a4ce529df96cb003f02cb70dfdac309079a3 Mon Sep 17 00:00:00 2001 From: Andy Gup Date: Tue, 30 Sep 2014 16:28:55 -0600 Subject: [PATCH] adds isDBValid() to TPKLayer --- doc/tpklayer.md | 1 + lib/tpk/TPKLayer.js | 13 ++++++++++++- test/spec/tpkLayerSpec.js | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/doc/tpklayer.md b/doc/tpklayer.md index c8b6e6b..1d3bfa8 100644 --- a/doc/tpklayer.md +++ b/doc/tpklayer.md @@ -32,6 +32,7 @@ Methods | Returns | Description `setMaxDBSize(size)`| nothing | (Optional) Let's you specify a maximum size in MBs for the local database. The default is 75MBs. Recommended maximum is 100MBs. Important: Making the database too large can result in browser crashes and slow application performance. `getDBSize(callback)`| `callback(size,err)` | Returns the size of local database in bytes or an error message. Calling this too often during parsing operations can affect application performance. `setDBWriteable(value)`| nothing | Default is true. Value is boolean. Let's you programmatically allow or not allow the storing of tiles in the local database. This method can help you manage the size of the database. Use this in conjunction with `getDBSize()` on a map pan or zoom event listener. Tile retrieval times from images stored in the database are significantly faster than pulling images from the TPK. +`isDBValid()` | boolean | Verifies whether not the browser supports this library. ###Events Event | Value | Description diff --git a/lib/tpk/TPKLayer.js b/lib/tpk/TPKLayer.js index 42283e8..d18f2d6 100644 --- a/lib/tpk/TPKLayer.js +++ b/lib/tpk/TPKLayer.js @@ -45,6 +45,7 @@ define([ // _maxDBSize: 75, // User configurable maximum size in MBs. _isDBWriteable: true, // Manually allow or stop writing to the database. + _isDBValid: false, // Does the browser support IndexedDB or IndexedDBShim _autoCenter: null, // Auto center the map _fileEntriesLength: 0, // Number of files in zip _inMemTilesObject: null, // Stores unzipped files from tpk @@ -186,6 +187,15 @@ define([ this._isDBWriteable = value; }, + /** + * Validates whether or not the browser supports this library + * @returns {boolean} + */ + isDBValid: function(){ + this._validate(); + return this._isDBValid; + }, + /** * Runs specific validation tasks. Reserved for future use. * Currently only throws console errors. Does not stop execution of the library! @@ -217,7 +227,8 @@ define([ this.emit(this.DATABASE_ERROR_EVENT,{msg:this.DB_FULL_ERROR,err : err}); } this.emit(this.VALIDATION_EVENT,{msg:this.DB_VALIDATED,err : null}) - console.log("DB size: " + mb + " MBs, Tile count: " + size.tileCount + ", Error: " + err) + console.log("DB size: " + mb + " MBs, Tile count: " + size.tileCount + ", Error: " + err); + this._isDBValid = true; }.bind(this)) } }.bind(this)); diff --git a/test/spec/tpkLayerSpec.js b/test/spec/tpkLayerSpec.js index 3ed934a..cc81ac3 100644 --- a/test/spec/tpkLayerSpec.js +++ b/test/spec/tpkLayerSpec.js @@ -21,6 +21,7 @@ describe("TPKLayer module", function(){ { expect(tpkLayer).toEqual(jasmine.any(Object)); expect(tpkLayer.store).toEqual(jasmine.any(Object)); + expect(tpkLayer.isDBValid()).toBe(true); done(); });