var NR_OSM_Map=function(){function t(t){if(t){if(this.ref=t,this.wrapper=null,this.map_element=null,this.map=null,this.options={},this.markers_draggable=!1,this.markersObjects=[],this.defaults={lat:0,long:0,zoom:5,view:"road",scale:!1,enable_info_window:!1,markers:[],map_center:null,markerImage:""},this.ref instanceof HTMLElement)this.initWithDataAttributes();else{if(!(this.ref instanceof Object))return;this.initWithOptions(this.ref)}this.defaultZoom=parseInt(this.options.zoom)||15,this.used_marker_ids=[],this.scale=this.options.scale||null,this.scaleControl=null}}var e=t.prototype;return e.initWithDataAttributes=function(){this.wrapper=this.ref,this.map_element=this.wrapper.querySelector(".map-item"),this.initWithOptions(JSON.parse(this.wrapper.dataset.options))},e.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.openstreetmap#"+this.options.id)),this.map_element||(this.map_element=this.wrapper.querySelector(".map-item"))},e.render=function(){var e=this,t=(this.map=L.map(this.map_element,{gestureHandling:!0,gestureHandlingOptions:{text:{touch:"Use two fingers to move the map",scroll:"Use ctrl + scroll to zoom the map",scrollMac:"Use ⌘ + scroll to zoom the map"}},contextmenu:!0,contextmenuWidth:140,contextmenuItems:[{text:window.parent.Joomla?window.parent.Joomla.Text._("NR_ADD_MARKER"):"",callback:function(t){t=new CustomEvent("onTFMapContextMenuAddMarker",{detail:{map:e.wrapper,service:"openstreetmap",e:t}});document.dispatchEvent(t)}}]}),this.map.contextmenu&&this.map.contextmenu.disable(),("satellite"===this.options.view?L.esri.Vector.vectorBasemapLayer("ArcGIS:Imagery",{apiKey:this.options.provider_key}):L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",{attribution:'© OpenStreetMap',subdomains:["a","b","c"]})).addTo(this.map),this.map.setView([this.options.lat,this.options.long],this.defaultZoom),this.setScale(this.options.scale),this.wrapper.OpenStreetMap=this,new CustomEvent("onTFMapWidgetRender",{detail:{map:this.wrapper,service:"openstreetmap"}}));document.dispatchEvent(t)},e.setScale=function(t){var e;this.scaleControl&&(this.map.removeControl(this.scaleControl),this.scaleControl=null),t&&(e={},"imperial"===t?(e.imperial=!0,e.metric=!1):(e.imperial=!1,e.metric=!0),this.scaleControl=L.control.scale(e).addTo(this.map))},e.getMarkerContent=function(t){var e,i=document.createElement("div"),r=(i.classList.add("nr-map-map-marker-container"),document.createElement("div"));return r.classList.add("nr-map-map-marker-label"),r.innerHTML=t.label&&""!==t.label?t.label:t.address&&""!==t.address?t.address:"",i.appendChild(r),t.description&&""!==t.description&&((r=document.createElement("div")).classList.add("nr-map-map-marker-content"),(e=document.createElement("p")).innerHTML=t.description.replace(/\n/g,"
"),r.appendChild(e),i.appendChild(r)),i},e.createMarker=function(e,i){var r,s,t,n=this;e.id||(e.id=(new Date).getTime()),this.used_marker_ids.includes(e.id)||(r={id:e.id,draggable:this.markers_draggable},""!==this.options.markerImage?((s=new Image).src=this.options.markerImage,s.onload=function(){var t=new window.L.DivIcon({html:'
',iconAnchor:[12,s.height],popupAnchor:[10,-s.height]}),t=(r.icon=t,n.afterMarkerCreate(e,r));i(t)}):(t=this.afterMarkerCreate(e,r),i(t)))},e.afterMarkerCreate=function(t,e){t.id||(t.id=(new Date).getTime());var i=window.L.marker([t.latitude,t.longitude],e),r=(this.options.enable_info_window&&(t.label&&""!==t.label||t.description&&""!==t.description||t.address&&""!==t.address)&&i.bindPopup(this.getMarkerContent(t)),new CustomEvent("onTFMapMarkerCreate",{detail:{map:this.wrapper,markerMap:i,markerProps:t,service:"openstreetmap"}}));return document.dispatchEvent(r),0===this.options.markers.filter(function(t){return t.id===e.id}).length&&this.options.markers.push(t),0===this.markersObjects.filter(function(t){return t.options.id===e.id}).length&&this.markersObjects.push(i),this.used_marker_ids.push(t.id),i},e.deleteMarker=function(e){this.map.removeLayer(e),this.options.markers=this.options.markers.filter(function(t){return t.id!==e.options.id}),this.markersObjects=this.markersObjects.filter(function(t){return t.options.id!==e.options.id});var t=this.used_marker_ids.indexOf(e.options.id);this.used_marker_ids.splice(t,1)},e.updateMarkers=function(){var s=this;this.options.markers.map(function(t,e){var i,r=new L.LatLng(t.latitude,t.longitude);for(i in s.markersObjects)if(s.markersObjects[i].options.id===t.id){s.markersObjects[e].setLatLng(r,{animate:!1}),s.markersObjects[e].closePopup(),s.markersObjects[e].unbindPopup(),(t.label&&""!==t.label||t.description&&""!==t.description||t.address&&""!==t.address)&&s.markersObjects[e].bindPopup(s.getMarkerContent(t));break}})},e.renderMarkers=function(){var i=this,r=this,s=0;this.options.markers.map(function(t,e){i.used_marker_ids.includes(t.id)||i.createMarker(t,function(t){r.map.addLayer(t),++s===r.options.markers.length&&r.centerMap()})})},e.centerMap=function(){var t,e,i;0!==this.markersObjects.length&&(e=L.featureGroup(this.markersObjects),t=1