@antv/data-wizard
Version:
A js/ts library for data processing
53 lines (52 loc) • 1.95 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LocationRandom = void 0;
var tslib_1 = require("tslib");
var utils_1 = require("../utils");
var basic_random_1 = require("./basic-random");
var utils_2 = require("./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) {
tslib_1.__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 = utils_2.initOptions({ max: MAX_LONG, min: MIN_LONG, fixed: 7 }, options);
utils_1.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 = utils_2.initOptions({ max: MAX_LAT, min: MIN_LAT, fixed: 7 }, options);
utils_1.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 = utils_2.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;
}(basic_random_1.BasicRandom));
exports.LocationRandom = LocationRandom;