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