UNPKG

ravendb

Version:
116 lines 4.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GeographySpatialOptionsFactory = exports.SpatialBounds = exports.CartesianSpatialOptionsFactory = exports.SpatialOptionsFactory = exports.SpatialOptions = exports.DEFAULT_QUAD_TREE_LEVEL = exports.DEFAULT_GEOHASH_LEVEL = void 0; const index_js_1 = require("../../Exceptions/index.js"); // about 4.78 meters at equator, should be good enough // (see: http://unterbahn.com/2009/11/metric-dimensions-of-geohash-partitions-at-the-equator/) exports.DEFAULT_GEOHASH_LEVEL = 9; // about 4.78 meters at equator, should be good enough exports.DEFAULT_QUAD_TREE_LEVEL = 23; class SpatialOptions { type; strategy; maxTreeLevel; minX; maxX; minY; maxY; // Circle radius units, only used for geography indexes units; constructor(options) { options = options || {}; this.type = options.type || "Geography"; this.strategy = options.strategy || "GeohashPrefixTree"; this.maxTreeLevel = options.maxTreeLevel || exports.DEFAULT_GEOHASH_LEVEL; this.minX = options.minX || -180; this.maxX = options.maxX || 180; this.minY = options.minY || -90; this.maxY = options.maxY || 90; this.units = options.units || "Kilometers"; } } exports.SpatialOptions = SpatialOptions; class SpatialOptionsFactory { geography() { return new GeographySpatialOptionsFactory(); } cartesian() { return new CartesianSpatialOptionsFactory(); } } exports.SpatialOptionsFactory = SpatialOptionsFactory; class CartesianSpatialOptionsFactory { boundingBoxIndex() { const opts = new SpatialOptions(); opts.type = "Cartesian"; opts.strategy = "BoundingBox"; return opts; } quadPrefixTreeIndex(maxTreeLevel, bounds) { if (maxTreeLevel === 0) { (0, index_js_1.throwError)("InvalidArgumentException", "maxTreeLevel can't be 0."); } const opts = new SpatialOptions(); opts.type = "Cartesian"; opts.maxTreeLevel = maxTreeLevel; opts.strategy = "QuadPrefixTree"; opts.minX = bounds.minX; opts.minY = bounds.minY; opts.maxX = bounds.maxX; opts.maxY = bounds.maxY; return opts; } } exports.CartesianSpatialOptionsFactory = CartesianSpatialOptionsFactory; class SpatialBounds { minX; maxX; minY; maxY; constructor(minX, minY, maxX, maxY) { this.minX = minX; this.maxX = maxX; this.minY = minY; this.maxY = maxY; } } exports.SpatialBounds = SpatialBounds; class GeographySpatialOptionsFactory { /** * Defines a Geohash Prefix Tree index using a default Max Tree Level {@link SpatialOptions} */ defaultOptions(circleRadiusUnits = "Kilometers") { return this.geohashPrefixTreeIndex(0, circleRadiusUnits); } boundingBoxIndex(circleRadiusUnits = "Kilometers") { const ops = new SpatialOptions(); ops.type = "Geography"; ops.strategy = "BoundingBox"; ops.units = circleRadiusUnits; return ops; } geohashPrefixTreeIndex(maxTreeLevel, circleRadiusUnits = "Kilometers") { if (maxTreeLevel === 0) { maxTreeLevel = exports.DEFAULT_GEOHASH_LEVEL; } const opts = new SpatialOptions(); opts.type = "Geography"; opts.maxTreeLevel = maxTreeLevel; opts.strategy = "GeohashPrefixTree"; opts.units = circleRadiusUnits; return opts; } quadPrefixTreeIndex(maxTreeLevel, circleRadiusUnits = "Kilometers") { if (maxTreeLevel === 0) { maxTreeLevel = exports.DEFAULT_QUAD_TREE_LEVEL; } const opts = new SpatialOptions(); opts.type = "Geography"; opts.maxTreeLevel = maxTreeLevel; opts.strategy = "QuadPrefixTree"; opts.units = circleRadiusUnits; return opts; } } exports.GeographySpatialOptionsFactory = GeographySpatialOptionsFactory; //# sourceMappingURL=Spatial.js.map