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

/**
 * Geocoding service constructor
 * @class
 * @constructor
 * @param {cercaliax.service.GeocodingOptions} options Opciones Geocoding
 */ 
cercalia.service.Geocoding = function(options) {
	
	options = options ? options : {};
	
	/**
	 * Class name
	 * @private
	 * @type {string}
	 */
	this.CLASS_NAME_ = "cercalia.service.Geocoding";
	
	/**
	 * @private
	 * @type {string}
	 */
	this.cercaliaKey_ = cercaliaGlobals.key;	//Esta variable siempre se pasara al descargar la API
	
	/**
	 * @private
	 * @type {string}
	 */
	this.server_ = servers.servlet;

	/**
	 * @private
	 * @type {boolean}	 
	 */
	this.async_ = true;
	
	/**
	 * @type {Object}
	 * @private
	 */
	this.response_ = null;
	
	/**
	 * Name general filter (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 and 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;
	
	/**
	 * Town code filter (ctc)
	 * @type {string}
	 */
	this.cityId = options.cityId ? options.cityId : null;
	
	/**
	 * Town name filter (ctn)
	 * @type {string}
	 */
	this.city = options.city ? options.city : null;
	
	/**
	 * Postal code filter (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;
	
	/**
	 * Secondary street name filter to search cross-streets (istn)
	 * @type {string}
	 */
	this.street2 = options.street2 ? options.street2 : null;
	
	/**
	 * Secondary street code filter to search cross-streets (istc)
	 * @type {string}
	 */
	this.street2Id = options.street2Id ? options.street2Id : null;
	
	/**
	 * House number filter (stnum)
	 * @type {number}
	 */
	this.housenumber = options.housenumber ? options.housenumber : null;
	
	/**
	 * Street name filter with house number
	 * @type {string}
	 */
	this.address = options.address ? options.address : null;
	
	/**
	 * Road name filter (rdn)
	 * @type {string}
	 */
	this.roadName = options.roadName ? options.roadName : null;
	
	/**
	 * Road code filter (rdc)
	 * @type {string}
	 */
	this.roadId = options.roadId ? options.roadId : null;
	
	/**
	 * Mile marker filter (km)
	 * @type {number}
	 */
	this.km = options.km ? options.km : null;
	
	/**
	 * Use all candidates parameters (fullsearch)
	 * @type {string}
	 */
	this.fullSearch = options.fullSearch ? options.fullSearch : null;
	
	/**
	 * Number of candidates per page (numcand) 
	 * @type {string}
	 */
	this.numCand = options.numCand ? options.numCand : null;
	
	/**
	 * First candidate position, begining with 0 (poscand)
	 * @type {string}
	 */
	this.posCand = options.posCand ? options.posCand : null;
	
	/**
	 * Maximum number of results (num)
	 * @type {number}
	 */
	this.num = options.num ? options.num : null;
	
	/**
	 * POIs categories filter (poicat)
	 * @type {string}
	 */
	this.poicat = options.poicat ? options.poicat : null;
	
	/**
	 * POI code filter (poic)
	 * @type {string}
	 */
	this.poiId = options.poiId ? options.poiId : null;
	
	/**
	 * POI name filter (poiname)
	 * @type {string}
	 */
	this.poiName = options.poiName ? options.poiName : null;
	
};


/**
 * Change the geocoding request synchronously.
 * @param {boolean} async
 */
cercalia.service.Geocoding.prototype.setAsync = function(async){
	this.async_ = async;
};

/**
 * Use null to all properties. 
 */
cercalia.service.Geocoding.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.address = 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.poicat = null;
	this.poiId = null;
	this.poiName = null;
	
	this.response_ = null;
};

/**
 * @param {cercaliax.service.Geocoding} options
 */
cercalia.service.Geocoding.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.address = options.address ? options.address : 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.poicat = options.poicat ? options.poicat : null;
	this.poiId = options.poiId ? options.poiId : null;
	this.poiName = options.poiName ? options.poiName : null;
	
	this.response_ = null;
};


/**
 * Returns the response once the 'geocode' function finished
 * @return {Object} response
 */
cercalia.service.Geocoding.prototype.getResponse = function() {
	return this.response_;
};

/**
 * AJAX request
 * @param {Function} callbackFn
 * @param {Function|undefined} callbackErrorFn
 */
cercalia.service.Geocoding.prototype.geocode = function(callbackFn, callbackErrorFn) {
	
	var self = this;
	
	var params = {
			key : this.cercaliaKey_,
			cmd : 'geocoding'
	};
	

	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.address) params.address = this.address;
	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.poicat) params.poicat = this.poicat;
	if(this.poiId) params.poiId = this.poiId;
	if(this.poiName) params.poiName = this.poiName;
	
	cercalia.jQuery.ajax({
		url: this.server_,
		data: params,
		type: "GET",
		method: "GET",
		dataType: cercalia.Util.isIEUnderTen() ? "jsonp" : "json",
		//contentType: 'application/json; charset=utf-8',
		crossDomain: true,
		async: this.async_ ? this.async_ : true,
		timeout: 5000,
		success: function(data){
			self.response_ = data;

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

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