/**
* @classdesc
*
* Coordinates. Let you specify the coordinates in the desired projection. <br/>
* Default value: `EPSG:4326`.
*
* @constructor
* @param {number} lon Longitude, in geographic coordinate system
* @param {number} lat Latitude, in geographic coordinate system
* @param {srs|undefined} srs SRS
*/
cercalia.LonLat = function(lon, lat, srs) {
/**
* @private
* @type {string}
*/
this.srs_ = srs ? srs : 'EPSG:4326';
/**
* @private
* @type {string}
*/
this.srsOriginal_ = srs ? srs : 'EPSG:4326';
/**
* @private
* @type {number}
*/
this.lon_ = isNaN(lon) ? lon : parseFloat(lon);
/**
* @private
* @type {number}
*/
this.lat_ = isNaN(lat) ? lat : parseFloat(lat);
if(this.srs_!='EPSG:4326'){
var coord = ol.proj.transform([this.lon_, this.lat_], srs,'EPSG:4326');
this.lon_ = coord[0];
this.lat_ = coord[1];
this.srs_ = 'EPSG:4326'; // com es modifica les coords es posa en el que es mostra;
}
/**
* Class name
* @private
* @type {string}
*/
this.CLASS_NAME_ = "cercalia.LonLat";
};
/**
* @param {number} lon Longitude
*/
cercalia.LonLat.prototype.setLon = function(lon){
this.lon_ = lon;
};
/**
* @return {number} Coordinate Longitude
*/
cercalia.LonLat.prototype.getLon = function(){
return this.lon_;
};
/**
* @param {number} lat Coordinate Latitude
*/
cercalia.LonLat.prototype.setLat = function(lat){
this.lat_ = lat;
};
/**
* @return {number} Latitud
*/
cercalia.LonLat.prototype.getLat = function(){
return this.lat_;
};
/**
* Transform the coordinates to a new projection (need SRS projection parameter).
* @param {string} srs SRS [EPSG:23030,EPSG:23031,EPSG:23032,EPSG32629,EPSG:32630,EPSG:32631,EPSG:32632,EPSG:54004]
* @return {ol.Coord} Array `[x,y]` projected coordinates.
*/
cercalia.LonLat.prototype.transform = function(srs){
return ol.proj.transform([this.lon_,this.lat_], 'EPSG:4326', srs);
};
/**
* @return {string} To string longitude,latitude. For example: `"1.41651,41.541451"
*/
cercalia.LonLat.prototype.toString = function(){
return this.lon_ + "," + this.lat_;
};
/**
* Obtain the coordinates projection code
* @return {string} EPSG code. For example: `EPSG:3857`.
*/
cercalia.LonLat.prototype.getProjectionCode = function(){
return this.srs_;
};
/**
* Obtain the original coordinates projection code
* @return {string} EPSG code. For example: `EPSG:3857`.
*/
cercalia.LonLat.prototype.getProjectionCodeOriginal = function(){
return this.srsOriginal_;
};
/**
* @return {string} Class name
*/
cercalia.LonLat.prototype.getClass = function(){
return this.CLASS_NAME_;
};