CursorTrack.js
Summary
No overview generated for 'CursorTrack.js'
mapbuilder.loadScript(baseDir+"/widget/WidgetBaseXSL.js");
function CursorTrack(widgetNode, model) {
WidgetBaseXSL.apply(this,new Array(widgetNode, model));
this.showPx = Mapbuilder.parseBoolean(this.getProperty("mb:showPx", false)); // pixel coordinates
this.showXY = Mapbuilder.parseBoolean(this.getProperty("mb:showXY", false)); // XY Coordinates
this.showLatLong = Mapbuilder.parseBoolean(this.getProperty("mb:showLatLong", true)); // Standard lat long
this.showDMS = Mapbuilder.parseBoolean(this.getProperty("mb:showDMS", false)); // Lat/long in DD MM SS.S format
this.showDM = Mapbuilder.parseBoolean(this.getProperty("mb:showDM", false)); // Lat/long in DD MM.MMMM format
this.showMGRS = Mapbuilder.parseBoolean(this.getProperty("mb:showMGRS", false)); // Military Grid Reference System
if( this.showMGRS ) {
mapbuilder.loadScript(baseDir+"/util/MGRS.js");
}
this.precision = this.getProperty("mb:precision", 2);
this.formName = "CursorTrackForm_" + mbIds.getId();
this.stylesheet.setParameter("formName", this.formName);
this.init = function(objRef) {
objRef.proj = new OpenLayers.Projection( objRef.model.getSRS() );
objRef.model.map.events.register('mousemove', objRef, objRef.mousemoveHandler);
objRef.model.map.events.register('mouseout', objRef, objRef.mouseoutHandler);
if( this.showMGRS )
this.MGRS = new MGRS();
}
this.model.addListener("loadModel", this.init, this );
this.clear = function(objRef) {
if (objRef.model.map && objRef.model.map.events) {
objRef.model.map.events.unregister('mousemove', objRef, objRef.mousemoveHandler);
objRef.model.map.events.unregister('mouseout', objRef, objRef.mouseoutHandler);
}
}
this.model.addListener("newModel", this.clear, this);
this.mousemoveHandler = function(evt) {
var coordForm = document.getElementById(this.formName);
if (!evt) return;
var evXY = this.model.map.getLonLatFromPixel(evt.xy);
var pt=new OpenLayers.Geometry.Point(evXY.lon, evXY.lat)
pt.transform(this.proj, new OpenLayers.Projection("EPSG:4326"));
var evLonLat = new OpenLayers.LonLat(pt.x,pt.y);
if( this.showPx ) {
if( coordForm.px )
coordForm.px.value = evt.xy.x;
if( coordForm.py )
coordForm.py.value = evt.xy.y;
}
if( this.showXY ) {
if( coordForm.x )
coordForm.x.value = evXY.lon.toFixed(this.precision);;
if( coordForm.y )
coordForm.y.value = evXY.lat.toFixed(this.precision);;
}
if( this.showLatLong ) {
if( coordForm.longitude )
coordForm.longitude.value = evLonLat.lon.toFixed(this.precision);
if( coordForm.latitude )
coordForm.latitude.value = evLonLat.lat.toFixed(this.precision);
}
if( this.showDMS ) {
var longitude = this.convertDMS(evLonLat.lon, 'LON');
if( coordForm.longdeg )
coordForm.longdeg.value = longitude[0];
if( coordForm.longmin )
coordForm.longmin.value = longitude[1];
if( coordForm.longsec )
coordForm.longsec.value = longitude[2];
if( coordForm.longH )
coordForm.longH.value = longitude[3];
var latitude = this.convertDMS(evLonLat.lat, 'LAT');
if( coordForm.latdeg )
coordForm.latdeg.value = latitude[0];
if( coordForm.latmin )
coordForm.latmin.value = latitude[1];
if( coordForm.latsec )
coordForm.latsec.value = latitude[2];
if( coordForm.latH )
coordForm.latH.value = latitude[3];
}
if( this.showDM ) {
var longitude = this.convertDM(evLonLat.lon, 'LON');
if( coordForm.longDMdeg )
coordForm.longDMdeg.value = longitude[0];
if( coordForm.longDMmin )
coordForm.longDMmin.value = longitude[1];
if( coordForm.longDMH )
coordForm.longDMH.value = longitude[2];
var latitude = this.convertDM(evLonLat.lat, 'LAT');
if( coordForm.latDMdeg )
coordForm.latDMdeg.value = latitude[0];
if( coordForm.latDMmin )
coordForm.latDMmin.value = latitude[1];
if( coordForm.latDMH )
coordForm.latDMH.value = latitude[2];
}
if( this.showMGRS ) {
if( !this.MGRS )
this.MGRS = new MGRS();
coordForm.mgrs.value = this.MGRS.convert(evLonLat.lat,evLonLat.lon) ;
}
}
this.mouseoutHandler = function(evt) {
var coordForm = document.getElementById(this.formName);
if( this.showPx ) {
if( coordForm.px)
coordForm.px.value = "";
if( coordForm.py)
coordForm.py.value = "";
}
if( this.showXY ) {
if( coordForm.x)
coordForm.x.value = "";
if( coordForm.y)
coordForm.y.value = "";
}
if( this.showLatLong ) {
if( coordForm.longitude )
coordForm.longitude.value = "";
if( coordForm.latitude )
coordForm.latitude.value = "";
}
if( this.showDMS ) {
if( coordForm.longdeg )
coordForm.longdeg.value = "";
if( coordForm.longmin )
coordForm.longmin.value = "";
if( coordForm.longsec )
coordForm.longsec.value = "";
if( coordForm.longH )
coordForm.longH.value = "";
if( coordForm.latdeg )
coordForm.latdeg.value = "";
if( coordForm.latmin )
coordForm.latmin.value = "";
if( coordForm.latsec )
coordForm.latsec.value = "";
if( coordForm.latH )
coordForm.latH.value = "";
}
if( this.showDM ) {
if( coordForm.longDMdeg )
coordForm.longDMdeg.value = "";
if( coordForm.longDMmin )
coordForm.longDMmin.value = "";
if( coordForm.longDMH )
coordForm.longDMH.value = "";
if( coordForm.latDMdeg )
coordForm.latDMdeg.value = "";
if( coordForm.latDMmin )
coordForm.latDMmin.value = "";
if( coordForm.latDMH )
coordForm.latDMH.value = "";
}
if( this.showMGRS ) {
if( coordForm.mgrs )
coordForm.mgrs.value = "";
}
}
this.convertDMS = function(coordinate, type) {
var coords = new Array();
abscoordinate = Math.abs(coordinate)
coordinatedegrees = Math.floor(abscoordinate);
coordinateminutes = (abscoordinate - coordinatedegrees)/(1/60);
tempcoordinateminutes = coordinateminutes;
coordinateminutes = Math.floor(coordinateminutes);
coordinateseconds = (tempcoordinateminutes - coordinateminutes)/(1/60);
coordinateseconds = Math.round(coordinateseconds*10);
coordinateseconds /= 10;
if( coordinatedegrees < 10 )
coordinatedegrees = "0" + coordinatedegrees;
if( coordinateminutes < 10 )
coordinateminutes = "0" + coordinateminutes;
if( coordinateseconds < 10 )
coordinateseconds = "0" + coordinateseconds;
coords[0] = coordinatedegrees;
coords[1] = coordinateminutes;
coords[2] = coordinateseconds;
coords[3] = this.getHemi(coordinate, type);
return coords;
}
this.convertDM = function(coordinate, type) {
var coords = new Array();
abscoordinate = Math.abs(coordinate)
coordinatedegrees = Math.floor(abscoordinate);
coordinateminutes = (abscoordinate - coordinatedegrees)*60;
coordinateminutes = Math.round(coordinateminutes*1000);
coordinateminutes /= 1000;
if( coordinatedegrees < 10 )
coordinatedegrees = "0" + coordinatedegrees;
if( coordinateminutes < 10 )
coordinateminutes = "0" + coordinateminutes;
coords[0] = coordinatedegrees;
coords[1] = coordinateminutes;
coords[2] = this.getHemi(coordinate, type);
return coords;
}
this.getHemi = function(coordinate, type) {
var coordinatehemi = "";
if (type == 'LAT') {
if (coordinate >= 0) {
coordinatehemi = "N";
}
else {
coordinatehemi = "S";
}
}
else if (type == 'LON') {
if (coordinate >= 0) {
coordinatehemi = "E";
} else {
coordinatehemi = "W";
}
}
return coordinatehemi;
}
}
Documentation generated by
JSDoc on Sun Apr 27 20:30:54 2008