function initRightCallout(n){n.getPopup()._updatePosition=function(){var r,u;if(this._map){var t=this._map.latLngToLayerPoint(this._latlng),n=L.point(this.options.offset),i=this._getAnchor();this._zoomAnimated?L.DomUtil.setPosition(this._container,t.add([i.x,0])):n=n.add(t).add([i.x,0]);r=this._containerBottom=0-this._container.offsetHeight/2;u=this._containerLeft=n.x;this._container.classList.add("leaflet-popup-right");this._container.style.bottom=r+"px";this._container.style.left=u+"px"}}}function getRtcmId(n){return n.pad(4)}function getSiteStatusClass(n,t){switch(n){case 0:return"siteStatusUnavailable";case 3:return window.canViewFixingstatus=="True"&&t==3?"siteWithNetworkStatus":"siteStatusOnline";default:return"siteStatusOffline"}}function getDbSiteUniqueId(n){return n.NetworkServerHostName.toLowerCase()+n.SiteServerId+""+n.SiteId}function getRtdmSiteUniqueId(n){return n.networkServerHostName.toLowerCase()+n.siteServerId+""+n.siteId}function updateSiteMarkerIcon(n,t){n._icon&&(n.CurrentStatusClass&&L.DomUtil.removeClass(n._icon,n.CurrentStatusClass),n.CurrentStatusClass=getSiteStatusClass(n.site.Status,n.site.FixingStatus),L.DomUtil.addClass(n._icon,n.CurrentStatusClass),n.site.HideFromUserInterface&&t!=!0?L.DomUtil.addClass(n._icon,"hidden"):L.DomUtil.removeClass(n._icon,"hidden"))}function createSiteMarkers(n,t){for(var f,r,u=[],e={className:"siteMarkerPopup",maxWidth:"auto",autoPan:!1},i=0;i<n.length;i++){f=projectLatLng(L.latLng(radToDeg(n[i].Latitude),radToDeg(n[i].Longitude)));r=new L.MultiPopupMarker(f,{icon:siteMapIcon});r.site=n[i];r.bindSiteTooltip(n[i].SiteCode,{direction:"right"});siteMarkerCalloutTemplate&&t!==!1&&(r.bindPopup(siteMarkerCalloutTemplate(n[i]),e),initRightCallout(r));r.on("add",function(){updateSiteMarkerIcon(this)});u.push(r)}return u}function updateSiteMarker(n){var t=n.site,i=[radToDeg(t.Latitude),radToDeg(t.Longitude)];n.getTooltip().setTooltipContent(t.SiteCode);n.setLatLng(i);updateSiteMarkerIcon(n)}function updateSiteData(n,t){for(var i in t)n[i]=t[i]}function initCalloutTabs(n){n._contentNode?($(".calloutdata",n._contentNode).each(function(){var t=$(this);t.data("ui-tabs")||t.tabs({activate:function(){n._updatePosition()}})}),$(".zoomToSite",n._contentNode).each(function(){var t=$(this);t.data("zoomSite")||(t.data("zoomSite",n.marker),t.click(function(){var n=$(this).data("zoomSite");n.closePopup();n._map.setZoomAround(n.getLatLng(),n._map.getMaxZoom());n.openPopup()}))})):$(".calloutdata",n).each(function(){var n=$(this);n.data("ui-tabs")||n.tabs({activate:function(){}})})}function setupLeafletForSiteMarkers(n){n.on("popupopen",function(t){var r,i;t.popup.marker&&(r=t.popup._map,t.popup.marker.closeTooltip(),initCalloutTabs(t.popup),i=t.popup.marker.getLatLng(),i=r.latLngToLayerPoint(i),i.x+=t.popup._containerLeft+t.popup.marker._icon.offsetWidth+t.popup._containerWidth/2,i=r.layerPointToLatLng(i),n.panTo(i),t.popup._updateLayout(),t.popup._updatePosition())})}(function(){var n=L.Popup.prototype.getEvents,t=L.Popup.prototype.onAdd,i=L.Popup.prototype.onRemove;L.Popup.addInitHook(function(){this.options.closeOnClick=!1});L.Popup.include({getEvents:function(){var t=n.call(this);return t.preclick=this._autoClose,t},_autoClose:function(){this._map._multiPopup||this._close()},onAdd:function(n){t.call(this,n);n._openedPopups||(n._openedPopups=[]);n._openedPopups.push(this)},onRemove:function(n){i.call(this,n);n._openedPopups||(n._openedPopups=[]);var t=n._openedPopups.indexOf(this);t!==-1&&n._openedPopups.splice(t,1)}})})();L.MultiPopupMarker=L.Marker.extend({openPopup:function(){var i=this._latlng,n=this._map,t=this._popup,r=n._popup,u;if(t&&this._map&&!n.hasLayer(t)&&!(i.lat==0&&i.lng==0)){if(t.marker=this,t.setLatLng(this._latlng),r&&r.options.autoClose&&!n._multiPopup)while(n._openedPopups.length>0)u=n._openedPopups[0],n.removeLayer(u);return n._popup=t,n._multiPopup=!1,n.addLayer(t)}return this},onAdd:function(n){this._map=n;n.on("viewreset",this.update,this);n.on("mousedown",function(n){this._multiPopup=n.originalEvent.shiftKey||n.originalEvent.ctrlKey});if(this._initIcon(),this.update(),this.fire("add"),n.options.zoomAnimation&&n.options.markerZoomAnimation)n.on("zoomanim",this._animateZoom,this)}});Handlebars.registerHelper("GetSiteCondition",function(n,t){switch(n){case 0:return"siteStatusUnavailable";case 3:return window.canViewFixingstatus=="True"&&t==3?"siteWithNetworkStatus":"siteStatusOnline";default:return"siteStatusOffline"}});Handlebars.registerHelper("GetSiteTextColor",function(n){switch(n){case 3:return"siteStatusTextOnline";default:return"siteStatusTextOffline"}});Handlebars.registerHelper("GetSiteStatus",function(n){switch(n){case 3:return window.Localisation_Site_Connected;default:return window.Localisation_Site_Disconnected}});Handlebars.registerHelper("GetSiteStatusMessage",function(n){switch(n){case 0:return window.Localisation_Site_NotAvailable;case 3:return window.Localisation_Site_Connected;default:return window.Localisation_Site_Disconnected_Message}});Handlebars.registerHelper("GetRtcmId",getRtcmId);Handlebars.registerHelper("GetNetworkFixingStatus",function(n,t){switch(n){case 3:switch(t){case 0:return window.Localisation_NetworkProcessingStatus_Invalid;case 1:return window.Localisation_NetworkProcessingStatus_NotFixed;case 2:return window.Localisation_NetworkProcessingStatus_Initialising;case 3:return window.Localisation_NetworkProcessingStatus_Fixed;default:return window.Localisation_NetworkProcessingStatus_Invalid}default:return window.Localisation_NetworkProcessingStatus_Invalid}});Handlebars.registerHelper("GetNPSTextColor",function(n,t){switch(n){case 3:switch(t){case 0:return"FixingStatusTextInvalid";case 1:return"FixingStatusTextNotFixed";case 2:return"FixingStatusTextInitialising";case 3:return"FixingStatusTextFixed";default:return"FixingStatusTextInvalid"}default:return"FixingStatusTextInvalid"}});var siteMarkerCalloutTemplate=null;$(function(){var n=$("#siteMarkerCalloutTemplate").html();n&&(siteMarkerCalloutTemplate=Handlebars.compile(n))});$(document).ready(function(){for(var e,n=loadMapOriginFromStorage("SiteStatus.mapOriginLastUserSelection"),r=initLeaflet("siteMap",{center:L.latLng(n.lat,n.lon),zoom:n.zoom}),u=L.layerGroup(),f=[],i=createSiteMarkers(window.Sites),t=0;t<i.length;t++)f.push(i[t].getLatLng()),u.addLayer(i[t]);r.addLayer(u);e=L.latLngBounds(f);window.Sites.length>0&&!n.ignoreAutoZoom&&setTimeout(function(){r.fitBounds(e,{padding:[5,5],animate:!0})},100)})