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

/**
 * Routing Logistics Service constructor
 * @class
 * @constructor
 * @param {cercaliax.service.LogisticsRoutingOptions} options
 */
cercalia.service.LogisticsRouting = function(options) {

    var options = options ? options : {};

    cercalia.service.Routing.call(this, options);

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

    this.vweight_ = options.vweight ? options.vweight : null;

    this.vaxleweight_ = options.vaxleweight ? options.vaxleweight : null;

    this.vheight_ = options.vheight ? options.vheight : null;

    this.vlength_ = options.vlength ? options.vlength : null;

    this.vwidth_ = options.vwidth ? options.vwidth : null;

    this.vmaxvel_ = options.vmaxvel ? options.vmaxvel : null;

    this.trstart_ = options.trstart ? options.trstart : null;

    /*this.response_ = null;

    this.routeid_ = null;

    this.wkt_ = null;*/

	/**
	 * @type {string}
	 * @private
	 */
	this.intoll_x_ = options.intoll_x ? options.intoll_x : "1";

};
ol.inherits(cercalia.service.LogisticsRouting, cercalia.service.Routing);

/**
 * Get the vehicle weight.
 * @return {number} Vehicle weight.
 */
cercalia.service.LogisticsRouting.prototype.getVWeight = function(){
    return this.vweight_;
};

/**
 * Set the vehicle weight.
 * @param {number} vweight Vehicle weight.
 */
cercalia.service.LogisticsRouting.prototype.setVWeight = function(vweight) {
    this.vweight_ = vweight;
};

/**
 * Get the vehicle axel weight.
 * @return {number} Vehicle axel weight.
 */
cercalia.service.LogisticsRouting.prototype.getVAxleWeight = function(){
    return this.vaxleweight_;
};

/**
 * Set the vehicle axel weight.
 * @param {number} vaxleweight Vehicle axel weight.
 */
cercalia.service.LogisticsRouting.prototype.setVAxleWeight = function(vaxleweight) {
    this.vaxleweight_ = vaxleweight;
};

/**
 * Get the vehicle height.
 * @return {number} Vehicle height.
 */
cercalia.service.LogisticsRouting.prototype.getVHeight = function(){
    return this.vheight_;
};

/**
 * Set the vehicle height.
 * @param {number} vheight Vehicle height.
 */
cercalia.service.LogisticsRouting.prototype.setVHeight = function(vheight) {
    this.vheight_ = vheight;
};

/**
 * Get the vehicle length.
 * @return {number} Vehicle length.
 */
cercalia.service.LogisticsRouting.prototype.getVLength = function(){
    return this.vlength_;
};

/**
 * Set the vehicle length.
 * @param {number} vlength Vehicle length.
 */
cercalia.service.LogisticsRouting.prototype.setVLength = function(vlength) {
    this.vlength_ = vlength;
};

/**
 * Get the vehicle width.
 * @return {number} Vehicle width.
 */
cercalia.service.LogisticsRouting.prototype.getVWidth = function(){
    return this.vwidth_;
};

/**
 * Set the vehicle width.
 * @param {number} vwidth Vehicle width.
 */
cercalia.service.LogisticsRouting.prototype.setVWidth = function(vwidth) {
    this.vwidth_ = vwidth;
};

/**
 * Get the vehicle maximum speed.
 * @return {number} Vehicle maximum speed.
 */
cercalia.service.LogisticsRouting.prototype.getVMaxVel = function(){
    return this.vmaxvel_;
};

/**
 * Set the vehicle maximum speed.
 * @param {number} vmaxvel Vehicle maximum speed.
 */
cercalia.service.LogisticsRouting.prototype.setVMaxVel = function(vmaxvel) {
    this.vmaxvel_ = vmaxvel;
};

/**
 * Get the restriction time start.
 * @return {number} Restriction time start.
 */
cercalia.service.LogisticsRouting.prototype.getTRStart = function(){
    return this.trstart_;
};

