[OpenLayers-Dev] Formatting degrees in MousePosition

Lance Dyas lancelot at inetnebr.com
Mon Jan 29 09:30:29 EST 2007


Fairly simple code... makes it more glossy/finished seeming.


formatCoords: function (base) {
            var t, t2;
           var degrees = Math.floor(base);
            var minutes = Math.floor(t = ( base - degrees ) * 60);
           var seconds = Math.floor(t2 = ( t - minutes ) * 6000);
            seconds = seconds / 100.00;
            return ("" + degrees + "\u00B0 " + minutes + "\u0027 " + 
seconds + "\u0022" );

AND

    if (this.map.units == "degrees") {
          newHtml =  this.formatCoords(lonLat.lon)  + this.separator + 
this.formatCoords(lonLat.lat);
        }
    else {
         var digits = parseInt(this.numdigits);
             newHtml =
            this.prefix +
            lonLat.lon.toFixed(digits) +
            this.separator +
            lonLat.lat.toFixed(digits) +
            this.suffix;
        }



More information about the Dev mailing list