this repo has no description

widget-leaflet: queue commands until map is ready

Commands sent before Leaflet finishes loading were silently dropped.
Now they are queued and replayed once the map initializes. This fixes
enableBboxDraw being lost when called immediately after display_managed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

+8 -3
+8 -3
widget-leaflet/widget_leaflet.ml
··· 15 15 s.src = url; s.onload = cb; 16 16 document.body.appendChild(s); 17 17 } 18 - return { 18 + var adapter = { 19 19 create: function(container, config, send) { 20 - var state = { map: null, geojsonLayer: null, bboxRect: null, bboxDrawing: false, imageOverlay: null, markers: [], _send: null }; 20 + var self = adapter; 21 + var state = { map: null, geojsonLayer: null, bboxRect: null, bboxDrawing: false, imageOverlay: null, markers: [], _send: null, _pendingCmds: [] }; 21 22 ensureCSS(CSS_URL); 22 23 ensureScript(JS_URL, function() { 23 24 var cfg = JSON.parse(config); ··· 42 43 }); 43 44 state.map = map; 44 45 state._send = send; 46 + var pending = state._pendingCmds; 47 + state._pendingCmds = []; 48 + pending.forEach(function(p) { self.command(state, p[0], p[1]); }); 45 49 }); 46 50 return state; 47 51 }, ··· 51 55 if (cfg.center) state.map.setView(cfg.center, cfg.zoom || state.map.getZoom()); 52 56 }, 53 57 command: function(state, cmd, data) { 54 - if (!state.map) return; 58 + if (!state.map) { state._pendingCmds.push([cmd, data]); return; } 55 59 var d = data ? JSON.parse(data) : {}; 56 60 if (cmd === "flyTo") state.map.flyTo(L.latLng(d.lat, d.lng), d.zoom || state.map.getZoom()); 57 61 else if (cmd === "fitBounds") state.map.fitBounds(d); ··· 123 127 }, 124 128 destroy: function(state) { if (state.map) state.map.remove(); } 125 129 }; 130 + return adapter; 126 131 })() 127 132 |js} 128 133