/**
 * Set the restriction time start.
 * @param {number} trstart Restriction time start.
 */
cercalia.service.LogisticsRouting.prototype.setTRStart = function(trstart) {
    this.trstart_ = trstart;
};

/**
 * Resets the values to null
 */
cercalia.service.LogisticsRouting.prototype.clear = function() {

    this.vweight_ = null;
    this.vaxleweight_ = null;
    this.vheight_ = null;
    this.vlength_ = null;
    this.vwidth_ = null;
    this.vmaxvel_ = null;
    this.trstart_ = null;

    cercalia.service.Routing.call(this);
};

/**
 * Calculates the route specifying a callback function to be executed when obtains the response
 * @param {Function} callbackFn
 */
cercalia.service.LogisticsRouting.prototype.calculateRoute = function(callbackFn) {

    var self = this;

    //Parámetros obligatorios
    var params = {
        key: this.cercaliaKey_,
        cmd: 'routinglogistics',
        weight: this.weight_,
        tolerance: this.tolerance_,
        edges: this.edges_,
        report: this.report_
    };

    if(this.vweight_) params.vweight = this.vweight_;
    if(this.vaxleweight_) params.vaxleweight = this.vaxleweight_;
    if(this.vheight_) params.vheight = this.vheight_;
    if(this.vlength_) params.vlength = this.vlength_;
    if(this.vwidth_) params.vwidth = this.vwidth_;
    if(this.vmaxvel_) params.vmaxvel = this.vmaxvel_;
    if(this.trstart_) params.trstart = this.trstart_;

    //Generamos los parámetros de forma dinámica según los valors de la variables origin/destination/steps

    //Origen
    if(this.origin_ instanceof cercalia.LonLat){
        params["mo_o"] = this.origin_.getLat() + "," + this.origin_.getLon() + "|" + cercalia.i18n._('Origin');
		params["intoll_o"] = this.intoll_x_; // posem el parametre 'intoll_o'

    } else {
        if(this.origin_.streetId){
            params["stc_o"] = this.origin_.streetId;
            if(this.origin_.streetNum){
                params["stnum_o"] = this.origin_.streetNum;
            }
        } else if ( this.origin_.cityId ) {
            params["ctc_o"] = this.origin_.cityId;
        } else if ( this.origin_.municipalityId ) {
            params["munc_o"] = this.origin_.municipalityId;
        } else {
            alert('No se puede calcular la ruta: El origen es incorrecto');
        }
    }

    //Pasos intermedios (opcional)
    this.steps_.forEach(function(elem,i){
        if(elem instanceof cercalia.LonLat){
            params["mo_"+(i+1)] =  elem.getLat() + "," + elem.getLon() + "|" + cercalia.i18n._('Step "%"', (i+1) );
			params["intoll_"+(i+1)] = this.intoll_x_; // posem el parametre 'intoll_x'
        } else {
            if(elem.streetId){
                params["stc_"+(i+1)] = elem.streetId;
                if(elem.streetNum){
                    params["stnum_"+(i+1)] = elem.streetNum;
                }
            } else if ( elem.cityId ) {
                params["ctc_"+(i+1)] = elem.cityId;
            } else if ( elem.municipalityId ) {
                params["munc_"+(i+1)] = elem.municipalityId;
            } else {
                alert('No se puede calcular la ruta: La etapa ('+(i+1)+') es inválida');
            }
        }
    });

    //Destination
    if(this.destination_ instanceof cercalia.LonLat){
        params["mo_d"] = this.destination_.getLat() + "," + this.destination_.getLon() + "|" + cercalia.i18n._('Destination');
		params["intoll_d"] = this.intoll_x_; // posem el parametre 'intoll_d'
    } else {
        if( this.destination_.streetId ){
            params["stc_d"] = this.destination_.streetId;
            if(this.destination_.streetNum){
                params["stnum_d"] = this.destination_.streetNum;
            }
        } else if ( this.destination_.cityId ) {
            params["ctc_d"] = this.destination_.cityId;
        } else if ( this.destination_.municipalityId ) {
            params["munc_d"] = this.destination_.municipalityId;
        } else {
            alert('No se puede calcular la ruta: El destino es incorrecto');
            return;
        }
    }


    //Parametros opcionales
    //if(this.poicats_.length>0) params.getpoicats = this.poicats_.join(",");
    if(this.reorder_) params.reorder = this.reorder_;
    if(this.report_){
        params.lang = this.lang_ ? this.lang_ : 'es';
        params.mindist = this.mindist_;
    }
    if(this.toll_) params.toll = this.toll_;

    cercalia.jQuery.ajax({
    	type: "GET",
		method: "GET",
		dataType: cercalia.Util.isIEUnderTen() ? "jsonp" : "json",
		//contentType: 'application/json; charset=utf-8',
        url: this.server_,
        data: params,
        async: this.async_ ? this.async_ : true,
        success: function(data){
//          try {
                self.response_ = data;

                if(data.cercalia.error){
                    var error = data.cercalia.error;
                    cercalia.Exception('Cercalia Error:' + error.id + ', type_id:' + error.type + ', value:' + error.value);
                }

                //self.routeid_ = data.cercalia.geometry.route.id;
                self.routeid_ = data.cercalia.route.id;

				if(data.cercalia.geometry.route instanceof Array){
					self.wkt_ = self.createWKTWithArrayLineString_(data.cercalia.geometry.route);
					self.arrayStages_ = data.cercalia.geometry.route;
				} else {
                    self.wkt_ = data.cercalia.geometry.route.wkt.value;
					self.arrayStages_ = [ data.cercalia.geometry.route ];
				}

				//Actualitzem l'origen/desti/step si cal
				self.updateStops_(data);

                callbackFn(data);
//          } catch (e) {
//              console.error(e);
//          }
        },
        error: cercalia.AJAXException
    });

};


