|
| 1 | +var register = require("./util").register; |
| 2 | +var Factory = require("../factory").Factory; |
| 3 | +var Workspace = require("./workspace").Workspace; |
| 4 | +var UTIL = require("../util"); |
| 5 | + |
| 6 | +var FlatgeobufDataStoreFactory = Packages.org.geotools.data.flatgeobuf.FlatgeobufDataStoreFactory; |
| 7 | + |
| 8 | +/** private: (define) |
| 9 | + * module = workspace |
| 10 | + * class = Flatgeobuf |
| 11 | + */ |
| 12 | + |
| 13 | +var prepConfig = function(config) { |
| 14 | + if (config) { |
| 15 | + if (typeof config === "string") { |
| 16 | + config = {'flatgeobuf-file': config}; |
| 17 | + } |
| 18 | + if (!(typeof config.file === "string")) { |
| 19 | + throw "Flatgeobuf config must include file path."; |
| 20 | + } |
| 21 | + config = { |
| 22 | + 'flatgeobuf-file': String(config.file) |
| 23 | + }; |
| 24 | + } |
| 25 | + return config; |
| 26 | +}; |
| 27 | + |
| 28 | +/** private: (extends) |
| 29 | + * workspace/workspace.js |
| 30 | + */ |
| 31 | +var Flatgeobuf = UTIL.extend(Workspace, { |
| 32 | + |
| 33 | + /** private: config[file] |
| 34 | + * ``String`` |
| 35 | + * Path to the file (required). |
| 36 | + */ |
| 37 | + |
| 38 | + /** private: constructor |
| 39 | + * .. class:: Flatgeobuf |
| 40 | + * |
| 41 | + * :arg config: ``Object`` Configuration object. |
| 42 | + * |
| 43 | + * Create a workspace from a Flatgeobuf directory. |
| 44 | + */ |
| 45 | + constructor: function Flatgeobuf(config) { |
| 46 | + Workspace.prototype.constructor.apply(this, [prepConfig(config)]); |
| 47 | + }, |
| 48 | + |
| 49 | + /** private: method[_create] |
| 50 | + * :arg config: ``Object`` |
| 51 | + * :returns: ``org.geotools.data.flatgeobuf.FlatgeobufDataStore`` |
| 52 | + * |
| 53 | + * Create the underlying store for the workspace. |
| 54 | + */ |
| 55 | + _create: function(config) { |
| 56 | + var factory = new FlatgeobufDataStoreFactory(); |
| 57 | + return factory.createDataStore(config); |
| 58 | + }, |
| 59 | + |
| 60 | + /** private: property[config] |
| 61 | + */ |
| 62 | + get config() { |
| 63 | + return { |
| 64 | + type: this.constructor.name, |
| 65 | + file: this.file |
| 66 | + }; |
| 67 | + } |
| 68 | + |
| 69 | +}); |
| 70 | + |
| 71 | +exports.Flatgeobuf = Flatgeobuf; |
| 72 | + |
| 73 | +// register a Flatgeobuf factory for the module |
| 74 | +register(new Factory(Flatgeobuf, { |
| 75 | + handles: function(config) { |
| 76 | + var capable = false; |
| 77 | + if (typeof config.type === "string" && config.type.toLowerCase() === "Flatgeobuf") { |
| 78 | + try { |
| 79 | + config = prepConfig(config); |
| 80 | + capable = true; |
| 81 | + } catch (err) { |
| 82 | + // pass |
| 83 | + } |
| 84 | + } |
| 85 | + return capable; |
| 86 | + } |
| 87 | +})); |
0 commit comments