async function w(){let t=window.L;while(!t)await h(100),t=window.L;return t}function h(t){return new Promise((o)=>setTimeout(o,t))}var d=new Map,p=new Map,P=new Map;async function g(t){let o=d.get(t);if(!o){let e=P.get(t);if(!e)e=new Promise((n)=>{p.set(t,n)}),P.set(t,e);o=await e}return o}async function b(t,o,e){let n=await w(),r=d.get(t)??n.map(`dioxus-leaflet-map-${t}`,{zoomControl:e.zoom_control,scrollWheelZoom:e.scroll_wheel_zoom,doubleClickZoom:e.double_click_zoom,touchZoom:e.touch_zoom,dragging:e.dragging,keyboard:e.keyboard,attributionControl:e.attribution_control});if(r.setView(o.coordinates,o.zoom),n.tileLayer(e.tile_layer.url,{attribution:e.tile_layer.attribution,maxZoom:e.tile_layer.max_zoom,subdomains:e.tile_layer.subdomains}).addTo(r),d.set(t,r),p.has(t))p.get(t)(r),p.delete(t),P.delete(t);await h(100),r.invalidateSize()}function O(t){d.delete(t)}async function T(t,o){await w();let e=await g(t);if(!e)throw Error(`Map with id ${t} not found when setting onClick handler`);e.on("click",async(n)=>{try{await o([n.latlng.lat,n.latlng.lng])}catch(r){console.error("Error in on_map_click callback:",r)}})}async function R(t,o){await w();let e=await g(t);if(!e)throw Error(`Map with id ${t} not found when setting onMove handler`);e.on("move",async()=>{let n=e.getCenter(),r=e.getZoom();try{await o([n.lat,n.lng,r])}catch(f){console.error("Error in map_on_move callback:",f)}})}var c=new Map;function x(t){return c.get(t)}async function J(t,o,e,n){let r=await w(),f=await g(t);if(!f)throw Error(`Map with id ${t} not found when updating polygon ${o}`);let u=c.get(o)??r.polygon([]).addTo(f);c.set(o,u),u.setLatLngs(e),u.setStyle(n);let y=I(o);if(y)u.unbindPopup(),u.bindPopup(y.body,y.options)}async function S(t,o){let e=await w();if(!await g(t))throw Error(`Map with id ${t} not found when deleting polygon ${o}`);c.delete(o)}var s=new Map;function I(t){return s.get(t)}async function D(t,o,e){let n=await w(),r=`dioxus-leaflet-popup-${o}`,f=document.getElementById(r);if(!f)throw Error(`Popup body element with id ${r} not found when updating popup for object ${t}`);s.set(t,{body:f,options:e});let u=$(t)??x(t);if(u)u.unbindPopup(),u.bindPopup(f,e)}var L=new Map;function $(t){return L.get(t)}async function U(t,o,e,n){let r=await w(),f=await g(t);if(!f)throw Error(`Map with id ${t} not found when updating marker ${o}`);let u=L.get(o)??r.marker([0,0]).addTo(f);if(L.set(o,u),u.setLatLng(e),n)u.setIcon(r.icon(n));let y=I(o);if(y)u.unbindPopup(),u.bindPopup(y.body,y.options)}async function V(t,o){let e=await w(),n=await g(t);if(!n)throw Error(`Map with id ${t} not found when deleting marker ${o}`);let r=L.get(o);if(!r)throw Error(`Marker with id ${o} not found when deleting`);n.removeLayer(r),L.delete(o)}export{D as update_popup,J as update_polygon,U as update_marker,b as update_map,R as on_map_move,T as on_map_click,I as get_popup,x as get_polygon,$ as get_marker,g as get_map,S as delete_polygon,V as delete_marker,O as delete_map};