(()=>{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:function(){var 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();var n=e(this).data("latitude"),i=e(this).data("longitude"),r={type:"Feature",properties:{id:"dokan-geolocation-item-"+t,info:e(this).data("info")},geometry:{type:"Point",coordinates:[i,n,0]}};o.data.features.push(r),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());o.map.setCenter([a.longitude,a.latitude])}o.map.on("load",(function(){o.loadImages("image",DokanGeo.marker.image),o.loadImages("clusterer",DokanGeo.marker.clusterer)}))},loadImages:function(e,o){var a=this;a.map.loadImage(o,(function(o,t){o||(a.marker[e]=t,a.map.addImage("dokan-marker-"+e,t),a.addMapLayers())}))},addMapLayers:function(){var 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}}),e.map.on("click","clusters",(function(o){var a=e.map.queryRenderedFeatures(o.point,{layers:["clusters"]})[0].properties.cluster_id;e.map.getSource("dokan_geolocation_map_main_data").getClusterLeaves(a,255,0,(function(o,t){if(e.map.getZoom()>9&&t.length>1){var n='<div class="white-popup dokan-geo-map-info-windows-in-popup">',i=0;for(i=0;i<t.length;i++)n+=e.getInfoWindowContent(t[i].properties.info);n+="</div>",e.modal.iziModal("setContent",n.trim()),e.modal.iziModal("open")}else e.map.getSource("dokan_geolocation_map_main_data").getClusterExpansionZoom(a,(function(o,a){o||e.map.easeTo({center:t[0].geometry.coordinates,zoom:a})}))}))})),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){var 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:function(e){"string"==typeof e&&(e=JSON.parse(e));var 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()})();