function GPSPosInterface(map) { this.map = map; // map interface object this.elFlipper = null; this.elDisplay = null; this.elArea = null; this.displayType = 0; this.lat = 0; this.lng = 0; this._create = function() { this.elFlipper = document.getElementById('gps_pozice_flip'); this.elDisplay = document.getElementById('gps_span'); this.attachEvents(); this.hide(); } this.hide = function() { this.elDisplay.style.display = 'none'; } this.show = function() { this.elDisplay.style.display = 'inline'; } this.flip = function() { if (this.elDisplay.style.display == 'none') { this.show(); } else { this.hide(); } } this.onClickFlip = function(e) { this.flip(); return false; } this.flipDisplay = function() { if (this.displayType == 0) { this.displayType = 1; } else if (this.displayType == 1) { this.displayType = 2; } else { this.displayType = 0; } this.updateDisplay(); } this.onClickDisplay = function(e) { this.flipDisplay(); } this.DtoDMS = function(a) { var res = Math.floor(a); res+= "°"; var b = (a - Math.floor(a)) * 60; res+= (Math.floor(b) < 10)?("0" + Math.floor(b)):(Math.floor(b)); res+= "'"; var c = (b - Math.floor(b)) * 60; res+= (Math.floor(c) < 10)?("0" + Math.floor(c)):(Math.floor(c)); res+= '"'; return res; } this.DtoDMM = function(a) { var res = Math.floor(a); res+= "°"; var b = (a - Math.floor(a)) * 60; res+= (Math.floor(b) < 10)?("0" + b.toFixed(3)):(b.toFixed(3)); res+= "'"; return res; } this.formatDtoDMS = function(lat, lon) { var intAbsLatDeg = Math.floor(Math.abs(lat)); var fAbsLatMin = (Math.abs(lat) - intAbsLatDeg) * 60; var intAbsLatMin = Math.floor(fAbsLatMin); var intAbsLatSec = Math.floor((fAbsLatMin - intAbsLatMin) * 60); var strLat = intAbsLatDeg + '°' + intAbsLatMin + "'" + intAbsLatSec + '"' + ((lat < 0)?('S'):('N')); var intAbsLonDeg = Math.floor(Math.abs(lon)); var fAbsLonMin = (Math.abs(lon) - intAbsLonDeg) * 60; var intAbsLonMin = Math.floor(fAbsLonMin); var intAbsLonSec = Math.floor((fAbsLonMin - intAbsLonMin) * 60); var strLon = intAbsLonDeg + '°' + intAbsLonMin + "'" + intAbsLonSec + '"' + ((lon < 0)?('W'):('E')); var str = strLat + ' ' + strLon; return str; } this.formatDtoDMf = function(lat, lon) { var intAbsLat = Math.floor(Math.abs(lat)); var strLat = ((lat < 0)?('S'):('N')) + intAbsLat + '°' + ((Math.abs(lat) - intAbsLat) * 60).toFixed(3) + "'"; var intAbsLon = Math.floor(Math.abs(lon)); var strLon = ((lon < 0)?('W'):('E')) + intAbsLon + '°' + ((Math.abs(lon) - intAbsLon) * 60).toFixed(3) + "'"; var str = strLat + ' ' + strLon; return str; } this.formatDtoDf = function(lat, lon) { var str = Math.abs(lat).toFixed(6) + ((lat < 0)?('S'):('N')) + ', ' + Math.abs(lon).toFixed(6) + ((lon < 0)?('W'):('E')); return str; } this.updateDisplay = function() { if ((this.lat) && (this.lng)) { var str = ''; if (this.displayType == 0) { str = "  " + this.formatDtoDMS(this.lat, this.lng); } else if (this.displayType == 1) { str = "  " + this.formatDtoDMf(this.lat, this.lng); } else if (this.displayType == 2) { str = "  " + this.formatDtoDf(this.lat, this.lng); } this.elDisplay.innerHTML = str; } } this.onClickMap = function(ev) { var ll = this.map.getLatLngFromPixel(ev.xy); this.lat = ll.lat; this.lng = ll.lng; this.updateDisplay(); } this.attachEvents = function() { $(this.elFlipper).bind('click', jQuery.proxy(this.onClickFlip, this)); $(this.elDisplay).bind('click', jQuery.proxy(this.onClickDisplay, this)); this.map.map.events.register('click', this, this.onClickMap); } this._create(); }