UNPKG

@antv/data-wizard

Version:
50 lines (49 loc) 1.77 kB
import { __extends } from "tslib"; import { assert } from '../utils'; import { BasicRandom } from './basic-random'; import { initOptions } from './utils'; var MAX_LAT = 90; var MIN_LAT = -90; var MAX_LONG = 180; var MIN_LONG = -180; /** * The Generator for location * @public */ var LocationRandom = /** @class */ (function (_super) { __extends(LocationRandom, _super); function LocationRandom() { return _super !== null && _super.apply(this, arguments) || this; } /** * return a random longtitude * @param options - the params */ LocationRandom.prototype.longtitude = function (options) { var opts = initOptions({ max: MAX_LONG, min: MIN_LONG, fixed: 7 }, options); assert(opts.min >= -180 && opts.max <= 180, 'longtitude must between [-180, 180]'); return this.float(opts); }; /** * return a random latitude * @param options - the params */ LocationRandom.prototype.latitude = function (options) { var opts = initOptions({ max: MAX_LAT, min: MIN_LAT, fixed: 7 }, options); assert(opts.min >= -90 && opts.max <= 90, 'latitude must between [-90, 90]'); return this.float(opts); }; /** * return a random coordinates * @param options - the params */ LocationRandom.prototype.coordinates = function (options) { var _a = initOptions({}, options), minLat = _a.minLat, maxLat = _a.maxLat, minLong = _a.minLong, maxLong = _a.maxLong, fixed = _a.fixed; return [ this.longtitude({ min: minLong, max: maxLong, fixed: fixed }), this.latitude({ min: minLat, max: maxLat, fixed: fixed }), ].join(', '); }; return LocationRandom; }(BasicRandom)); export { LocationRandom };