universal-geocoder
Version:
Universal geocoding abstraction server-side and client-side with multiple built-in providers
80 lines • 3.04 kB
JavaScript
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
var provider_1 = require("../provider");
var GeocodeQuery = /** @class */ (function () {
function GeocodeQuery(_a) {
var text = _a.text, ip = _a.ip, bounds = _a.bounds, locale = _a.locale, _b = _a.limit, limit = _b === void 0 ? provider_1.DEFAULT_RESULT_LIMIT : _b;
this.limit = provider_1.DEFAULT_RESULT_LIMIT;
this.text = text;
this.ip = ip;
if (!text && !ip) {
throw new Error('Either "text" or "ip" parameter is required.');
}
if (bounds &&
(!bounds.latitudeSW ||
!bounds.longitudeSW ||
!bounds.latitudeNE ||
!bounds.longitudeNE)) {
throw new Error('The "bounds" parameter must be an object with the keys: "latitudeSW", "longitudeSW", "latitudeNE", "longitudeNE".');
}
this.bounds = bounds;
this.locale = locale;
this.limit = limit;
}
GeocodeQuery.create = function (object) {
return new this(object);
};
GeocodeQuery.prototype.toObject = function () {
return {
text: this.text,
ip: this.ip,
bounds: this.bounds,
locale: this.locale,
limit: this.limit,
};
};
GeocodeQuery.prototype.withText = function (text) {
return this.constructor.create(__assign(__assign({}, this.toObject()), { text: text }));
};
GeocodeQuery.prototype.withIp = function (ip) {
return this.constructor.create(__assign(__assign({}, this.toObject()), { ip: ip }));
};
GeocodeQuery.prototype.withBounds = function (bounds) {
return this.constructor.create(__assign(__assign({}, this.toObject()), { bounds: bounds }));
};
GeocodeQuery.prototype.withLocale = function (locale) {
return this.constructor.create(__assign(__assign({}, this.toObject()), { locale: locale }));
};
GeocodeQuery.prototype.withLimit = function (limit) {
return this.constructor.create(__assign(__assign({}, this.toObject()), { limit: limit }));
};
GeocodeQuery.prototype.getText = function () {
return this.text;
};
GeocodeQuery.prototype.getIp = function () {
return this.ip;
};
GeocodeQuery.prototype.getBounds = function () {
return this.bounds;
};
GeocodeQuery.prototype.getLocale = function () {
return this.locale;
};
GeocodeQuery.prototype.getLimit = function () {
return this.limit;
};
return GeocodeQuery;
}());
exports.default = GeocodeQuery;
//# sourceMappingURL=GeocodeQuery.js.map