Source: temp/jsdocinputdirs/cercalia.service.proximity.js

/**
 * Proximity service constructor
 * @class
 * @constructor
 * @param {cercaliax.service.ProximityOptions} options Proximity options
 * @param {Function} callbackFn Callback function
 */
cercalia.service.Proximity = function(options) {

	options = options ? options : {};

	/**
	 * Class name
	 * @private
	 * @type {string}
	 */
	this.CLASS_NAME_ = "cercalia.service.Proximity";

	/**
	 * @private
	 * @type {string}
	 */
	this.cercaliaKey_ = cercaliaGlobals.key;	//Esta variable siempre se pasara al descargar la API

	/**
	 * @private
	 * @type {string}
	 */
	this.server_ = servers.servlet;

	/**
	 * @type {Object}
	 * @private
	 */
	this.response_ = null;

	/**
	 * Search parameters with the same geocoding values
	 */


	/**
	 * Search by name, general search with no filters (locn)
	 * @type {string}
	 */
	this.name = options.name ? options.name : null;

	/**
	 * Country code filter (ctryc)
	 * @type {string}
	 */
	this.countryId = options.countryId ? options.countryId : null;

	/**
	 * Country name filter (ctryn)
	 * @type {string}
	 */
	this.country = options.country ? options.country : null;

	/**
	 * Region code filter (regc)
	 * @type {string}
	 */
	this.regionId = options.regionId ? options.regionId : null;

	/**
	 * Region name filter (regn)
	 * @type {string}
	 */
	this.region = options.region ? options.region : null;

	/**
	 * Subregion code filter (subregc)
	 * @type {string}
	 */
	this.subregionId = options.subregionId ? options.subregionId : null;

	/**
	 * Subregion name filter (subregn)
	 * @type {string}
	 */
	this.subregion = options.subregion ? options.subregion : null;

	/**
	 * Region / subregion name filter (rsn)
	 * @type {string}
	 */
	this.subOrRegion = options.subOrRegion ? options.subOrRegion : null;

	/**
	 * Municipality code filter (munc)
	 * @type {string}
	 */
	this.municipalityId = options.municipalityId ? options.municipalityId : null;

	/**
	 * Municipality name filter (munn)
	 * @type {string}
	 */
	this.municipality = options.municipality ? options.municipality : null;

	/**
	 * City code filter (ctc)
	 * @type {string}
	 */
	this.cityId = options.cityId ? options.cityId : null;

	/**
	 * City name filter (ctn)
	 * @type {string}
	 */
	this.city = options.city ? options.city : null;

	/**
	 * Postal code filter, requires country code (pcode)
	 * @type {string}
	 */
	this.postalCode = options.postalCode ? options.postalCode : null;

	/**
	 * Street code filter (stc)
	 * @type {string}
	 */
	this.streetId = options.streetId ? options.streetId : null;

	/**
	 * Street name filter (stn)
	 * @type {string}
	 */
	this.street = options.street ? options.street : null;

	/**
	 * Second street name filter, for street intersection seach (istn)
	 * @type {string}
	 */
	this.street2 = options.street2 ? options.street2 : null;

	/**
	 * Second street code filter, for street intersection seach  (istc)
	 * @type {string}
	 */
	this.street2Id = options.street2Id ? options.street2Id : null;

	/**
	 * Housenumber filter (stnum)
	 * @type {number}
	 */
	this.housenumber = options.housenumber ? options.housenumber : null;

	/**
	 * Road name filter (rdn)
	 * @type {string}
	 */
	this.roadName = options.roadName ? options.roadName : null;

	/**
	 * Road cod filter (rdc)
	 * @type {string}
	 */
	this.roadId = options.roadId ? options.roadId : null;

	/**
	 * Road milestone filter (km)
	 * @type {number}
	 */
	this.km = options.km ? options.km : null;

	/**
	 * Solve all the candidate params (fullsearch)
	 * @type {string}
	 */
	this.fullSearch = options.fullSearch ? options.fullSearch : null;

	/**
	 * Maximum number of candidates per page (numcand)
	 * @type {string}
	 */
	this.numCand = options.numCand ? options.numCand : null;

	/**
	 * First candidate position for every page, starting from 0 (poscand)
	 * @type {string}
	 */
	this.posCand = options.posCand ? options.posCand : null;

	/**
	 * Maximum number of candidates. Maxim server value 99 (num)
	 * @type {number}
	 */
	this.num = options.num ? options.num : null;

	/**
	 *
	 * Geometry.
	 * Required parameters:
	 * 	- wkt
	 *  - srs (default: EPSG:4326)
	 */

	/**
	 * @type {string}
	 */
	this.wkt = options.wkt ? options.wkt : null;


	/**
	 * @type {string}
	 */
	this.srs = options.srs ? options.srs : 'EPSG:4326';


	/**
	 *
	 * Coordinate.
	 * Required parameters:
	 * 	- x
	 *  - y
	 *  - srs (por defecto: EPSG:4326)
	 */

	/**
	* @type {number}
	*/
	this.x = options.x ? options.x : null;

	/**
	* @type {number}
	*/
	this.y = options.y ? options.y : null;

	/**
	* @type {string}
	*/
	this.rqge = options.rqge ? options.rqge : null;

	/**
	* @type {Array.<string>}
	*/
	this.rqpoicats = options.rqpoicats ? options.rqpoicats : null;

	/**
	* @type {boolean}
	*/
	this.infoxml = options.infoxml ? 1 : 0;

	/**
	* @type {string}
	*/
	this.weight = options.weight ? options.weight : null;

	/**
	* @type {boolean}
	*/
	this.inverse = options.inverse ? 1 : 0;

	/**
	* @type {Array.<string>}
	*/
	this.mos = options.mos ? options.mos : null;

	/**
	* @type {number}
	*/
	this.rad = options.rad ? options.rad : null;

};

