Skip to content

Instantly share code, notes, and snippets.

@sepulchered
Created June 6, 2013 11:53
Show Gist options
  • Save sepulchered/5720985 to your computer and use it in GitHub Desktop.
Save sepulchered/5720985 to your computer and use it in GitHub Desktop.
Custom OpenLayers mouse position format
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