/**
* BeNomad BeMap JavaScript API - GeocodingRequest
*
* Typed request object for `bemap.Geocoder.geocode(request)`. Carrying a
* dedicated class (rather than a free-form `options` object) is the marker
* the refreshed Geocoder uses to decide between the Promise-based v1.5 path
* and the legacy callback-based path — see `bemap-geocoder-v2.js`.
*
* The class is intentionally tolerant: every field is optional and the
* server validates the combination. Fluent setters return `this` so the
* request can be built in one expression.
*
* @since 1.5.0
* @public
* @constructor
* @param {Object} [options]
* @param {String} [options.place] Free-text input ("100 rue de Rivoli, Paris").
* @param {bemap.Address} [options.address] Structured input (alternative to `place`).
* @param {String} [options.searchType] One of `bemap.GeocodingSearchType.*`.
* @param {String} [options.assetType] One of `bemap.AssetSearchType.*`.
* @param {String} [options.language] BCP-47 language code (e.g. 'fr', 'en-US').
* @param {Number} [options.maxResult=10]
* @param {bemap.BoundingBox} [options.boundingBox] Restrict the lookup to a bbox.
* @param {bemap.Coordinate} [options.proximity] Bias the lookup to results near this point.
* @param {Boolean} [options.addressDetails=true] Include the full PostalAddress in results.
*/
bemap.GeocodingRequest = function(options) {
var opts = options || {};
this.place = opts.place || null;
this.address = opts.address || null;
this.searchType = opts.searchType || null;
this.assetType = opts.assetType || null;
this.language = opts.language || null;
this.maxResult = (typeof opts.maxResult === 'number') ? opts.maxResult : 10;
this.boundingBox = opts.boundingBox || null;
this.proximity = opts.proximity || null;
this.addressDetails = (opts.addressDetails === undefined) ? true : !!opts.addressDetails;
};
bemap.GeocodingRequest.prototype.setPlace = function(v) { this.place = v; return this; };
bemap.GeocodingRequest.prototype.setAddress = function(v) { this.address = v; return this; };
bemap.GeocodingRequest.prototype.setSearchType = function(v) { this.searchType = v; return this; };
bemap.GeocodingRequest.prototype.setAssetType = function(v) { this.assetType = v; return this; };
bemap.GeocodingRequest.prototype.setLanguage = function(v) { this.language = v; return this; };
bemap.GeocodingRequest.prototype.setMaxResult = function(v) { this.maxResult = v; return this; };
bemap.GeocodingRequest.prototype.setBoundingBox = function(v) { this.boundingBox = v; return this; };
bemap.GeocodingRequest.prototype.setProximity = function(v) { this.proximity = v; return this; };
bemap.GeocodingRequest.prototype.setAddressDetails = function(v) { this.addressDetails = !!v; return this; };
/**
* Serialise the request to the JSON shape posted to the BeMap geocoding
* endpoint. `null` fields are stripped.
*
* @return {Object}
*/
bemap.GeocodingRequest.prototype.toJson = function() {
var body = {};
if (this.place) body.place = this.place;
if (this.address) {
body.address = (typeof this.address.toJson === 'function')
? this.address.toJson() : this.address;
}
if (this.searchType) body.searchType = this.searchType;
if (this.assetType) body.assetType = this.assetType;
if (this.language) body.language = this.language;
if (this.maxResult !== null && this.maxResult !== undefined) body.maxResult = this.maxResult;
body.addressDetails = !!this.addressDetails;
if (this.boundingBox) {
body.boundingBox = {
minLon: this.boundingBox.minLon,
minLat: this.boundingBox.minLat,
maxLon: this.boundingBox.maxLon,
maxLat: this.boundingBox.maxLat
};
}
if (this.proximity) {
body.proximity = {
longitude: (typeof this.proximity.getLon === 'function')
? this.proximity.getLon() : this.proximity.lon,
latitude: (typeof this.proximity.getLat === 'function')
? this.proximity.getLat() : this.proximity.lat
};
}
return body;
};