UNPKG

@configurator/ravendb

Version:
101 lines 3.74 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 Exceptions_1 = require("../../Exceptions"); exports.DEFAULT_GEOHASH_LEVEL = 9; exports.DEFAULT_QUAD_TREE_LEVEL = 23; class SpatialOptions { 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, Exceptions_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 { constructor(minX, minY, maxX, maxY) { this.minX = minX; this.maxX = maxX; this.minY = minY; this.maxY = maxY; } } exports.SpatialBounds = SpatialBounds; class GeographySpatialOptionsFactory { defaultOptions(circleRadiusUnits) { circleRadiusUnits = circleRadiusUnits || "Kilometers"; return this.geohashPrefixTreeIndex(0, circleRadiusUnits); } boundingBoxIndex(circleRadiusUnits) { circleRadiusUnits = circleRadiusUnits || "Kilometers"; const ops = new SpatialOptions(); ops.type = "Geography"; ops.strategy = "BoundingBox"; ops.units = circleRadiusUnits; return ops; } geohashPrefixTreeIndex(maxTreeLevel, circleRadiusUnits) { circleRadiusUnits = 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) { circleRadiusUnits = 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