var trackdirect={services:{},models:{},_time:null,_timetravel:null,_center:null,_zoom:null,_maptype:null,_mid:null,_rulers:[],_filterTimeoutId:null,_waitForFilterResponse:false,_doNotChangeLocationOnFilterResponse:false,_doNotChangeLocationOnFilterResponseTmp:false,_filters:{},_defaultLatitude:null,_defaultLongitude:null,_eventListeners:{},_eventListenersOnce:{},_cordinatesContainerElementId:null,_statusContainerElementId:"td-status-text",_mapElementId:null,_wsServerUrl:null,_map:null,_websocket:null,_mapCreated:false,_trackdirectInitDone:false,isMobile:false,coverageDataUrl:null,coveragePercentile:95,settings:{},init:function(wsServerUrl,mapElementId,options){this._initSettings();this._wsServerUrl=wsServerUrl;this._mapElementId=mapElementId;if($("#"+mapElementId).length<=0){console.log("ERROR: Specified map element missing");return;} if(typeof google==="object"&&typeof google.maps==="object"){this.settings.defaultMinZoomForMarkerLabel=12;this.settings.minZoomForMarkerLabel=12;} this._parseOptions(options);var me=this;this.addListener("map-created",function(){me._initTime();me._websocket=new trackdirect.Websocket(me._wsServerUrl);me._initWebsocketListeners();me._handleWebsocketStateChange();me._initMapListeners();if(!me._initFilterUrlRequest()){trackdirect.services.callbackExecutor.add(me,me._sendPositionRequest,[]);} me._setWebsocketStateIdle();if(inIframe()){var parentUrl="";try{parentUrl=window.location!=window.parent.location?document.referrer:document.location.href;}catch(e){parentUrl="Unknown";}} me._emitEventListeners("trackdirect-init-done");});this._mapInit(options);},enableImperialUnits:function(){this._map.state.useImperialUnit=true;if(this._map.state.openInfoWindow!==null){this._map.state.openInfoWindow.hide();}},enableMetricUnits:function(){this._map.state.useImperialUnit=false;if(this._map.state.openInfoWindow!==null){this._map.state.openInfoWindow.hide();}},toggleImperialUnits:function(){if(this._map.state.useImperialUnit){this.enableMetricUnits();}else{this.enableImperialUnits();}},isImperialUnits:function(){return this._map.state.useImperialUnit;},addListener:function(event,handler,execOnce){execOnce=typeof execOnce!=="undefined"?execOnce:false;if((event=="map-created"&&this._mapCreated)||(event=="trackdirect-init-done"&&this._trackdirectInitDone)){handler();if(execOnce){return;}} if(execOnce){if(!(event in this._eventListenersOnce)){this._eventListenersOnce[event]=[];} this._eventListenersOnce[event].push(handler);}else{if(!(event in this._eventListeners)){this._eventListeners[event]=[];} this._eventListeners[event].push(handler);}},setCenter:function(latitude,longitude,zoom){latitude=typeof latitude!=="undefined"?latitude:this._defaultLatitude;longitude=typeof longitude!=="undefined"?longitude:this._defaultLongitude;zoom=typeof zoom!=="undefined"?zoom:this.settings.defaultCurrentZoom;if(this._map!==null){this._map.setCenter({lat:latitude,lng:longitude},zoom);}},setZoom:function(value){if(this._map!==null){this._map.setZoom(value);}},addRuler:function(){if(this._rulers.length>0){var ruler=this._rulers.pop();ruler.hide();}else{var ruler=new trackdirect.models.Ruler((this._map.getCurrentRadiusInKm()*1000)/2,this._map);this._rulers.push(ruler);}},isFilteredMode:function(){return this._map.state.isFilterMode;},stopFilterOnStationId:function(stationId){var currentFilterStationIds=this._map.state.getFilterStationIds();if(currentFilterStationIds.length==1&¤tFilterStationIds.indexOf(stationId)>=0){this.filterOnStationId([]);}else{if(this._map.state.getTrackStationId()==stationId){this.stopTrackStation();} this._setWebsocketStateLoading(false);this._websocket.doSendStopFilterRequest(stationId);}},filterOnStationId:function(stationIdArray){if(!Array.isArray(stationIdArray)){stationIdArray=[stationIdArray];} var currentFilterStationIds=this._map.state.getFilterStationIds();if(currentFilterStationIds.length==0){if(this._map.state.getTrackStationId()!==null&&stationIdArray.indexOf(this._map.state.getTrackStationId())==-1){this.stopTrackStation();}} this._setWebsocketStateLoading(false);this._websocket.doSendFilterRequest(stationIdArray,this._map.state.getTimeLength()/60,this.getTimeTravelTimestamp());},filterOnStationName:function(stationNameArray){if(!Array.isArray(stationNameArray)){stationNameArray=[stationNameArray];} var currentFilterStationIds=this._map.state.getFilterStationIds();if(currentFilterStationIds.length==0){if(this._map.state.getTrackStationId()!==null&&stationIdArray.indexOf(this._map.state.getTrackStationId())==-1){this.stopTrackStation();}} this._setWebsocketStateLoading(false);this._websocket.doSendFilterRequestByName(stationNameArray,this._map.state.getTimeLength()/60,this.getTimeTravelTimestamp());},stopTrackStation:function(){this._map.state.onlyTrackRecentPackets=false;this._map.state.trackStationId=null;this._emitEventListeners("track-changed",[null,null]);},trackStation:function(stationId,stationName,alsoFilterOnStation,onlyTrackRecentPackets){onlyTrackRecentPackets=typeof onlyTrackRecentPackets!=="undefined"?onlyTrackRecentPackets:false;if(alsoFilterOnStation){var currentFilterStationIds=this._map.state.getFilterStationIds();if(currentFilterStationIds.length>0){if(currentFilterStationIds.indexOf(stationId)==-1){this.filterOnStationId(stationId);}}} if(stationId!==null){var trackLinkElementClass="trackStationLink"+stationId;$("."+trackLinkElementClass).html("Untrack");} if(this._map.state.trackStationId!==null){var trackLinkElementClass="trackStationLink"+this._map.state.trackStationId;$("."+trackLinkElementClass).html("Track");} this._map.state.onlyTrackRecentPackets=onlyTrackRecentPackets;this._map.state.trackStationId=stationId;this._emitEventListeners("track-changed",[stationId,stationName]);},focusOnStation:function(stationId,openInfoWindow){var map=this._map;openInfoWindow=typeof openInfoWindow!=="undefined"?openInfoWindow:false;var marker=map.markerCollection.getStationLatestMarker(stationId);if(marker!==null){marker.show();marker.showLabel();if(openInfoWindow){map.openMarkerInfoWindow(marker,false);}else{this.setCenter(marker.packet.latitude,marker.packet.longitude);} marker.hide(5000,true);}},focusOnMarkerId:function(markerId,zoom){var map=this._map;var markerIdKey=map.markerCollection.getMarkerIdKey(markerId);if(map.markerCollection.isExistingMarker(markerIdKey)){var marker=map.markerCollection.getMarker(markerIdKey);if(map.markerCollection.hasRelatedDashedPolyline(marker)){newerMarker=map.markerCollection.getMarker(marker._relatedMarkerOriginDashedPolyLine.ownerMarkerIdKey);if(newerMarker.packet.hasConfirmedMapId()){return this.focusOnMarkerId(newerMarker.packet.marker_id);}} marker.show();marker.showLabel();this.setCenter(marker.packet.latitude,marker.packet.longitude,zoom);map.openMarkerInfoWindow(marker);marker.hide(5000,true);}},toggleStationCoverage:function(stationId,coverageLinkElementClass){coverageLinkElementClass=typeof coverageLinkElementClass!=="undefined"?coverageLinkElementClass:null;var coveragePolygon=this._map.markerCollection.getStationCoverage(stationId);if(coveragePolygon!==null&&coveragePolygon.isRequestedToBeVisible()){coveragePolygon.hide();if(coverageLinkElementClass!==null){$("."+coverageLinkElementClass).html("Coverage");}}else{if(coveragePolygon!==null){coveragePolygon.show();if(!coveragePolygon.hasContent()){alert("Currently we do not have enough data to create a max range coverage plot for this station. Try again later!");}else{if(coverageLinkElementClass!==null){$("."+coverageLinkElementClass).html("Hide coverage");}}}else{var packet=this._map.markerCollection.getStationLatestPacket(stationId);var center={lat:parseFloat(packet.latitude),lng:parseFloat(packet.longitude),};var coveragePolygon=new trackdirect.models.StationCoveragePolygon(center,this._map,true);this._map.markerCollection.addStationCoverage(stationId,coveragePolygon);coveragePolygon.showWhenDone();if(coverageLinkElementClass!==null){$("."+coverageLinkElementClass).html('Loading ');coveragePolygon.addTdListener("visible",function(){if(!coveragePolygon.hasContent()){coveragePolygon.hide();alert("Currently we do not have enough data to create a max range coverage plot for this station. Try again later!");$("."+coverageLinkElementClass).html("Coverage");}else{$("."+coverageLinkElementClass).html("Hide coverage");}},true);} var me=this;$.getJSON(this.coverageDataUrl+"?id="+stationId,function(data){if("station_id"in data&&"coverage"in data){coveragePolygon.setData(data["coverage"],me.coveragePercentile);var marker=me._map.markerCollection.getStationLatestMarker(stationId);if(marker.isVisible()){if(coveragePolygon.isRequestedToBeVisible()){coveragePolygon.show();}}}}).fail(function(){coveragePolygon.hide();alert("Failed to fetch coverage data. Try again later!");$("."+coverageLinkElementClass).html("Coverage");}).always(function(){});}}},setMapType:function(mapType){if(this._map!==null){this._map.setMapType(mapType);}},getMapType:function(){if(this._map!==null){return this._map.getMapType();}},setMapDefaultLocation:function(setDefaultZoom){this._map.setMapDefaultLocation(setDefaultZoom);},setMapLocationByGeoLocation:function(failCallBack,successCallBack,timeout){var me=this;if(navigator&&navigator.geolocation){navigator.geolocation.getCurrentPosition(function(position){var pos={lat:position.coords.latitude,lng:position.coords.longitude,};me._map.setCenter(pos,12);if(successCallBack!==null){successCallBack();}},function(error){if(failCallBack!==null){failCallBack(error.message);}},{enableHighAccuracy:false,timeout:timeout,maximumAge:5000,});}else{if(failCallBack!==null){failCallBack();}}},openStationInformationDialog:function(stationId){var packet=this._map.markerCollection.getStationLatestPacket(stationId);if(packet==null){packet={station_id:stationId,id:null};} this._emitEventListeners("station-name-clicked",packet);},openMarkerInfoWindow:function(markerId){var markerIdKey=this._map.markerCollection.getMarkerIdKey(markerId);if(this._map.markerCollection.isExistingMarker(markerIdKey)){var marker=this._map.markerCollection.getMarker(markerIdKey);this._map.openMarkerInfoWindow(marker);}},closeAnyOpenInfoWindow:function(){if(this._map!==null){var state=this._map.state;if(state.isInfoWindowOpen()){state.openInfoWindow.hide();}}},setTimeTravelTimestamp:function(ts,sendRequestToServer){if(ts!=0||this._map.state.endTimeTravelTimestamp!=null){sendRequestToServer=typeof sendRequestToServer!=="undefined"?sendRequestToServer:true;if(this._map.state.endTimeTravelTimestamp!=ts){if(ts!=null&&ts!=0&&ts!=""){this._map.state.endTimeTravelTimestamp=ts;}else{this._map.state.endTimeTravelTimestamp=null;} if(sendRequestToServer){trackdirect.services.callbackExecutor.add(this,this._handleTimeChange,[]);}} this._emitEventListeners("time-travel-changed",ts);this._emitEventListeners("mode-changed");}},getTimeTravelTimestamp:function(){return this._map.state.endTimeTravelTimestamp;},setTimeLength:function(time,sendRequestToServer){sendRequestToServer=typeof sendRequestToServer!=="undefined"?sendRequestToServer:true;if(this._map.state.getTimeLength()/60!=time){this._map.state.setTimeLength(time*60);if(sendRequestToServer){trackdirect.services.callbackExecutor.add(this,this._handleTimeChange,[]);}} this._emitEventListeners("time-length-changed",time);this._updateMinZoomLevels();},togglePHGCircles:function(){var state=this._map.state;if(state.showPHGCircles==0){state.showPHGCircles=1;}else if(state.showPHGCircles==1){state.showPHGCircles=2;}else{state.showPHGCircles=0;} this._map.showHidePHGCircles();},toggleRNGCircles:function(){var state=this._map.state;if(state.showRNGCircles==0){state.showRNGCircles=1;}else if(state.showRNGCircles==1){state.showRNGCircles=2;}else{state.showRNGCircles=0;} this._map.showHideRNGCircles();},toggleStationaryPositions:function(){if(this.isStationaryMarkersVisible()){this._map.state.isStationaryMarkersVisible=false;}else{this._map.state.isStationaryMarkersVisible=true;} this._map.showHideMarkers();},toggleUnknownPositions:function(){if(this.isUnknownMarkersVisible()){this._map.state.isUnknownMarkersVisible=false;}else{this._map.state.isUnknownMarkersVisible=true;} this._map.showHideMarkers();},toggleOgflymPositions:function(){if(this.isOgflymMarkersVisible()){this._map.state.isOgflymMarkersVisible=false;}else{this._map.state.isOgflymMarkersVisible=true;} this._map.showHideMarkers();},toggleInternetPositions:function(){if(this.isInternetMarkersVisible()){this._map.state.isInternetMarkersVisible=false;}else{this._map.state.isInternetMarkersVisible=true;} this._map.showHideMarkers();},toggleCwopPositions:function(){if(this.isCwopMarkersVisible()){this._map.state.isCwopMarkersVisible=false;}else{this._map.state.isCwopMarkersVisible=true;} this._map.showHideMarkers();},toggleGhostPositions:function(){if(this.isGhostMarkersVisible()){this._map.state.isGhostMarkersVisible=false;}else{this._map.state.isGhostMarkersVisible=true;} this._map.showHideMarkers();},isGhostMarkersVisible:function(){return this._map.state.isGhostMarkersVisible;},isCwopMarkersVisible:function(){return this._map.state.isCwopMarkersVisible;},isInternetMarkersVisible:function(){return this._map.state.isInternetMarkersVisible;},isStationaryMarkersVisible:function(){return this._map.state.isStationaryMarkersVisible;},setVisibleSymbols:function(symbols){this._map.state.visibleSymbols=symbols;this._map.showHideMarkers();},addVisibleSymbol:function(symbol){this._map.state.visibleSymbols.push(symbol);this._map.showHideMarkers();},removeVisibleSymbol:function(symbol){var indexToRemove=null;for(var i=0;i0&&this._map.state.filterStationIds.indexOf(stationId)>-1){this.stopFilterOnStationId(stationId);if(filterLinkElementClass!==null){$("."+filterLinkElementClass).html("Filter");}}else{this.filterOnStationId(stationId);if(filterLinkElementClass!==null){$("."+filterLinkElementClass).html("Unfilter");}}},handleTrackStationRequest:function(stationId,trackLinkElementClass){stationId=typeof stationId!=="undefined"?stationId:0;trackLinkElementClass=typeof trackLinkElementClass!=="undefined"?trackLinkElementClass:null;if(this._map.state.getTrackStationId()!==null&&(stationId===0||this._map.state.getTrackStationId()==stationId)){if(trackLinkElementClass!==null){$("."+trackLinkElementClass).html("Track");}else if(this._map.state.openInfoWindow!==null){this._map.state.openInfoWindow.hide();} this.stopTrackStation();}else if(stationId!==0){if(trackLinkElementClass!==null){$("."+trackLinkElementClass).html("Untrack");} var packet=this._map.markerCollection.getStationLatestPacket(stationId);if(packet!==null){var stationName=packet.station_name;if(packet.sender_name!=packet.station_name){stationName=packet.station_name+" ("+packet.sender_name+")";} this.trackStation(stationId,stationName,true);}}},_initSettings:function(){this.settings={animate:true,defaultMinZoomForMarkerLabel:11,defaultMinZoomForMarkerPrevPosition:11,defaultMinZoomForMarkerTail:9,minZoomForMarkerLabel:11,minZoomForMarkerPrevPosition:11,minZoomForMarkerTail:9,minZoomForMarkers:8,markerSymbolBaseDir:"/symbols/",imagesBaseDir:"/images/",defaultCurrentZoom:11,defaultCurrentZoomMobile:11,dateFormat:"L LTSZ",dateFormatNoTimeZone:"L LTS",host:"www.aprsdirect.com",baseUrl:"https://www.aprsdirect.com",defaultTimeLength:60,symbolsToScale:[],primarySymbolWithNoDirectionPolyline:[87,64,95],alternativeSymbolWithNoDirectionPolyline:[40,42,64,74,84,85,96,98,101,102,112,116,119,121,123,],};},_parseOptions:function(options){if(typeof options["cordinatesContainerElementId"]!==undefined){this._cordinatesContainerElementId=options["cordinatesContainerElementId"];} if(typeof options["statusContainerElementId"]!==undefined){this._statusContainerElementId=options["statusContainerElementId"];} if(typeof options["isMobile"]!==undefined){this.isMobile=options["isMobile"];} if(typeof options["coverageDataUrl"]!==undefined){this.coverageDataUrl=options["coverageDataUrl"];} if(typeof options["coveragePercentile"]!==undefined){this.coveragePercentile=options["coveragePercentile"];} if(typeof options["time"]!==undefined){this._time=options["time"];} if(typeof options["timetravel"]!==undefined){this._timetravel=options["timetravel"];} if(typeof options["center"]!==undefined){this._center=options["center"];} if(typeof options["zoom"]!==undefined){this._zoom=options["zoom"];} if(typeof options["maptype"]!==undefined){this._maptype=options["maptype"];} if(typeof options["mid"]!==undefined){this._mid=options["mid"];} if(typeof options["filters"]!==undefined&&options["filters"]!==null){for(var i in options["filters"]){if(options["filters"][i]!==null&&options["filters"][i]!=""){this._filters[i]=options["filters"][i];}}} if(typeof options["disableLocationChangeOnFilterResponse"]!==undefined&&options["disableLocationChangeOnFilterResponse"]){this._doNotChangeLocationOnFilterResponse=true;} if(typeof options["defaultMinZoomForMarkerLabel"]!==undefined&&options["defaultMinZoomForMarkerLabel"]!=null){this.settings.defaultMinZoomForMarkerLabel=options["defaultMinZoomForMarkerLabel"];} if(typeof options["defaultMinZoomForMarkerPrevPosition"]!==undefined&&options["defaultMinZoomForMarkerPrevPosition"]!=null){this.settings.defaultMinZoomForMarkerPrevPosition=options["defaultMinZoomForMarkerPrevPosition"];} if(typeof options["defaultMinZoomForMarkerTail"]!==undefined&&options["defaultMinZoomForMarkerTail"]!=null){this.settings.defaultMinZoomForMarkerTail=options["defaultMinZoomForMarkerTail"];} if(typeof options["animate"]!==undefined&&options["animate"]!=null){this.settings.animate=options["animate"];} if(typeof options["host"]!==undefined&&options["host"]!=null){this.settings.host=options["host"];this.settings.baseUrl=this._getMapBaseUrl(options["host"]);}else{this.settings.baseUrl=this._getMapBaseUrl();} if(typeof options["defaultTimeLength"]!==undefined&&options["defaultTimeLength"]!=null){this.settings.defaultTimeLength=options["defaultTimeLength"];} if(typeof options["symbolsToScale"]!==undefined&&options["symbolsToScale"]!==null){this.settings.symbolsToScale=options["symbolsToScale"];} this._initDefaultLocation(options);},_initDefaultLocation:function(options){if(typeof options["defaultLatitude"]!=="undefined"&&typeof options["defaultLongitude"]!=="undefined"){this._defaultLatitude=options["defaultLatitude"];this._defaultLongitude=options["defaultLongitude"];}else{this._defaultLatitude=0;this._defaultLongitude=0;}},_initTime:function(){var filterMode=false;if("sid"in this._filters||"sidlist"in this._filters||"sname"in this._filters||"snamelist"in this._filters){filterMode=true;} if(this._time!=null&&this._isValidTime(this._time,filterMode)){this.setTimeLength(this._time,false);}else{this.setTimeLength(this.settings.defaultTimeLength,false);} now=new Date();if(this._timetravel!=null&&this._timetravel>=0&&this._timetravel<=now.getTime()/1000){this.setTimeTravelTimestamp(this._timetravel,false);} this._updateMinZoomLevels();},_mapInit:function(options){if("sid"in this._filters||"sidlist"in this._filters||"sname"in this._filters||"snamelist"in this._filters){this._waitForFilterResponse=true;if(window.location.href.indexOf("/center/")>=0){this._doNotChangeLocationOnFilterResponseTmp=true;}} var tdMapOptions=this._getMapInitOptions(options);var me=this;$(document).ready(function(){me._map=new trackdirect.models.Map(me._mapElementId,tdMapOptions);me._markerCreator=new trackdirect.MarkerCreator(me._map);if(typeof options["useImperialUnit"]!=="undefined"&&options["useImperialUnit"]==true){me.enableImperialUnits();} me._emitEventListeners("map-created");});},_getMapInitOptions:function(options){var center=this._getMapInitCenter();var tdMapOptions={zoom:this._getMapInitZoom(),maptype:this._getMapInitMapType(),cordinatesContainer:this._cordinatesContainerElementId,defaultLatitude:this._defaultLatitude,defaultLongitude:this._defaultLongitude,initCenter:center,mid:this._getMapInitMid(),};if("supportedMapTypes"in options){tdMapOptions["supportedMapTypes"]=options["supportedMapTypes"];} if("mapboxGLStyle"in options){tdMapOptions["mapboxGLStyle"]=options["mapboxGLStyle"];} if("mapboxGLAccessToken"in options){tdMapOptions["mapboxGLAccessToken"]=options["mapboxGLAccessToken"];} if("mapboxGLAttribution"in options){tdMapOptions["mapboxGLAttribution"]=options["mapboxGLAttribution"];} return tdMapOptions;},_getMapInitCenter:function(){if(this._center!=null){var centerParts=this._center.split(",");if(centerParts.length==2&&this._isValidLatitude(centerParts[0])&&this._isValidLongitude(centerParts[1])){return{lat:parseFloat(centerParts[0]),lng:parseFloat(centerParts[1]),};}} return null;},_getMapInitZoom:function(){var zoom=null;if(this._zoom!=null&&this._isValidZoom(this._zoom)){zoom=this._zoom;} return zoom;},_getMapInitMid:function(){var mid=null;if(this._mid!=null){mid=this._mid;} return mid;},_getMapInitMapType:function(){var maptype=null;if(this._maptype!=null){maptype=this._maptype;} return maptype;},_initFilterUrlRequest:function(){if("sid"in this._filters){stationId=this._filters["sid"];if(isNumeric(stationId)){this.filterOnStationId(stationId);}}else if("sname"in this._filters){stationName=this._filters["sname"];if(stationName!=""){this.filterOnStationName(stationName);}}else if("sidlist"in this._filters){stationIdArray=this._filters["sidlist"].split(",");var isValid=true;for(var i=0;i0){return true;}else if(filteredMode==false&&time<=1440&&time>0){return true;}} return false;},_isValidZoom:function(zoom){if(isNumeric(zoom)){if(zoom<=21&&zoom>=0){return true;}} return false;},_isValidLatitude:function(lat){if(isNumeric(lat)){if(lat<=90&&lat>=-90){return true;}} return false;},_isValidLongitude:function(lng){if(isNumeric(lng)){if(lng<=180&&lng>=-180){return true;}} return false;},_initMapListeners:function(){var me=this;this._map.addTdListener("change",function(){trackdirect.services.callbackExecutor.add(me,me._sendPositionRequest,[]);trackdirect.services.mapAttributionModifier.update(me._map);});this._map.addTdListener("moving",function(){trackdirect.services.callbackExecutor.addIfUnique(me,me._sendIdleRequest,[]);});this._map.addTdListener("station-tail-needed",function(stationId){me._websocket.doSendCompleteStationRequest(stationId,me._map.state.getTimeLength()/60,me.getTimeTravelTimestamp());});this._map.addTdListener("station-information",function(stationId){me.openStationInformationDialog(stationId);});},_initWebsocketListeners:function(){this._initWebsocketStateChangeListener();this._initWebsocketAprsPacketListener();this._initWebsocketPayloadDoneListener();this._initWebsocketFilterResponseListener();this._initWebsocketServerTimestampResponseListener();this._initWebsocketResetListener();},_initWebsocketStateChangeListener:function(){var me=this;this._websocket.addListener("state-change",function(){var callback=function(){me._handleWebsocketStateChange();};trackdirect.services.callbackExecutor.add(this,callback,[]);});},_initWebsocketAprsPacketListener:function(){var me=this;this._websocket.addListener("aprs-packet",function(packetData){var packet=new trackdirect.models.Packet(packetData);var queueTimestamp=Math.floor(Date.now()/1000);var callback=function(){var dequeueTimestamp=Math.floor(Date.now()/1000);if(dequeueTimestamp-queueTimestamp>5||!this.settings.animate){me._handleAprsPacket(packet,false);}else{me._handleAprsPacket(packet,true);}};trackdirect.services.callbackExecutor.add(me,callback,[]);});},_initWebsocketPayloadDoneListener:function(){var me=this;this._websocket.addListener("aprs-packet-payload-done",function(){var callback=function(){me._map.showNewMarkersInQueue(true);};trackdirect.services.callbackExecutor.add(this,callback,[]);});},_initWebsocketFilterResponseListener:function(){var me=this;this._websocket.addListener("filter-response",function(data){var callback=function(){me._handleFilterResponse(data);};trackdirect.services.callbackExecutor.add(this,callback,[]);});},_initWebsocketServerTimestampResponseListener:function(){var me=this;this._websocket.addListener("server-timestamp-response",function(data){var callback=function(){me._map.state.setServerCurrentTimestamp(data.timestamp);};trackdirect.services.callbackExecutor.add(this,callback,[]);if(me._map.getNumberOfNewMarkersToShow()>0){var callback2=function(){me._map.showNewMarkersInQueue(true);};trackdirect.services.callbackExecutor.addIfUnique(this,callback2,[]);}});},_initWebsocketResetListener:function(){var me=this;this._websocket.addListener("reset",function(){trackdirect.services.callbackExecutor.add(me._map,me._map.resetAllMarkers,[]);});},_updateMinZoomLevels:function(){if(this._map.state.getTimeLength()/60>720){trackdirect.settings.minZoomForMarkerPrevPosition=trackdirect.settings.defaultMinZoomForMarkerPrevPosition+1;trackdirect.settings.minZoomForMarkerTail=trackdirect.settings.defaultMinZoomForMarkerTail+1;trackdirect.settings.minZoomForMarkerLabel=trackdirect.settings.defaultMinZoomForMarkerLabel+1;}else{trackdirect.settings.minZoomForMarkerPrevPosition=trackdirect.settings.defaultMinZoomForMarkerPrevPosition;trackdirect.settings.minZoomForMarkerTail=trackdirect.settings.defaultMinZoomForMarkerTail;trackdirect.settings.minZoomForMarkerLabel=trackdirect.settings.defaultMinZoomForMarkerLabel;}},_handleTimeChange:function(){this._updateMinZoomLevels();this._map.resetAllMarkers();this._websocket.clearLastSentPositionRequest();trackdirect.services.callbackExecutor.add(this,this._sendPositionRequest,[]);this._emitEventListeners("mode-changed");},_handleFilterResponse:function(data){if(this._filterTimeoutId!==null){clearTimeout(this._filterTimeoutId);this._filterTimeoutId=null;} if(data.length==0){this._handleEmptyFilterResponse();}else{this._handleNonEmptyFilterResponse(data);}},_unMarkMissingStationsAsFiltered:function(data){var filterStationIds=this._map.state.getFilterStationIds();for(var key in filterStationIds){var stationId=filterStationIds[key];var foundStation=false;for(var i=0;i-1){map.state.filterStationIds.splice(index,1);var filterLinkElementClass="filterStationLink"+stationId;$("."+filterLinkElementClass).html("Filter");for(var markerIdKey in map.markerCollection.getStationMarkerIdKeys(stationId)){var marker=this._map.markerCollection.getMarker(markerIdKey);if(marker!==null){marker.hideCompleteMarker();}}}},_getNumberOfUniqeStationsInArray:function(data){var numberOfStationPackets=0;for(var i=0;i12){this._map.setZoom(12);}}},_handleAprsPacket:function(packet,animate){var markerIdKey=this._markerCreator.addPacket(packet,true);if(markerIdKey!==null){var highlight=false;var autoRender=false;var marker=this._map.markerCollection.getMarker(markerIdKey);if(animate&&packet.db==0&&packet.station_name==packet.sender_name&&marker.shouldMarkerBeVisible()&&(this.isFilteredMode()||this._isPacketOnMap(packet))){highlight=true;var tdTransmitAnimation=new trackdirect.models.TransmitAnimation(marker,this._map);tdTransmitAnimation.show();} if(packet.realtime==1&&animate){autoRender=true;}}},_linkifyPacketRaw:function(packet){if(typeof packet.raw!=="undefined"&&typeof packet.raw=="string"){var raw=escapeHtml(packet.raw);var stationNameReplacement=''+ escapeHtml(packet.sender_name)+ "";raw=raw.replaceAll(escapeHtml(packet.sender_name)+">",stationNameReplacement+">");for(var i=0;i'+ escapeHtml(relatedStationLatestPacket.sender_name)+ "";var relatedStationSenderName=escapeHtml(relatedStationLatestPacket.sender_name);raw=raw.replaceAll(">"+relatedStationSenderName+":",">"+relatedStationNameReplacement+":");raw=raw.replaceAll(">"+relatedStationSenderName+",",">"+relatedStationNameReplacement+",");raw=raw.replaceAll(">"+relatedStationSenderName+"*",">"+relatedStationNameReplacement+"*");raw=raw.replaceAll(","+relatedStationSenderName+":",","+relatedStationNameReplacement+":");raw=raw.replaceAll(","+relatedStationSenderName+",",","+relatedStationNameReplacement+",");raw=raw.replaceAll(","+relatedStationSenderName+"*",","+relatedStationNameReplacement+"*");}} raw=Autolinker.link(raw,{newWindow:true});return raw;} return"";},_isPacketOnMap:function(packet){if(packet.latitude<=this._map.getNorthEastLat()&&packet.latitude>=this._map.getSouthWestLat()){if(packet.longitude<=this._map.getNorthEastLng()&&packet.longitude>=this._map.getSouthWestLng()){return true;}} return false;},_handleWebsocketStateChange:function(){switch(this._websocket.getState()){case this._websocket.State.CONNECTING:this._setWebsocketStateConnecting();break;case this._websocket.State.CONNECTED:this._setWebsocketStateConnected();trackdirect.services.callbackExecutor.add(this,this._sendPositionRequest,[]);break;case this._websocket.State.CLOSED:case this._websocket.State.ERROR:this._setWebsocketStateError();break;case this._websocket.State.LOADING:this._setWebsocketStateLoading(true,false);break;case this._websocket.State.LOADING_DONE:this._setWebsocketStateLoadingDone();break;case this._websocket.State.LISTENING_APRSIS:this._setWebsocketStateAprsISConnected();break;case this._websocket.State.CONNECTING_APRSIS:this._setWebsocketStateAprsISConnecting();break;case this._websocket.State.IDLE:this._setWebsocketStateIdle();break;case this._websocket.State.INACTIVE:this._setWebsocketStateInactive();break;}},_setWebsocketStateConnecting:function(){if(this._statusContainerElementId!==null){$("#"+this._statusContainerElementId).html("Connecting").css("color","blue");}},_setWebsocketStateConnected:function(){this._map.resetAllMarkers();if(this._statusContainerElementId!==null){$("#"+this._statusContainerElementId).html("Connected").css("color","green");}},_setWebsocketStateError:function(){if(this._statusContainerElementId!==null){$("#"+this._statusContainerElementId).html("Disconnected").css("color","red");} this._map.resetAllMarkers();this._deactivateFiltered(false);var me=this;if(confirm("You have been disconnected, this can be caused by a network error, by the timeout limit or if maintenance occurs while you’re logged in. Do you want to reconnect?")){me._websocket=new trackdirect.Websocket(me._wsServerUrl);me._initWebsocketListeners();trackdirect.services.callbackExecutor.add(me,me._sendPositionRequest,[]);}},_setWebsocketStateLoading:function(isStateConfirmed,showOnMobile){isStateConfirmed=typeof isStateConfirmed!=="undefined"?isStateConfirmed:true;showOnMobile=typeof showOnMobile!=="undefined"?showOnMobile:true;if(this._statusContainerElementId!==null){$("#"+this._statusContainerElementId).html('Loading ').css("color","green");}},_setWebsocketStateLoadingDone:function(){if(this._statusContainerElementId!==null){$("#"+this._statusContainerElementId).html("Complete").css("color","green");}},_setWebsocketStateAprsISConnected:function(){if(this._statusContainerElementId!==null){$("#"+this._statusContainerElementId).html("Connected to APRS feed").css("color","green");}},_setWebsocketStateAprsISConnecting:function(){if(this._statusContainerElementId!==null){$("#"+this._statusContainerElementId).html("Waiting for APRS feed").css("color","green");}},_setWebsocketStateIdle:function(){if(this._statusContainerElementId!==null){$("#"+this._statusContainerElementId).html("Idle").css("color","green");}},_setWebsocketStateInactive:function(){if(this._statusContainerElementId!==null){$("#"+this._statusContainerElementId).html("Inactive").css("color","orange");} this._websocket.close();this._map.resetAllMarkers();var me=this;if(confirm("No activity for a long time, map updates has been stopped. Do you want to reconnect?")){me._websocket=new trackdirect.Websocket(me._wsServerUrl);me._initWebsocketListeners();trackdirect.services.callbackExecutor.add(me,me._sendPositionRequest,[]);}},_sendPositionRequest:function(){if(!this._waitForFilterResponse&&this._map.isMapReady()){if(!this.isFilteredMode()){if(this._map.getZoom()=trackdirect.settings.minZoomForMarkerTail){this._websocket.doSendNewPositionRequest(this._map.getNorthEastLat(),this._map.getNorthEastLng(),this._map.getSouthWestLat(),this._map.getSouthWestLng(),this._map.state.getTimeLength()/60,this.getTimeTravelTimestamp(),false);}else{this._websocket.doSendNewPositionRequest(this._map.getNorthEastLat(),this._map.getNorthEastLng(),this._map.getSouthWestLat(),this._map.getSouthWestLng(),this._map.state.getTimeLength()/60,this.getTimeTravelTimestamp(),true);}}else{this._websocket.doSendNewPositionRequest(90,180,-90,-180,this._map.state.getTimeLength()/60,this.getTimeTravelTimestamp(),false);} var data={center:this._map.getCenterLiteral(),zoom:this._map.getZoom(),};this._emitEventListeners("position-request-sent",data);}},_sendIdleRequest:function(){if(this._websocket.isPositionRequestSent()){this._websocket.doSendNewPositionRequest(0,0,0,0,this._map.state.getTimeLength()/60,this.getTimeTravelTimestamp(),false);}},_deactivateFiltered:function(sendNewRequest){this.setTimeTravelTimestamp(null);this._map.resetAllMarkers();if(this._map.state.openInfoWindow!==null){this._map.state.openInfoWindow.hide();} this._map.deactivateFilteredMode();this.stopTrackStation();this.setTimeLength(this.settings.defaultTimeLength,false);this._emitEventListeners("filter-changed",[]);this._emitEventListeners("filter-stopped");if(sendNewRequest){trackdirect.services.callbackExecutor.add(this,this._sendPositionRequest,[]);} this._emitEventListeners("mode-changed");},_getMapBaseUrl:function(host){host=typeof host!=="undefined"?host:"";host=host.replace("http://","");host=host.replace("https://","");if(host==""){host=window.location.host;} if(location.protocol==="https:"){return"https://"+host;}else{return"http://"+host;}},_emitEventListeners:function(event,arg){if(event in this._eventListeners){for(var i=0;i=1&&symbolTable.length>=1){var symbolAsciiValue=symbol.charCodeAt(0);var symbolTableAsciiValue=symbolTable.charCodeAt(0);}else{var symbolAsciiValue=125;var symbolTableAsciiValue=47;} var sizeStrValue="";if(width!==null&&height!==null){sizeStrValue="-"+width+"x"+height;} var scaleStrValue=this._getIconFilePathScalePart(scaleWidth,scaleHeight);var courseStrValue=this._getIconFilePathCoursePart(course);var url=trackdirect.settings.markerSymbolBaseDir+ "symbol-"+ symbolAsciiValue+ "-"+ symbolTableAsciiValue+ courseStrValue+ sizeStrValue+ scaleStrValue+ ".png";return trackdirect.settings.baseUrl+url;},_getIconFilePathCoursePart:function(course){var courseStrValue="";if(course!==null){var courseValue=Math.round(parseInt(course)/10)*10;while(courseValue>360){courseValue=courseValue-360;} while(courseValue<0){courseValue=courseValue+360;} courseStrValue="-"+courseValue;} return courseStrValue;},_getIconFilePathScalePart:function(scaleWidth,scaleHeight){var scaleStrValue="";if(scaleWidth!==null&&scaleHeight!==null){if(isHighDensity()){scaleStrValue="-scale"+scaleWidth*2+"x"+scaleHeight*2;}else{scaleStrValue="-scale"+scaleWidth+"x"+scaleHeight;}} return scaleStrValue;},}; trackdirect.services.stationColorCalculator={_colors:["#3333ff","#9900cc","#006600","#cc0000",],_stationColorId:{},getColor:function(packet){var colorId=this.getColorId(packet);return this._colors[colorId];},getKmlColor(packet){var hex=this.getColor(packet);var result=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);if(result){return"FF"+result[3]+result[2]+result[1];} return null;},getColorId:function(packet){if(packet.station_name in this._stationColorId){colorId=this._stationColorId[packet.station_name];return colorId;}else{var hash=this._simplehashStr(packet.station_name);var colorId=hash%this._colors.length;this._stationColorId[packet.station_name]=colorId;} return colorId;},_simplehashStr:function(str){var hash=0;for(var i=0;i=0){return true;} return false;},_getMapTileOptions:function(map){var tileLayer=map.getLeafletTileLayer();if(tileLayer!==null&&typeof tileLayer.options!=="undefined"){return tileLayer.options;} return null;},_getMapTileVariant:function(map){var options=this._getMapTileOptions(map);if(options.variant!=="undefined"){return options.variant;} return null;},_getMapTileInitialVariant:function(map){var mapVariant=this._getMapTileVariant(map);var dotIndex=mapVariant.indexOf(".");if(dotIndex>=0){return mapVariant.substring(0,dotIndex);} return mapVariant;},_getMapTileBase:function(map){var options=this._getMapTileOptions(map);if(options.base!=="undefined"){return options.base;} return null;},_getHereAttributionString:function(map){var result=[];var mapBaseVariant=this._getMapTileInitialVariant(map);if(this._getMapTileBase(map)=="base"){var data=this._hereBaseAttributionData;}else if(this._getMapTileBase(map)=="aerial"){var data=this._hereAerialAttributionData;} if(data!==null&&typeof data[mapBaseVariant]!=="undefined"){for(var i=0,len=data[mapBaseVariant].length;i=parseInt(attributionArea.minLevel)&&parseInt(map.getZoom())<=parseInt(attributionArea.maxLevel)){if(typeof attributionArea.boxes==="undefined"||this._isAnyBoxVisible(attributionArea.boxes,map)){var attributionText=''+ attributionArea.label+ "";if(result.indexOf(attributionText)<0){result.push(attributionText);}}}}} return result.join(", ");},_isAnyBoxVisible:function(boxes,map){if(typeof boxes!=="undefined"&&Array.isArray(boxes)){for(var i=0,len=boxes.length;i=4){var boxBounds=L.latLngBounds(L.latLng(parseFloat(box[0]),parseFloat(box[1])),L.latLng(parseFloat(box[2]),parseFloat(box[3])));if(boxBounds.isValid()&&boxBounds.intersects(map.getBounds())){return true;}}}} return false;},_loadHereAttributionData:function(map){var options=this._getMapTileOptions(map);var base=this._getMapTileBase(map);if((this._hereBaseAttributionData===null&&base=="base")||(this._hereAerialAttributionData===null&&base=="aerial")){var me=this;jQuery.ajax({url:"https://1."+ base+ ".maps.api.here.com/maptile/2.1/copyright/"+ options.mapID+ "?app_id="+ options.app_id+ "&app_code="+ options.app_code,type:"GET",dataType:"json",timeout:5000,success:function(result){if(base=="base"){me._hereBaseAttributionData=result;me._isHereBaseInitialized=true;me._emitEventListeners("init-here-base");}else if(base=="aerial"){me._hereAerialAttributionData=result;me._isHereAerialInitialized=true;me._emitEventListeners("init-here-aerial");}},error:function(xhr){console.log("Failed to load map copyright data");},});}},_emitEventListeners:function(event,arg){if(event in this._eventListeners){for(var i=0;iMath.PI){if(dLong>0.0){dLong=-(2.0*Math.PI-dLong);}else{dLong=2.0*Math.PI+dLong;}} return(this._degrees(Math.atan2(dLong,dPhi))+360.0)%360.0;},_radians:function(n){return n*(Math.PI/180);},_degrees:function(n){return n*(180/Math.PI);},}; trackdirect.services.dateFormatter={getDateString:function(timestamp,includeTimeZone,includeTime,useLocalTimeZone){includeTimeZone=typeof includeTimeZone!=="undefined"?includeTimeZone:true;includeTime=typeof includeTime!=="undefined"?includeTime:true;useLocalTimeZone=typeof useLocalTimeZone!=="undefined"?useLocalTimeZone:true;var date=new Date(timestamp*1000);if(useLocalTimeZone){var theMoment=moment(date);}else{var theMoment=moment.utc(date);} if(!theMoment.isValid()){return timestamp;} if(includeTime){if(includeTimeZone){return theMoment.format("L LTSZ");}else{return theMoment.format("L LTS");}}else{return theMoment.format("L");}},getAgeString:function(timestamp){var delta=Math.abs(Math.floor(Date.now()/1000)-timestamp);var days=Math.floor(delta/86400);delta-=days*86400;var hours=Math.floor(delta/3600)%24;delta-=hours*3600;var minutes=Math.floor(delta/60)%60;delta-=minutes*60;var seconds=Math.floor(delta%60);var timeAgoList=[];if(days>1){timeAgoList.push(days+" days");}else if(days>0){timeAgoList.push(days+" day");} if(hours>1){timeAgoList.push(hours+" hours");}else if(hours>0){timeAgoList.push(hours+" hour");} if(minutes>1){timeAgoList.push(minutes+" minutes");}else if(minutes>0){timeAgoList.push(minutes+" minute");} if(seconds==1){timeAgoList.push(seconds+" second");}else{timeAgoList.push(seconds+" seconds");} if(timeAgoList.length>1){return(timeAgoList.slice(0,timeAgoList.length-1).join(", ")+ " and "+ timeAgoList[timeAgoList.length-1]);}else{return timeAgoList[timeAgoList.length-1];}},}; if(!Date.now){Date.now=function(){return new Date().getTime();};} function escapeRegExp(str){return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&");} String.prototype.replaceAll=function(search,replacement){var target=this;return target.replace(new RegExp(escapeRegExp(search),"gi"),replacement);};function isNumeric(n){return!isNaN(parseFloat(n))&&isFinite(n);} Number.prototype.mod=function(n){return((this%n)+n)%n;};function isDate(str){var d=new Date(str);var now=new Date();if(Object.prototype.toString.call(d)==="[object Date]"){if(isNaN(d.getTime())){return false;}else{if(d.getTime()>0){return true;}else{return false;}}}else{return false;}} if(!Array.prototype.fill){Array.prototype.fill=function(value){if(this==null){throw new TypeError("this is null or not defined");} var O=Object(this);var len=O.length>>>0;var start=arguments[1];var relativeStart=start>>0;var k=relativeStart<0?Math.max(len+relativeStart,0):Math.min(relativeStart,len);var end=arguments[2];var relativeEnd=end===undefined?len:end>>0;var final=relativeEnd<0?Math.max(len+relativeEnd,0):Math.min(relativeEnd,len);while(k1.3));} function escapeHtml(text){if(typeof text==="undefined"||text==null){return null;} var map={"&":"&","<":"<",">":">",'"':""","'":"'",};return text.replace(/[&<>"']/g,function(m){return map[m];});} trackdirect.services.callbackExecutor={settings:{minTimeBeforeSleep:30,},_running:false,_lastSleepTimestamp:0,_lastAddedUniqueCallback:null,_lowPriorityQueue:[],_normalPriorityQueue:[],_highPriorityQueue:[],add:function(thisObj,callback,argsArray){var callBackString=callback.toString()+":"+argsArray.toString();this._lastAddedUniqueCallback=callBackString;this._normalPriorityQueue.push(function(){callback.apply(thisObj,argsArray);trackdirect.services.callbackExecutor._next();});this.start();return this;},addIfUnique:function(thisObj,callback,argsArray){var callBackString=callback.toString()+":"+argsArray.toString();if(this._lastAddedUniqueCallback==callBackString){return this;} this._lastAddedUniqueCallback=callBackString;this._normalPriorityQueue.push(function(){callback.apply(thisObj,argsArray);trackdirect.services.callbackExecutor._next();});this.start();return this;},addWithPriority:function(thisObj,callback,argsArray){this._highPriorityQueue.push(function(){callback.apply(thisObj,argsArray);trackdirect.services.callbackExecutor._next();});this.start();return this;},addWithLowPriority:function(thisObj,callback,argsArray){this._lowPriorityQueue.push(function(){callback.apply(thisObj,argsArray);trackdirect.services.callbackExecutor._next();});this.start();return this;},start:function(){if(!this._running){this._next();} return this;},_next:function(){var secondsSinceLastSleep=Date.now()-this._lastSleepTimestamp;if(secondsSinceLastSleep>this.settings.minTimeBeforeSleep){this._lastSleepTimestamp=Date.now();var me=this;setTimeout(function(){me._dequeue();},1);}else{this._dequeue();}},_dequeue:function(){var shift=this._highPriorityQueue.shift();if(shift){this._running=true;shift();return;} shift=this._normalPriorityQueue.shift();if(shift){this._running=true;shift();return;} shift=this._lowPriorityQueue.shift();if(shift){this._running=true;shift();return;} this._running=false;},}; trackdirect.Websocket=function(wsServerUrl){this._wsServerUrl=wsServerUrl;this._init();this._state=this.State.CONNECTING;this._emitEventListeners("state-change");this._instance=new WebSocket(this._wsServerUrl);var me=this;this._instance.onopen=function(evt){me._onOpen(evt);};this._instance.onclose=function(evt){me._onClose(evt);};this._instance.onmessage=function(evt){me._onMessage(evt);};this._instance.onerror=function(evt){me._onError(evt);};};trackdirect.Websocket.prototype._init=function(){this._instance=null;this._eventListeners={};this._lastSentPositionRequest="";this._state=0;this._lastMessageTimestamp=null;this._queue=[];this._running=false;this._sendPositionRequestIntervalId=null;this.State={CONNECTING:0,CONNECTED:1,CLOSING:2,CLOSED:3,ERROR:4,LOADING:5,LOADING_DONE:6,LISTENING_APRSIS:7,CONNECTING_APRSIS:8,IDLE:9,INACTIVE:10,};};trackdirect.Websocket.prototype.send=function(data){this._instance.send(data);};trackdirect.Websocket.prototype.close=function(){this._instance.close();};trackdirect.Websocket.prototype.getState=function(){return this._state;};trackdirect.Websocket.prototype.clearLastSentPositionRequest=function(){this._lastSentPositionRequest="";};trackdirect.Websocket.prototype.isPositionRequestSent=function(){if(this._lastSentPositionRequest!=""){return true;}else{return false;}};trackdirect.Websocket.prototype.doSendFilterRequest=function(list,historyMinutes,referenceTime){var request={};request.payload_request_type=4;request.list=list;request.minutes=historyMinutes;if(referenceTime!=""){request.time=parseInt(referenceTime,10);}else{request.time=null;} return this._addToSendQueue(request);};trackdirect.Websocket.prototype.doSendFilterRequestByName=function(namelist,historyMinutes,referenceTime){var request={};request.payload_request_type=8;request.namelist=namelist;request.minutes=historyMinutes;if(referenceTime!=""){request.time=parseInt(referenceTime,10);}else{request.time=null;} return this._addToSendQueue(request);};trackdirect.Websocket.prototype.doSendCompleteStationRequest=function(stationId,historyMinutes,referenceTime){var request={};request.payload_request_type=7;request.station_id=stationId;request.minutes=historyMinutes;if(referenceTime!=""){request.time=parseInt(referenceTime,10);}else{request.time=null;} return this._addToSendQueue(request);};trackdirect.Websocket.prototype.doSendStopFilterRequest=function(stationId){var request={};request.payload_request_type=6;request.station_id=stationId;return this._addToSendQueue(request);};trackdirect.Websocket.prototype.doSendNewPositionRequest=function(neLat,neLng,swLat,swLng,historyMinutes,referenceTime,onlyRequestLatestPacket){var request={};request.payload_request_type=1;request.neLat=neLat;request.neLng=neLng;request.swLat=swLat;request.swLng=swLng;request.minutes=historyMinutes;if(referenceTime!=""){request.time=parseInt(referenceTime,10);}else{request.time=null;} if(onlyRequestLatestPacket){request.onlyLatestPacket=1;}else{request.onlyLatestPacket=0;} var requestStr=JSON.stringify(request);if(requestStr!=this._lastSentPositionRequest){this._lastSentPositionRequest=requestStr;if(this._sendPositionRequestIntervalId!==null){clearInterval(this._sendPositionRequestIntervalId);} if(this._addToSendQueue(request)){var me=this;this._sendPositionRequestIntervalId=window.setInterval(function(){request.payload_request_type=11;if(me._lastSentPositionRequest==requestStr){me._addToSendQueue(request);}},60*1000);return true;} return false;}else{return true;}};trackdirect.Websocket.prototype.addListener=function(event,handler){if(!(event in this._eventListeners)){this._eventListeners[event]=[];} this._eventListeners[event].push(handler);};trackdirect.Websocket.prototype._onOpen=function(evt){this._state=this.State.CONNECTING;this._emitEventListeners("state-change");};trackdirect.Websocket.prototype._onClose=function(evt){this._state=this.State.CLOSED;this._emitEventListeners("state-change");};trackdirect.Websocket.prototype._onError=function(evt){this._state=this.State.ERROR;this._emitEventListeners("state-change");};trackdirect.Websocket.prototype._onMessage=function(evt){this._lastMessageTimestamp=Math.floor(Date.now()/1000);var packet=JSON.parse(evt.data);trackdirect.services.callbackExecutor.add(this,this._handleMessage,[packet,]);};trackdirect.Websocket.prototype._handleMessage=function(packet){switch(packet.payload_response_type){case 1:this._emitEventListeners("aprs-packet",packet.data);this._emitEventListeners("aprs-packet-payload-done");break;case 2:for(i=0;typeof packet.data!=="undefined"&&i1){return false;} var currentTs=Math.floor(Date.now()/1000);if(this._lastMessageTimestamp!==null&&this._lastMessageTimestamp1){me._running=false;return;}else{me._dequeue();}},5);};trackdirect.Websocket.prototype._emitEventListeners=function(event,arg){if(typeof this._eventListeners!=="undefined"&&event in this._eventListeners){for(var i=0;i0){return true;} return false;};trackdirect.models.StationCoveragePolygon.prototype.isRequestedToBeVisible=function(){return this._isRequestedToBeVisible;};trackdirect.models.StationCoveragePolygon.prototype.showWhenDone=function(){this._isRequestedToBeVisible=true;};trackdirect.models.StationCoveragePolygon.prototype.show=function(){if(typeof google==="object"&&typeof google.maps==="object"){if(this._polygon!==null){this._polygon.setMap(this._map);} if(this._heatmap!==null){this._heatmap.setMap(this._map);}}else if(typeof L==="object"){if(this._polygon!==null){this._polygon.addTo(this._map);} if(this._heatmap!==null){this._heatmap.addTo(this._map);}} this._isRequestedToBeVisible=true;if(this._showPolygon&&this._polygonCoordinates!==null){this._emitTdEventListeners("visible");}else if(this._heatmapCoordinates!==null){this._emitTdEventListeners("visible");}};trackdirect.models.StationCoveragePolygon.prototype.hide=function(stillMarkAsVisible){stillMarkAsVisible=typeof stillMarkAsVisible!=="undefined"?stillMarkAsVisible:false;if(typeof google==="object"&&typeof google.maps==="object"){if(this._polygon!==null){this._polygon.setMap(null);} if(this._heatmap!==null){this._heatmap.setMap(null);}}else if(typeof L==="object"){if(this._polygon!==null){this._map.removeLayer(this._polygon);} if(this._heatmap!==null){this._map.removeLayer(this._heatmap);}} if(!stillMarkAsVisible){this._isRequestedToBeVisible=false;} this._emitTdEventListeners("hidden");};trackdirect.models.StationCoveragePolygon.prototype._googleMapsInit=function(){if(this._polygonCoordinates!==null&&this._polygonCoordinates.length>0){this._polygon=new google.maps.Polygon({paths:this._polygonCoordinates,strokeColor:"#0000FF",strokeOpacity:0,strokeWeight:0,fillColor:"#0000FF",fillOpacity:0.2,});} if(this._heatmapCoordinates!==null&&this._heatmapCoordinates.length>0){var data=[];for(var i=0;i0){this._polygon=new L.polygon(this._polygonCoordinates,{color:"#0000FF",opacity:0,weight:0,fillColor:"#0000FF",fillOpacity:0.2,});} if(this._heatmapCoordinates!==null&&this._heatmapCoordinates.length>0){var data=[];for(var i=0;imaxRange){continue;} result.push(data[i].latLngLiteral);} return result;};trackdirect.models.StationCoveragePolygon.prototype._getCoveragePolygonMaxRange=function(data,percentile){var maxRange=this._getDistancePercentile(data,percentile,this._upperMaxRangeInMeters);if(isNaN(maxRange)){maxRange=0;} return maxRange;};trackdirect.models.StationCoveragePolygon.prototype._getDistancePercentile=function(data,percentile,upperMaxRange){var values=[];for(var i=0;imaxRange){continue;} counter++;} return counter;};trackdirect.models.StationCoveragePolygon.prototype._convertToXYPos=function(positions){var result=[];for(var i=0;i99999){if(this._map.state.useImperialUnit){distance=Math.round(trackdirect.services.imperialConverter.convertKilometerToMile(distance/1000)).toString()+" miles";}else{distance=Math.round(distance/1000).toString()+" km";}}else if(distance>999){if(this._map.state.useImperialUnit){distance=(Math.round(trackdirect.services.imperialConverter.convertKilometerToMile(distance/1000)*10)/10).toString()+" miles";}else{distance=(Math.round(distance/100)/10).toString()+" km";}}else{distance=distance.toString()+" m";} var bearing=Math.round(trackdirect.services.distanceCalculator.getBearing(p2,p1),0).toString();return bearing+"º "+distance;};trackdirect.models.Ruler.prototype._getPositionLiteral=function(marker){if(typeof google==="object"&&typeof google.maps==="object"){var latLng=marker.getPosition();if(typeof latLng!=="undefined"&&typeof latLng.lat==="function"){return{lat:latLng.lat(),lng:latLng.lng()};}else{return latLng;}}else if(typeof L==="object"){var latLng=marker.getLatLng();if(typeof latLng!=="undefined"){return{lat:latLng.lat,lng:latLng.lng};}else{return latLng;}} return null;}; trackdirect.models.RngCircle=function(packet,map,isHalf){this._defaultMap=map;if(typeof google==="object"&&typeof google.maps==="object"){google.maps.Circle.call(this,this._getGoogleCircleOptions(packet,isHalf));}else if(typeof L==="object"){var center=packet.getLatLngLiteral();if(L.version<="0.7.7"){var range=this._getCircleRadius(packet,isHalf);L.Circle.call(this,[center.lat,center.lng],range,this._getLeafletCircleOptions(packet,isHalf));}else{L.Circle.call(this,center,this._getLeafletCircleOptions(packet,isHalf));}}};if(typeof google==="object"&&typeof google.maps==="object"){trackdirect.models.RngCircle.prototype=Object.create(google.maps.Circle.prototype);}else if(typeof L==="object"){trackdirect.models.RngCircle.prototype=Object.create(L.Circle.prototype);} trackdirect.models.RngCircle.prototype.constructor=trackdirect.models.RngCircle;trackdirect.models.RngCircle.prototype.show=function(){if(typeof google==="object"&&typeof google.maps==="object"){if(typeof this.getMap()==="undefined"||this.getMap()===null){this.setMap(this._defaultMap);}}else if(typeof L==="object"){if(!this._defaultMap.hasLayer(this)){this.addTo(this._defaultMap);}}};trackdirect.models.RngCircle.prototype.hide=function(){if(typeof google==="object"&&typeof google.maps==="object"){if(this.getMap()!==null){this.setMap(null);}}else if(typeof L==="object"){if(this._defaultMap.hasLayer(this)){this._defaultMap.removeLayer(this);}}};trackdirect.models.RngCircle.prototype._getGoogleCircleOptions=function(packet,isHalf){var color=trackdirect.services.stationColorCalculator.getColor(packet);var range=this._getCircleRadius(packet,isHalf);var options={strokeColor:color,strokeOpacity:0.6,strokeWeight:1,fillColor:color,fillOpacity:0.3,map:null,center:packet.getLatLngLiteral(),radius:range*1000,};return options;};trackdirect.models.RngCircle.prototype._getLeafletCircleOptions=function(packet,isHalf){var color=trackdirect.services.stationColorCalculator.getColor(packet);var range=this._getCircleRadius(packet,isHalf);var options={color:color,opacity:0.6,weight:1,fillColor:color,fillOpacity:0.3,radius:range*1000,};return options;};trackdirect.models.RngCircle.prototype._getCircleRadius=function(packet,isHalf){var range=packet.getRNGRange();if(range===null){range=0;} if(isHalf){range=range/2;} return range;}; trackdirect.models.PhgCircle=function(packet,map,isHalf){this._defaultMap=map;if(typeof google==="object"&&typeof google.maps==="object"){google.maps.Circle.call(this,this._getGoogleCircleOptions(packet,isHalf));}else if(typeof L==="object"){if(L.version<="0.7.7"){var range=this._getCircleRadius(packet,isHalf);var center=this._getCircleCenter(packet,isHalf);L.Circle.call(this,[center.lat,center.lng],range,this._getLeafletCircleOptions(packet,isHalf));}else{L.Circle.call(this,this._getCircleCenter(packet,isHalf),this._getLeafletCircleOptions(packet,isHalf));}}};if(typeof google==="object"&&typeof google.maps==="object"){trackdirect.models.PhgCircle.prototype=Object.create(google.maps.Circle.prototype);}else if(typeof L==="object"){trackdirect.models.PhgCircle.prototype=Object.create(L.Circle.prototype);} trackdirect.models.PhgCircle.prototype.constructor=trackdirect.models.PhgCircle;trackdirect.models.PhgCircle.prototype.show=function(){if(typeof google==="object"&&typeof google.maps==="object"){if(typeof this.getMap()==="undefined"||this.getMap()===null){this.setMap(this._defaultMap);}}else if(typeof L==="object"){if(!this._defaultMap.hasLayer(this)){this.addTo(this._defaultMap);}}};trackdirect.models.PhgCircle.prototype.hide=function(){if(typeof google==="object"&&typeof google.maps==="object"){if(this.getMap()!==null){this.setMap(null);}}else if(typeof L==="object"){if(this._defaultMap.hasLayer(this)){this._defaultMap.removeLayer(this);}}};trackdirect.models.PhgCircle.prototype._getGoogleCircleOptions=function(packet,isHalf){var color=trackdirect.services.stationColorCalculator.getColor(packet);var range=this._getCircleRadius(packet,isHalf);var center=this._getCircleCenter(packet,isHalf);var options={strokeColor:color,strokeOpacity:0.6,strokeWeight:1,fillColor:color,fillOpacity:0.3,map:null,center:center,radius:range,};return options;};trackdirect.models.PhgCircle.prototype._getLeafletCircleOptions=function(packet,isHalf){var color=trackdirect.services.stationColorCalculator.getColor(packet);var range=this._getCircleRadius(packet,isHalf);var options={color:color,opacity:0.6,weight:1,fillColor:color,fillOpacity:0.3,radius:range,};return options;};trackdirect.models.PhgCircle.prototype._getCircleRadius=function(packet,isHalf){var range=packet.getPHGRange();if(range===null){range=0;} if(isHalf){range=range/2;} return range;};trackdirect.models.PhgCircle.prototype._getCircleCenter=function(packet,isHalf){var direction=packet.getPhgDirectionDegree();var center=packet.getLatLngLiteral();if(direction!=null){var range=packet.getPHGRange();if(range===null){range=0;} if(isHalf){range=range/2;} var distance=(range*2)/3/2;center=trackdirect.services.distanceCalculator.getPositionByDistance(center,direction,distance);} return center;}; trackdirect.models.Packet=function(data){this.init();for(var key in data){this[key]=data[key];}};trackdirect.models.Packet.prototype.init=function(){this["altitude"]=null;this["comment"]="";this["course"]=null;this["db"]=null;this["id"]=null;this["latest_phg_timestamp"]=null;this["latest_rng_timestamp"]=null;this["latitude"]=null;this["longitude"]=null;this["map_id"]=null;this["map_sector"]=null;this["marker_counter"]=null;this["marker_id"]=null;this["ogn"]=null;this["overwrite"]=null;this["is_moving"]=1;this["packet_order_id"]=null;this["packet_tail_timestamp"]=null;this["packet_type_id"]=null;this["phg"]=null;this["posambiguity"]=0;this["position_timestamp"]=null;this["raw"]="";this["raw_path"]="";this["realtime"]=0;this["related_map_sectors"]=[];this["reported_timestamp"]=null;this["rng"]=null;this["sender_id"]=null;this["sender_name"]=null;this["source_id"]=null;this["speed"]=null;this["station_id"]=null;this["station_id_path"]=[];this["station_location_path"]=[];this["station_name"]=null;this["station_name_path"]=[];this["symbol"]=null;this["symbol_table"]=null;this["telemetry"]=null;this["timestamp"]=null;this["weather"]=null;};trackdirect.models.Packet.prototype.getStationName=function(){if(this.station_name==this.sender_name){return escapeHtml(this.station_name);}else{return escapeHtml(this.station_name+" ("+this.sender_name+")");}};trackdirect.models.Packet.prototype.getLatLngLiteral=function(){return{lat:parseFloat(this.latitude),lng:parseFloat(this.longitude)};};trackdirect.models.Packet.prototype.hasConfirmedMapId=function(){if([1,2,12].indexOf(this.map_id)>=0){return true;} return false;};trackdirect.models.Packet.prototype.getOgnAircraftType=function(){if(typeof this.ogn!=="undefined"&&this.ogn!==null){if(typeof this.ogn.ogn_aircraft_type_id!=="undefined"&&this.ogn.ogn_aircraft_type_id!=""){if(this.ogn.ogn_aircraft_type_id==1){return"Glider";}else if(this.ogn.ogn_aircraft_type_id==2){return"Tow Plane";}else if(this.ogn.ogn_aircraft_type_id==3){return"Helicopter";}else if(this.ogn.ogn_aircraft_type_id==4){return"Parachute";}else if(this.ogn.ogn_aircraft_type_id==5){return"Drop Plane";}else if(this.ogn.ogn_aircraft_type_id==6){return"Hang Glider";}else if(this.ogn.ogn_aircraft_type_id==7){return"Para Glider";}else if(this.ogn.ogn_aircraft_type_id==8){return"Powered Aircraft";}else if(this.ogn.ogn_aircraft_type_id==9){return"Jet Aircraft";}else if(this.ogn.ogn_aircraft_type_id==10){return"UFO";}else if(this.ogn.ogn_aircraft_type_id==11){return"Balloon";}else if(this.ogn.ogn_aircraft_type_id==12){return"Airship";}else if(this.ogn.ogn_aircraft_type_id==13){return"UAV";}else if(this.ogn.ogn_aircraft_type_id==14){return"";}else if(this.ogn.ogn_aircraft_type_id==15){return"Static Object";}}} return null;};trackdirect.models.Packet.prototype.getOgnDdbAircraftType=function(){if(typeof this.ogn_device!=="undefined"&&this.ogn_device!==null){if(typeof this.ogn_device.ddb_aircraft_type!=="undefined"&&this.ogn_device.ddb_aircraft_type!=""){if(this.ogn_device.ddb_aircraft_type==1){return"Glider/Motoglider";}else if(this.ogn_device.ddb_aircraft_type==2){return"Plane";}else if(this.ogn_device.ddb_aircraft_type==3){return"Ultralight";}else if(this.ogn_device.ddb_aircraft_type==4){return"Helicopter";}else if(this.ogn_device.ddb_aircraft_type==5){return"Drone/UAV";}else if(this.ogn_device.ddb_aircraft_type==6){return"Other";}}} return null;};trackdirect.models.Packet.prototype.getOgnAddressType=function(){if(typeof this.ogn!=="undefined"&&this.ogn!==null){if(typeof this.ogn.ogn_address_type_id!=="undefined"&&this.ogn.ogn_address_type_id!=""){if(this.ogn.ogn_address_type_id==1){return"ICAO";}else if(this.ogn.ogn_address_type_id==2){return"FLARM";}else if(this.ogn.ogn_address_type_id==3){return"OGN";}}} return null;};trackdirect.models.Packet.prototype.getOgnSenderAddress=function(){if(typeof this.ogn!=="undefined"&&this.ogn!==null){if(typeof this.ogn.ogn_sender_address!=="undefined"&&this.ogn.ogn_sender_address!=""){return this.ogn.ogn_sender_address;}} return null;};trackdirect.models.Packet.prototype.getOgnRegistration=function(){if(typeof this.ogn_device!=="undefined"&&this.ogn_device!==null){if(typeof this.ogn_device.registration!=="undefined"&&this.ogn_device.registration!=""){return this.ogn_device.registration;}} return null;};trackdirect.models.Packet.prototype.getOgnCN=function(){if(typeof this.ogn_device!=="undefined"&&this.ogn_device!==null){if(typeof this.ogn_device.cn!=="undefined"&&this.ogn_device.cn!=""){return this.ogn_device.cn;}} return null;};trackdirect.models.Packet.prototype.getOgnSummary=function(){var senderAddress=this.getOgnSenderAddress();var aircraftType=this.getOgnAircraftType();var ddbAircraftType=this.getOgnDdbAircraftType();var addressType=this.getOgnAddressType();var summary="";if(ddbAircraftType!==null){summary+=ddbAircraftType;}else if(aircraftType!==null){summary+=aircraftType;} if(senderAddress!==null){if(summary!=""){summary+=" ";} summary+=senderAddress;if(addressType!==null){summary+=" ("+addressType+")";}} return summary;};trackdirect.models.Packet.prototype.hasDirectionSupport=function(){if(this.course!==null&&this.speed!==null&&this.speed>0&&this.source_id==1&&this.packet_order_id==1&&this.is_moving==1&&this.hasConfirmedMapId()){var symbolCategory=1;if(this.symbol_table.charCodeAt(0)=="92"){symbolCategory=2;} if(symbolCategory==1&&trackdirect.settings.primarySymbolWithNoDirectionPolyline.indexOf(parseInt(this.symbol.charCodeAt(0)))>-1){return false;} if(symbolCategory==2&&trackdirect.settings.alternativeSymbolWithNoDirectionPolyline.indexOf(parseInt(this.symbol.charCodeAt(0)))>-1){return false;} return true;} return false;};trackdirect.models.Packet.prototype.getPhg=function(){if(this.phg!==null){if(this.phg==0){return null;}else if(this.phg<10){return"000"+String(this.phg);}else if(this.phg<100){return"00"+String(this.phg);}else if(this.phg<1000){return"0"+String(this.phg);}else{return String(this.phg);}} return null;};trackdirect.models.Packet.prototype.getRNGRange=function(){if(this.rng!==null){return this.rng;} return null;};trackdirect.models.Packet.prototype.getPHGRange=function(){if(this.getPhg()!==null){var p=this.getPhgPower();var h=this.getPhgHaat(false);var g=this.getPhgGain();var gain=Math.pow(10,g/10);var range=Math.sqrt(2*h*Math.sqrt((p/10)*(gain/2)));return range/0.000621371192;} return null;};trackdirect.models.Packet.prototype.getPHGDescription=function(){if(this.getPhg()!==null){var power=this.getPhgPower();var haat=this.getPhgHaat();var gain=this.getPhgGain();var direction=this.getPhgDirection();var description="";if(power!==null){description+="Power "+power+"W";} if(haat!==null){if(description.length>0){description+=", ";} description+="Height "+haat+"m";} if(gain!==null&&direction!==null){if(description.length>0){description+=", ";} description+="Gain "+gain+"dB "+direction;} return description;} return null;};trackdirect.models.Packet.prototype.getPhgPower=function(){if(this.getPhg()!==null){return Math.pow(parseInt(this.getPhg().substring(0,1)),2);} return null;};trackdirect.models.Packet.prototype.getPhgHaat=function(inMeters){inMeters=typeof inMeters!=="undefined"?inMeters:true;if(this.getPhg()!=null){value=parseInt(this.getPhg().substring(1,2));var haat=10;if(value==1){haat=20;}else if(value>1){haat=10*Math.pow(value,2);} if(inMeters){return Math.round(haat*0.3048,0);}else{return haat;}} return null;};trackdirect.models.Packet.prototype.getPhgGain=function(){if(this.getPhg()!=null){return parseInt(this.getPhg().substring(2,3));} return null;};trackdirect.models.Packet.prototype.getPhgDirection=function(){if(this.getPhg()!=null){switch(parseInt(this.getPhg().substring(3,4))){case 0:return"omni";break;case 1:return"North East";break;case 2:return"East";break;case 3:return"South East";break;case 4:return"South";break;case 5:return"South West";break;case 6:return"West";break;case 7:return"North West";break;case 8:return"North";break;}} return null;};trackdirect.models.Packet.prototype.getPhgDirectionDegree=function(){if(this.getPhg()!=null){switch(parseInt(this.getPhg().substring(3,4))){case 0:return null;break;case 1:return 45;break;case 2:return 90;break;case 3:return 135;break;case 4:return 180;break;case 5:return 225;break;case 6:return 270;break;case 7:return 315;break;case 8:return 360;break;}} return null;};trackdirect.models.Packet.prototype.getMarkerDistance=function(marker){var packetLatLng={lat:parseFloat(this.latitude),lng:parseFloat(this.longitude),};var markerPacketLatLng={lat:parseFloat(marker.packet.latitude),lng:parseFloat(marker.packet.longitude),};return trackdirect.services.distanceCalculator.getDistance(packetLatLng,markerPacketLatLng);};trackdirect.models.Packet.prototype.hasSameSymbol=function(marker){if(marker.packet.symbol==this.symbol&&marker.packet.symbol_table==this.symbol_table){return true;} return false;};trackdirect.models.Packet.prototype.getLinkifiedRawPath=function(){if(typeof this.raw_path!=="undefined"&&this.raw_path!==null&&this.raw_path!==""){var rawPath=escapeHtml(this.raw_path);rawPath="#"+rawPath+"#";for(var i=0;i'+ relatedStationName+ "";rawPath=rawPath.replaceAll("#"+relatedStationName+",","#"+relatedStationNameReplacement+",");rawPath=rawPath.replaceAll("#"+relatedStationName+"*","#"+relatedStationNameReplacement+"*");rawPath=rawPath.replaceAll("#"+relatedStationName+":","#"+relatedStationNameReplacement+":");rawPath=rawPath.replaceAll("#"+relatedStationName+"#","#"+relatedStationNameReplacement+"#");rawPath=rawPath.replaceAll(","+relatedStationName+",",","+relatedStationNameReplacement+",");rawPath=rawPath.replaceAll(","+relatedStationName+"*",","+relatedStationNameReplacement+"*");rawPath=rawPath.replaceAll(","+relatedStationName+":",","+relatedStationNameReplacement+":");rawPath=rawPath.replaceAll(","+relatedStationName+"#",","+relatedStationNameReplacement+"#");}} rawPath=rawPath.replace(/#+$/,"");rawPath=rawPath.replace(/^#+/,"");var rawPathArray=rawPath.split(",");if(rawPathArray.length>0){var rawPath=rawPathArray[0]+ " via "+ rawPathArray.join(",").replace(rawPathArray[0]+",","");} return rawPath;} return null;}; trackdirect.MarkerCreator=function(map){this._map=map;this._currentPacketSequenceStationId=null;};trackdirect.MarkerCreator.prototype.addPacket=function(packet,tryToShowPacket){if(this.isBadPacket(packet)){return null;} var markerIdKey=this._map.markerCollection.getMarkerIdKey(packet.marker_id);if(this._map.markerCollection.isExistingMarker(markerIdKey)){var marker=this._map.markerCollection.getMarker(markerIdKey);if(marker.packet.is_moving==1&&packet.is_moving!=1){packet.is_moving=1;}}else{if(packet.packet_order_id==2){packet.packet_order_id=3;}} markerIdKeyToOverwrite=this._getMarkerIdKeyToOverwrite(packet);if(markerIdKeyToOverwrite!==null){this._overwriteMarker(markerIdKeyToOverwrite,markerIdKey);} if(this._map.markerCollection.isPacketReplacingMarker(packet)){this._replaceMarker(markerIdKey);} this._setCurrentPacketSequenceStationId(packet);this._convertLostMarkersToGhost(packet);this._connectToPreviousMarker(packet);marker=this._createMarker(packet);this._map.addMarkerToMapSectors(markerIdKey,packet,tryToShowPacket);if(packet.overwrite==1){marker.overwrite=true;} return markerIdKey;};trackdirect.MarkerCreator.prototype._getMarkerIdKeyToOverwrite=function(packet){var markerIdKey=this._map.markerCollection.getMarkerIdKey(packet.marker_id);if(this._map.markerCollection.isExistingMarker(markerIdKey)){var marker=this._map.markerCollection.getMarker(markerIdKey);if(marker.overwrite==true&&packet.overwrite==0){return markerIdKey;}}else{var prevMarker=this._map.markerCollection.getStationLatestMarker(packet.station_id);if(prevMarker!==null){if(packet.is_moving==0&&packet.station_id==prevMarker.packet.station_id&&packet.timestamp-prevMarker.packet.timestamp>86400&&Math.round(prevMarker.packet.latitude*100000)==Math.round(packet.latitude*100000)&&Math.round(prevMarker.packet.longitude*100000)==Math.round(packet.longitude*100000)&&prevMarker.packet.symbol==packet.symbol&&prevMarker.packet.symbol_table==packet.symbol_table){return prevMarker.markerIdKey;}}} return null;};trackdirect.MarkerCreator.prototype._replaceMarker=function(markerIdKey){if(this._map.markerCollection.isExistingMarker(markerIdKey)){var marker=this._map.markerCollection.getMarker(markerIdKey);if(this._map.state.isMarkerInfoWindowOpen(marker)){this._map.state.openInfoWindowForMarkerIdKey=markerIdKey;} marker.hide(0,false,false);marker.stopDirectionPolyline();}};trackdirect.MarkerCreator.prototype._overwriteMarker=function(prevMarkerIdKey,newMarkerIdKey){var prevMarker=this._map.markerCollection.getMarker(prevMarkerIdKey);if(this._map.state.isMarkerInfoWindowOpen(prevMarker)){this._map.state.openInfoWindowForMarkerIdKey=newMarkerIdKey;} var markerLabel=prevMarker.label;var markerPolyLine=this._map.markerCollection.getMarkerPolyline(prevMarkerIdKey);var markerDotMarkers=this._map.markerCollection.getDotMarkers(prevMarkerIdKey);var markerOriginDashedPolyline=this._map.markerCollection.getMarkerDashedPolyline(prevMarkerIdKey);clearTimeout(prevMarker.toOldTimerId);if(markerDotMarkers!=null){for(var i=0;i('+ escapeHtml(marker.packet.sender_name)+ ")";} if(marker.packet.comment){var opIndex=marker.packet.comment.indexOf("OP:");if(opIndex>-1){opStr=marker.packet.comment.substring(opIndex+3).replace(/^\s+/,"")+" ";opStr=opStr.substring(0,opStr.indexOf(" "));if(opStr.length<=10&&opStr.length>0){labelText+=' ['+ escapeHtml(opStr)+ "]";}}}} var markerLabel=new trackdirect.models.Label({position:position,text:labelText,},this._map);this._map.markerCollection.setMarkerLabel(marker.markerIdKey,markerLabel);}};trackdirect.MarkerCreator.prototype._extendTail=function(prevmarker,newmarker){if(this._map.state.getClientTimestamp(newmarker.packet.timestamp)<=this._map.state.getOldestAllowedPacketTimestamp()){return;} if(this._map.markerCollection.hasPolyline(newmarker.markerIdKey)){var polyline=this._map.markerCollection.getMarkerPolyline(newmarker.markerIdKey);polyline.addMarker(newmarker);}else{if(this._map.state.getClientTimestamp(this._map.markerCollection.getMarker(newmarker.markerIdKey).packet.timestamp)<=this._map.state.getOldestAllowedPacketTimestamp()){return;}else{var color=trackdirect.services.stationColorCalculator.getColor(newmarker.packet);var newTailPolyline=new trackdirect.models.TailPolyline(color,this._map);newTailPolyline.setMarkerIdKey(newmarker.markerIdKey);newTailPolyline.addMarker(prevmarker);newTailPolyline.addMarker(newmarker);this._map.markerCollection.setMarkerPolyline(newmarker.markerIdKey,newTailPolyline);}}};trackdirect.MarkerCreator.prototype._replaceTailMarker=function(markerIdKey){if(this._map.markerCollection.hasPolyline(markerIdKey)){var marker=this._map.markerCollection.getMarker(markerIdKey);var polylines=this._map.markerCollection.getMarkerPolyline(markerIdKey);var latestIndex=polylines.getPath().length-1;if(latestIndex>=0){polylines.getPathItem(latestIndex).marker=marker;}}};trackdirect.MarkerCreator.prototype.isBadPacket=function(packet){if(typeof packet.latitude==="undefined"||typeof packet.longitude==="undefined"||packet.marker_id==null){return true;} var markerIdKey=this._map.markerCollection.getMarkerIdKey(packet.marker_id);if(this._map.markerCollection.isExistingMarker(markerIdKey)){var marker=this._map.markerCollection.getMarker(markerIdKey);if(packet.packet_order_id==1&&this._currentPacketSequenceStationId==packet.station_id){return false;} if(packet.db==0){if(this._map.markerCollection.isDuplicate(packet)){return true;}} if(packet.db==1&&marker.packet.db==1&&marker.packet.source===0&&packet.id===marker.packet.id){return true;} if(marker.overwrite==true&&packet.overwrite==0){return false;}else{if(marker.packet.timestamp>=packet.timestamp){return true;} if(marker.packet.reported_timestamp!==null&&packet.reported_timestamp!==null&&Math.abs(marker.packet.reported_timestamp-packet.reported_timestamp)<600){if(marker.packet.reported_timestamp>packet.reported_timestamp){return true;}}}} if(packet.is_moving==1){var list=this._map.markerCollection.getStationMarkerIdKeys(packet.station_id);for(var relatedMarkerIdKey in list){var relatedMarker=this._map.markerCollection.getMarker(relatedMarkerIdKey);if(relatedMarker!==null&&relatedMarker.overwrite==false&&relatedMarker.packet.timestamp>packet.timestamp){return true;}}} return false;}; trackdirect.models.MarkerCollection=function(){this._markerKeys={};this._markers=[];this._stationMarkers={};this._stationLastMovingMarkerIdKey={};this._stationLastMarker={};this._senderLastMarker={};this._positionMarkersIdKeys={};this._dotMarkers=[];this._markerPolyLines=[];this._markerOriginDashedPolyLines=[];this._mapSectorMarkerIdKeys={};this._stationCoverage={};this.resetAllMarkers();};trackdirect.models.MarkerCollection.prototype.getMarkerIdKey=function(markerId){if(!(markerId in this._markerKeys)){this._markers.push(null);this._markerPolyLines.push(null);this._dotMarkers.push(null);this._markerOriginDashedPolyLines.push(null);var markerIdKey=this._markers.length-1;this._markerKeys[markerId]=markerIdKey;return markerIdKey;}else{return this._markerKeys[markerId];}};trackdirect.models.MarkerCollection.prototype.isExistingMarker=function(markerIdKey){if(markerIdKey in this._markers&&this._markers[markerIdKey]!==null){return true;} return false;};trackdirect.models.MarkerCollection.prototype.setMarker=function(markerIdKey,marker){if(marker!==null&&typeof marker.packet!=="undefined"){var packet=marker.packet;this._markers[markerIdKey]=marker;this._addStationMarkerId(markerIdKey,packet);this._addStationLastMarker(packet,marker);this.addPostionMarkerId(markerIdKey,packet);}};trackdirect.models.MarkerCollection.prototype.getMarker=function(markerIdKey){if(markerIdKey!==null&&markerIdKey in this._markers){return this._markers[markerIdKey];} return null;};trackdirect.models.MarkerCollection.prototype.getAllMarkers=function(){return this._markers;};trackdirect.models.MarkerCollection.prototype.removeMarker=function(markerIdKey){if(markerIdKey!==null&&markerIdKey in this._markers){this._markers.splice(markerIdKey,1);}};trackdirect.models.MarkerCollection.prototype.getNumberOfMarkers=function(){return this._markers.length;};trackdirect.models.MarkerCollection.prototype.setMarkerLabel=function(markerIdKey,label){if(markerIdKey in this._markers&&this._markers[markerIdKey]!==null){this._markers[markerIdKey].label=label;}};trackdirect.models.MarkerCollection.prototype.getMarkerLabel=function(markerIdKey){if(markerIdKey in this._markers&&this._markers[markerIdKey]!==null){return this._markers[markerIdKey].label;} return null;};trackdirect.models.MarkerCollection.prototype.hasMarkerLabel=function(markerIdKey){if(markerIdKey in this._markers&&this._markers[markerIdKey]!==null&&this._markers[markerIdKey].label!==null){return true;} return false;};trackdirect.models.MarkerCollection.prototype.setMarkerLabelPosition=function(markerIdKey,position){if(markerIdKey in this._markers&&this._markers[markerIdKey]!==null&&this._markers[markerIdKey].label!==null){this._markers[markerIdKey].label.position=position;}};trackdirect.models.MarkerCollection.prototype.isDuplicate=function(packet){if(packet.is_moving==0){return false;} for(var markerIdKey in this.getPositionMarkerIdKeys(packet.latitude,packet.longitude)){var marker=this.getMarker(markerIdKey);if(marker!==null&&marker.packet.station_id==packet.station_id&&marker.packet.symbol==packet.symbol&&marker.packet.symbol_table==packet.symbol_table&&marker.packet.course==packet.course){return true;}} return false;};trackdirect.models.MarkerCollection.prototype.addDotMarker=function(markerIdKey,dotMarker){if(markerIdKey in this._dotMarkers){if(this._dotMarkers[markerIdKey]===null){this._dotMarkers[markerIdKey]=[];} this._dotMarkers[markerIdKey].push(dotMarker);}};trackdirect.models.MarkerCollection.prototype.getDotMarkers=function(markerIdKey){if(markerIdKey in this._dotMarkers&&this._dotMarkers[markerIdKey]!==null){return this._dotMarkers[markerIdKey];} return[];};trackdirect.models.MarkerCollection.prototype.hasDotMarkers=function(markerIdKey){if(markerIdKey in this._dotMarkers&&this._dotMarkers[markerIdKey]!==null&&this._dotMarkers[markerIdKey].length>0){return true;} return false;};trackdirect.models.MarkerCollection.prototype.addStationCoverage=function(stationId,stationCoveragePolygon){this._stationCoverage[stationId]=stationCoveragePolygon;};trackdirect.models.MarkerCollection.prototype.getStationCoverage=function(stationId){if(stationId in this._stationCoverage&&this._stationCoverage[stationId]!==null){return this._stationCoverage[stationId];} return null;};trackdirect.models.MarkerCollection.prototype.getStationIdListWithVisibleCoverage=function(){var result=[];for(var stationId in this._stationCoverage){if(this._stationCoverage[stationId].isRequestedToBeVisible()){result.push(stationId);}} return result;};trackdirect.models.MarkerCollection.prototype.hasCoveragePolygon=function(stationId){if(stationId in this._stationCoverage&&this._stationCoverage[stationId]!==null){return true;} return false;};trackdirect.models.MarkerCollection.prototype.resetDotMarkers=function(markerIdKey){if(markerIdKey in this._dotMarkers&&this._dotMarkers[markerIdKey]!==null){this._dotMarkers[markerIdKey]=[];}};trackdirect.models.MarkerCollection.prototype.removeOldestDotMarker=function(markerIdKey){if(this.hasDotMarkers(markerIdKey)){latestMarker=this.getMarker(markerIdKey);var latestMarkerIndex=this.getDotMarkerIndex(markerIdKey,latestMarker);var dotMarkers=this.getDotMarkers(markerIdKey);var maxNumberOfPolyLinePoints=dotMarkers.length;if(latestMarkerIndex>-1){maxNumberOfPolyLinePoints=maxNumberOfPolyLinePoints-1;} var removedItems=this._dotMarkers[markerIdKey].splice(0,1);if(removedItems.length==1){var removedMarker=removedItems[0];removedMarker.hide();if(this.hasPolyline(removedMarker.markerIdKey)){var polyline=this.getMarkerPolyline(removedMarker.markerIdKey);while(polyline.getPathLength()>maxNumberOfPolyLinePoints){polyline.removePathItem(0);}} removedMarker=null;return true;}} return false;};trackdirect.models.MarkerCollection.prototype.getDotMarkerIndex=function(markerIdKey,marker){if(!this.hasDotMarkers(markerIdKey)){return-1;} for(var i=0,len=this._dotMarkers[markerIdKey].length;i1){return true;}else{this._markerPolyLines[markerIdKey].hide();this._markerPolyLines[markerIdKey]=null;return false;}} return false;};trackdirect.models.MarkerCollection.prototype.resetMarkerPolyline=function(markerIdKey){if(markerIdKey in this._markerPolyLines){this._markerPolyLines[markerIdKey]=null;}};trackdirect.models.MarkerCollection.prototype.setMarkerDashedPolyline=function(markerIdKey,polyline){if(markerIdKey in this._markerOriginDashedPolyLines){this._markerOriginDashedPolyLines[markerIdKey]=polyline;}};trackdirect.models.MarkerCollection.prototype.getMarkerDashedPolyline=function(markerIdKey){if(this.hasDashedPolyline(markerIdKey)){return this._markerOriginDashedPolyLines[markerIdKey];} return null;};trackdirect.models.MarkerCollection.prototype.hasDashedPolyline=function(markerIdKey){if(markerIdKey in this._markerOriginDashedPolyLines&&this._markerOriginDashedPolyLines[markerIdKey]!==null){if(this._markerOriginDashedPolyLines[markerIdKey].getPathLength()>1){return true;}else{this._markerOriginDashedPolyLines[markerIdKey].hide();this._markerOriginDashedPolyLines[markerIdKey]=null;return false;}} return false;};trackdirect.models.MarkerCollection.prototype.resetMarkerDashedPolyline=function(markerIdKey){if(markerIdKey in this._markerOriginDashedPolyLines){this._markerOriginDashedPolyLines[markerIdKey]=null;}};trackdirect.models.MarkerCollection.prototype.getStationLatestPacket=function(stationId){if(typeof this._stationLastMarker[stationId]!=="undefined"&&this._stationLastMarker[stationId]!==null&&typeof this._stationLastMarker[stationId].packet!=="undefined"){return this._stationLastMarker[stationId].packet;}else{return null;}};trackdirect.models.MarkerCollection.prototype.getStationLatestMarker=function(stationId){if(typeof this._stationLastMarker[stationId]!=="undefined"&&this._stationLastMarker[stationId]!==null){return this._stationLastMarker[stationId];}else{return null;}};trackdirect.models.MarkerCollection.prototype.getSenderLatestPacket=function(senderId){if(typeof this._senderLastMarker[senderId]!=="undefined"&&this._senderLastMarker[senderId]!==null&&typeof this._senderLastMarker[senderId].packet!=="undefined"){return this._senderLastMarker[senderId].packet;}else{return null;}};trackdirect.models.MarkerCollection.prototype.getStationLatestMovingMarkerIdKey=function(stationId){if(this._stationLastMovingMarkerIdKey!==null&&typeof this._stationLastMovingMarkerIdKey[stationId]!=="undefined"&&this._stationLastMovingMarkerIdKey[stationId]!==null&&this.isExistingMarker(this._stationLastMovingMarkerIdKey[stationId])){return this._stationLastMovingMarkerIdKey[stationId];} return null;};trackdirect.models.MarkerCollection.prototype.getMarkerMasterMarkerKeyId=function(markerIdKey){if(this.isExistingMarker(markerIdKey)){var marker=this._markers[markerIdKey];if(this.hasRelatedDashedPolyline(marker)){return this.getMarkerMasterMarkerKeyId(marker._relatedMarkerOriginDashedPolyLine.ownerMarkerIdKey);}} return markerIdKey;};trackdirect.models.MarkerCollection.prototype.getStationLatestVisibleMarker=function(stationId){var latestVisibleMarker=null;var latestVisibleMarkerTimestamp=null;for(var markerIdKey in this._stationMarkers[stationId]){var marker=this._markers[markerIdKey];if(typeof marker!=="undefined"&&marker!==null&&typeof marker.getMap()!=="undefined"&&marker.getMap()!==null){if(latestVisibleMarkerTimestamp===null||marker.packet.timestamp>latestVisibleMarkerTimestamp){latestVisibleMarker=marker;latestVisibleMarkerTimestamp=marker.packet.timestamp;}}} return latestVisibleMarker;};trackdirect.models.MarkerCollection.prototype.getStationMarkerIdKeys=function(stationId){if(stationId in this._stationMarkers){return this._stationMarkers[stationId];} return{};};trackdirect.models.MarkerCollection.prototype.getPositionMarkerIdKeys=function(latitude,longitude){var key=this._getCompareablePosition(latitude,longitude);if(key in this._positionMarkersIdKeys){return this._positionMarkersIdKeys[key];} return{};};trackdirect.models.MarkerCollection.prototype.addPostionMarkerId=function(markerIdKey,packet){var key=this._getCompareablePosition(packet.latitude,packet.longitude);if(!(key in this._positionMarkersIdKeys)){this._positionMarkersIdKeys[key]={};} this._positionMarkersIdKeys[key][markerIdKey]=true;};trackdirect.models.MarkerCollection.prototype.removePostionMarkerId=function(latitude,longitude,markerIdKey){var key=this._getCompareablePosition(latitude,longitude);if(key in this._positionMarkersIdKeys){if(markerIdKey in this._positionMarkersIdKeys[key]){this._positionMarkersIdKeys[key][markerIdKey]=false;}}};trackdirect.models.MarkerCollection.prototype.addMarkerToMapSector=function(markerIdKey,markerMapSector){if(!(markerMapSector in this._mapSectorMarkerIdKeys)){this._mapSectorMarkerIdKeys[markerMapSector]=[];} if(this._mapSectorMarkerIdKeys[markerMapSector].indexOf(markerIdKey)<0){this._mapSectorMarkerIdKeys[markerMapSector].push(markerIdKey);}};trackdirect.models.MarkerCollection.prototype.getMapSectorMarkerKeys=function(mapSector){if(mapSector in this._mapSectorMarkerIdKeys){return this._mapSectorMarkerIdKeys[mapSector];} return[];};trackdirect.models.MarkerCollection.prototype.resetAllMarkers=function(){this._markerKeys={};this._markers=[];this._markerPolyLines=[];this._dotMarkers=[];this._markerOriginDashedPolyLines=[];this._stationMarkers={};this._stationLastMovingMarkerIdKey={};this._stationLastMarker={};this._senderLastMarker={};this._positionMarkersIdKeys={};this._mapSectorMarkerIdKeys={};this._stationCoverage={};};trackdirect.models.MarkerCollection.prototype.resetMarker=function(markerIdKey){if(this.isExistingMarker(markerIdKey)){var marker=this._markers[markerIdKey];this._markers[markerIdKey]=null;this._markerPolyLines[markerIdKey]=null;this._dotMarkers[markerIdKey]=null;this._markerOriginDashedPolyLines[markerIdKey]=null;if(typeof marker.packet.latitude!="undefined"&&typeof marker.packet.longitude!="undefined"){this.removePostionMarkerId(marker.packet.latitude,marker.packet.longitude,markerIdKey);}}};trackdirect.models.MarkerCollection.prototype.hasRelatedDashedPolyline=function(marker){if(typeof marker._relatedMarkerOriginDashedPolyLine!=="undefined"&&marker._relatedMarkerOriginDashedPolyLine!==null){return true;} return false;};trackdirect.models.MarkerCollection.prototype.hasNonRelatedMovingMarkerId=function(packet){var latestStationMovingMarkerIdKey=this.getStationLatestMovingMarkerIdKey(packet.station_id);var newMarkerIdKey=this.getMarkerIdKey(packet.marker_id);if(latestStationMovingMarkerIdKey!==null&&latestStationMovingMarkerIdKey!==newMarkerIdKey){var latestStationMovingMarker=this.getMarker(latestStationMovingMarkerIdKey);if(latestStationMovingMarker.packet.hasConfirmedMapId()){return true;}} return false;};trackdirect.models.MarkerCollection.prototype.isPacketReplacingMarker=function(packet){var markerIdKey=this.getMarkerIdKey(packet.marker_id);if(this.isExistingMarker(markerIdKey)){var marker=this.getMarker(markerIdKey);if(marker!==null){if(packet.map_id==14){return true;} if(packet.is_moving==0){return true;} if([1,2,7,12].indexOf(packet.map_id)<0){return true;}}} return false;};trackdirect.models.MarkerCollection.prototype._addStationMarkerId=function(markerIdKey,packet){if(!(packet.station_id in this._stationMarkers)){this._stationMarkers[packet.station_id]={};} this._stationMarkers[packet.station_id][markerIdKey]=true;if(packet.is_moving==1&&packet.hasConfirmedMapId()){this._stationLastMovingMarkerIdKey[packet.station_id]=markerIdKey;}};trackdirect.models.MarkerCollection.prototype._addStationLastMarker=function(packet,marker){if(packet.hasConfirmedMapId()){if(typeof this._stationLastMarker[packet.station_id]==="undefined"||this._stationLastMarker[packet.station_id]===null){this._stationLastMarker[packet.station_id]=marker;if(packet.station_name==packet.sender_name){this._senderLastMarker[packet.sender_id]=marker;}}else if(this._stationLastMarker[packet.station_id].packet.timestamp<=packet.timestamp){this._stationLastMarker[packet.station_id]=marker;if(packet.station_name==packet.sender_name){this._senderLastMarker[packet.sender_id]=marker;}}}};trackdirect.models.MarkerCollection.prototype._getCompareablePosition=function(latitude,longitude){var latCmp=Math.round(latitude*100000);var lngCmp=Math.round(longitude*100000);return String(latCmp)+":"+String(lngCmp);}; trackdirect.models.Marker=function(packet,isDotMarker,map){this.packet=packet;this._isDotMarker=isDotMarker;this._defaultMap=map;if(typeof google==="object"&&typeof google.maps==="object"){google.maps.Marker.call(this,this._getGoogleMarkerOptions());}else if(typeof L==="object"){L.Marker.call(this,this.packet.getLatLngLiteral(),this._getLeafletMarkerOptions());} this._init();if(typeof google==="object"&&typeof google.maps==="object"){this.setMap(null);}};if(typeof google==="object"&&typeof google.maps==="object"){trackdirect.models.Marker.prototype=Object.create(google.maps.Marker.prototype);}else if(typeof L==="object"){trackdirect.models.Marker.prototype=Object.create(L.Marker.prototype);} trackdirect.models.Marker.prototype.constructor=trackdirect.models.Marker;trackdirect.models.Marker.prototype._init=function(){this._tdEventListeners={};this.hasLabel=false;this.showAsMarker=false;this.overwrite=false;this.markerIdKey=null;this.label=null;this.transmitPolyLine=null;this.directionPolyLine=null;this.phgCircle=null;this.rngCircle=null;this.hideTimerId=null;this.toOldTimerId=null;if(!this._isDotMarker){this.showAsMarker=true;if(this.packet.map_id!=1&&this.packet.map_id!=2&&this.packet.map_id!=12){this.setOpacity(0.5);}else{this.hasLabel=true;}} if(this._defaultMap.state.endTimeTravelTimestamp===null){this._addMarkerToOldTimeout(0);} this._addMarkerTooltip();};trackdirect.models.Marker.prototype.addTdListener=function(event,handler){if(!(event in this._tdEventListeners)){this._tdEventListeners[event]=[];} this._tdEventListeners[event].push(handler);};trackdirect.models.Marker.prototype.isDotMarker=function(){return this._isDotMarker;};trackdirect.models.Marker.prototype.isVisible=function(){if(typeof google==="object"&&typeof google.maps==="object"){if(typeof this.getMap()!=="undefined"&&this.getMap()!==null){return true;}}else if(typeof L==="object"){if(this._defaultMap.hasLayer(this)){return true;}} return false;};trackdirect.models.Marker.prototype.getPositionLiteral=function(){if(typeof google==="object"&&typeof google.maps==="object"){var latLng=this.getPosition();if(typeof latLng!=="undefined"&&typeof latLng.lat==="function"){return{lat:latLng.lat(),lng:latLng.lng()};}else{return latLng;}}else if(typeof L==="object"){var latLng=this.getLatLng();if(typeof latLng!=="undefined"){return{lat:latLng.lat,lng:latLng.lng};}else{return latLng;}} return{};};trackdirect.models.Marker.prototype.show=function(){if(typeof google==="object"&&typeof google.maps==="object"){if(typeof this.getMap()==="undefined"||this.getMap()===null){this.setMap(this._defaultMap);}}else if(typeof L==="object"){if(!this._defaultMap.hasLayer(this)){this.addTo(this._defaultMap);}} if(this.hideTimerId!==null){clearTimeout(this.hideTimerId);} this._emitTdEventListeners("onshow");};trackdirect.models.Marker.prototype.hide=function(delayInMilliSeconds,onlyHideIfNeeded,hideOpenInfoWindow){delayInMilliSeconds=typeof delayInMilliSeconds!=="undefined"?delayInMilliSeconds:0;onlyHideIfNeeded=typeof onlyHideIfNeeded!=="undefined"?onlyHideIfNeeded:false;hideOpenInfoWindow=typeof hideOpenInfoWindow!=="undefined"?hideOpenInfoWindow:true;if(delayInMilliSeconds>0){this._hideLater(delayInMilliSeconds,onlyHideIfNeeded);return;} if(onlyHideIfNeeded&&this.shouldMarkerBeVisible()){return;} if(hideOpenInfoWindow&&this._defaultMap.state.isMarkerInfoWindowOpen(this)){this._defaultMap.state.openInfoWindow.hide();} if(this.isVisible()){if(typeof google==="object"&&typeof google.maps==="object"){this.setMap(null);}else if(typeof L==="object"){this._defaultMap.removeLayer(this);}} if(this.showAsMarker){this.hideLabel();} this.hidePHGCircle();this.hideRNGCircle();if(this.hideTimerId!==null){clearTimeout(this.hideTimerId);} this._emitTdEventListeners("onhide");};trackdirect.models.Marker.prototype.getDefaultMap=function(){return this._defaultMap;};trackdirect.models.Marker.prototype.getMap=function(){if(typeof google==="object"&&typeof google.maps==="object"){var map=google.maps.Marker.prototype.getMap.call(this);if(typeof map!=="undefined"){return map;}}else if(typeof L==="object"){if(this._defaultMap.hasLayer(this)){return this._defaultMap;}} return null;};trackdirect.models.Marker.prototype.getState=function(){return this._defaultMap.state;};trackdirect.models.Marker.prototype.getZIndex=function(){if(typeof google==="object"&&typeof google.maps==="object"){return this.zIndex;}else if(typeof L==="object"){return this.options.zIndexOffset;} return 0;};trackdirect.models.Marker.prototype.showCompleteMarker=function(){if(this._defaultMap.state.isFilterMode&&this._defaultMap.state.filterStationIds.indexOf(this.packet.station_id)==-1){return;} if(this.shouldMarkerBeVisible()){if(this.showAsMarker){this.show();} if(this._defaultMap.state.isFilterMode){this.showMarkerPrevPosition();this.showMarkerTail();this.showLabel();}else{if(this._defaultMap.getZoom()>=trackdirect.settings.minZoomForMarkerPrevPosition){this.showMarkerPrevPosition();} if(this._defaultMap.getZoom()>=trackdirect.settings.minZoomForMarkerTail){this.showMarkerTail();} if(this._defaultMap.getZoom()>=trackdirect.settings.minZoomForMarkerLabel){this.showLabel();}} if(this._defaultMap.state.showPHGCircles==1){this.showPHGCircle(true);}else if(this._defaultMap.state.showPHGCircles==2){this.showPHGCircle(false);} if(this._defaultMap.state.showRNGCircles==1){this._showRNGCircle(true);}else if(this._defaultMap.state.showRNGCircles==2){this._showRNGCircle(false);}}};trackdirect.models.Marker.prototype.hideCompleteMarker=function(){this.hide();this.hideMarkerPrevPosition();this.hideMarkerTail();};trackdirect.models.Marker.prototype.showMarkerDetails=function(){if(this._defaultMap.getZoom()>=trackdirect.settings.minZoomForMarkerPrevPosition){this.showMarkerPrevPosition();} if(this._defaultMap.getZoom()>=trackdirect.settings.minZoomForMarkerTail){this.showMarkerTail();} if(this._defaultMap.getZoom()>=trackdirect.settings.minZoomForMarkerLabel){this.showLabel();}};trackdirect.models.Marker.prototype.hideMarkerDetails=function(){if(this._defaultMap.getZoom()-1){if(this.isVisible()&&this.label!==null&&(this._defaultMap.getZoom()>=trackdirect.settings.minZoomForMarkerLabel||this._defaultMap.state.filterStationIds.indexOf(this.packet.station_id)>-1)&&this.hasLabel&&this.packet.hasConfirmedMapId()){this.label.show();}}};trackdirect.models.Marker.prototype.hideLabel=function(){if(this.label!==null&&this.hasLabel){this.label.hide();}};trackdirect.models.Marker.prototype.showMarkerPrevPosition=function(){if(this.shouldMarkerBeVisible()&&this.packet.hasConfirmedMapId()){var oldestAllowedPacketTimestamp=this._defaultMap.state.getOldestAllowedPacketTimestamp();var dotMarkers=this._defaultMap.markerCollection.getDotMarkers(this.markerIdKey);for(var i=0;ioldestAllowedPacketTimestamp){dotMarker.show();}} if(!this.showAsMarker){this.show();}}};trackdirect.models.Marker.prototype.hideMarkerPrevPosition=function(){if(this.packet.hasConfirmedMapId()){var dotMarkers=this._defaultMap.markerCollection.getDotMarkers(this.markerIdKey);for(var i=0;ithis._defaultMap.state.getOldestAllowedPacketTimestamp()){dashedPolyline.show();if(typeof dashedPolyline.relatedMarkerIdKey!=="undefined"){var relatedMarker=this._defaultMap.markerCollection.getMarker(dashedPolyline.relatedMarkerIdKey);if(relatedMarker!==null&&relatedMarker.markerIdKey!==this.markerIdKey){relatedMarker.showMarkerTail();}}}} if(this.directionPolyLine!==null){this.directionPolyLine.show();}}};trackdirect.models.Marker.prototype.hideMarkerTail=function(markerIdKey){var latestMarker=this._defaultMap.markerCollection.getStationLatestMarker(this.packet.station_id);if(this._defaultMap.state.isMarkerInfoWindowOpen(this)||this._defaultMap.state.isMarkerInfoWindowOpen(latestMarker)){return;} if(this.packet.map_id!=1&&this.packet.map_id!=2&&this.packet.map_id!=12){this.hide();if(this.showAsMarker){this.hideLabel();}} var polyline=this._defaultMap.markerCollection.getMarkerPolyline(this.markerIdKey);if(polyline!==null){if(this._defaultMap.state.isPolylineInfoWindowOpen(polyline)){this._defaultMap.state.openInfoWindow.hide();} polyline.hide();} var dashedPolyline=this._defaultMap.markerCollection.getMarkerDashedPolyline(this.markerIdKey);if(dashedPolyline!==null){dashedPolyline.hide();if(typeof dashedPolyline.relatedMarkerIdKey!=="undefined"){var relatedMarker=this._defaultMap.markerCollection.getMarker(dashedPolyline.relatedMarkerIdKey);if(relatedMarker!==null&&relatedMarker.markerIdKey!==this.markerIdKey){relatedMarker.hideMarkerTail();}}} if(this.directionPolyLine!==null){this.directionPolyLine.hide();}};trackdirect.models.Marker.prototype.hideRNGCircle=function(){if(this.rngCircle!==null){this.rngCircle.hide();}};trackdirect.models.Marker.prototype.showRNGCircle=function(isHalf){this.hideRNGCircle();this.rngCircle=new trackdirect.models.RngCircle(this.packet,this._defaultMap,isHalf);this.rngCircle.show();};trackdirect.models.Marker.prototype.hidePHGCircle=function(){if(this.phgCircle!==null){this.phgCircle.hide();}};trackdirect.models.Marker.prototype.showPHGCircle=function(isHalf){this.hidePHGCircle();this.phgCircle=new trackdirect.models.PhgCircle(this.packet,this._defaultMap,isHalf);this.phgCircle.show();};trackdirect.models.Marker.prototype.markToBeOverWritten=function(){this.overwrite=true;};trackdirect.models.Marker.prototype.isSingleMovingMarker=function(){var markerCounter=0;if(typeof this.packet.marker_counter!=="undefined"&&this.packet.marker_counter!==null){markerCounter=this.packet.marker_counter;} if(this.packet.position_timestamp==this.packet.timestamp&&this.packet.is_moving==1&&[1,2,7,12].indexOf(this.packet.map_id)>=0&&markerCounter<=1&&!this._defaultMap.markerCollection.hasDotMarkers(this.markerIdKey)){return true;} return false;};trackdirect.models.Marker.prototype.shouldMarkerBeVisible=function(){if(this.packet.map_id==14){return false;} if(this.packet.source_id==2&&!this._defaultMap.state.isCwopMarkersVisible){return false;} if(!this._defaultMap.state.isStationaryMarkersVisible){if(!this.isMovingStation()){return false;}} if(!this._defaultMap.state.isUnknownMarkersVisible){if(this.packet.station_name.substring(0,7)=="UNKNOWN"){return false;}} if(!this._defaultMap.state.isOgflymMarkersVisible){if(this.packet.raw_path.indexOf("OGFLYM")>=0){return false;}} if(!this._defaultMap.state.isInternetMarkersVisible){if(this.packet.raw_path.indexOf("TCPIP")>=0||this.packet.raw_path.indexOf("qAC")>=0||this.packet.raw_path.indexOf("qAX")>=0||this.packet.raw_path.indexOf("qAU")>=0||this.packet.raw_path.indexOf("qAS")>=0){if(this.packet.station_id_path.length==0){return false;}}} if(this._defaultMap.state.visibleSymbols.length>0){var symbolFound=false;for(var key in this._defaultMap.state.visibleSymbols){var visibleSymbol=this._defaultMap.state.visibleSymbols[key];if(this.packet.symbol.charCodeAt(0)==visibleSymbol[0]&&this.packet.symbol_table.charCodeAt(0)==visibleSymbol[1]){symbolFound=true;}} if(!symbolFound){return false;}} if(this.packet.map_id!=1&&this.packet.map_id!=2&&this.packet.map_id!=12&&!this._defaultMap.state.isGhostMarkersVisible){return false;} if(this._defaultMap.state.isFilterMode&&this._defaultMap.state.filterStationIds.indexOf(this.packet.station_id)>-1){var latestStationMarker=this._defaultMap.markerCollection.getStationLatestMarker(this.packet.station_id);if(this._defaultMap.state.getClientTimestamp(this.packet.timestamp)<=this._defaultMap.state.getOldestAllowedPacketTimestamp()&&typeof latestStationMarker!=="undefined"&&latestStationMarker!==null&&!this._isMarkersEqual(latestStationMarker)){return false;} return true;}else{if(this._defaultMap.state.isFilterMode&&this._defaultMap.state.filterStationIds.indexOf(this.packet.station_id)===-1){return false;} if(this.packet.map_id!=1&&this.packet.map_id!=2&&this.packet.map_id!=12&&this._defaultMap.getZoom()this.packet.position_timestamp){dateString=moment(positionDate).format(trackdirect.settings.dateFormatNoTimeZone)+ " - "+ moment(date).format(trackdirect.settings.dateFormatNoTimeZone);} if(this.packet.getOgnRegistration()!=null){var name=escapeHtml(this.packet.station_name);name+=", ";name+=escapeHtml(this.packet.getOgnRegistration());if(this.packet.getOgnCN()!==null){name+=" ["+escapeHtml(this.packet.getOgnCN())+"]";} return('
'+ ''+ name+ "
"+ '
'+ dateString+ "
");}else if(this.packet.station_name==this.packet.sender_name){return('
'+ ''+ escapeHtml(this.packet.station_name)+ "
"+ '
'+ dateString+ "
");}else{return('
'+ ''+ escapeHtml(this.packet.station_name)+ "
"+ '
Sent by '+ escapeHtml(this.packet.sender_name)+ "
"+ '
'+ dateString+ "
");}};trackdirect.models.Marker.prototype._getGoogleMarkerOptions=function(){var anchorPoint=null;if(this._isDotMarker){var colorId=trackdirect.services.stationColorCalculator.getColorId(this.packet);var iconUrl=trackdirect.settings.baseUrl+ trackdirect.settings.imagesBaseDir+ "dotColor"+ colorId+ ".png";var scaledImageSize=new google.maps.Size(12,12);var imageSize=new google.maps.Size(12,12);var imageAnchor=new google.maps.Point(6,6);var opacity=1.0;}else{var scalePx=24;var sizePx=24;if(this._shouldMarkerSymbolBeScaled()){scalePx=48;} if(this.packet.course!==null){sizePx=sizePx+7;if(scalePx0){var dotMarkers=markerCollection.getDotMarkers(me.markerIdKey);dotMarkers[0]._addMarkerToOldTimeout(0);me._addMarkerToOldTimeout(100);}}}else{me._addMarkerToOldTimeout(1000);}}},delay);}),(trackdirect.models.Marker.prototype._emitTdEventListeners=function(event,arg){if(event in this._tdEventListeners){for(var i=0;i0){this._supportedMapTypes=this._tdMapOptions.supportedMapTypes;}else if(typeof google==="object"&&typeof google.maps==="object"){this._supportedMapTypes["roadmap"]=google.maps.MapTypeId.ROADMAP;this._supportedMapTypes["terrain"]=google.maps.MapTypeId.TERRAIN;this._supportedMapTypes["satellite"]=google.maps.MapTypeId.SATELLITE;this._supportedMapTypes["hybrid"]=google.maps.MapTypeId.HYBRID;}else if(typeof L==="object"){this._supportedMapTypes["roadmap"]="OpenStreetMap.Mapnik";this._supportedMapTypes["terrain"]="OpenTopoMap";} if(typeof this._tdMapOptions.maptype!=="undefined"&&this._tdMapOptions.maptype!==null&&this._tdMapOptions.maptype in this._supportedMapTypes){this._mapType=this._tdMapOptions.maptype;}else{this._mapType=Object.keys(this._supportedMapTypes)[0];}};trackdirect.models.Map.prototype._initMap=function(){this._heatMap=new trackdirect.models.HeatMap(this);this._setMapInitialLocation();this._initOms();this._initInfoWindowEvent();this._updateMapContent();this._initMapEvents();if(typeof google==="object"&&typeof google.maps==="object"){if(typeof this._tdMapOptions.mid!=="undefined"){var kmlUrl="https://www.google.com/maps/d/u/0/kml?mid="+this._tdMapOptions.mid;var kmlLayer=new google.maps.KmlLayer(kmlUrl,{map:this});}}};trackdirect.models.Map.prototype.triggerResize=function(){if(typeof google==="object"&&typeof google.maps==="object"){google.maps.event.trigger(this,"resize");}else if(typeof L==="object"){L.Map.prototype._onResize.call(this);}};trackdirect.models.Map.prototype.setCenter=function(pos,zoom){if(typeof google==="object"&&typeof google.maps==="object"){google.maps.Map.prototype.setCenter.call(this,pos);if(typeof zoom!=="undefined"){google.maps.Map.prototype.setZoom.call(this,zoom);}}else if(typeof L==="object"){zoom=typeof zoom!=="undefined"?zoom:this.getZoom();L.Map.prototype.setView.call(this,pos,zoom);} this._renderCordinatesContainer(pos);};trackdirect.models.Map.prototype.getCenterLiteral=function(){if(typeof google==="object"&&typeof google.maps==="object"){var latLng=google.maps.Map.prototype.getCenter.call(this);if(typeof latLng!=="undefined"&&typeof latLng.lat==="function"){return{lat:latLng.lat(),lng:latLng.lng()};}else{return latLng;}}else if(typeof L==="object"){var latLng=L.Map.prototype.getCenter.call(this);if(typeof latLng!=="undefined"){return{lat:latLng.lat,lng:latLng.lng};}else{return latLng;}} return null;};trackdirect.models.Map.prototype.fitBounds=function(bounds){if(typeof google==="object"&&typeof google.maps==="object"){var latLngBounds=new google.maps.LatLngBounds();for(var i=0;i=0||this.state.isFilterMode){return true;} return false;};trackdirect.models.Map.prototype.getNumberOfNewMarkersToShow=function(){return this._newMarkersToShow;};trackdirect.models.Map.prototype.showNewMarkersInQueue=function(track){track=typeof track!=="undefined"?track:true;var oldestAllowedTrackingTimestamp=0;if(this.state.onlyTrackRecentPackets){oldestAllowedTrackingTimestamp=Math.floor(Date.now()/1000)-60;} while((markerIdKey=this._newMarkersToShow.pop())!=null){if(!this.markerCollection.isExistingMarker(markerIdKey)){continue;} var marker=this.markerCollection.getMarker(markerIdKey);trackdirect.services.callbackExecutor.addWithPriority(marker,marker.showCompleteMarker,[]);if(track&&marker.packet.packet_order_id==1){if(marker.shouldMarkerBeVisible()&&marker.showAsMarker&&this.state.trackStationId!==null&&this.state.trackStationId==marker.packet.station_id&&this.state.getClientTimestamp(marker.packet.timestamp)>oldestAllowedTrackingTimestamp){trackdirect.services.callbackExecutor.addWithPriority(this,this.setCenterByStationId,[marker.packet.station_id]);}} if(this.state.openInfoWindowForMarkerIdKey!==null&&this.state.openInfoWindowForMarkerIdKey==markerIdKey&&marker.packet.packet_order_id==1&&marker.shouldMarkerBeVisible()&&marker.showAsMarker){trackdirect.services.callbackExecutor.addWithPriority(this,this.openLatestStationInfoWindow,[marker.packet.station_id]);}} this.state.openInfoWindowForMarkerIdKey=null;};trackdirect.models.Map.prototype.activateFilteredMode=function(){this.state.isFilterMode=true;this._deactivateHeatMap();this._updateMapContent();};trackdirect.models.Map.prototype.deactivateFilteredMode=function(){if(this.state.isFilterMode){this._activateHeatMap();this.state.isFilterMode=false;this.state.filterStationIds=[];this._updateMapContent();}};trackdirect.models.Map.prototype.getNorthEastLat=function(){if(this.getBounds()!=null){if(typeof google==="object"&&typeof google.maps==="object"){return this.getBounds().getNorthEast().lat();}else if(typeof L==="object"){return this.getBounds().getNorthEast().lat;}} return 0;};trackdirect.models.Map.prototype.getNorthEastLng=function(){if(this.getBounds()!=null){if(typeof google==="object"&&typeof google.maps==="object"){return this.getBounds().getNorthEast().lng();}else if(typeof L==="object"){return this.getBounds().getNorthEast().lng;}} return 0;};trackdirect.models.Map.prototype.getSouthWestLat=function(){if(this.getBounds()!=null){if(typeof google==="object"&&typeof google.maps==="object"){return this.getBounds().getSouthWest().lat();}else if(typeof L==="object"){return this.getBounds().getSouthWest().lat;}} return 0;};trackdirect.models.Map.prototype.getSouthWestLng=function(){if(this.getBounds()!=null){if(typeof google==="object"&&typeof google.maps==="object"){return this.getBounds().getSouthWest().lng();}else if(typeof L==="object"){return this.getBounds().getSouthWest().lng;}} return 0;};trackdirect.models.Map.prototype.isMapReady=function(){if(this.getBounds()!=null){return true;} return false;};trackdirect.models.Map.prototype.setMapType=function(mapType){if(mapType in this._supportedMapTypes){this._mapType=mapType;if(typeof google==="object"&&typeof google.maps==="object"){this._updateGoogleMapTileLayer();}else if(typeof L==="object"){this._updateLeafletTileLayer();} this._emitTdEventListeners("change");}};trackdirect.models.Map.prototype.getMapType=function(){return this._mapType;};trackdirect.models.Map.prototype.getLeafletTileLayer=function(){return this._leafletTileLayer;};trackdirect.models.Map.prototype.getMid=function(){if(typeof this._tdMapOptions.mid!=="undefined"){return this._tdMapOptions.mid;} return null;};trackdirect.models.Map.prototype.resetAllMarkers=function(){while(this.markerCollection.getNumberOfMarkers()>0){var i=this.markerCollection.getNumberOfMarkers();while(i--){var marker=this.markerCollection.getMarker(i);if(marker!==null){marker.stopToOldTimeout();marker.stopDirectionPolyline();marker.hide();marker.hideMarkerPrevPosition();marker.hideMarkerTail();var stationCoverage=this.markerCollection.getStationCoverage(marker.packet.station_id);if(stationCoverage){stationCoverage.hide();}} this.markerCollection.removeMarker(i);}} if(this.state.openInfoWindow!==null){this.state.openInfoWindow.hide();} if(this.oms){this.oms.clearMarkers();} this.markerCollection.resetAllMarkers();};trackdirect.models.Map.prototype.openMarkerInfoWindow=function(marker,disableAutoPan){disableAutoPan=typeof disableAutoPan!=="undefined"?disableAutoPan:true;if(marker.getMap()!==null){if(this.state.openInfoWindow!==null&&this.state.openInfoWindow.getMarker().packet.id!=marker.packet.id){this.state.openInfoWindow.hide();} if(this.state.openInfoWindow!==null&&this.state.openInfoWindow.getMarker().packet.id==marker.packet.id){this.state.openInfoWindow.setMarker(marker);}else{this.state.openInfoWindow=new trackdirect.models.InfoWindow(marker,this,disableAutoPan);} this._addInfoWindowListeners(this.state.openInfoWindow);this.state.openInfoWindow.show();}};trackdirect.models.Map.prototype.openLatestStationInfoWindow=function(stationId){var latestVisibleMarker=this.markerCollection.getStationLatestVisibleMarker(stationId);if(latestVisibleMarker!==null){this.openMarkerInfoWindow(latestVisibleMarker);}};trackdirect.models.Map.prototype.openPolylineInfoWindow=function(marker,position){if(this.state.openInfoWindow!==null){this.state.openInfoWindow.hide();} this.state.openInfoWindow=new trackdirect.models.InfoWindow(marker,this);this._addInfoWindowListeners(this.state.openInfoWindow);this.state.openInfoWindow.show(true,position);};trackdirect.models.Map.prototype._addInfoWindowListeners=function(infoWindow){var me=this;infoWindow.addTdListener("station-tail-needed",function(stationId){me._emitTdEventListeners("station-tail-needed",stationId);});};(trackdirect.models.Map.prototype.addTdListener=function(event,handler){if(!(event in this._tdEventListeners)){this._tdEventListeners[event]=[];} this._tdEventListeners[event].push(handler);}),(trackdirect.models.Map.prototype._emitTdEventListeners=function(event,arg){if(event in this._tdEventListeners){for(var i=0;i0){this.overlayMapTypes.clear();}}else if(typeof L==="object"){if(this._heatMap!==null){this.removeLayer(this._heatMap);}}});trackdirect.models.Map.prototype._activateHeatMap=function(){if(typeof google==="object"&&typeof google.maps==="object"){if(typeof this.overlayMapTypes!=="undefined"&&this.overlayMapTypes.length==0){this.overlayMapTypes.setAt(0,this._heatMap);}}else if(typeof L==="object"){if(this._heatMap!==null){this._heatMap.addTo(this);this._heatMap.bringToFront();this._heatMap.setZIndex(1000);}}};trackdirect.models.Map.prototype._updateGoogleMapTileLayer=function(){this.setMapTypeId(this._supportedMapTypes[this._mapType]);};trackdirect.models.Map.prototype._updateLeafletTileLayer=function(){if(typeof windyInit!=="function"){if(this._leafletTileLayer!==null){this._leafletTileLayer.remove();} if(typeof L.mapboxGL==="function"){var attribution="";var accessToken="no-token";var style="https://api.maptiler.com/maps/basic/style.json?optimize=true&key=MYwA9fnolsOrAYyiBx6J";if("mapboxGLStyle"in this._tdMapOptions){style=this._tdMapOptions["mapboxGLStyle"];} if("mapboxGLAccessToken"in this._tdMapOptions){accessToken=this._tdMapOptions["mapboxGLAccessToken"];} if("mapboxGLAttribution"in this._tdMapOptions){attribution=this._tdMapOptions["mapboxGLAttribution"];} this._leafletTileLayer=L.mapboxGL({accessToken:accessToken,style:style,});this.addLayer(this._leafletTileLayer);this.attributionControl.addAttribution(attribution);}else{var options={};if(isHighDensity()){options["ppi"]="320";options["size"]="512";}else if(trackdirect.isMobile){options["ppi"]="250";} this._leafletTileLayer=L.tileLayer.provider(this._supportedMapTypes[this._mapType],options);this.addLayer(this._leafletTileLayer);this._leafletTileLayer.bringToBack();}}};trackdirect.models.Map.prototype._updateMapContent=function(){if(this.getBounds()!=null){var previousVisibleMapSectors=[];for(var i=0;i=trackdirect.settings.minZoomForMarkerPrevPosition&&this._currentContentZoom=trackdirect.settings.minZoomForMarkerTail&&this._currentContentZoom=trackdirect.settings.minZoomForMarkerLabel&&this._currentContentZoom=trackdirect.settings.minZoomForMarkerPrevPosition;var hideMarkerTail=this.getZoom()=trackdirect.settings.minZoomForMarkerTail;var hideMarkerLabel=this.getZoom()=trackdirect.settings.minZoomForMarkerLabel;if(hidePrevPosition||hideMarkerTail||hideMarkerLabel){return true;} return false;};trackdirect.models.Map.prototype._showVisibleMarkerDetails=function(){for(var i=0;i=trackdirect.settings.minZoomForMarkers){if(this.state.isFilterMode){for(var markerIdKey in this.markerCollection.getAllMarkers()){if(this.markerCollection.isExistingMarker(markerIdKey)){var marker=this.markerCollection.getMarker(markerIdKey);if(marker.showAsMarker&&marker.packet.phg!=null&&marker.getMap()!==null&&marker.shouldMarkerBeVisible()){if(this.state.showPHGCircles==0){marker.hidePHGCircle();}else if(this.state.showPHGCircles==1){marker.showPHGCircle(true);}else if(this.state.showPHGCircles==2){marker.showPHGCircle(false);}}}}}else{for(var i=0;i=trackdirect.settings.minZoomForMarkers){if(this.state.isFilterMode){for(var markerIdKey in this.markerCollection.getAllMarkers()){if(this.markerCollection.isExistingMarker(markerIdKey)){var marker=this.markerCollection.getMarker(markerIdKey);if(marker.showAsMarker&&marker.packet.rng!=null&&marker.getMap()!==null&&marker.shouldMarkerBeVisible()){if(this.state.showRNGCircles==0){marker.hideRNGCircle();}else if(this.state.showRNGCircles==1){marker.showRNGCircle(true);}else if(this.state.showRNGCircles==2){marker.showRNGCircle(false);}}}}}else{for(var i=0;i1){for(var markerIdKey in this.markerCollection.getPositionMarkerIdKeys(latitude,longitude)){var marker=this.markerCollection.getMarker(markerIdKey);if(marker!==null&&marker.shouldMarkerBeVisible()){if(marker.getZIndex()>topMarkerZindex){topMarkerZindex=marker.getZIndex();topMarkerIdKey=markerIdKey;} marker.hideLabel();marker.hasLabel=false;}} if(topMarkerIdKey!=-1){var topMarker=this.markerCollection.getMarker(topMarkerIdKey);topMarker.hasLabel=true;var topMarkerMapSector=trackdirect.services.MapSectorCalculator.getMapSector(topMarker.getPositionLiteral().lat,topMarker.getPositionLiteral().lng);if(this.state.isFilterMode){topMarker.showLabel();}else if(this.isMapSectorVisible(topMarkerMapSector)&&this.getZoom()>=trackdirect.settings.minZoomForMarkerLabel){topMarker.showLabel();}}}};trackdirect.models.Map.prototype._hideMarkersInPreviousVisibleMapSectors=function(previousVisibleMapSectors){if(this._currentContentZoom>=trackdirect.settings.minZoomForMarkers){var markerIdKeyListToMaybeHide={};var markerIdKeyListNotToHide={};for(var i=0;i=trackdirect.settings.minZoomForMarkers){var mapSectorMarkerKeys=this.markerCollection.getMapSectorMarkerKeys(mapSector);for(var j=0;j=trackdirect.settings.minZoomForMarkers){for(var i=0;i=-90&&lng<=180&&lng>=-180){var content="";content+=this._getGpsDegreeFromGpsDecimal(lat.toFixed(5),"lat");content+=" "+this._getGpsDegreeFromGpsDecimal(lng.toFixed(5),"lon");content+="
"+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;} 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;}; 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;i0){if($(window).height()>=300){packetDiv.append(this._getPacketPathDiv());} var phgRange=this._marker.packet.getPHGRange();var rngRange=this._marker.packet.getRNGRange();if(phgRange!==null||rngRange!==null){packetDiv.append(this._getSpaceDiv());packetDiv.append(this._getPhgDiv(phgRange));packetDiv.append(this._getRngDiv(rngRange));} if($(window).height()>=300){var transmitDistance=this._getTransmitDistance(this._marker.packet);var tailDistance=this._getTailDistance(this._defaultMap.markerCollection.getMarkerMasterMarkerKeyId(this._marker.markerIdKey));if((transmitDistance!==null&&Math.round(transmitDistance/100)!=0)||(tailDistance!==null&&Math.round(tailDistance)>0)){packetDiv.append(this._getSpaceDiv());packetDiv.append(this._getTransmitDistanceDiv(transmitDistance));packetDiv.append(this._getTailDistanceDiv(tailDistance));}} if(this._marker.packet.speed!==null||this._marker.packet.course!==null||this._marker.packet.altitude!==null){packetDiv.append(this._getSpaceDiv());packetDiv.append(this._getPacketSpeedAltitudeCourseDiv());} if(typeof this._marker.packet.weather!=="undefined"&&this._marker.packet.weather!==null){packetDiv.append(this._getSpaceDiv());packetDiv.append(this._getWeatherDiv());} if(typeof this._marker.packet.latest_telemetry_packet_timestamp!=="undefined"&&this._marker.packet.latest_telemetry_packet_timestamp!==null){packetDiv.append(this._getSpaceDiv());packetDiv.append(this._getTelemetryDiv());} var commentDiv=this._getPacketCommentDiv();if(commentDiv!=null){packetDiv.append(this._getSpaceDiv());packetDiv.append(commentDiv);}} return packetDiv;};trackdirect.models.InfoWindow.prototype._getPacketTimeDiv=function(){if(this._marker.packet.timestamp==0){dateString='No known packet for specified limits.';}else{var date=new Date(this._marker.packet.timestamp*1000);var dateString=moment(date).format(trackdirect.settings.dateFormatNoTimeZone);if(this._marker.packet.timestamp>this._marker.packet.position_timestamp&&!trackdirect.isMobile){var positionDate=new Date(this._marker.packet.position_timestamp*1000);dateString=moment(positionDate).format(trackdirect.settings.dateFormatNoTimeZone)+ " - "+ moment(date).format(trackdirect.settings.dateFormatNoTimeZone);} if(this._defaultMap.state.endTimeTravelTimestamp!==null&&this._marker.packet.map_id==12){dateString+='
(exact time for this is not known)';}} var timeDiv=$(document.createElement("div"));timeDiv.css("clear","both");timeDiv.html(dateString);return timeDiv;};trackdirect.models.InfoWindow.prototype._getPacketPathDiv=function(){var rawPath=this._marker.packet.getLinkifiedRawPath();if(rawPath!==null){var rawPathDiv=$(document.createElement("div"));rawPathDiv.css("clear","both");rawPathDiv.html("["+rawPath+"]");return rawPathDiv;} return null;};trackdirect.models.InfoWindow.prototype._getSpaceDiv=function(){var spaceDiv=$(document.createElement("div"));spaceDiv.css("clear","both");spaceDiv.css("line-height","4px");spaceDiv.html(" ");return spaceDiv;};trackdirect.models.InfoWindow.prototype._getPhgDiv=function(phgRange){if(phgRange!==null){if(this._defaultMap.state.useImperialUnit){var phgRange=Math.round(trackdirect.services.imperialConverter.convertKilometerToMile(phgRange/1000)*10)/10;var phgRangeUnit="miles";}else{var phgRange=Math.round(phgRange/10)/100;var phgRangeUnit="km";} var phgDiv=$(document.createElement("div"));phgDiv.attr("id","phglinks-"+ this._marker.packet.station_id+ "-"+ this._marker.packet.id);var halfPhgLink=$("Half");var fullPhgLink=$("Full");var nonePhgLink=$("None");phgDiv.css("clear","both");phgDiv.css("display","none");phgDiv.css("color","#440B2A");phgDiv.append("PHG calculated range: "+phgRange+" "+phgRangeUnit);if(typeof L==="object"&&L.version<="0.7.7"){return phgDiv;} if(phgRange>0){phgDiv.append("
");phgDiv.append("PHG circle: ");phgDiv.append(fullPhgLink);phgDiv.append(' - ');phgDiv.append(halfPhgLink);phgDiv.append(' - ');phgDiv.append(nonePhgLink);} return phgDiv;} return null;};trackdirect.models.InfoWindow.prototype._getRngDiv=function(rngRange){if(rngRange!==null){if(this._defaultMap.state.useImperialUnit){var rngRange=Math.round(trackdirect.services.imperialConverter.convertKilometerToMile(rngRange/1000)*10)/10;var rngRangeUnit="miles";}else{var rngRange=Math.round(rngRange*100)/100;var rngRangeUnit="km";} var rngDiv=$(document.createElement("div"));rngDiv.attr("id","rnglinks-"+ this._marker.packet.station_id+ "-"+ this._marker.packet.id);var halfRngLink=$("Half");var fullRngLink=$("Full");var noneRngLink=$("None");rngDiv.css("clear","both");rngDiv.css("display","none");rngDiv.css("color","#440B2A");rngDiv.append("RNG precalculated range: "+rngRange+" "+rngRangeUnit);if(typeof L==="object"&&L.version<="0.7.7"){return rngDiv;} if(rngRange>0){rngDiv.append("
");rngDiv.append("RNG circle: ");rngDiv.append(fullRngLink);rngDiv.append(' - ');rngDiv.append(halfRngLink);rngDiv.append(' - ');rngDiv.append(noneRngLink);} return rngDiv;} return null;};trackdirect.models.InfoWindow.prototype._getTransmitDistanceDiv=function(transmitDistance){if(transmitDistance!==null&&Math.round(transmitDistance/100)!=0){var transmitDistanceDiv=$(document.createElement("div"));transmitDistanceDiv.css("clear","both");transmitDistanceDiv.css("color","#273c20");if(this._defaultMap.state.useImperialUnit){transmitDistance=Math.round(trackdirect.services.imperialConverter.convertKilometerToMile(transmitDistance/1000)*10)/10;transmitDistanceUnit="miles";}else{transmitDistance=Math.round(transmitDistance/100)/10;transmitDistanceUnit="km";} transmitDistanceDiv.append('Transmit distance: '+ transmitDistance+ " "+ transmitDistanceUnit+ "");return transmitDistanceDiv;} return null;};trackdirect.models.InfoWindow.prototype._getTailDistanceDiv=function(tailDistance){if(tailDistance!==null&&Math.round(tailDistance)>0){var distanceDiv=$(document.createElement("div"));distanceDiv.css("clear","both");distanceDiv.css("color","#273c20");if(tailDistance<1000){if(this._defaultMap.state.useImperialUnit){tailDistance=Math.round(trackdirect.services.imperialConverter.convertMeterToYard(tailDistance));tailDistanceUnit="yd";}else{tailDistance=Math.round(tailDistance);tailDistanceUnit="m";}}else{if(this._defaultMap.state.useImperialUnit){tailDistance=Math.round(trackdirect.services.imperialConverter.convertKilometerToMile(tailDistance/1000)*10)/10;tailDistanceUnit="miles";}else{tailDistance=Math.round(tailDistance/100)/10;tailDistanceUnit="km";}} distanceDiv.append('Current tail distance: '+ tailDistance+ " "+ tailDistanceUnit+ "");return distanceDiv;} return null;};trackdirect.models.InfoWindow.prototype._getPacketSpeedAltitudeCourseDiv=function(){if(Math.round(this._marker.packet.speed)!=0||Math.round(this._marker.packet.course)!=0||Math.round(this._marker.packet.altitude)!=0){var speedDiv=$(document.createElement("div"));speedDiv.css("clear","both");speedDiv.css("font-weight","bold");if(this._marker.packet.speed!==null){if(this._defaultMap.state.useImperialUnit){speedDiv.append(Math.round(trackdirect.services.imperialConverter.convertKilometerToMile(this._marker.packet.speed))+" mph ");}else{speedDiv.append(Math.round(this._marker.packet.speed)+" km/h ");}} if(this._marker.packet.course!==null){speedDiv.append(Math.round(this._marker.packet.course)+"° ");} if(this._marker.packet.course!==null){if(this._defaultMap.state.useImperialUnit){speedDiv.append(" alt "+ Math.round(trackdirect.services.imperialConverter.convertMeterToFeet(this._marker.packet.altitude))+ " ft ");}else{speedDiv.append(" alt "+Math.round(this._marker.packet.altitude)+" m ");}} return speedDiv;} return null;};trackdirect.models.InfoWindow.prototype._getWeatherDivRainString=function(){if(isNumeric(this._marker.packet.weather.rain_1h)){if(this._defaultMap.state.useImperialUnit){var rain1h="-";if(isNumeric(this._marker.packet.weather.rain_1h)){rain1h=Math.round(trackdirect.services.imperialConverter.convertMmToInch(this._marker.packet.weather.rain_1h))+"in";} var rain24h="-";if(isNumeric(this._marker.packet.weather.rain_24h)){rain24h=Math.round(trackdirect.services.imperialConverter.convertMmToInch(this._marker.packet.weather.rain_24h))+"in";} var rainSinceMidnight="-";if(isNumeric(this._marker.packet.weather.rain_since_midnight)){rainSinceMidnight=Math.round(trackdirect.services.imperialConverter.convertMmToInch(this._marker.packet.weather.rain_since_midnight))+"in";}}else{var rain1h="-";if(isNumeric(this._marker.packet.weather.rain_1h)){rain1h=Math.round(this._marker.packet.weather.rain_1h)+"mm";} var rain24h="-";if(isNumeric(this._marker.packet.weather.rain_24h)){rain24h=Math.round(this._marker.packet.weather.rain_24h)+"mm";} var rainSinceMidnight="-";if(isNumeric(this._marker.packet.weather.rain_since_midnight)){rainSinceMidnight=Math.round(this._marker.packet.weather.rain_since_midnight)+"mm";}} return("Rain "+ rain1h+ "/"+ rain24h+ "/"+ rainSinceMidnight+ " (1h/24h/midnight)
");} return null;};trackdirect.models.InfoWindow.prototype._getWeatherDivTemperatureString=function(){if(isNumeric(this._marker.packet.weather.temperature)){if(this._defaultMap.state.useImperialUnit){return("Temperature "+ Math.round(trackdirect.services.imperialConverter.convertCelciusToFahrenheit(this._marker.packet.weather.temperature))+ "°F"+ "
");}else{return("Temperature "+ Math.round(this._marker.packet.weather.temperature)+ "°C"+ "
");}} return null;};trackdirect.models.InfoWindow.prototype._getWeatherDivHumidityString=function(){if(isNumeric(this._marker.packet.weather.humidity)){return("Humidity "+ Math.round(this._marker.packet.weather.humidity)+ "%
");} return null;};trackdirect.models.InfoWindow.prototype._getWeatherDivPressureString=function(){if(isNumeric(this._marker.packet.weather.pressure)){if(this._defaultMap.state.useImperialUnit){return("Pressure "+ Math.round(trackdirect.services.imperialConverter.convertMbarToMmhg(this._marker.packet.weather.pressure))+ " mmHg
");}else{return("Pressure "+ Math.round(this._marker.packet.weather.pressure)+ " hPa
");}} return null;};trackdirect.models.InfoWindow.prototype._getWeatherDivWindString=function(){if(isNumeric(this._marker.packet.weather.wind_speed)){var windDir="";if(typeof this._marker.packet.weather.wind_direction!=="undefined"&&isNumeric(this._marker.packet.weather.wind_direction)){windDir=this._marker.packet.weather.wind_direction.toString()+"° ";} if(this._defaultMap.state.useImperialUnit){if(isNumeric(this._marker.packet.weather.wind_gust)){return("Wind "+ windDir+ Math.round(trackdirect.services.imperialConverter.convertMpsToMph(this._marker.packet.weather.wind_speed)*10)/ 10+ " mph"+ " ("+ Math.round(trackdirect.services.imperialConverter.convertMpsToMph(this._marker.packet.weather.wind_gust)*10)/ 10+ " mph)
");}else{return("Wind "+ windDir+ Math.round(trackdirect.services.imperialConverter.convertMpsToMph(this._marker.packet.weather.wind_speed)*10)/ 10+ " mph
");}}else{if(isNumeric(this._marker.packet.weather.wind_gust)){return("Wind "+ windDir+ Math.round(this._marker.packet.weather.wind_speed*10)/10+ " m/s"+ " ("+ Math.round(this._marker.packet.weather.wind_gust*10)/10+ " m/s)
");}else{return("Wind "+ windDir+ Math.round(this._marker.packet.weather.wind_speed*10)/10+ " m/s
");}}} return null;};trackdirect.models.InfoWindow.prototype._getWeatherDiv=function(){var weatherDiv=$(document.createElement("div"));weatherDiv.css("clear","both");weatherDiv.css("color","#227152");var weatherDate=new Date(this._marker.packet.timestamp*1000);if(typeof this._marker.packet.weather.timestamp!=="undefined"&&this._marker.packet.weather.timestamp!==null){weatherDate=new Date(this._marker.packet.weather.timestamp*1000);} weatherDateString=moment(weatherDate).format(trackdirect.settings.dateFormatNoTimeZone);weatherDiv.append("Latest Weather "+weatherDateString+"
");if(!trackdirect.isMobile&&$(window).height()>=300){weatherDiv.append(this._getWeatherDivTemperatureString());weatherDiv.append(this._getWeatherDivHumidityString());weatherDiv.append(this._getWeatherDivPressureString());weatherDiv.append(this._getWeatherDivRainString());weatherDiv.append(this._getWeatherDivWindString());} return weatherDiv;};trackdirect.models.InfoWindow.prototype._getTelemetryDiv=function(){var telemetryDiv=$(document.createElement("div"));telemetryDiv.css("clear","both");telemetryDiv.css("color","#823030");var telemetryDate=new Date(this._marker.packet.latest_telemetry_packet_timestamp*1000);telemetryDateString=moment(telemetryDate).format(trackdirect.settings.dateFormatNoTimeZone);telemetryDiv.append("Latest Telemetry "+telemetryDateString+"
");return telemetryDiv;};trackdirect.models.InfoWindow.prototype._getPacketCommentDiv=function(){var comment="";var ognSummary=escapeHtml(this._marker.packet.getOgnSummary());if(ognSummary!=""){comment=ognSummary;}else if(typeof this._marker.packet.comment!=="undefined"&&this._marker.packet.comment!==null){comment=Autolinker.link(escapeHtml(this._marker.packet.comment),{newWindow:true,});} if(comment==""){return null;} var commentDiv=$(document.createElement("div"));commentDiv.css("clear","both");commentDiv.css("font-weight","bold");if(!trackdirect.isMobile){commentDiv.css("font-size","11px");}else{commentDiv.css("font-size","10px");} commentDiv.html(comment);return commentDiv;};trackdirect.models.InfoWindow.prototype._addPhgLinkListeners=function(){var marker=this._marker;$("#half-phg-"+marker.packet.station_id+"-"+marker.packet.id).click(function(e){marker.showPHGCircle(true);return false;});$("#full-phg-"+marker.packet.station_id+"-"+marker.packet.id).click(function(e){marker.showPHGCircle(false);return false;});$("#none-phg-"+this._marker.packet.station_id+"-"+marker.packet.id).click(function(e){marker.hidePHGCircle();return false;});if($("#phglinks-"+marker.packet.station_id+"-"+marker.packet.id).length){$("#phglinks-"+marker.packet.station_id+"-"+marker.packet.id).show();}};trackdirect.models.InfoWindow.prototype._addRngLinkListeners=function(){var marker=this._marker;$("#half-rng-"+marker.packet.station_id+"-"+marker.packet.id).click(function(e){marker.showRNGCircle(true);return false;});$("#full-rng-"+marker.packet.station_id+"-"+marker.packet.id).click(function(e){marker.showRNGCircle(false);return false;});$("#none-rng-"+marker.packet.station_id+"-"+marker.packet.id).click(function(e){marker.hideRNGCircle();return false;});if($("#rnglinks-"+marker.packet.station_id+"-"+marker.packet.id).length){$("#rnglinks-"+marker.packet.station_id+"-"+marker.packet.id).show();}};trackdirect.models.InfoWindow.prototype._getMenuDiv=function(isInfoWindowOpen){var menuWrapperDiv=this._getMenuDivWrapperDiv();var menuDiv=this._getMenuDivMainDiv();menuWrapperDiv.append(menuDiv);var menuUl=this._getMenuDivUlDiv();menuDiv.append(menuUl);menuUl.append(this._getMenuDivTrackLink());menuUl.append(this._getMenuDivFilterLink());if(!trackdirect.isMobile){menuUl.append(this._getMenuDivCenterLink(isInfoWindowOpen));} menuUl.append(this._getMenuDivZoomLink(isInfoWindowOpen));if(!trackdirect.isEmbedded&&!inIframe()&&!this._marker.isMovingStation()&&this._marker.packet.source_id!=2){menuUl.append(this._getMenuDivCoverageLink());} return menuWrapperDiv;};trackdirect.models.InfoWindow.prototype._getMenuDivWrapperDiv=function(){var menuWrapperDiv=$(document.createElement("div"));menuWrapperDiv.addClass("infowindow-menu-wrapper");menuWrapperDiv.css("clear","both");menuWrapperDiv.css("width","100%");menuWrapperDiv.css("padding-top","8px");return menuWrapperDiv;};trackdirect.models.InfoWindow.prototype._getMenuDivMainDiv=function(){var menuDiv=$(document.createElement("div"));menuDiv.addClass("infowindow-menu");menuDiv.css("width","100%");menuDiv.css("border-top","1px solid #cecece");return menuDiv;};trackdirect.models.InfoWindow.prototype._getMenuDivUlDiv=function(){var menuUl=$(document.createElement("ul"));menuUl.css("list-style-type","none");menuUl.css("list-style","none");menuUl.css("text-align","center");menuUl.css("margin","0");menuUl.css("padding","0");menuUl.css("display","table");return menuUl;};trackdirect.models.InfoWindow.prototype._getMenuDivLinkCss=function(){var liLinkCss={"list-style":"none",display:"table-cell","text-align":"center","padding-right":"10px",width:"auto",};return liLinkCss;};trackdirect.models.InfoWindow.prototype._getMenuDivTrackLink=function(){var trackLinkElementClass="trackStationLink"+this._marker.packet.station_id;var menuLi=$(document.createElement("li"));menuLi.css(this._getMenuDivLinkCss());var menuLink=$(document.createElement("a"));menuLink.css("color","#337ab7");menuLink.attr("href","#");menuLink.addClass(trackLinkElementClass);menuLink.attr("onclick","trackdirect.handleTrackStationRequest("+ this._marker.packet.station_id+ ', "'+ trackLinkElementClass+ '"); return false;');if(this._defaultMap.state.getTrackStationId()!==null&&this._defaultMap.state.getTrackStationId()==this._marker.packet.station_id){menuLink.html("Untrack");}else{menuLink.html("Track");} menuLi.append(menuLink);return menuLi;};trackdirect.models.InfoWindow.prototype._getMenuDivFilterLink=function(){var filterLinkElementClass="filterStationLink"+this._marker.packet.station_id;var menuLi=$(document.createElement("li"));menuLi.css(this._getMenuDivLinkCss());var menuLink=$(document.createElement("a"));menuLink.css("color","#337ab7");menuLink.addClass(filterLinkElementClass);menuLink.attr("onclick","trackdirect.handleFilterStationRequest("+ this._marker.packet.station_id+ ', "'+ filterLinkElementClass+ '"); return false;');if(this._defaultMap.state.filterStationIds.length>0&&this._defaultMap.state.filterStationIds.indexOf(this._marker.packet.station_id)>-1){menuLink.html("Unfilter");var center=this._defaultMap.getCenterLiteral();menuLink.attr("href","/center/"+ Number.parseFloat(center.lat).toFixed(5)+ ","+ Number.parseFloat(center.lng).toFixed(5)+ "/zoom/"+ this._defaultMap.getZoom());}else{menuLink.html("Filter");menuLink.attr("href","/sid/"+this._marker.packet.station_id);} menuLi.append(menuLink);return menuLi;};trackdirect.models.InfoWindow.prototype._getMenuDivCoverageLink=function(){var coverageLinkElementClass="stationCoverageLink"+this._marker.packet.station_id;var menuLi=$(document.createElement("li"));menuLi.css(this._getMenuDivLinkCss());var menuLink=$(document.createElement("a"));menuLink.css("color","#337ab7");menuLink.css("white-space","nowrap");menuLink.attr("href","#");menuLink.addClass(coverageLinkElementClass);menuLink.attr("onclick","trackdirect.toggleStationCoverage("+ this._marker.packet.station_id+ ', "'+ coverageLinkElementClass+ '"); return false;');var coveragePolygon=this._defaultMap.markerCollection.getStationCoverage(this._marker.packet.station_id);if(coveragePolygon!==null&&coveragePolygon.isRequestedToBeVisible()){menuLink.html("Hide Coverage");}else{menuLink.html("Coverage");} menuLi.append(menuLink);return menuLi;};trackdirect.models.InfoWindow.prototype._getMenuDivCenterLink=function(isInfoWindowOpen){var menuLi=$(document.createElement("li"));menuLi.css(this._getMenuDivLinkCss());var menuLink=$(document.createElement("a"));menuLink.css("color","#337ab7");if(isInfoWindowOpen){menuLink.attr("href","/center/"+ this._marker.packet.latitude.toFixed(5)+ ","+ this._marker.packet.longitude.toFixed(5)+ "/zoom/"+ this._defaultMap.getZoom());menuLink.attr("onclick","trackdirect.setCenter("+ this._marker.packet.latitude+ ","+ this._marker.packet.longitude+ "); return false;");menuLink.html("Center");}else{menuLink.attr("href","/center/"+ this._marker.packet.latitude.toFixed(5)+ ","+ this._marker.packet.longitude.toFixed(5)+ "/zoom/"+ this._defaultMap.getZoom());menuLink.attr("onclick","trackdirect.focusOnMarkerId("+ this._marker.packet.marker_id+ "); return false;");menuLink.html("Focus");} menuLi.append(menuLink);return menuLi;};trackdirect.models.InfoWindow.prototype._getMenuDivZoomLink=function(isInfoWindowOpen){var menuLi=$(document.createElement("li"));menuLi.css(this._getMenuDivLinkCss());var menuLink=$(document.createElement("a"));menuLink.css("color","#337ab7");if(isInfoWindowOpen){menuLink.attr("href","/center/"+ this._marker.packet.latitude.toFixed(5)+ ","+ this._marker.packet.longitude.toFixed(5)+ "/zoom/14");menuLink.attr("onclick","trackdirect.setCenter("+ this._marker.packet.latitude+ ","+ this._marker.packet.longitude+ ", 14); return false;");menuLink.html("Zoom");}else{menuLink.attr("href","/center/"+ this._marker.packet.latitude.toFixed(5)+ ","+ this._marker.packet.longitude.toFixed(5)+ "/zoom/14");menuLink.attr("onclick","trackdirect.focusOnMarkerId("+ this._marker.packet.marker_id+ ", 14); return false;");menuLink.html("Zoom");} menuLi.append(menuLink);return menuLi;};trackdirect.models.InfoWindow.prototype._getCompactMainDiv=function(){var packet=this._marker.packet;var mainDiv=$(document.createElement("div"));mainDiv.css("font-family","Verdana,Arial,sans-serif");if(!trackdirect.isMobile){mainDiv.css("font-size","11px");}else{mainDiv.css("font-size","10px");} mainDiv.css("line-height","1.42857143");mainDiv.css("color","#333");mainDiv.css("text-align","left");var polylineDiv=$(document.createElement("div"));polylineDiv.css("float","left");var nameDiv=$(document.createElement("div"));nameDiv.css("clear","both");nameDiv.css("font-size","12px");nameDiv.css("font-weight","bold");var iconUrl24=trackdirect.services.symbolPathFinder.getFilePath(packet.symbol_table,packet.symbol,null,null,null,24,24);var iconImg=$(document.createElement("img"));iconImg.css("vertical-align","middle");iconImg.css("width","24px");iconImg.css("height","24px");iconImg.attr("src",iconUrl24);iconImg.attr("alt","");iconImg.attr("title","");nameDiv.append(iconImg);nameDiv.append(" ");nameDiv.append(" ");var nameLink=$(document.createElement("a"));nameLink.css("color","#337ab7");if(trackdirect.isMobile){nameLink.css("vertical-align","-2px");} nameLink.attr("href","");nameLink.attr("onclick","trackdirect.openStationInformationDialog("+ packet.station_id+ "); return false;");nameLink.html(escapeHtml(packet.station_name));nameDiv.append(nameLink);if(packet.sender_name!=packet.station_name){nameDiv.append(" (");var nameLink2=$(document.createElement("span"));if(trackdirect.isMobile){nameLink2.css("vertical-align","-2px");} nameLink2.html(escapeHtml(packet.sender_name));nameDiv.append(nameLink2);nameDiv.append(")");} polylineDiv.append(nameDiv);var tailDistance=this._getTailDistance(this._defaultMap.markerCollection.getMarkerMasterMarkerKeyId(this._marker.markerIdKey));if(tailDistance!==null&&Math.round(tailDistance)>0){var distanceDiv=$(document.createElement("div"));distanceDiv.css("clear","both");distanceDiv.css("padding-top","4px");distanceDiv.append("Tail distance: ");if(tailDistance<1000){if(this._defaultMap.state.useImperialUnit){distanceDiv.append(Math.round(trackdirect.services.imperialConverter.convertMeterToYard(tailDistance))+" yd ");}else{distanceDiv.append(Math.round(tailDistance)+" m ");}}else{if(this._defaultMap.state.useImperialUnit){distanceDiv.append(Math.round(trackdirect.services.imperialConverter.convertKilometerToMile(tailDistance/1000)*10)/ 10+ " miles ");}else{distanceDiv.append(Math.round(tailDistance/100)/10+" km ");}} polylineDiv.append(distanceDiv);} mainDiv.append(polylineDiv);return mainDiv;};trackdirect.models.InfoWindow.prototype._getTailDistance=function(markerIdKey){if(this._defaultMap.markerCollection.isExistingMarker(markerIdKey)){var marker=this._defaultMap.markerCollection.getMarker(markerIdKey);if(marker.packet.hasConfirmedMapId()&&marker.packet.is_moving==1&&marker.overwrite!==true){var distance=0;if(this._defaultMap.markerCollection.hasDotMarkers(markerIdKey)){var prevLatLng=null;var dotMarkers=this._defaultMap.markerCollection.getDotMarkers(markerIdKey);for(var i=0;i=1){var relatedStationLatLng={lat:parseFloat(packet.station_location_path[0][0]),lng:parseFloat(packet.station_location_path[0][1]),};var distance=trackdirect.services.distanceCalculator.getDistance(packet.getLatLngLiteral(),relatedStationLatLng);if(distance!==null){return distance;}} if(typeof packet.station_id_path!=="undefined"&&packet.station_id_path!==null&&packet.station_id_path.length>=1){for(var i=0;itrackdirect.settings.minZoomForMarkers-1){return trackdirect.settings.baseUrl+"/heatmaps/transparent.png";} var normalizedCoord=me._getNormalizedCoord(coord,zoom);if(!normalizedCoord){return trackdirect.settings.baseUrl+"/heatmaps/transparent.png";} var xString=String(normalizedCoord.x);var yString=String(normalizedCoord.y);return me._getUrlTemplate().replace("{z}",zoom).replace("{y}",yString).replace("{x}",xString);},tileSize:new google.maps.Size(256,256),maxZoom:trackdirect.settings.minZoomForMarkers-1,minZoom:0,radius:1738000,name:"APRSHEAT",};return options;};trackdirect.models.HeatMap.prototype._getUrlTemplate=function(){return(trackdirect.settings.baseUrl+ "/heatmaps/latest-heatmap.{z}.{y}.{x}.png?version="+ this._getHeatMapVersion());};trackdirect.models.HeatMap.prototype._getHeatMapVersion=function(){var today=new Date();var dd=today.getDate();var mm=today.getMonth()+1;var yyyy=today.getFullYear();var hh=today.getHours();if(dd<10){dd="0"+dd;} if(mm<10){mm="0"+mm;} return yyyy+"-"+mm+"-"+dd+"-"+hh;};trackdirect.models.HeatMap.prototype._getNormalizedCoord=function(coord,zoom){var y=coord.y;var x=coord.x;var tileRange=1<=tileRange){return null;} if(x<0||x>=tileRange){x=((x%tileRange)+tileRange)%tileRange;} return{x:x,y:y};}; trackdirect.models.DirectionPolyline=function(marker,map){this._marker=marker;this._defaultMap=map;this.startTimestamp=this._marker.packet.timestamp;this.speed=this._marker.packet.speed;this.course=this._marker.packet.course;this.stopped=false;this.timerId=null;if(typeof google==="object"&&typeof google.maps==="object"){google.maps.Polyline.call(this,this._getGooglePolylineOptions());}else if(typeof L==="object"){L.Polyline.call(this,{},this._getLeafletPolylineOptions());this.setLatLngs([this._getFirstCoordinate(),this._getExpectedCoordinate(),]);}};if(typeof google==="object"&&typeof google.maps==="object"){trackdirect.models.DirectionPolyline.prototype=Object.create(google.maps.Polyline.prototype);}else if(typeof L==="object"){trackdirect.models.DirectionPolyline.prototype=Object.create(L.Polyline.prototype);} trackdirect.models.DirectionPolyline.prototype.constructor=trackdirect.models.DirectionPolyline;trackdirect.models.DirectionPolyline.prototype.setPathItems=function(pathItems){if(typeof google==="object"&&typeof google.maps==="object"){this.setPath(pathItems);}else if(typeof L==="object"){this.setLatLngs(pathItems);}};trackdirect.models.DirectionPolyline.prototype.getMap=function(){if(typeof google==="object"&&typeof google.maps==="object"){var map=google.maps.Polyline.prototype.getMap.call(this);if(typeof map!=="undefined"){return map;}}else if(typeof L==="object"){if(this._defaultMap.hasLayer(this)){return this._defaultMap;}} return null;};trackdirect.models.DirectionPolyline.prototype.show=function(){var timeInSeconds=this._getAgeInSeconds();if(this.stopped===false&&timeInSeconds<=900&&this._marker.packet.hasConfirmedMapId()&&(this._defaultMap.state.isFilterMode||this._defaultMap.getZoom()>=trackdirect.settings.minZoomForMarkerTail)){if(typeof google==="object"&&typeof google.maps==="object"){if(typeof this.getMap()==="undefined"||this.getMap()===null){this.setMap(this._defaultMap);}}else if(typeof L==="object"){if(!this._defaultMap.hasLayer(this)){this.addTo(this._defaultMap);}} this.recalculate();}};trackdirect.models.DirectionPolyline.prototype.hide=function(){if(typeof google==="object"&&typeof google.maps==="object"){if(this.getMap()!==null){this.setMap(null);}}else if(typeof L==="object"){if(this._defaultMap.hasLayer(this)){this._defaultMap.removeLayer(this);}}};trackdirect.models.DirectionPolyline.prototype.stop=function(){this.stopped=true;this.hide();};trackdirect.models.DirectionPolyline.prototype._getGooglePolylineOptions=function(){var lineCoordinates=[this._getFirstCoordinate(),this._getExpectedCoordinate(),];var lineSymbol={path:google.maps.SymbolPath.FORWARD_OPEN_ARROW,strokeOpacity:1,scale:0.65,};var options={path:lineCoordinates,strokeOpacity:0,strokeColor:trackdirect.services.stationColorCalculator.getColor(this._marker.packet),map:null,icons:[{icon:lineSymbol,offset:"0px",repeat:"8px",},],};return options;};trackdirect.models.DirectionPolyline.prototype._getLeafletPolylineOptions=function(){return{color:trackdirect.services.stationColorCalculator.getColor(this._marker.packet),weight:4,opacity:0.7,dashArray:"2,8",lineJoin:"round",};};trackdirect.models.DirectionPolyline.prototype._getFirstCoordinate=function(){return this._marker.packet.getLatLngLiteral();};trackdirect.models.DirectionPolyline.prototype._getExpectedCoordinate=function(){var timeInSeconds=this._getAgeInSeconds();var distance=(this.speed/3.6)*timeInSeconds;var startPosition=this._getFirstCoordinate();if(startPosition!=null){return trackdirect.services.distanceCalculator.getPositionByDistance(startPosition,this.course,distance);} return null;};trackdirect.models.DirectionPolyline.prototype.recalculate=function(){var interval=1000;var me=this;this.timerId=window.setInterval(function(){if(!me._marker.isVisible()||me.stopped||!me._marker.showAsMarker){me.hide();clearInterval(me.timerId);return;} var timeInSeconds=me._getAgeInSeconds();if(timeInSeconds>900){me.stop();if(me.timerId!==null){clearInterval(me.timerId);}}else{var firstPosition=me._getFirstCoordinate();var newPosition=me._getExpectedCoordinate();if(firstPosition!=null&&newPosition!=null){me.setPathItems([firstPosition,newPosition]);}}},interval);};trackdirect.models.DirectionPolyline.prototype._getAgeInSeconds=function(){var timeInSeconds=0;var startTimestamp=this._defaultMap.state.getClientTimestamp(this.startTimestamp);if(startTimestamp