var TF_Bing_Map=function(){function t(t){if(t){if(this.ref=t,this.wrapper=null,this.map_element=null,this.map=null,this.options={},this.defaults={lat:0,long:0,zoom:5,view:"Road",scale:!1,enable_info_window:!1,markers:[],markerImage:""},this.ref instanceof HTMLElement)this.initWithDataAttributes();else{if(!(this.ref instanceof Object))return;this.initWithOptions(this.ref)}this.pinInfobox=null,this.pushpinLocations=[],this.defaultZoom=parseInt(this.options.zoom)||15}}var i=t.prototype;return i.initWithDataAttributes=function(){this.wrapper=this.ref,this.map_element=this.wrapper.querySelector(".map-item"),this.initWithOptions(JSON.parse(this.wrapper.dataset.options))},i.initWithOptions=function(t){void 0===t&&(t={}),this.options=Object.assign({},this.defaults,t);t=this.options.value.split(",");this.options.lat=parseFloat(t[0])||this.options.lat,this.options.long=parseFloat(t[1])||this.options.long,this.wrapper||(this.wrapper=document.querySelector(".nrf-widget.bingmap#"+this.options.id)),this.map_element||(this.map_element=this.wrapper.querySelector(".map-item"))},i.render=function(){this.map=new Microsoft.Maps.Map(this.map_element,{center:new Microsoft.Maps.Location(this.options.lat,this.options.long),zoom:this.defaultZoom,showScalebar:this.options.scale,showMapTypeSelector:this.options.pro,showLocateMeButton:this.options.pro,mapTypeId:this.getMapTypeID()}),this.wrapper.BingMap=this;var t=new CustomEvent("onTFMapWidgetRender",{detail:{map:this.wrapper,service:"bingmap"}});document.dispatchEvent(t)},i.getMapTypeID=function(){var t=Microsoft.Maps.MapTypeId.road;switch(this.options.view){case"road":t=Microsoft.Maps.MapTypeId.road;break;case"aerial":t=Microsoft.Maps.MapTypeId.aerial;break;case"birdseye":t=Microsoft.Maps.MapTypeId.birdseye;break;case"grayscale":t=Microsoft.Maps.MapTypeId.grayscale;break;case"ordnanceSurvey":t=Microsoft.Maps.MapTypeId.ordnanceSurvey;break;case"canvasDark":t=Microsoft.Maps.MapTypeId.canvasDark;break;case"canvasLight":t=Microsoft.Maps.MapTypeId.canvasLight}return t},i.renderMarkers=function(){var o,s,t,n=this;0!==this.options.markers.length&&(t=new Microsoft.Maps.EntityCollection,o=new Microsoft.Maps.EntityCollection,this.pinInfobox=new Microsoft.Maps.Infobox(new Microsoft.Maps.Location(0,0),{visible:!1}),t.push(this.pinInfobox),s=[],this.options.markers.map(function(t,i){var e={lat:t.latitude,lng:t.longitude},e=(s[i]=new Microsoft.Maps.Location(e.lat,e.lng),new Microsoft.Maps.Pushpin(s[i],{icon:n.options.markerImage}));n.options.enable_info_window&&(t.label&&""!==t.label||t.description&&""!==t.description||t.address&&""!==t.address)&&(e.Title=t.label&&""!==t.label?t.label:t.address&&""!==t.address?t.address:"",""!==(t=t.description&&""!==t.description?t.description:"")&&(e.Description=t),Microsoft.Maps.Events.addHandler(e,"click",n.displayInfobox.bind(n))),n.pushpinLocations.push(s[i]),o.push(e)}),this.map.entities.push(o),this.map.entities.push(t),t=Microsoft.Maps.LocationRect.fromLocations(s),this.map.setView({center:t.center,zoom:this.defaultZoom}))},i.displayInfobox=function(t){""===t.target.Title&&""===t.target.Description||(this.pinInfobox.setOptions({title:t.target.Title,description:t.target.Description,visible:!0,offset:new Microsoft.Maps.Point(0,25)}),this.pinInfobox.setLocation(t.target.getLocation()))},i.centerMap=function(){var t,i,e;0!==this.options.markers.length&&("fitbounds"===this.options.zoom_level?(t=Microsoft.Maps.LocationRect.fromLocations(this.pushpinLocations),this.map.setView({bounds:t,padding:20})):(t=this.options.markers[0].latitude,i=this.options.markers[0].longitude,null!==this.options.map_center&&2===(e=this.options.map_center.split(",")).length&&(t=e[0],i=e[1]),e=new Microsoft.Maps.Location(t,i),this.map.setView({center:e,zoom:this.defaultZoom})))},i.getMap=function(){return this.map},t}(),TF_Bing_Maps=function(){function t(){this.init()}return t.prototype.init=function(){var t,o,i;window.IntersectionObserver&&0!==(t=document.querySelectorAll(".nrf-widget.bingmap:not(.no-map):not(.done)")).length&&(o=1,i=new IntersectionObserver(function(t,e){t.forEach(function(t){var i;t.isIntersecting&&(t.target.id=t.target.id+"-"+o,t.target.classList.add("done"),(i=t.target.hasAttribute("data-options")?JSON.parse(t.target.dataset.options):t.target).id=t.target.id,(i=new TF_Bing_Map(i)).render(),i.renderMarkers(),i.centerMap(),e.unobserve(t.target),o++)})},{rootMargin:"0px 0px 0px 0px"}),t.forEach(function(t){i.observe(t)}))},t}();window.TFBingMapsCallback=function(){new TF_Bing_Maps};