/**
 * Set null all the properties.
 */
cercalia.service.Proximity.prototype.clear = function() {
	this.name = null;
	this.countryId = null;
	this.country = null;
	this.regionId = null;
	this.region = null;
	this.subregionId = null;
	this.subregion = null;
	this.subOrRegion = null;
	this.municipalityId = null;
	this.municipality = null;
	this.cityId = null;
	this.city = null;
	this.postalCode = null;
	this.streetId = null;
	this.street = null;
	this.street2 = null;
	this.street2Id = null;
	this.housenumber = null;
	this.roadName = null;
	this.roadId = null;
	this.km = null;
	this.fullSearch = null;
	this.numCand = null;
	this.posCand = null;
	this.num = null;
	this.rqge = null;
	this.rqpoicats = null;
	this.infoxml = null;
	this.weight = null;
	this.inverse = null;
	this.mos = null;
	this.rad = null;


	this.response_ = null;
};

/**
 * @param {cercaliax.service.Proximity} options
 */
cercalia.service.Proximity.prototype.setSearch = function(options) {

	this.name = options.name ? options.name : null;
	this.countryId = options.countryId ? options.countryId : null;
	this.country = options.country ? options.country : null;
	this.regionId = options.regionId ? options.regionId : null;
	this.region = options.region ? options.region : null;
	this.subregionId = options.subregionId ? options.subregionId : null;
	this.subregion = options.subregion ? options.subregion : null;
	this.subOrRegion = options.subOrRegion ? options.subOrRegion : null;
	this.municipalityId = options.municipalityId ? options.municipalityId : null;
	this.municipality = options.municipality ? options.municipality : null;
	this.cityId = options.cityId ? options.cityId : null;
	this.city = options.city ? options.city : null;
	this.postalCode = options.postalCode ? options.postalCode : null;
	this.streetId = options.streetId ? options.streetId : null;
	this.street = options.street ? options.street : null;
	this.street2 = options.street2 ? options.street2 : null;
	this.street2Id = options.street2Id ? options.street2Id : null;
	this.housenumber = options.housenumber ? options.housenumber : null;
	this.roadName = options.roadName ? options.roadName : null;
	this.roadId = options.roadId ? options.roadId : null;
	this.km = options.km ? options.km : null;
	this.fullSearch = options.fullSearch ? options.fullSearch : null;
	this.numCand = options.numCand ? options.numCand : null;
	this.posCand = options.posCand ? options.posCand : null;
	this.num = options.num ? options.num : null;

	this.wkt = options.wkt ? options.wkt : null;
	this.srs = options.srs ? options.srs : 'EPSG:4326';

	this.x = options.x ? options.x : null;
	this.y = options.y ? options.y : null;

	this.rqge = options.rqge ? options.rqge : null;
	this.rqpoicats = options.rqpoicats ? options.rqpoicats : null;
	this.infoxml = options.infoxml ? options.infoxml : null;
	this.weight = options.weight ? options.weight : null;
	this.inverse = options.inverse ? options.inverse : null;
	this.mos = options.mos ? options.mos : null;
	this.rad = options.rad ? options.rad : null;


	this.response_ = null;
};


