diff --git a/htdocs/public/js/trackdirect.min.js b/htdocs/public/js/trackdirect.min.js index dbe8ba199c619815f1091259167e3b1a6fc95754..8bcd1e463f45e759435b7a65d83e45fe1fcaad12 100755 --- a/htdocs/public/js/trackdirect.min.js +++ b/htdocs/public/js/trackdirect.min.js @@ -640,10 +640,10 @@ return(trackdirect.services.distanceCalculator.getDistance(this.getCenterLiteral return 0;};trackdirect.models.Map.prototype._renderCordinatesContainer=function(mouseLatLng){var options=this.getTdMapOptions();if(typeof options.cordinatesContainer==="undefined"){return;} if(options.cordinatesContainer==null){return;} var lat=null;var lng=null;if(typeof mouseLatLng.lat=="function"){lat=mouseLatLng.lat();lng=mouseLatLng.lng();}else{lat=mouseLatLng.lat;lng=mouseLatLng.lng;} -if(lat<=90&&lat>=-90&&lng<=180&&lng>=-180){var content="";content+=this._getGpsDegreeFromGpsDecimal(lat.toFixed(5),"lat");content+=" "+this._getGpsDegreeFromGpsDecimal(lng.toFixed(5),"lon");content+="<br>"+lat.toFixed(5)+", "+lng.toFixed(5);$("#"+options.cordinatesContainer).html(content);}};trackdirect.models.Map.prototype._getGpsDegreeFromGpsDecimal=function(dms,type){var sign=1,Abs=0;var days,minutes,secounds,direction;if(dms<0){sign=-1;} +if(lat<=90&&lat>=-90&&lng<=180&&lng>=-180){var content="";content+=this._getGpsDegreeFromGpsDecimal(lat.toFixed(5),"lat");content+=" "+this._getGpsDegreeFromGpsDecimal(lng.toFixed(5),"lon");content+="<br>"+lat.toFixed(5)+", "+lng.toFixed(5);content+="<br>"+this._getMaidenheadLocatorFromGpsDecimal(lat,lng);$("#"+options.cordinatesContainer).html(content);}};trackdirect.models.Map.prototype._getGpsDegreeFromGpsDecimal=function(dms,type){var sign=1,Abs=0;var days,minutes,secounds,direction;if(dms<0){sign=-1;} Abs=Math.abs(Math.round(dms*1000000));if(type=="lat"&&Abs>90*1000000){return false;}else if(type=="lon"&&Abs>180*1000000){return false;} days=Math.floor(Abs/1000000);minutes=Math.floor((Abs/1000000-days)*60);secounds=((Math.floor(((Abs/1000000-days)*60-minutes)*100000)*60)/ -100000).toFixed();days=days*sign;if(type=="lat")direction=days<0?"S":"N";if(type=="lon")direction=days<0?"W":"E";return days*sign+"º "+minutes+"' "+secounds+"'' "+direction;}; +100000).toFixed();days=days*sign;if(type=="lat")direction=days<0?"S":"N";if(type=="lon")direction=days<0?"W":"E";return days*sign+"º "+minutes+"' "+secounds+"'' "+direction;};trackdirect.models.Map.prototype._getMaidenheadLocatorFromGpsDecimal=function(lat,lng,){const chars='ABCDEFGHIJKLMNOPQRSTUVX';var result='';lng=lng+180;lat=lat+90;result=chars.charAt(parseInt(lng/20));result+=chars.charAt(parseInt(lat/10));result+=parseInt(lng/2%10);result+=parseInt(lat%10);lng_r=(lng-parseInt(lng/2)*2)*60;lat_r=(lat-parseInt(lat))*60;result+=chars.charAt(parseInt(lng_r/5));result+=chars.charAt(parseInt(lat_r/2.5));return result;}; if(typeof google==="object"&&typeof google.maps==="object"){trackdirect.models.Label=function(options,map){this._defaultMap=map;options.map=null;this.setValues(options);this.div_=null;};trackdirect.models.Label.prototype=new google.maps.OverlayView();trackdirect.models.Label.prototype.show=function(){if(typeof this.getMap()==="undefined"||this.getMap()===null){this.setMap(this._defaultMap);}};trackdirect.models.Label.prototype.hide=function(){if(this.getMap()!==null){this.setMap(null);}};trackdirect.models.Label.prototype.onAdd=function(){if(this.div_===null){var jqSpan=$(document.createElement("span"));jqSpan.css("color","#101010");jqSpan.css("text-shadow","1px 1px 1px #FFF, -1px -1px 1px #FFF, 1px -1px 1px #FFF, -1px 1px 1px #FFF, 1px 1px 1px #FFF");jqSpan.css("position","relative");jqSpan.css("top","10px");jqSpan.css("white-space","nowrap");jqSpan.css("font-family","Helvetica");jqSpan.css("font-weight","bold");jqSpan.css("font-size","10px");jqSpan.css("padding","0px");jqSpan.css("z-index","1000");jqSpan.css("margin","0");jqSpan.css("line-height","10px");var span=(this.span_=jqSpan[0]);span.innerHTML=this.get("text").toString();var div=(this.div_=document.createElement("div"));div.appendChild(span);div.style.cssText="position: absolute; display: none";} var pane=this.getPanes().overlayLayer;pane.appendChild(this.div_);var me=this;this.listeners_=[google.maps.event.addListener(this,"position_changed",function(){me.draw();}),google.maps.event.addListener(this,"text_changed",function(){me.draw();}),];};trackdirect.models.Label.prototype.onRemove=function(){if(this.div_!==null&&this.div_.parentNode!==null){this.div_.parentNode.removeChild(this.div_);for(var i=0,I=this.listeners_.length;i<I;++i){google.maps.event.removeListener(this.listeners_[i]);}}};trackdirect.models.Label.prototype.draw=function(){var projection=this.getProjection();if(typeof this.get("position").lat==="function"){var latLng=new google.maps.LatLng({lat:this.get("position").lat(),lng:this.get("position").lng(),});}else{var latLng=new google.maps.LatLng({lat:this.get("position").lat,lng:this.get("position").lng,});} var position=projection.fromLatLngToDivPixel(latLng);var div=this.div_;var span=this.span_;span.innerHTML=this.get("text").toString();div.style.left=position.x+"px";div.style.top=position.y+"px";div.style.display="block";};}else if(typeof L==="object"&&typeof L.Tooltip!=="undefined"){trackdirect.models.Label=function(options,map){this._defaultMap=map;L.Tooltip.call(this,this._getBasicOptions(options));this.setContent(options.text);if(typeof options.position!=="undefined"&&typeof options.position.lat!=="undefined"&&typeof options.position.lng!=="undefined"){this.setLatLng(new L.LatLng(options.position.lat,options.position.lng));}};trackdirect.models.Label.prototype=new L.Tooltip();trackdirect.models.Label.prototype.show=function(){if(!this._defaultMap.hasLayer(this)){this.addTo(this._defaultMap);}};trackdirect.models.Label.prototype.hide=function(){if(this._defaultMap.hasLayer(this)){this._defaultMap.removeLayer(this);}};trackdirect.models.Label.prototype._getBasicOptions=function(options){return{direction:"right",noWrap:true,offset:L.point(2,10),className:"leaflet-marker-labeltext",permanent:true,};};}else if(typeof L==="object"){trackdirect.models.Label=function(options,map){this._defaultMap=map;var position=null;if(typeof options.position!=="undefined"&&typeof options.position.lat!=="undefined"&&typeof options.position.lng!=="undefined"){position=[options.position.lat,options.position.lng];} diff --git a/jslib/src/trackdirect/models/Map.js b/jslib/src/trackdirect/models/Map.js index 931216df81f4ea70cba11b81d3f2c65d4ea6bfa2..47d022192584832bf7ead8fb5a715ebf0c7e849f 100755 --- a/jslib/src/trackdirect/models/Map.js +++ b/jslib/src/trackdirect/models/Map.js @@ -1494,6 +1494,7 @@ trackdirect.models.Map.prototype._renderCordinatesContainer = function ( content += this._getGpsDegreeFromGpsDecimal(lat.toFixed(5), "lat"); content += " " + this._getGpsDegreeFromGpsDecimal(lng.toFixed(5), "lon"); content += "<br>" + lat.toFixed(5) + ", " + lng.toFixed(5); + content += "<br>" + this._getMaidenheadLocatorFromGpsDecimal(lat, lng); $("#" + options.cordinatesContainer).html(content); } @@ -1540,3 +1541,28 @@ trackdirect.models.Map.prototype._getGpsDegreeFromGpsDecimal = function ( //else return value return days * sign + "º " + minutes + "' " + secounds + "'' " + direction; }; + +/** + * Convert decimal gps position to maidenhead locator + * @param {float} lat + * @param {float} lng + * @return {string} + */ +trackdirect.models.Map.prototype._getMaidenheadLocatorFromGpsDecimal = function ( + lat, + lng, +) { + const chars = 'ABCDEFGHIJKLMNOPQRSTUVX'; + var result = ''; + lng = lng + 180; + lat = lat + 90; + result = chars.charAt(parseInt(lng / 20)); + result += chars.charAt(parseInt(lat / 10)); + result += parseInt(lng / 2 % 10); + result += parseInt(lat % 10); + lng_r = (lng - parseInt(lng/2)*2) * 60; + lat_r = (lat - parseInt(lat)) * 60; + result += chars.charAt(parseInt(lng_r/5)); + result += chars.charAt(parseInt(lat_r/2.5)); + return result; +};