/**
* BeNomad BeMap JavaScript API - Address (structured query input)
*
* Lightweight value object used to build a structured geocoding query.
* Distinct from `bemap.PostalAddress`, which represents the *result* of a
* lookup. The v1.5 `Geocoder.geocode()` request accepts either an `address`
* (this class — for structured input) or a `place` string (free-text input).
*
* Every field is optional. Fields the server cannot use are silently ignored.
*
* @since 1.5.0
* @public
* @constructor
* @param {Object} [options]
* @param {String} [options.countryCode]
* @param {String} [options.country]
* @param {String} [options.state]
* @param {String} [options.county]
* @param {String} [options.city]
* @param {String} [options.district]
* @param {String} [options.postalCode]
* @param {String} [options.street]
* @param {String} [options.streetNumber]
*/
bemap.Address = function(options) {
var opts = options || {};
this.countryCode = opts.countryCode || null;
this.country = opts.country || null;
this.state = opts.state || null;
this.county = opts.county || null;
this.city = opts.city || null;
this.district = opts.district || null;
this.postalCode = opts.postalCode || null;
this.street = opts.street || null;
this.streetNumber = opts.streetNumber || null;
};
/**
* Serialise the address to the JSON shape expected by the BeMap geocoding
* Worker. `null` / `undefined` fields are stripped so the request body stays
* minimal.
*
* @return {Object}
*/
bemap.Address.prototype.toJson = function() {
var out = {};
var keys = ['countryCode', 'country', 'state', 'county', 'city',
'district', 'postalCode', 'street', 'streetNumber'];
for (var i = 0; i < keys.length; i++) {
var k = keys[i];
if (this[k] !== null && this[k] !== undefined && this[k] !== '') {
out[k] = this[k];
}
}
return out;
};