/**
 * Returns response to the query with function 'proximity'
 * @return {Object} response
 */
cercalia.service.Proximity.prototype.getResponse = function() {
	return this.response_;
};

/**
 * Execute AJAX request
 * @param {Function} callbackFn
 */
cercalia.service.Proximity.prototype.proximity = function(callbackFn) {

	var self = this;

	var params = {
			key : this.cercaliaKey_,
			cmd : 'proximity'
	};


	if (this.name) params.name = this.name;
	if (this.countryId) params.countryId = this.countryId;
	if (this.country) params.country = this.country;
	if (this.regionId) params.regionId = this.regionId;
	if (this.region) params.region = this.region;
	if (this.subregionId) params.subregionId = this.subregionId;
	if (this.subregion) params.subregion = this.subregion;
	if (this.subOrRegion) params.subOrRegion = this.subOrRegion;
	if (this.municipalityId) params.municipalityId = this.municipalityId;
	if (this.municipality) params.municipality = this.municipality;
	if (this.cityId) params.cityId = this.cityId;
	if (this.city) params.city = this.city;
	if (this.postalCode) params.postalCode = this.postalCode;
	if (this.streetId) params.streetId = this.streetId;
	if (this.street) params.street = this.street;
	if (this.street2) params.street2 = this.street2;
	if (this.street2Id) params.street2Id = this.street2Id;
	if (this.housenumber) params.housenumber = this.housenumber;
	if (this.roadName) params.roadName = this.roadName;
	if (this.roadId) params.roadId = this.roadId;
	if (this.km) params.km = this.km;
	if (this.fullSearch) params.fullSearch = this.fullSearch;
	if (this.numCand) params.numCand = this.numCand;
	if (this.posCand) params.posCand = this.posCand;
	if (this.num) params.num = this.num;
	if (this.wkt) params.wkt = this.wkt;
	if (this.srs) params.srs = this.srs;
	if (this.x) params.x = this.x;
	if (this.y) params.y = this.y;
	if (this.rqge) params.rqge = this.rqge;
	if (this.rqpoicats) params.rqpoicats = this.rqpoicats.join(",");
	if (this.infoxml) params.infoxml = this.infoxml;
	if (this.weight) params.weight = this.weight;
	if (this.inverse) params.inverse  = this.inverse;
	if (this.mos) params.mos = this.mos.join(",");
	if (this.rad) params.rad = this.rad;


	cercalia.jQuery.ajax({
		url: this.server_,
		type: this.wkt?'POST':'GET',   //An alias for method. You should use type if you're using versions of jQuery prior to 1.9.0.
		method: this.wkt?'POST':'GET', //The HTTP method to use for the request (e.g. "POST", "GET", "PUT"). (version added: 1.9.0)
		data: params,
		dataType: this.wkt? "json" : cercalia.Util.isIEUnderTen() ? "jsonp" : "json",
		//contentType: 'application/json; charset=utf-8',
		async:true,
		crossDomain: true,
		timeout: 10000,
		success: function(data) {
			self.response_ = data;

			if (callbackFn) {
				callbackFn(self.response_);
			} else {
				console.error("No callbackfunction defined");
			}
		},
		error: cercalia.AJAXException
	});

};

/**
* Returns the object type.
* @return {string}
*/
cercalia.service.Proximity.prototype.getClass = function() {
	return this.CLASS_NAME_;
};