Created
June 6, 2013 11:53
-
-
Save sepulchered/5720985 to your computer and use it in GitHub Desktop.
Custom OpenLayers mouse position format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OpenLayers.Control.CustomMousePosition = OpenLayers.Class(OpenLayers.Control.MousePosition, { | |
formatOutput: function(lonLat){ // override this function | |
var formatLonLat = function(val, lon){ | |
var dir, degrees, minutes, seconds; | |
if (lon) { | |
dir = val >= 0 ? 'E' : 'W'; | |
} else { | |
dir = val >= 0 ? 'N' : 'S'; | |
} | |
val = Math.abs(val); | |
degrees = Math.floor( val ); | |
minutes = Math.floor( (val - degrees ) * 60 ); | |
seconds = ((val - degrees - ( minutes / 60 )) * 3600).toFixed(4); | |
return ""+degrees+"° "+minutes+"′ "+seconds+"″ "+dir; | |
}; | |
var newHtml = | |
this.prefix + | |
formatLonLat(lonLat.lon, true) + | |
this.separator + | |
formatLonLat(lonLat.lat, false) + | |
this.suffix; | |
return newHtml; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment