[OpenLayers-Dev] formatting in sexagesimal (dms) format
Richard didier
didier.richard at ign.fr
Wed Feb 11 07:23:41 EST 2009
Le Mercredi 11 Février 2009 12:51, Christopher Schmidt a écrit :
> On Wed, Feb 11, 2009 at 12:48:43PM +0100, Ivan Grcic wrote:
> > Hi,
> >
> > i needed to show my mouse coordinates in sexagesimal format ( DMS ),
> > but couldnt find any method that would format it like that, nor in
> > mosuePosition control nor in OpenLayers.Number.format function. So i
> > ended writing my custom control...
> >
> > Is this functionality implemented somewhere in OL 2.7 (or in trunk)?
>
> Nope.
>
> > it seems they have all these methods there, can we maybe make use of
> > it (if its not allready somewhere in OL2.7)
>
> IGN's code is not open source, and they are not in a position to offer
> patches to the project.
>
Hi all,
@Christ, you should have hit that before (since the API's openning on april,
28th 2008) :
https://api.ign.fr/geoportail/doc/webmaster/license.html
The full source is downloable there :
https://api.ign.fr/geoportail/doc/developpeur/download.html
And you are right we have not yet been in a position to offer patches cause we
have still problems in signing the CCLA. We are talking with the french local
chapter of OSGeo for resolving this issue cause with need to localize CLA
(even if we can sign it in english, it is not a legal document if we have not
the localized (french in our case) counterpart).
@Ivan, we have developped for the next API's release two methods :
Geoportal.Util.dmsToDeg(<String>) and
Geoportal.UtildegToDMS(<Number>,Array(<String>))
for converting forth and back to DMS.
Here is an extract of Geoportal.Util (See license too) :
/*
* Copyright 2008 Institut Geographique National France, released under the
* BSD license.
*/
/**
* Header: Geoportal Utilities
* Geoportal functions for handling Geoportal theme, degrees convertions and
* cookies.
*/
/**
* Namespace: Geoportal.Util
* Convenience methods for the Geoportal API.
*/
Geoportal.Util = {
/**
* APIFunction: dmsToDeg
* Convert a string representation of a sexagecimal degree into a numeric
* representation of decimal degree.
*
* Parameters:
* dms - {String} a sexagecimal value. The supported syntax is :
*
* (start code)
*
\s?-?(\d{1,3})[.,°d]?\s?(\d{0,2})[']?\s?(\d{0,2})[.,]?(\d{0,})(?:["]|[']{2})?
* |
*
\s?(\d{1,3})[.,°d]?\s?(\d{0,2})[']?\s?(\d{0,2})[.,]?(\d{0,})(?:["]|[']{2})?\s?([NSEW])?
* (end)
*
* Returns:
* {Number} the decimal value or Number.NaN if error occurs.
*/
dmsToDeg: function(dms) {
if (!dms) {
return Number.NaN;
}
var neg= dms.match(/(^\s?-)|(\s?[SW]\s?$)/)!=null? -1.0 : 1.0;
dms= dms.replace(/(^\s?-)|(\s?[NSEW]\s?)$/,'');
dms= dms.replace(/\s/g,'');
var parts=
dms.match(/(\d{1,3})[.,°d]?(\d{0,2})[']?(\d{0,2})[.,]?(\d{0,})(?:["]|[']{2})?/);
if (parts==null) {
return Number.NaN;
}
// parts:
// 0 : degree
// 1 : degree
// 2 : minutes
// 3 : secondes
// 4 : fractions of seconde
var d= (parts[1]? parts[1] : '0.0')*1.0;
var m= (parts[2]? parts[2] : '0.0')*1.0;
var s= (parts[3]? parts[3] : '0.0')*1.0;
var r= (parts[4]? ('0.' + parts[4]) : '0.0')*1.0;
var dec= (d + (m/60.0) + (s/3600.0) + (r/3600.0))*neg;
return dec;
},
/**
* APIMethod: degToDMS
* Convert decimal degrees number into sexagecimal degrees string.
*
* Parameters:
* dec - {Number} decimal degrees
* locals - {Array} the axis direction (N, S) or (E, W).
* If undefined, null or empty, the leading minus will prefix the
* decimal degrees string.
*
* Returns:
* {String} the sexagecimal value whose syntax conforms with
* <Geoportal.Util.dmsToDeg>() function.
*/
degToDMS: function(dec, locals) {
var positive_degrees= Math.abs(dec);
var degrees= Math.round(positive_degrees + 0.5) - 1;
var decimal_part= 60*(positive_degrees - degrees);
var minutes= Math.round(decimal_part + 0.5) - 1;
decimal_part= 60*(decimal_part - minutes);
var seconds= Math.round(decimal_part + 0.5) - 1;
var remains= 10 * (decimal_part - seconds);
remains= remains.toFixed(this.numDigits);
if (remains>=10) {
seconds= seconds+1;
remains= 0;
}
if (seconds==60) {
minutes= minutes+1;
seconds= 0;
}
if (minutes==60) {
degrees= degrees+1;
minutes= 0;
}
var sig= '';
var dir= '';
if (locals && (locals instanceof Array) && locals.length==2) {
dir= ' ' + (dec > 0 ? locals[0] : locals[1]);
} else {
sig= (dec >= 0 ? '' : '-');
}
var s= sig +
(degrees < 10 ? "0" + degrees : degrees) + "° " +
(minutes < 10 ? "0" + minutes : minutes) + "' " +
(seconds < 10 ? "0" + seconds : seconds) + "." +
remains + "\"" +
dir;
return s;
}
};
Regards,
didier
> Regards,
--
Didier RICHARD, chef du pôle technique Géoportail pour l'IGN
Institut Geographique National tel: +33/0 1.43.98.83.23
2/4 Avenue Pasteur fax: +33/0 1.43.98.80.88
F-94165 St-Mande Cedex e-mail: Didier.Richard at ign.fr
More information about the Dev
mailing list