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

/**
 * Isochrone service constructor
 * @class
 * @constructor
 * @param {cercaliax.service.IsochroneOptions} options Isochrone request options
 */
cercalia.service.Isochrone = function(options) {

	options = options ? options : {};

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

	/**
	 * @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;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	/**
	 * Street name filter with house number
	 * @type {string|undefined}
	 */
	this.address = options.address ? options.address : null;

	/**
	 * Position of center to calculate isochrone request.
	 * @type {cercalia.LonLat|undefined}
	 */
	this.position = options.position ? options.position : null;

	/**
	 * Type of search value. Possible values `distance` or `time`. Default value  `distance`
	 * @type {string|undefined}
	 */
	this.weight = options.weight ? options.weight : "distance";

	/**
	 * If `false`, the calculation is from the center to outside. If `true`, the calculation is from outside to the center. Default value `false`.
	 * @type {boolean|undefined}
	 */
	this.inverse = options.inverse ? options.inverse : false;

	/**
	 * Calculation method. Por defecto: `convexhull` or `concavehull`. Default value `convexhull`.
	 * @type {string|undefined}
	 */
	this.method = options.method ? options.method : "convexhull";

	/**
	 * Value, or incremental values list used for isochrone calculation (meters or miliseconds). Ex: `10000`, `5000,10000,20000`.
	 * @type {number|string}
	 */
	this.isolevels = options.isolevels ? options.isolevels : null;

};


/**
 * Use null to all properties.
 */
cercalia.service.Isochrone.prototype.clear = function(){
	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.housenumber = null;

	this.weight = null;
	this.inverse = null;
	this.method = null;
	this.isolevels = null;

	this.response_ = null;
};

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

	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.housenumber = options.housenumber ? options.housenumber : null;
	this.weight = options.weight ? options.weight : null;
	this.inverse = options.inverse ? options.inverse : null;
	this.method = options.method ? options.method : null;
	this.isolevels = options.isolevels ? options.isolevels : null;
	this.position =  options.position ? options.position : null;

	this.response_ = null;
};


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

/**
 * Do isochrone request.
 * @param {Function} callbackFn
 * @param {Function|undefined} callbackErrorFn
 */
cercalia.service.Isochrone.prototype.calculate = function(callbackFn, callbackErrorFn) {

	var self = this;

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


	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.housenumber) params.housenumber = this.housenumber;

	if(this.weight) params.weight = this.weight;
	if(this.inverse) params.inverse = this.inverse ? "1" : "0";
	if(this.method) params.method = this.method;
	if(this.isolevels) params.isolevels = this.isolevels;

	if(this.position){
		params.mo = this.position.getLat() + "," + this.position.getLon();
	}


	cercalia.jQuery.ajax({
		url: this.server_,
		data: params,
		type: "GET",
		method: "GET",
		dataType: cercalia.Util.isIEUnderTen() ? "jsonp" : "json",
		crossDomain: true,
		timeout: 30000,
		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.Isochrone.prototype.getClass = function(){
	return this.CLASS_NAME_;
};