/**
 * Obtains route WKT (polyline)
 * @return {string} Route WKT. Returns null if no route is calculated
 */
cercalia.service.Routing.prototype.getWKT = function(){
	return this.wkt_;
};

/**
 * Obtains route WKT (polyline)
 * @return {string} Route WKT. Returns null if no route is calculated
 */
cercalia.service.Routing.prototype.getStages = function(){
	return this.arrayStages_;
};

/**
 * Obtains a WKT (polyline) for every route substage specified. First the route must be calculated with
 * parameter "report=true"
 *
 * @param {Array.<stringr>} substages Subetapas. p.e: ["1,2", "3,4,5"]
 * @param {function} callbackFn Callback function
 */
/*cercalia.service.LogisticsRouting.prototype.getSubstageWKT= function (substages, callbackFn) {
    cercalia.service.LogisticsRouting.base(this, 'getSubstageWKT', substages, callbackFn);
};*/

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

/**
 * clone cercalia.service.LogisticsRouting to cercalia.service.Routing
 * @param {cercalia.service.LogisticsRouting} service
 * @returns {cercalia.service.Routing}
 */
cercalia.service.Routing.prototype.cloneToRoutingService = function(service) {

	var routingService = new cercalia.service.Routing();

	routingService.setOrigin(this.getOrigin());
	routingService.setDestination(this.getDestination());
	routingService.setSteps(this.getSteps());
	routingService.setReporting(this.isReporting());
	routingService.setTolerance(this.getTolerance());
	routingService.setEdges(this.getEdges());
	routingService.setPoicats(this.getPoicats());
	routingService.setReorder(this.isReorder());
	routingService.setToll(this.getToll());
	routingService.setToll_x(this.getToll_x());
	routingService.setMindist(this.getMindist());
	routingService.setAsync(this.getAsync());
	routingService.getWeight(this.setWeight());

	return routingService;
}