(()=>{var e;e=jQuery,DokanGeo.LocationsMaps={map:null,mapboxId:"dokan-geolocation-locations-map",items:[],data:{type:"FeatureCollection",features:[]},marker:{image:null,clusterer:null},modal:e(".dokan-geo-location-modals").iziModal({closeButton:!0,appendTo:"body",title:"",headerColor:dokan.modal_header_color}),init(){const o=this,a={longitude:0,latitude:0};if(mapboxgl.accessToken=DokanGeo.mapbox_access_token,o.map=new mapboxgl.Map({container:o.mapboxId,style:"mapbox://styles/mapbox/streets-v10",center:[DokanGeo.default_geolocation.longitude,DokanGeo.default_geolocation.latitude],zoom:DokanGeo.map_zoom}),o.map.addControl(new mapboxgl.NavigationControl),o.items=e('[name="dokan_geolocation[]"]'),o.items.each(function(t){e(this).val();const n=e(this).data("latitude"),i=e(this).data("longitude"),l={type:"Feature",properties:{id:"dokan-geolocation-item-"+t,info:e(this).data("info")},geometry:{type:"Point",coordinates:[i,n,0]}};o.data.features.push(l),a.longitude+=i,a.latitude+=n}),a.longitude&&a.latitude)o.map.setCenter([a.longitude/o.items.length,a.latitude/o.items.length]);else{const e=new URLSearchParams(window.location.search),a=Object.fromEntries(e.entries());a.longitude&&a.latitude&&!isNaN(parseFloat(a.longitude))&&!isNaN(parseFloat(a.latitude))?o.map.setCenter([parseFloat(a.longitude),parseFloat(a.latitude)]):o.map.setCenter([DokanGeo.default_geolocation.longitude,DokanGeo.default_geolocation.latitude])}o.map.on("load",function(){o.loadImages("image",DokanGeo.marker.image),o.loadImages("clusterer",DokanGeo.marker.clusterer)})},loadImages(e,o){const a=this;a.map.loadImage(o,function(o,t){o||(a.marker[e]=t,a.map.addImage("dokan-marker-"+e,t),a.addMapLayers())})},addMapLayers(){const e=this;e.marker.image&&e.marker.clusterer&&(e.map.addSource("dokan_geolocation_map_main_data",{type:"geojson",data:e.data,cluster:!0,clusterMaxZoom:14,clusterRadius:50}),e.map.addLayer({id:"clusters",type:"symbol",source:"dokan_geolocation_map_main_data",filter:["has","point_count"],layout:{"icon-image":"dokan-marker-clusterer","icon-allow-overlap":!0,"text-allow-overlap":!0}}),e.map.addLayer({id:"cluster-count",type:"symbol",source:"dokan_geolocation_map_main_data",filter:["has","point_count"],layout:{"text-field":"{point_count_abbreviated}","text-font":["DIN Offc Pro Medium","Arial Unicode MS Bold"],"text-size":12},paint:{"text-color":"rgb(253, 218, 206)"}}),e.map.addLayer({id:"unclustered-point",type:"symbol",source:"dokan_geolocation_map_main_data",filter:["!",["has","point_count"]],layout:{"icon-image":"dokan-marker-image","icon-allow-overlap":!0,"text-allow-overlap":!0,"icon-size":1,"icon-anchor":"bottom"}}),e.map.on("click","clusters",function(o){const a=e.map.queryRenderedFeatures(o.point,{layers:["clusters"]})[0].properties.cluster_id,t=e.map.getZoom();e.map.getSource("dokan_geolocation_map_main_data").getClusterLeaves(a,255,0,function(o,n){if(t<14)e.map.getSource("dokan_geolocation_map_main_data").getClusterExpansionZoom(a,function(o,a){if(!o){const o=Math.min(a,14);e.map.easeTo({center:n[0].geometry.coordinates,zoom:o})}});else if(n.length>1){let o='<div class="white-popup dokan-geo-map-info-windows-in-popup">';n.forEach(a=>{o+=e.getInfoWindowContent(a.properties.info)}),o+="</div>",e.modal.iziModal("setContent",o.trim()),e.modal.iziModal("open")}else e.map.easeTo({center:n[0].geometry.coordinates,zoom:t})})}),e.map.on("mouseenter","clusters",function(){e.map.getCanvas().style.cursor="pointer"}),e.map.on("mouseleave","clusters",function(){e.map.getCanvas().style.cursor=""}),e.map.on("click","unclustered-point",function(o){const a=e.map.queryRenderedFeatures(o.point,{layers:["unclustered-point"]})[0].properties.info;a&&(e.map.easeTo({center:o.lngLat}),new mapboxgl.Popup({closeOnClick:!0}).setLngLat(o.lngLat).setHTML(e.getInfoWindowContent(a)).setMaxWidth("654px").addTo(e.map))}))},getInfoWindowContent(e){"string"==typeof e&&(e=JSON.parse(e));let o,a=DokanGeo.info_window_template;for(o in e)a=a.replace("{"+o+"}",e[o]);return a}},e("#dokan-geolocation-locations-map").length&&DokanGeo.mapbox_access_token&&DokanGeo.LocationsMaps.init()})();