@mountaya/elements 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +273 -0
- package/LICENCE.fr.txt +280 -0
- package/LICENSE.txt +262 -0
- package/README.md +1510 -2
- package/THIRD-PARTY-NOTICES.txt +103 -0
- package/dist/agent/index.cjs +1211 -0
- package/dist/agent/index.cjs.map +1 -0
- package/dist/agent/index.d.cts +1966 -0
- package/dist/agent/index.d.ts +1966 -0
- package/dist/agent/index.js +1181 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/camera/index.cjs +2512 -0
- package/dist/camera/index.cjs.map +1 -0
- package/dist/camera/index.d.cts +1723 -0
- package/dist/camera/index.d.ts +1723 -0
- package/dist/camera/index.js +2443 -0
- package/dist/camera/index.js.map +1 -0
- package/dist/chunk-5pTPpv4v.d.cts +897 -0
- package/dist/chunk-5pTPpv4v.d.ts +897 -0
- package/dist/chunk-6JzFMFHh.d.ts +119 -0
- package/dist/chunk-6qyuJVvt.d.ts +513 -0
- package/dist/chunk-9fp0lDic.cjs +583 -0
- package/dist/chunk-9fp0lDic.cjs.map +1 -0
- package/dist/chunk-A48H1rDg.d.cts +73 -0
- package/dist/chunk-A48H1rDg.d.ts +73 -0
- package/dist/chunk-B-m1AchR.cjs +57 -0
- package/dist/chunk-B-m1AchR.cjs.map +1 -0
- package/dist/chunk-B-qFTf04.d.ts +216 -0
- package/dist/chunk-B0YROiZh.d.cts +1475 -0
- package/dist/chunk-B14wgOvH.d.cts +68 -0
- package/dist/chunk-B19l3j9r.cjs +150 -0
- package/dist/chunk-B19l3j9r.cjs.map +1 -0
- package/dist/chunk-B2PtjVKg.cjs +86 -0
- package/dist/chunk-B2PtjVKg.cjs.map +1 -0
- package/dist/chunk-B56Oyb7W.cjs +70 -0
- package/dist/chunk-B56Oyb7W.cjs.map +1 -0
- package/dist/chunk-B5WGMQwK.cjs +113 -0
- package/dist/chunk-B5WGMQwK.cjs.map +1 -0
- package/dist/chunk-B98mKrdu.d.cts +302 -0
- package/dist/chunk-BB0PmqIM.d.cts +44 -0
- package/dist/chunk-BBikve0Z.cjs +269 -0
- package/dist/chunk-BBikve0Z.cjs.map +1 -0
- package/dist/chunk-BHeXmM0X.js +37 -0
- package/dist/chunk-BHeXmM0X.js.map +1 -0
- package/dist/chunk-BI8WZLpU.cjs +281 -0
- package/dist/chunk-BI8WZLpU.cjs.map +1 -0
- package/dist/chunk-BIEc_SkR.cjs +29 -0
- package/dist/chunk-BIEc_SkR.cjs.map +1 -0
- package/dist/chunk-BJ6L6_W9.cjs +553 -0
- package/dist/chunk-BJ6L6_W9.cjs.map +1 -0
- package/dist/chunk-BJ91UCbB.js +11 -0
- package/dist/chunk-BJ91UCbB.js.map +1 -0
- package/dist/chunk-BJEZWTKj.cjs +166 -0
- package/dist/chunk-BJEZWTKj.cjs.map +1 -0
- package/dist/chunk-BJz54mfg.cjs +10 -0
- package/dist/chunk-BJz54mfg.cjs.map +1 -0
- package/dist/chunk-BNX5LAfN.d.cts +912 -0
- package/dist/chunk-BP6KgA86.js +35 -0
- package/dist/chunk-BP6KgA86.js.map +1 -0
- package/dist/chunk-BRnjQq6K.d.cts +157 -0
- package/dist/chunk-BSiMEwPS.js +46 -0
- package/dist/chunk-BSiMEwPS.js.map +1 -0
- package/dist/chunk-BTPjDw_y.cjs +16 -0
- package/dist/chunk-BTPjDw_y.cjs.map +1 -0
- package/dist/chunk-BTUUABGI.js +17 -0
- package/dist/chunk-BTUUABGI.js.map +1 -0
- package/dist/chunk-BUeL9y7s.cjs +45 -0
- package/dist/chunk-BUeL9y7s.cjs.map +1 -0
- package/dist/chunk-BWMuCNc9.cjs +172 -0
- package/dist/chunk-BWMuCNc9.cjs.map +1 -0
- package/dist/chunk-BWjRfhpF.js +126 -0
- package/dist/chunk-BWjRfhpF.js.map +1 -0
- package/dist/chunk-BZ5KyZXI.d.ts +302 -0
- package/dist/chunk-B_4SVmvh.js +94 -0
- package/dist/chunk-B_4SVmvh.js.map +1 -0
- package/dist/chunk-BcTUuZQ3.js +95 -0
- package/dist/chunk-BcTUuZQ3.js.map +1 -0
- package/dist/chunk-BdkqSsJe.cjs +140 -0
- package/dist/chunk-BdkqSsJe.cjs.map +1 -0
- package/dist/chunk-BfktMVmI.js +70 -0
- package/dist/chunk-BfktMVmI.js.map +1 -0
- package/dist/chunk-BfzQb0EK.cjs +6 -0
- package/dist/chunk-BhWfT-22.d.cts +808 -0
- package/dist/chunk-BjJcqX5J.cjs +60 -0
- package/dist/chunk-BjJcqX5J.cjs.map +1 -0
- package/dist/chunk-Bk0L8g5J.d.cts +77 -0
- package/dist/chunk-Bk0L8g5J.d.ts +77 -0
- package/dist/chunk-Bl4_uVa6.cjs +11 -0
- package/dist/chunk-Bl4_uVa6.cjs.map +1 -0
- package/dist/chunk-BlKF4lrp.js +43 -0
- package/dist/chunk-BlKF4lrp.js.map +1 -0
- package/dist/chunk-Bm1FieGR.js +4 -0
- package/dist/chunk-Bm1FieGR.js.map +1 -0
- package/dist/chunk-Bn6ZbxkS.cjs +27 -0
- package/dist/chunk-BpN3hr6a.cjs +541 -0
- package/dist/chunk-BpN3hr6a.cjs.map +1 -0
- package/dist/chunk-Bq_WHTfd.d.cts +119 -0
- package/dist/chunk-Bqt4LBBz.cjs +648 -0
- package/dist/chunk-Bqt4LBBz.cjs.map +1 -0
- package/dist/chunk-Bqt97zwf.d.cts +54 -0
- package/dist/chunk-Bqt97zwf.d.ts +54 -0
- package/dist/chunk-BsBiN4w6.d.cts +245 -0
- package/dist/chunk-BvTpOUoC.cjs +207 -0
- package/dist/chunk-BvTpOUoC.cjs.map +1 -0
- package/dist/chunk-BwK6Hl3q.cjs +446 -0
- package/dist/chunk-BwK6Hl3q.cjs.map +1 -0
- package/dist/chunk-BxDQZDXR.d.cts +76 -0
- package/dist/chunk-BxDQZDXR.d.ts +76 -0
- package/dist/chunk-BxUio8kX.js +20 -0
- package/dist/chunk-BxUio8kX.js.map +1 -0
- package/dist/chunk-BxaocpFi.d.cts +1 -0
- package/dist/chunk-Bywi0K1N.js +36 -0
- package/dist/chunk-Bywi0K1N.js.map +1 -0
- package/dist/chunk-C-IlmkDl.js +59 -0
- package/dist/chunk-C-IlmkDl.js.map +1 -0
- package/dist/chunk-C5PtVewq.d.ts +389 -0
- package/dist/chunk-C5dpC7mQ.js +19 -0
- package/dist/chunk-C5dpC7mQ.js.map +1 -0
- package/dist/chunk-C5q1sgSa.js +46 -0
- package/dist/chunk-C5q1sgSa.js.map +1 -0
- package/dist/chunk-C6fU9G5I.cjs +221 -0
- package/dist/chunk-C6fU9G5I.cjs.map +1 -0
- package/dist/chunk-C71dpWUK.js +5 -0
- package/dist/chunk-C71dpWUK.js.map +1 -0
- package/dist/chunk-C82N1gQX.d.ts +1831 -0
- package/dist/chunk-C8HdaHpu.js +118 -0
- package/dist/chunk-C8HdaHpu.js.map +1 -0
- package/dist/chunk-C8ZGryck.js +236 -0
- package/dist/chunk-C8ZGryck.js.map +1 -0
- package/dist/chunk-C95NG0oD.cjs +43 -0
- package/dist/chunk-C95NG0oD.cjs.map +1 -0
- package/dist/chunk-C9aR8DXb.js +9 -0
- package/dist/chunk-C9aR8DXb.js.map +1 -0
- package/dist/chunk-CAUZnoCs.d.ts +525 -0
- package/dist/chunk-CBXWWuM9.cjs +82 -0
- package/dist/chunk-CBXWWuM9.cjs.map +1 -0
- package/dist/chunk-CC_Kquu7.d.cts +125 -0
- package/dist/chunk-CC_Kquu7.d.ts +125 -0
- package/dist/chunk-CCp85vXg.cjs +60 -0
- package/dist/chunk-CCp85vXg.cjs.map +1 -0
- package/dist/chunk-CEcB1_uK.js +39 -0
- package/dist/chunk-CEcB1_uK.js.map +1 -0
- package/dist/chunk-CFIo021l.d.cts +216 -0
- package/dist/chunk-CH_IZoJE.js +33 -0
- package/dist/chunk-CH_IZoJE.js.map +1 -0
- package/dist/chunk-CHrasH_g.cjs +25 -0
- package/dist/chunk-CHrasH_g.cjs.map +1 -0
- package/dist/chunk-CJVoSaAE.cjs +3 -0
- package/dist/chunk-CJp8nGcb.js +96 -0
- package/dist/chunk-CJp8nGcb.js.map +1 -0
- package/dist/chunk-CJwUtkOt.js +112 -0
- package/dist/chunk-CJwUtkOt.js.map +1 -0
- package/dist/chunk-CKhCOVIf.d.cts +751 -0
- package/dist/chunk-CKiVSRYg.js +50 -0
- package/dist/chunk-CKiVSRYg.js.map +1 -0
- package/dist/chunk-CKtd19eD.cjs +59 -0
- package/dist/chunk-CKtd19eD.cjs.map +1 -0
- package/dist/chunk-CL92KE3j.d.ts +3188 -0
- package/dist/chunk-CLqUlkAe.js +54 -0
- package/dist/chunk-CLqUlkAe.js.map +1 -0
- package/dist/chunk-CMG5OV0q.cjs +4741 -0
- package/dist/chunk-CMG5OV0q.cjs.map +1 -0
- package/dist/chunk-CN_TKSgm.js +10 -0
- package/dist/chunk-CN_TKSgm.js.map +1 -0
- package/dist/chunk-CNe6MtqV.cjs +29 -0
- package/dist/chunk-CNe6MtqV.cjs.map +1 -0
- package/dist/chunk-COQkDTC5.js +83 -0
- package/dist/chunk-COQkDTC5.js.map +1 -0
- package/dist/chunk-CPBl6K4M.cjs +168 -0
- package/dist/chunk-CPBl6K4M.cjs.map +1 -0
- package/dist/chunk-CPx0ZYFB.d.ts +3 -0
- package/dist/chunk-CQQhcP_C.d.ts +197 -0
- package/dist/chunk-CTNoajFh.d.cts +389 -0
- package/dist/chunk-CTd-qgJc.cjs +384 -0
- package/dist/chunk-CTd-qgJc.cjs.map +1 -0
- package/dist/chunk-CW80YYtU.cjs +1056 -0
- package/dist/chunk-CW80YYtU.cjs.map +1 -0
- package/dist/chunk-CWpqBgkF.d.cts +24 -0
- package/dist/chunk-CWpqBgkF.d.ts +24 -0
- package/dist/chunk-CXjRArgy.d.ts +3 -0
- package/dist/chunk-CXonfH3-.cjs +14 -0
- package/dist/chunk-CXonfH3-.cjs.map +1 -0
- package/dist/chunk-CYcouGXN.d.ts +825 -0
- package/dist/chunk-CZDAzEBw.cjs +1621 -0
- package/dist/chunk-CZDAzEBw.cjs.map +1 -0
- package/dist/chunk-C_fQFr70.d.cts +159 -0
- package/dist/chunk-C_fQFr70.d.ts +159 -0
- package/dist/chunk-CbOtHnnB.cjs +359 -0
- package/dist/chunk-CbOtHnnB.cjs.map +1 -0
- package/dist/chunk-CdA6ZMGk.d.cts +825 -0
- package/dist/chunk-Ce1_thm7.js +146 -0
- package/dist/chunk-Ce1_thm7.js.map +1 -0
- package/dist/chunk-CeD8Hw0j.d.cts +3188 -0
- package/dist/chunk-CeiTuMyt.d.cts +525 -0
- package/dist/chunk-Ch1OLzLi.js +1 -0
- package/dist/chunk-Cizu_j1N.cjs +87 -0
- package/dist/chunk-Cizu_j1N.cjs.map +1 -0
- package/dist/chunk-CjDe9z6A.d.cts +427 -0
- package/dist/chunk-Cl1etdlu.js +63 -0
- package/dist/chunk-Cl1etdlu.js.map +1 -0
- package/dist/chunk-CmoVJDoz.js +4 -0
- package/dist/chunk-CmoVJDoz.js.map +1 -0
- package/dist/chunk-CnLucxjG.cjs +197 -0
- package/dist/chunk-CnLucxjG.cjs.map +1 -0
- package/dist/chunk-CsWjBmdi.cjs +56 -0
- package/dist/chunk-CsWjBmdi.cjs.map +1 -0
- package/dist/chunk-CuseO5MZ.d.cts +3 -0
- package/dist/chunk-CvMHibbA.d.ts +427 -0
- package/dist/chunk-CwDeiN5U.js +870 -0
- package/dist/chunk-CwDeiN5U.js.map +1 -0
- package/dist/chunk-Cwdmx4tG.js +1 -0
- package/dist/chunk-D-4MxHTt.d.cts +105 -0
- package/dist/chunk-D-4MxHTt.d.ts +105 -0
- package/dist/chunk-D0LF-99V.js +1093 -0
- package/dist/chunk-D0LF-99V.js.map +1 -0
- package/dist/chunk-D1fe-0c_.js +367 -0
- package/dist/chunk-D1fe-0c_.js.map +1 -0
- package/dist/chunk-D21fEI6A.d.ts +1926 -0
- package/dist/chunk-D39gAxya.cjs +89 -0
- package/dist/chunk-D39gAxya.cjs.map +1 -0
- package/dist/chunk-D6KdIW5e.cjs +228 -0
- package/dist/chunk-D6KdIW5e.cjs.map +1 -0
- package/dist/chunk-D6qHYbgW.d.cts +36 -0
- package/dist/chunk-D89E-w70.d.ts +44 -0
- package/dist/chunk-D8bdTysL.js +552 -0
- package/dist/chunk-D8bdTysL.js.map +1 -0
- package/dist/chunk-D96QJT24.cjs +109 -0
- package/dist/chunk-D96QJT24.cjs.map +1 -0
- package/dist/chunk-DAmkQl-i.js +119 -0
- package/dist/chunk-DAmkQl-i.js.map +1 -0
- package/dist/chunk-DEfsb2lc.cjs +10 -0
- package/dist/chunk-DEfsb2lc.cjs.map +1 -0
- package/dist/chunk-DIFjT5-V.d.cts +66 -0
- package/dist/chunk-DJpUw8TN.d.ts +912 -0
- package/dist/chunk-DK6lm2IZ.cjs +11 -0
- package/dist/chunk-DK6lm2IZ.cjs.map +1 -0
- package/dist/chunk-DKqgr31j.cjs +61 -0
- package/dist/chunk-DKqgr31j.cjs.map +1 -0
- package/dist/chunk-DLZ0QYm9.js +37 -0
- package/dist/chunk-DLZ0QYm9.js.map +1 -0
- package/dist/chunk-DLjS0uaC.js +4 -0
- package/dist/chunk-DLjS0uaC.js.map +1 -0
- package/dist/chunk-DMokwmOV.cjs +49 -0
- package/dist/chunk-DMokwmOV.cjs.map +1 -0
- package/dist/chunk-DMvWgBZL.d.cts +1831 -0
- package/dist/chunk-DNfGfIF3.js +31 -0
- package/dist/chunk-DNfGfIF3.js.map +1 -0
- package/dist/chunk-DQbSRe8D.d.ts +245 -0
- package/dist/chunk-DSGkP8_y.js +45 -0
- package/dist/chunk-DSGkP8_y.js.map +1 -0
- package/dist/chunk-DTctvfSd.d.cts +197 -0
- package/dist/chunk-DWe7igyw.cjs +206 -0
- package/dist/chunk-DWe7igyw.cjs.map +1 -0
- package/dist/chunk-DWsMP5JR.d.ts +68 -0
- package/dist/chunk-DWsm3HIW.d.cts +120 -0
- package/dist/chunk-DWsm3HIW.d.ts +120 -0
- package/dist/chunk-DXABHjLa.cjs +3 -0
- package/dist/chunk-D_BeqSbc.cjs +42 -0
- package/dist/chunk-D_BeqSbc.cjs.map +1 -0
- package/dist/chunk-D_svQNdW.d.ts +66 -0
- package/dist/chunk-Dav4xWrp.js +330 -0
- package/dist/chunk-Dav4xWrp.js.map +1 -0
- package/dist/chunk-DbCPhepL.js +293 -0
- package/dist/chunk-DbCPhepL.js.map +1 -0
- package/dist/chunk-DcrTy-y2.cjs +43 -0
- package/dist/chunk-DcrTy-y2.cjs.map +1 -0
- package/dist/chunk-Ddv484ld.js +487 -0
- package/dist/chunk-Ddv484ld.js.map +1 -0
- package/dist/chunk-De0bjnhY.cjs +88 -0
- package/dist/chunk-De0bjnhY.cjs.map +1 -0
- package/dist/chunk-De2FmNPu.cjs +32 -0
- package/dist/chunk-De2FmNPu.cjs.map +1 -0
- package/dist/chunk-DeSjQXiI.d.ts +157 -0
- package/dist/chunk-Den0Ta6C.js +132 -0
- package/dist/chunk-Den0Ta6C.js.map +1 -0
- package/dist/chunk-DiDKEeEa.js +8 -0
- package/dist/chunk-DiDKEeEa.js.map +1 -0
- package/dist/chunk-Dj60k5PU.js +197 -0
- package/dist/chunk-Dj60k5PU.js.map +1 -0
- package/dist/chunk-DjnYQBCN.js +4705 -0
- package/dist/chunk-DjnYQBCN.js.map +1 -0
- package/dist/chunk-Dk9VKvyq.d.ts +1 -0
- package/dist/chunk-Dor1ERI9.cjs +85 -0
- package/dist/chunk-Dor1ERI9.cjs.map +1 -0
- package/dist/chunk-DpMouOoH.js +451 -0
- package/dist/chunk-DpMouOoH.js.map +1 -0
- package/dist/chunk-DposgdNL.cjs +52 -0
- package/dist/chunk-DposgdNL.cjs.map +1 -0
- package/dist/chunk-DqLTG_5Q.d.cts +3 -0
- package/dist/chunk-Dr5MCIpS.d.cts +63 -0
- package/dist/chunk-Dr5MCIpS.d.ts +63 -0
- package/dist/chunk-DrudttCC.cjs +4 -0
- package/dist/chunk-DsDYVJQC.js +173 -0
- package/dist/chunk-DsDYVJQC.js.map +1 -0
- package/dist/chunk-Dw8ur6FJ.js +27 -0
- package/dist/chunk-Dw8ur6FJ.js.map +1 -0
- package/dist/chunk-DwG6M_0v.js +64 -0
- package/dist/chunk-DwG6M_0v.js.map +1 -0
- package/dist/chunk-Dy9a5ibO.js +284 -0
- package/dist/chunk-Dy9a5ibO.js.map +1 -0
- package/dist/chunk-DyayZlQJ.js +157 -0
- package/dist/chunk-DyayZlQJ.js.map +1 -0
- package/dist/chunk-DyhJZC2i.js +126 -0
- package/dist/chunk-DyhJZC2i.js.map +1 -0
- package/dist/chunk-F9zBzmmG.cjs +45 -0
- package/dist/chunk-F9zBzmmG.cjs.map +1 -0
- package/dist/chunk-FyCYofv2.js +116 -0
- package/dist/chunk-FyCYofv2.js.map +1 -0
- package/dist/chunk-GHJRjAk2.js +1 -0
- package/dist/chunk-H14isiSf.d.ts +751 -0
- package/dist/chunk-HIJzXoN4.js +7 -0
- package/dist/chunk-HIJzXoN4.js.map +1 -0
- package/dist/chunk-Id_8kRtu.d.ts +36 -0
- package/dist/chunk-KN60yxBQ.js +5 -0
- package/dist/chunk-KN60yxBQ.js.map +1 -0
- package/dist/chunk-NM5yg6bh.cjs +82 -0
- package/dist/chunk-NM5yg6bh.cjs.map +1 -0
- package/dist/chunk-OXr3zJfM.cjs +119 -0
- package/dist/chunk-OXr3zJfM.cjs.map +1 -0
- package/dist/chunk-QGqgNC4z.d.ts +928 -0
- package/dist/chunk-QJBtJrZ0.js +36 -0
- package/dist/chunk-QJBtJrZ0.js.map +1 -0
- package/dist/chunk-QKWhxfPv.d.cts +361 -0
- package/dist/chunk-QKWhxfPv.d.ts +361 -0
- package/dist/chunk-QXW7b4Ev.d.cts +410 -0
- package/dist/chunk-RHZrxUrM.cjs +39 -0
- package/dist/chunk-RHZrxUrM.cjs.map +1 -0
- package/dist/chunk-RTxe2i66.js +91 -0
- package/dist/chunk-RTxe2i66.js.map +1 -0
- package/dist/chunk-RrKkJb6P.js +16 -0
- package/dist/chunk-RrKkJb6P.js.map +1 -0
- package/dist/chunk-VOJqpcnM.cjs +181 -0
- package/dist/chunk-VOJqpcnM.cjs.map +1 -0
- package/dist/chunk-VljGTrid.js +1 -0
- package/dist/chunk-X3UVwUEK.d.cts +513 -0
- package/dist/chunk-X9K2WChn.cjs +28 -0
- package/dist/chunk-X9K2WChn.cjs.map +1 -0
- package/dist/chunk-YrtOx6oy.js +251 -0
- package/dist/chunk-YrtOx6oy.js.map +1 -0
- package/dist/chunk-bY7ySujI.d.cts +928 -0
- package/dist/chunk-bYf1sBz5.d.cts +11 -0
- package/dist/chunk-bYf1sBz5.d.ts +11 -0
- package/dist/chunk-blfknWoM.d.cts +1926 -0
- package/dist/chunk-blqsohAb.js +113 -0
- package/dist/chunk-blqsohAb.js.map +1 -0
- package/dist/chunk-cDMCjodI.cjs +58 -0
- package/dist/chunk-cDMCjodI.cjs.map +1 -0
- package/dist/chunk-cWjE3qd6.cjs +10 -0
- package/dist/chunk-cWjE3qd6.cjs.map +1 -0
- package/dist/chunk-dfOgV3fu.js +26 -0
- package/dist/chunk-dfOgV3fu.js.map +1 -0
- package/dist/chunk-f9cTwUX1.cjs +125 -0
- package/dist/chunk-f9cTwUX1.cjs.map +1 -0
- package/dist/chunk-fHVYEZs4.cjs +28 -0
- package/dist/chunk-fHVYEZs4.cjs.map +1 -0
- package/dist/chunk-fWRUMgRI.js +22 -0
- package/dist/chunk-fWRUMgRI.js.map +1 -0
- package/dist/chunk-fozLXfHY.d.cts +55 -0
- package/dist/chunk-fozLXfHY.d.ts +55 -0
- package/dist/chunk-gWmB1l3A.cjs +3122 -0
- package/dist/chunk-gWmB1l3A.cjs.map +1 -0
- package/dist/chunk-gbj2R-_w.js +58 -0
- package/dist/chunk-gbj2R-_w.js.map +1 -0
- package/dist/chunk-iIWxsAXd.js +59 -0
- package/dist/chunk-iIWxsAXd.js.map +1 -0
- package/dist/chunk-lItIuOIS.cjs +137 -0
- package/dist/chunk-lItIuOIS.cjs.map +1 -0
- package/dist/chunk-m6Rh4PCe.cjs +798 -0
- package/dist/chunk-m6Rh4PCe.cjs.map +1 -0
- package/dist/chunk-o3IRANDf.cjs +99 -0
- package/dist/chunk-o3IRANDf.cjs.map +1 -0
- package/dist/chunk-obUcg3Sk.d.ts +808 -0
- package/dist/chunk-ohsf-6Rn.js +600 -0
- package/dist/chunk-ohsf-6Rn.js.map +1 -0
- package/dist/chunk-pBleU6Nv.js +3061 -0
- package/dist/chunk-pBleU6Nv.js.map +1 -0
- package/dist/chunk-px4e99cy.js +71 -0
- package/dist/chunk-px4e99cy.js.map +1 -0
- package/dist/chunk-qwYDLeXc.cjs +99 -0
- package/dist/chunk-qwYDLeXc.cjs.map +1 -0
- package/dist/chunk-rF_859Qk.cjs +101 -0
- package/dist/chunk-rF_859Qk.cjs.map +1 -0
- package/dist/chunk-rLJkqJ5j.d.ts +1475 -0
- package/dist/chunk-twQItIRg.cjs +338 -0
- package/dist/chunk-twQItIRg.cjs.map +1 -0
- package/dist/chunk-vnPrMVjY.js +10 -0
- package/dist/chunk-vnPrMVjY.js.map +1 -0
- package/dist/chunk-ws3bVwaS.d.ts +410 -0
- package/dist/chunk-xh3UkuVs.cjs +246 -0
- package/dist/chunk-xh3UkuVs.cjs.map +1 -0
- package/dist/chunk-yMzRr26E.js +153 -0
- package/dist/chunk-yMzRr26E.js.map +1 -0
- package/dist/collab/index.cjs +831 -0
- package/dist/collab/index.cjs.map +1 -0
- package/dist/collab/index.d.cts +824 -0
- package/dist/collab/index.d.ts +824 -0
- package/dist/collab/index.js +819 -0
- package/dist/collab/index.js.map +1 -0
- package/dist/data/index.cjs +39 -0
- package/dist/data/index.d.cts +6 -0
- package/dist/data/index.d.ts +6 -0
- package/dist/data/index.js +7 -0
- package/dist/editor/index.cjs +2713 -0
- package/dist/editor/index.cjs.map +1 -0
- package/dist/editor/index.d.cts +10 -0
- package/dist/editor/index.d.ts +10 -0
- package/dist/editor/index.js +2702 -0
- package/dist/editor/index.js.map +1 -0
- package/dist/errors/index.cjs +11 -0
- package/dist/errors/index.d.cts +2 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/index.js +1 -0
- package/dist/geo/index.cjs +68 -0
- package/dist/geo/index.d.cts +6 -0
- package/dist/geo/index.d.ts +6 -0
- package/dist/geo/index.js +11 -0
- package/dist/i18n/fr/index.cjs +333 -0
- package/dist/i18n/fr/index.cjs.map +1 -0
- package/dist/i18n/fr/index.d.cts +18 -0
- package/dist/i18n/fr/index.d.ts +18 -0
- package/dist/i18n/fr/index.js +328 -0
- package/dist/i18n/fr/index.js.map +1 -0
- package/dist/i18n/index.cjs +451 -0
- package/dist/i18n/index.cjs.map +1 -0
- package/dist/i18n/index.d.cts +268 -0
- package/dist/i18n/index.d.ts +268 -0
- package/dist/i18n/index.js +430 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/icons/index.cjs +37 -0
- package/dist/icons/index.d.cts +4 -0
- package/dist/icons/index.d.ts +4 -0
- package/dist/icons/index.js +8 -0
- package/dist/index.cjs +517 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +174 -0
- package/dist/index.d.ts +174 -0
- package/dist/index.js +54 -0
- package/dist/index.js.map +1 -0
- package/dist/layers/index.cjs +83 -0
- package/dist/layers/index.d.cts +3 -0
- package/dist/layers/index.d.ts +3 -0
- package/dist/layers/index.js +5 -0
- package/dist/map-client/index.cjs +5 -0
- package/dist/map-client/index.d.cts +6 -0
- package/dist/map-client/index.d.ts +6 -0
- package/dist/map-client/index.js +0 -0
- package/dist/maplibre-worker.mjs +12 -0
- package/dist/navigation/index.cjs +612 -0
- package/dist/navigation/index.cjs.map +1 -0
- package/dist/navigation/index.d.cts +551 -0
- package/dist/navigation/index.d.ts +551 -0
- package/dist/navigation/index.js +599 -0
- package/dist/navigation/index.js.map +1 -0
- package/dist/profile/index.cjs +177 -0
- package/dist/profile/index.d.cts +8 -0
- package/dist/profile/index.d.ts +8 -0
- package/dist/profile/index.js +10 -0
- package/dist/seams/index.cjs +15 -0
- package/dist/seams/index.d.cts +4 -0
- package/dist/seams/index.d.ts +4 -0
- package/dist/seams/index.js +4 -0
- package/dist/search/index.cjs +39 -0
- package/dist/search/index.d.cts +6 -0
- package/dist/search/index.d.ts +6 -0
- package/dist/search/index.js +3 -0
- package/dist/style/index.cjs +34 -0
- package/dist/style/index.d.cts +5 -0
- package/dist/style/index.d.ts +5 -0
- package/dist/style/index.js +5 -0
- package/dist/styles.css +11 -0
- package/dist/testing/index.cjs +444 -0
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.cts +217 -0
- package/dist/testing/index.d.ts +217 -0
- package/dist/testing/index.js +435 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/timezone/index.cjs +1953 -0
- package/dist/timezone/index.cjs.map +1 -0
- package/dist/timezone/index.d.cts +28 -0
- package/dist/timezone/index.d.ts +28 -0
- package/dist/timezone/index.js +1948 -0
- package/dist/timezone/index.js.map +1 -0
- package/dist/units/index.cjs +29 -0
- package/dist/units/index.d.cts +3 -0
- package/dist/units/index.d.ts +3 -0
- package/dist/units/index.js +3 -0
- package/dist/video/index.cjs +1713 -0
- package/dist/video/index.cjs.map +1 -0
- package/dist/video/index.d.cts +846 -0
- package/dist/video/index.d.ts +846 -0
- package/dist/video/index.js +1689 -0
- package/dist/video/index.js.map +1 -0
- package/dist/view/index.cjs +7 -0
- package/dist/view/index.d.cts +3 -0
- package/dist/view/index.d.ts +3 -0
- package/dist/view/index.js +1 -0
- package/package.json +433 -4
- package/src/agent/engines/session.ts +2255 -0
- package/src/agent/index.ts +109 -0
- package/src/agent/rules/agentError.ts +128 -0
- package/src/agent/rules/boundedInputJson.ts +53 -0
- package/src/agent/rules/conversation.ts +629 -0
- package/src/agent/rules/conversationFaults.ts +349 -0
- package/src/agent/rules/conversationHost.ts +390 -0
- package/src/agent/rules/dispatcher.ts +102 -0
- package/src/agent/rules/errorCodes.ts +78 -0
- package/src/agent/rules/errorStatus.ts +65 -0
- package/src/agent/rules/scriptedTransport.ts +390 -0
- package/src/agent/rules/stickToBottom.ts +38 -0
- package/src/agent/rules/toolResultPayload.ts +197 -0
- package/src/auth/rules/clientHeader.ts +22 -0
- package/src/auth/rules/sentCredential.ts +76 -0
- package/src/auth/rules/transformRequest.ts +803 -0
- package/src/camera/engines/videoFlight.ts +1758 -0
- package/src/camera/index.ts +157 -0
- package/src/camera/rules/clearance.ts +1099 -0
- package/src/camera/rules/fit.ts +132 -0
- package/src/camera/rules/modes.ts +1019 -0
- package/src/camera/rules/plan.ts +478 -0
- package/src/camera/rules/planner.ts +129 -0
- package/src/camera/rules/poseRanges.ts +38 -0
- package/src/camera/rules/presets.ts +185 -0
- package/src/camera/rules/profileSamples.ts +243 -0
- package/src/camera/rules/route.ts +596 -0
- package/src/camera/rules/routeContent.ts +105 -0
- package/src/camera/rules/spline.ts +765 -0
- package/src/camera/rules/sweptViewports.ts +39 -0
- package/src/camera/rules/track.ts +1412 -0
- package/src/camera/rules/vocabulary.ts +130 -0
- package/src/camera/rules/zoom.ts +216 -0
- package/src/collab/engines/session.ts +1902 -0
- package/src/collab/engines/trailingThrottle.ts +151 -0
- package/src/collab/index.ts +52 -0
- package/src/collab/rules/dispatch.ts +143 -0
- package/src/collab/rules/peerNames.ts +51 -0
- package/src/collab/rules/scriptedTransport.ts +244 -0
- package/src/compose/engines/baseMapSwitch.ts +1136 -0
- package/src/compose/engines/events.ts +962 -0
- package/src/compose/engines/mountayaMap.ts +5648 -0
- package/src/compose/engines/sentCredentials.ts +146 -0
- package/src/compose/engines/slotRequests.ts +413 -0
- package/src/compose/rules/accessRefusal.ts +109 -0
- package/src/compose/rules/accessStanding.ts +75 -0
- package/src/compose/rules/analysisKinds.ts +331 -0
- package/src/compose/rules/analysisLayers.ts +176 -0
- package/src/compose/rules/cameraMoves.ts +38 -0
- package/src/compose/rules/carriedLayers.ts +87 -0
- package/src/compose/rules/developmentWarnings.ts +167 -0
- package/src/compose/rules/fitBox.ts +67 -0
- package/src/compose/rules/fitCamera.ts +54 -0
- package/src/compose/rules/geoJsonSlot.ts +61 -0
- package/src/compose/rules/geometrySlots.ts +155 -0
- package/src/compose/rules/glyphNode.ts +62 -0
- package/src/compose/rules/layerKeys.ts +92 -0
- package/src/compose/rules/layerOrder.ts +85 -0
- package/src/compose/rules/layersManifest.ts +26 -0
- package/src/compose/rules/mapOptions.ts +300 -0
- package/src/compose/rules/maplibreWorkerVersion.gen.ts +8 -0
- package/src/compose/rules/markerPin.ts +122 -0
- package/src/compose/rules/markerRegistry.ts +85 -0
- package/src/compose/rules/markerSprite.ts +382 -0
- package/src/compose/rules/maxBounds.ts +120 -0
- package/src/compose/rules/overlayLookup.ts +49 -0
- package/src/compose/rules/paintDiff.ts +38 -0
- package/src/compose/rules/panLock.ts +77 -0
- package/src/compose/rules/patch.ts +124 -0
- package/src/compose/rules/queriedFeature.ts +55 -0
- package/src/compose/rules/queryLayers.ts +46 -0
- package/src/compose/rules/searchHighlight.ts +313 -0
- package/src/compose/rules/slotNames.ts +19 -0
- package/src/compose/rules/stripeImage.ts +253 -0
- package/src/compose/rules/swapMarker.ts +66 -0
- package/src/compose/rules/terrainVariant.ts +88 -0
- package/src/compose/rules/types.ts +559 -0
- package/src/compose/rules/urlHash.ts +19 -0
- package/src/compose/rules/viewOptions.ts +451 -0
- package/src/compose/rules/workerUrl.ts +131 -0
- package/src/data/engines/itineraryResource.ts +643 -0
- package/src/data/index.ts +78 -0
- package/src/data/rules/adapt.ts +473 -0
- package/src/data/rules/editModes.ts +51 -0
- package/src/data/rules/itinerary.ts +168 -0
- package/src/data/rules/nullable.ts +63 -0
- package/src/data/rules/roadAccess.ts +169 -0
- package/src/data/rules/segmentGroups.ts +309 -0
- package/src/data/rules/selectors.ts +95 -0
- package/src/data/rules/zones.ts +79 -0
- package/src/draw/engines/boundaryEngine.ts +1003 -0
- package/src/draw/engines/framedAdapter.ts +198 -0
- package/src/draw/engines/pointerCursor.ts +205 -0
- package/src/draw/engines/segmentEngine.ts +1405 -0
- package/src/draw/engines/snapIndex.ts +254 -0
- package/src/draw/engines/waypointEngine.ts +574 -0
- package/src/draw/engines/zoneEngine.ts +1137 -0
- package/src/draw/rules/drawFrame.ts +123 -0
- package/src/draw/rules/insertVertex.ts +226 -0
- package/src/draw/rules/screenSpace.ts +62 -0
- package/src/draw/rules/seeds.ts +185 -0
- package/src/draw/rules/snap.ts +115 -0
- package/src/draw/rules/snapCameraKey.ts +50 -0
- package/src/draw/rules/terraDrawShared.ts +214 -0
- package/src/draw/rules/zoneOutline.ts +213 -0
- package/src/editing/engines/cursor.ts +505 -0
- package/src/editing/engines/draftMarker.ts +149 -0
- package/src/editing/rules/accent.ts +11 -0
- package/src/editing/rules/engine.ts +288 -0
- package/src/editing/rules/placement.ts +22 -0
- package/src/editing/rules/positions.ts +89 -0
- package/src/editing/rules/sources.ts +9 -0
- package/src/editing/rules/types.ts +457 -0
- package/src/editing/rules/vocabulary.ts +10 -0
- package/src/editing/rules/waypointCursor.ts +228 -0
- package/src/editor/engines/directionArrows.ts +459 -0
- package/src/editor/engines/directions.ts +1383 -0
- package/src/editor/engines/editorClient.ts +134 -0
- package/src/editor/engines/eventScope.ts +59 -0
- package/src/editor/engines/frameLoop.ts +159 -0
- package/src/editor/engines/itineraryPreview.ts +272 -0
- package/src/editor/engines/mapLockGuard.ts +66 -0
- package/src/editor/engines/overlayRenderer.ts +2696 -0
- package/src/editor/engines/peerDraft.ts +760 -0
- package/src/editor/engines/poiPick.ts +305 -0
- package/src/editor/engines/pointPick.ts +84 -0
- package/src/editor/engines/roadAccessLine.ts +140 -0
- package/src/editor/engines/searchHighlight.ts +183 -0
- package/src/editor/engines/viewClient.ts +4091 -0
- package/src/editor/engines/zoneBadges.ts +503 -0
- package/src/editor/index.ts +97 -0
- package/src/editor/rules/accentColor.ts +116 -0
- package/src/editor/rules/camera.ts +121 -0
- package/src/editor/rules/contract.ts +120 -0
- package/src/editor/rules/icons.ts +825 -0
- package/src/editor/rules/markerElements.ts +244 -0
- package/src/editor/rules/style.ts +51 -0
- package/src/editor/rules/terrain.ts +98 -0
- package/src/editor/rules/tileWarm.ts +191 -0
- package/src/editor/rules/tilesReload.ts +158 -0
- package/src/editor/rules/zoneBadgePlacement.ts +1832 -0
- package/src/editor/rules/zoneTimeStyling.ts +119 -0
- package/src/errors/index.ts +25 -0
- package/src/errors/rules/errors.ts +158 -0
- package/src/errors/rules/print.ts +129 -0
- package/src/geo/index.ts +89 -0
- package/src/geo/rules/boundaries.ts +105 -0
- package/src/geo/rules/camera.ts +496 -0
- package/src/geo/rules/corridor.ts +242 -0
- package/src/geo/rules/elevationTiles.ts +269 -0
- package/src/geo/rules/formatLngLat.ts +63 -0
- package/src/geo/rules/geodesy.ts +125 -0
- package/src/geo/rules/geometry.ts +362 -0
- package/src/geo/rules/lineWalk.ts +77 -0
- package/src/geo/rules/longitude.ts +99 -0
- package/src/geo/rules/searchLimits.ts +22 -0
- package/src/geo/rules/segmentGeometry.ts +80 -0
- package/src/geo/rules/terrain.ts +107 -0
- package/src/geo/rules/tuples.ts +124 -0
- package/src/geo/rules/types.ts +54 -0
- package/src/geo/rules/webMercator.ts +57 -0
- package/src/i18n/fr/index.ts +17 -0
- package/src/i18n/fr/rules/fr.ts +85 -0
- package/src/i18n/fr/rules/words.gen.ts +277 -0
- package/src/i18n/index.ts +82 -0
- package/src/i18n/rules/bundle.ts +378 -0
- package/src/i18n/rules/config.ts +71 -0
- package/src/i18n/rules/dates.ts +165 -0
- package/src/i18n/rules/endonyms.gen.ts +19 -0
- package/src/i18n/rules/language.ts +92 -0
- package/src/i18n/rules/localizedName.ts +33 -0
- package/src/i18n/rules/merge.ts +106 -0
- package/src/i18n/rules/scope.ts +127 -0
- package/src/i18n/rules/strings.ts +632 -0
- package/src/i18n/rules/videoOverlay.ts +121 -0
- package/src/i18n/rules/wordForms.ts +95 -0
- package/src/i18n/rules/words.gen.ts +277 -0
- package/src/icons/index.ts +54 -0
- package/src/icons/rules/activities.ts +40 -0
- package/src/icons/rules/amenities.ts +250 -0
- package/src/icons/rules/artwork.gen.ts +83 -0
- package/src/icons/rules/artwork.ts +47 -0
- package/src/icons/rules/fallback.ts +21 -0
- package/src/icons/rules/lucideMarkers.gen.ts +112 -0
- package/src/icons/rules/lucideUi.gen.ts +197 -0
- package/src/icons/rules/paint.ts +107 -0
- package/src/icons/rules/parse.ts +475 -0
- package/src/icons/rules/provider.ts +373 -0
- package/src/icons/rules/sprites.ts +54 -0
- package/src/icons/rules/ui.ts +348 -0
- package/src/icons/rules/waypoints.ts +215 -0
- package/src/index.ts +993 -0
- package/src/layers/engines/layersSelection.ts +515 -0
- package/src/layers/engines/readoutEngine.ts +131 -0
- package/src/layers/index.ts +151 -0
- package/src/layers/rules/analysis.ts +135 -0
- package/src/layers/rules/enrichment.ts +30 -0
- package/src/layers/rules/geoJson.ts +270 -0
- package/src/layers/rules/hover.ts +67 -0
- package/src/layers/rules/itineraries.ts +182 -0
- package/src/layers/rules/layersPanel.ts +237 -0
- package/src/layers/rules/order.ts +194 -0
- package/src/layers/rules/overlayInstant.ts +49 -0
- package/src/layers/rules/overlays.ts +52 -0
- package/src/layers/rules/poiPanel.ts +119 -0
- package/src/layers/rules/pois.ts +114 -0
- package/src/layers/rules/readout.ts +340 -0
- package/src/layers/rules/streetView.ts +16 -0
- package/src/layers/rules/tileTimestamp.ts +146 -0
- package/src/layers/rules/timeSlider.ts +192 -0
- package/src/layers/rules/timeWindow.ts +123 -0
- package/src/layers/rules/zones.ts +43 -0
- package/src/layers/rules/zoom.ts +77 -0
- package/src/map-client/index.ts +71 -0
- package/src/map-client/rules/mapClient.ts +1945 -0
- package/src/navigation/engines/navigation.ts +493 -0
- package/src/navigation/index.ts +51 -0
- package/src/navigation/rules/followedRoute.ts +78 -0
- package/src/navigation/rules/instructions.ts +89 -0
- package/src/navigation/rules/itineraryRoute.ts +232 -0
- package/src/navigation/rules/offRoute.ts +41 -0
- package/src/navigation/rules/progress.ts +230 -0
- package/src/navigation/rules/prompts.ts +217 -0
- package/src/navigation/rules/routeRequest.ts +98 -0
- package/src/navigation/rules/status.ts +142 -0
- package/src/navigation/rules/steps.ts +234 -0
- package/src/navigation/rules/types.ts +83 -0
- package/src/profile/index.ts +307 -0
- package/src/profile/rules/amenityBadge.ts +35 -0
- package/src/profile/rules/amenityFilter.ts +74 -0
- package/src/profile/rules/amenityStacks.ts +66 -0
- package/src/profile/rules/axis.ts +89 -0
- package/src/profile/rules/axisCulling.ts +83 -0
- package/src/profile/rules/axisLookup.ts +180 -0
- package/src/profile/rules/climbs.ts +292 -0
- package/src/profile/rules/cursorMarker.ts +122 -0
- package/src/profile/rules/cursorReadout.ts +104 -0
- package/src/profile/rules/curvePlacement.ts +216 -0
- package/src/profile/rules/dock.ts +293 -0
- package/src/profile/rules/elevation.ts +1263 -0
- package/src/profile/rules/instant.ts +89 -0
- package/src/profile/rules/intl.ts +237 -0
- package/src/profile/rules/legEmphasis.ts +53 -0
- package/src/profile/rules/profileColors.ts +66 -0
- package/src/profile/rules/profileLayout.ts +59 -0
- package/src/profile/rules/profileSlices.ts +55 -0
- package/src/profile/rules/routeProfile.ts +475 -0
- package/src/profile/rules/rowMatch.ts +50 -0
- package/src/profile/rules/scale.ts +646 -0
- package/src/profile/rules/scaleFrame.ts +171 -0
- package/src/profile/rules/sectionChips.ts +83 -0
- package/src/profile/rules/sections.ts +923 -0
- package/src/profile/rules/slopeRamp.ts +160 -0
- package/src/profile/rules/statStrip.ts +103 -0
- package/src/profile/rules/steepness.ts +51 -0
- package/src/profile/rules/tableCells.ts +269 -0
- package/src/profile/rules/tableCursor.ts +87 -0
- package/src/profile/rules/unitPatterns.ts +335 -0
- package/src/profile/rules/units.ts +1025 -0
- package/src/profile/rules/waypointCard.ts +590 -0
- package/src/profile/rules/webAddress.ts +130 -0
- package/src/profile/rules/windowSpans.ts +65 -0
- package/src/rules/asciiFold.ts +17 -0
- package/src/rules/inDevelopment.ts +54 -0
- package/src/rules/listeners.ts +62 -0
- package/src/rules/timers.ts +9 -0
- package/src/rules/types.ts +22 -0
- package/src/rules/uuid.ts +87 -0
- package/src/seams/engines/geolocateControl.ts +286 -0
- package/src/seams/index.ts +50 -0
- package/src/seams/rules/clock.ts +169 -0
- package/src/seams/rules/geolocation.ts +165 -0
- package/src/seams/rules/segmentRoute.ts +187 -0
- package/src/search/engines/search.ts +1093 -0
- package/src/search/index.ts +99 -0
- package/src/search/rules/describe.ts +383 -0
- package/src/search/rules/filters.ts +195 -0
- package/src/search/rules/highlight.ts +270 -0
- package/src/search/rules/pick.ts +90 -0
- package/src/search/rules/rows.ts +258 -0
- package/src/search/rules/searchFocus.ts +27 -0
- package/src/search/rules/searchViewport.ts +44 -0
- package/src/search/rules/shown.ts +77 -0
- package/src/search/rules/types.ts +340 -0
- package/src/stream/rules/reconnectSchedule.ts +83 -0
- package/src/style/engines/organizationRead.ts +80 -0
- package/src/style/index.ts +63 -0
- package/src/style/rules/apply.ts +268 -0
- package/src/style/rules/attribution.ts +119 -0
- package/src/style/rules/itineraryLine.ts +142 -0
- package/src/style/rules/language.ts +668 -0
- package/src/style/rules/layout.gen.ts +27 -0
- package/src/style/rules/organization.ts +96 -0
- package/src/style/rules/paint.ts +143 -0
- package/src/style/rules/panelLayout.ts +51 -0
- package/src/style/rules/roadAccessColors.ts +29 -0
- package/src/style/rules/roadAccessLine.ts +267 -0
- package/src/style/rules/segmentColors.ts +207 -0
- package/src/testing/catalogs.ts +103 -0
- package/src/testing/index.ts +30 -0
- package/src/testing/mapClient.ts +241 -0
- package/src/testing/mountayaMap.ts +741 -0
- package/src/timezone/index.ts +14 -0
- package/src/timezone/rules/viewport.ts +875 -0
- package/src/units/index.ts +55 -0
- package/src/units/rules/conversions.ts +620 -0
- package/src/units/rules/preferenceChoices.ts +124 -0
- package/src/units/rules/preferences.ts +77 -0
- package/src/units/rules/rounding.ts +69 -0
- package/src/video/engines/videoRun.ts +654 -0
- package/src/video/engines/viewClient.ts +6 -0
- package/src/video/index.ts +83 -0
- package/src/video/profileOverlay/rules/contract.ts +210 -0
- package/src/video/profileOverlay/rules/curve.ts +216 -0
- package/src/video/profileOverlay/rules/draw.ts +410 -0
- package/src/video/profileOverlay/rules/fonts.ts +54 -0
- package/src/video/profileOverlay/rules/graphDesign.ts +690 -0
- package/src/video/profileOverlay/rules/minimalDesign.ts +144 -0
- package/src/video/profileOverlay/rules/registry.ts +23 -0
- package/src/video/profileOverlay/rules/staticLayer.ts +582 -0
- package/src/video/profileOverlay/rules/stripDesign.ts +327 -0
- package/src/video/profileOverlay/rules/types.ts +78 -0
- package/src/video/rules/videoConstants.ts +250 -0
- package/src/video/rules/videoEncoder.ts +277 -0
- package/src/video/rules/videoFrames.ts +99 -0
- package/src/video/rules/videoPreview.ts +185 -0
- package/src/video/rules/videoRecorder.ts +746 -0
- package/src/video/rules/videoWatermark.ts +155 -0
- package/src/video/rules/watermarkMark.ts +40 -0
- package/src/view/engines/viewClient.ts +6 -0
- package/src/view/index.ts +20 -0
|
@@ -0,0 +1,4091 @@
|
|
|
1
|
+
import type { Feature, FeatureCollection, Geometry, LineString, Polygon, Position } from "geojson";
|
|
2
|
+
import {
|
|
3
|
+
type ErrorEvent,
|
|
4
|
+
type ExpressionSpecification,
|
|
5
|
+
LngLat,
|
|
6
|
+
type MapGeoJSONFeature,
|
|
7
|
+
type Map as MapLibreMap,
|
|
8
|
+
type MapMouseEvent,
|
|
9
|
+
type MapSourceDataEvent,
|
|
10
|
+
Marker,
|
|
11
|
+
} from "maplibre-gl";
|
|
12
|
+
|
|
13
|
+
import type { TileSchema } from "@mountaya/client";
|
|
14
|
+
|
|
15
|
+
import type { BoundsCamera } from "../../camera/rules/fit.js";
|
|
16
|
+
import { containerExtension } from "../../camera/rules/presets.js";
|
|
17
|
+
import {
|
|
18
|
+
isToldToNobody,
|
|
19
|
+
type MapEventEngine,
|
|
20
|
+
mapEventEngineOf,
|
|
21
|
+
} from "../../compose/engines/events.js";
|
|
22
|
+
import type { MountayaMap } from "../../compose/engines/mountayaMap.js";
|
|
23
|
+
import { accessRefusalSource, accessRefusalStatus } from "../../compose/rules/accessRefusal.js";
|
|
24
|
+
import {
|
|
25
|
+
type AccessAnswer,
|
|
26
|
+
accessStandingAfter,
|
|
27
|
+
type StandingRefusals,
|
|
28
|
+
} from "../../compose/rules/accessStanding.js";
|
|
29
|
+
import { fitCameraOn } from "../../compose/rules/fitCamera.js";
|
|
30
|
+
import { MARKER_SPRITE_PX } from "../../compose/rules/markerSprite.js";
|
|
31
|
+
import { readBoxLock } from "../../compose/rules/panLock.js";
|
|
32
|
+
import type { CameraPose, Overlay } from "../../compose/rules/types.js";
|
|
33
|
+
import { MAP_ZOOM_DEFAULT_CEILING, MAP_ZOOM_FLOOR } from "../../compose/rules/viewOptions.js";
|
|
34
|
+
import { type RoadAccessKind, roadAccessFeatures } from "../../data/rules/roadAccess.js";
|
|
35
|
+
import { CursorEngine } from "../../editing/engines/cursor.js";
|
|
36
|
+
import { DEFAULT_ACCENT } from "../../editing/rules/accent.js";
|
|
37
|
+
import type {
|
|
38
|
+
BoundaryEditEngine,
|
|
39
|
+
EmitBoundaryDraft,
|
|
40
|
+
EmitSegmentDraft,
|
|
41
|
+
EmitSegmentViaPrompt,
|
|
42
|
+
EmitWaypointDraftChange,
|
|
43
|
+
EmitZoneDraft,
|
|
44
|
+
SegmentEditEngine,
|
|
45
|
+
WaypointEditEngine,
|
|
46
|
+
ZoneEditEngine,
|
|
47
|
+
} from "../../editing/rules/engine.js";
|
|
48
|
+
import type { LayerPlacement } from "../../editing/rules/placement.js";
|
|
49
|
+
import { isGeoJsonSource } from "../../editing/rules/sources.js";
|
|
50
|
+
import { errorFrom, MountayaElementsError } from "../../errors/rules/errors.js";
|
|
51
|
+
import { accuracyBounds, LOCATE_MAX_ZOOM, normalizeBoundingBox } from "../../geo/rules/camera.js";
|
|
52
|
+
import { geometriesEqual } from "../../geo/rules/geometry.js";
|
|
53
|
+
import { wrapLongitudePastRange } from "../../geo/rules/longitude.js";
|
|
54
|
+
import { groundMetersPerPixel } from "../../geo/rules/webMercator.js";
|
|
55
|
+
import type { IconProvider } from "../../icons/index.js";
|
|
56
|
+
import { LayerRank, poiSourceLayers } from "../../layers/rules/order.js";
|
|
57
|
+
import { notifyListeners, surfaceFault } from "../../rules/listeners.js";
|
|
58
|
+
import type { SegmentRoute } from "../../seams/rules/segmentRoute.js";
|
|
59
|
+
import { DEGREES_PER_TURN } from "../../units/rules/conversions.js";
|
|
60
|
+
import { accentHexAt } from "../rules/accentColor.js";
|
|
61
|
+
import type {
|
|
62
|
+
RecordingCamera,
|
|
63
|
+
RecordOutput,
|
|
64
|
+
RecordProfile,
|
|
65
|
+
VideoProgress,
|
|
66
|
+
VideoRecordingResult,
|
|
67
|
+
} from "../rules/camera.js";
|
|
68
|
+
import type {
|
|
69
|
+
BaseTerrainConfig,
|
|
70
|
+
BoundaryDraft,
|
|
71
|
+
BoundaryEditOptions,
|
|
72
|
+
BoundingBox,
|
|
73
|
+
ContextMenuZone,
|
|
74
|
+
FeatureHit,
|
|
75
|
+
FeatureHoverHandlers,
|
|
76
|
+
FeatureSubscriptionOptions,
|
|
77
|
+
FitBoundsPadding,
|
|
78
|
+
GeolocateResult,
|
|
79
|
+
ItineraryEmphasis,
|
|
80
|
+
ItineraryExclusions,
|
|
81
|
+
ItineraryPreviewRender,
|
|
82
|
+
MapClient,
|
|
83
|
+
MapConstraints,
|
|
84
|
+
MapContextMenuEvent,
|
|
85
|
+
MapPointerMove,
|
|
86
|
+
MapViewport,
|
|
87
|
+
MapViewportChange,
|
|
88
|
+
OverlayFeature,
|
|
89
|
+
OverlayZoomRange,
|
|
90
|
+
PeerDraftEntity,
|
|
91
|
+
PoiInfo,
|
|
92
|
+
PointPickChange,
|
|
93
|
+
PointPickOptions,
|
|
94
|
+
ProfileMarkerIcon,
|
|
95
|
+
SearchHighlight,
|
|
96
|
+
SegmentDraft,
|
|
97
|
+
SegmentEditOptions,
|
|
98
|
+
SegmentViaPromptEvent,
|
|
99
|
+
VideoSeam,
|
|
100
|
+
WaypointCursorOptions,
|
|
101
|
+
WaypointDraftSnapshot,
|
|
102
|
+
WaypointEditOptions,
|
|
103
|
+
WaypointEngineDraftChange,
|
|
104
|
+
ZoneDraft,
|
|
105
|
+
ZoneEditOptions,
|
|
106
|
+
} from "../rules/contract.js";
|
|
107
|
+
import { prebakeMarkerIcons, refuseUndrawableProvider } from "../rules/icons.js";
|
|
108
|
+
import {
|
|
109
|
+
buildMiniBearingMarkerElement,
|
|
110
|
+
buildProfileMarkerElement,
|
|
111
|
+
MINI_BEARING_ROTATOR_DATA,
|
|
112
|
+
profileMarkerIconKey,
|
|
113
|
+
} from "../rules/markerElements.js";
|
|
114
|
+
import { bakeTerrain } from "../rules/style.js";
|
|
115
|
+
import { queryTerrainElevation, sampleTerrainAt } from "../rules/terrain.js";
|
|
116
|
+
import { warmPosesThrough } from "../rules/tileWarm.js";
|
|
117
|
+
import {
|
|
118
|
+
DirectionArrowLayer,
|
|
119
|
+
DirectionFlowAnimator,
|
|
120
|
+
lineFromSegmentDraft,
|
|
121
|
+
} from "./directionArrows.js";
|
|
122
|
+
import { MapEventScopeEngine } from "./eventScope.js";
|
|
123
|
+
import { ItineraryPreviewLayer } from "./itineraryPreview.js";
|
|
124
|
+
import { MapLockGuard, type MapLockHolder } from "./mapLockGuard.js";
|
|
125
|
+
import { OverlayRenderer } from "./overlayRenderer.js";
|
|
126
|
+
import { PeerDraftLayer } from "./peerDraft.js";
|
|
127
|
+
import { PointPickEngine } from "./pointPick.js";
|
|
128
|
+
import type { MapClickQuery } from "./poiPick.js";
|
|
129
|
+
import { RoadAccessLineEngine } from "./roadAccessLine.js";
|
|
130
|
+
import { SearchHighlightLayer } from "./searchHighlight.js";
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The map client, as `MapLibreViewClient`: every command of `MapClient` over a MapLibre map,
|
|
134
|
+
* with no edit engine.
|
|
135
|
+
*
|
|
136
|
+
* `MapClient` is declared in `map-client` as a contract with no renderer in it, so a component,
|
|
137
|
+
* a tool handler and a test double all speak it without installing `maplibre-gl`; this module
|
|
138
|
+
* and `editorClient.ts`, which adds the edit engines as `MapLibreClient`, implement it.
|
|
139
|
+
*
|
|
140
|
+
* What is here is what a published map cannot hold on its own. `MountayaMap` from
|
|
141
|
+
* `@mountaya/elements` owns the parts a licensee also needs (the ranked layer registry, the
|
|
142
|
+
* style swap and its replay, layer visibility, the map's language, and the exclusive category
|
|
143
|
+
* overlay and stacking enrichment slots), and this delegates every one of them rather than
|
|
144
|
+
* keeping a second answer. Around that sit the things that are a studio's rather than anyone's
|
|
145
|
+
* map: the peer draft and itinerary preview layers, Street View coverage, and the cursor and
|
|
146
|
+
* lock guards. The edit engines are not among them. They stand on `terra-draw` and the
|
|
147
|
+
* directions plugin, and `editorClient.ts` gives them to `MapLibreClient`, so a host of this
|
|
148
|
+
* module's `MapLibreViewClient` installs neither.
|
|
149
|
+
*
|
|
150
|
+
* Recording is NOT among them, and the difference is the point. It arrives as an optional
|
|
151
|
+
* `VideoSeam` rather than a field, so the encoder is a dependency of whoever wants a video
|
|
152
|
+
* and of nobody else: a map asked only to draw a route never loads one. The glyph set the
|
|
153
|
+
* waypoint cursor is painted from is the map's own (`MountayaMap.icons`), because the markup
|
|
154
|
+
* is licensed and cannot be redistributed. An absent recorder has a defined behavior, which is
|
|
155
|
+
* what lets this class be mounted by a host that supplies none.
|
|
156
|
+
*
|
|
157
|
+
* Two collaborators carry state this file reads back rather than recomputing: the
|
|
158
|
+
* `MapEventEngine` every listener is routed through, so a listener can be removed by
|
|
159
|
+
* reference on dispose and deferred work lands on the style that survives a swap; and the
|
|
160
|
+
* `OverlayRenderer`, which holds the desired ALWAYS-ON tile sources (the itineraries and
|
|
161
|
+
* zones) so a terrain switch replays them onto the fresh style with their emphasis,
|
|
162
|
+
* exclusions and edit styling intact. The overlays and enrichments beside them are the
|
|
163
|
+
* façade's; what the renderer keeps for those is the studio's own paint, re-applied through
|
|
164
|
+
* the mount hook so it survives the same switch.
|
|
165
|
+
*/
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* MapLibreClientOptions is what the host supplies at construction: the recorder the map cannot
|
|
169
|
+
* carry itself, and the one fact about the URL it cannot observe.
|
|
170
|
+
*
|
|
171
|
+
* Every field is optional and every absence has a defined behavior rather than a broken one: no
|
|
172
|
+
* recorder means the recording methods report unsupported, and no hash means the map wrote its
|
|
173
|
+
* own. That is what makes the map mountable by a consumer who wants a route on a page and
|
|
174
|
+
* nothing else.
|
|
175
|
+
*/
|
|
176
|
+
export interface MapLibreClientOptions {
|
|
177
|
+
/**
|
|
178
|
+
* Whether the map was constructed with a MapLibre `#view` hash on the URL: a genuine
|
|
179
|
+
* publisher default view, captured before the map writes its own `#view` on the first
|
|
180
|
+
* move, so the embed can defer its fit to a real captured view.
|
|
181
|
+
*/
|
|
182
|
+
initialViewHash?: boolean | undefined;
|
|
183
|
+
/**
|
|
184
|
+
* The recording subsystem. Absent, the map previews and records nothing and carries no
|
|
185
|
+
* video encoder in its bundle.
|
|
186
|
+
*/
|
|
187
|
+
video?: VideoSeam | undefined;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// The Street View coverage raster is the façade's: source id, layer id, tile URL and rank
|
|
191
|
+
// all live there, so nothing here names them.
|
|
192
|
+
//
|
|
193
|
+
// The Street View corridor band: a soft line drawn along the embedded itinerary
|
|
194
|
+
// during a pegman drag, marking the droppable zone where Street View is bounded to
|
|
195
|
+
// the route. It replaces the global coverage overlay on the embed surface.
|
|
196
|
+
const SV_CORRIDOR_SOURCE = "sv-corridor";
|
|
197
|
+
const SV_CORRIDOR_LAYER = "sv-corridor-layer";
|
|
198
|
+
// Google's coverage tiles are tinted with their brand blue (hue 217); the
|
|
199
|
+
// overlay rotates that hue toward the host's accent so it reads as ours.
|
|
200
|
+
const GOOGLE_BLUE_HUE = 217;
|
|
201
|
+
// The minimum per-side padding (in degrees) prewarmTerrain adds around a route's
|
|
202
|
+
// bounds before fitting, so a short route (whose bbox span is tiny) still frames
|
|
203
|
+
// enough surrounding terrain for the camera eye and its sightline samples to land
|
|
204
|
+
// on loaded tiles. ~0.02° is on the order of a kilometer, matching the eye's
|
|
205
|
+
// typical ground offset.
|
|
206
|
+
const TERRAIN_PREWARM_MIN_PAD_DEG = 0.02;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* poiCategory reads the OpenMapTiles class/subclass that names what a feature is.
|
|
210
|
+
* `subclass` is the more specific value (e.g. "restaurant", "hotel") and is
|
|
211
|
+
* preferred; `class` is the coarser fallback (e.g. "accommodation"). A feature
|
|
212
|
+
* carrying neither (some `road`/`parking` geometries) yields an empty category,
|
|
213
|
+
* which the caller drops so only nameable POIs surface.
|
|
214
|
+
*/
|
|
215
|
+
const poiCategory = (properties: Record<string, unknown>): string => {
|
|
216
|
+
const subclass = properties.subclass;
|
|
217
|
+
if (typeof subclass === "string" && subclass.length > 0) {
|
|
218
|
+
return subclass;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const klass = properties.class;
|
|
222
|
+
|
|
223
|
+
return typeof klass === "string" ? klass : "";
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* featureToPoi maps a queried vector feature to the {@link PoiInfo} a POI query and a POI pick
|
|
228
|
+
* read, or null when it carries neither a name nor a category: a bare road or parking polygon
|
|
229
|
+
* names no place. The name is the feature's `name` string when present and null otherwise, so an
|
|
230
|
+
* unnamed feature with a category, a viewpoint, still surfaces; the category comes from class or
|
|
231
|
+
* subclass. The id is the tile feature's id written as a string, null when the tile carries none.
|
|
232
|
+
*/
|
|
233
|
+
const featureToPoi = (feature: MapGeoJSONFeature): PoiInfo | null => {
|
|
234
|
+
const properties = feature.properties ?? {};
|
|
235
|
+
const category = poiCategory(properties);
|
|
236
|
+
const rawName = properties.name;
|
|
237
|
+
const name = typeof rawName === "string" && rawName.length > 0 ? rawName : null;
|
|
238
|
+
|
|
239
|
+
// A feature with no name and no category names nothing the popup can show, so
|
|
240
|
+
// it is dropped rather than surfaced as an empty row.
|
|
241
|
+
if (name === null && category === "") {
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return { category, id: feature.id === undefined ? null : String(feature.id), name };
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* featureToHit maps a rendered tile feature to the platform-neutral FeatureHit
|
|
250
|
+
* the layer-event seam emits: the feature's id (null when the tile carries none),
|
|
251
|
+
* the source-layer it was drawn from when it has one, and a flat properties map of
|
|
252
|
+
* its display primitives. It keeps string, number,
|
|
253
|
+
* and boolean values (and explicit null), dropping nested-object values a vector
|
|
254
|
+
* tile rarely carries, so every value matches the FeatureHit property union and
|
|
255
|
+
* the raw renderer feature never crosses MapClient. The id is the tile feature
|
|
256
|
+
* id (a segment or waypoint id on the itinerary layers), not a property.
|
|
257
|
+
*/
|
|
258
|
+
const featureToHit = (feature: MapGeoJSONFeature): FeatureHit => {
|
|
259
|
+
const properties: FeatureHit["properties"] = {};
|
|
260
|
+
for (const [key, value] of Object.entries(feature.properties ?? {})) {
|
|
261
|
+
if (
|
|
262
|
+
value === null ||
|
|
263
|
+
typeof value === "string" ||
|
|
264
|
+
typeof value === "number" ||
|
|
265
|
+
typeof value === "boolean"
|
|
266
|
+
) {
|
|
267
|
+
properties[key] = value;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return feature.sourceLayer === undefined
|
|
272
|
+
? { id: feature.id ?? null, properties }
|
|
273
|
+
: { id: feature.id ?? null, properties, sourceLayer: feature.sourceLayer };
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
// The vector feature property keys the overlay-feature readout drops: the
|
|
277
|
+
// renderer's synthetic feature id (and the OpenMapTiles `_symbol` rank) name
|
|
278
|
+
// nothing the popup shows, so they are skipped rather than surfaced as rows.
|
|
279
|
+
const overlayInternalKeys = new Set<string>(["id", "_symbol"]);
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* featureToOverlayFeature cleans a queried overlay vector feature's properties
|
|
283
|
+
* into an OverlayFeature: it keeps the display primitives (string/number/boolean)
|
|
284
|
+
* the popup can render, drops null/undefined values and the renderer's internal
|
|
285
|
+
* keys (a synthetic feature id, the symbol rank), and returns null when nothing
|
|
286
|
+
* displayable remains: a feature carrying only internal/empty keys names no
|
|
287
|
+
* readout. Non-primitive property values (a nested object a vector tile rarely
|
|
288
|
+
* carries) are dropped too, so every retained value is a primitive the popup
|
|
289
|
+
* shows as text, as the tile states it, with no unit applied.
|
|
290
|
+
*/
|
|
291
|
+
const featureToOverlayFeature = (feature: MapGeoJSONFeature): OverlayFeature | null => {
|
|
292
|
+
const properties = feature.properties ?? {};
|
|
293
|
+
const cleaned: OverlayFeature = {};
|
|
294
|
+
for (const [key, value] of Object.entries(properties)) {
|
|
295
|
+
if (overlayInternalKeys.has(key) || value === null || value === undefined) {
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
300
|
+
cleaned[key] = value;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// A feature whose only properties were internal or empty names nothing the
|
|
305
|
+
// popup can show, so it is dropped rather than surfaced as an empty row.
|
|
306
|
+
return Object.keys(cleaned).length === 0 ? null : cleaned;
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* zoneEpochProperty reads a zone tile feature's temporal-bound property as epoch
|
|
311
|
+
* seconds, or null when the bound is unset. The zone tile emits start_at/end_at
|
|
312
|
+
* as `extract(epoch from …)` (a number) and omits the key (or carries null) for an
|
|
313
|
+
* unbounded zone, so a numeric value passes through and anything else maps to null,
|
|
314
|
+
* the "no bound" the ContextMenuZone schema expects.
|
|
315
|
+
*/
|
|
316
|
+
const zoneEpochProperty = (properties: Record<string, unknown>, key: string): number | null => {
|
|
317
|
+
const value = properties[key];
|
|
318
|
+
|
|
319
|
+
return typeof value === "number" ? value : null;
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* featureToContextMenuZone maps a queried zone tile feature to a ContextMenuZone,
|
|
324
|
+
* or null when it carries no zone id (a non-zone feature that slipped through the
|
|
325
|
+
* layer scope). The zone tile carries its UUID as the `id` PROPERTY (not the tile
|
|
326
|
+
* feature id) alongside the name, level, description, the start_at/end_at
|
|
327
|
+
* epoch-second window, and the owning organization_id: the properties the zone
|
|
328
|
+
* tile specification documents and the popup shows. The name, description and
|
|
329
|
+
* level fall back to empty strings so a feature missing one still renders the
|
|
330
|
+
* rest; the organization_id is null when the tile omits it, which it does for a
|
|
331
|
+
* personal zone.
|
|
332
|
+
*/
|
|
333
|
+
const featureToContextMenuZone = (feature: MapGeoJSONFeature): ContextMenuZone | null => {
|
|
334
|
+
const properties = feature.properties ?? {};
|
|
335
|
+
const rawId = properties.id;
|
|
336
|
+
// The zone id property is the one indispensable field: without it the popup has
|
|
337
|
+
// no zone to show, so a feature missing it is dropped (it is not a zone tile).
|
|
338
|
+
if (typeof rawId !== "string" || rawId.length === 0) {
|
|
339
|
+
return null;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const description = typeof properties.description === "string" ? properties.description : "";
|
|
343
|
+
const level = typeof properties.level === "string" ? properties.level : "";
|
|
344
|
+
const name = typeof properties.name === "string" ? properties.name : "";
|
|
345
|
+
const organizationId =
|
|
346
|
+
typeof properties.organization_id === "string" ? properties.organization_id : null;
|
|
347
|
+
|
|
348
|
+
return {
|
|
349
|
+
description,
|
|
350
|
+
endAt: zoneEpochProperty(properties, "end_at"),
|
|
351
|
+
id: rawId,
|
|
352
|
+
level,
|
|
353
|
+
name,
|
|
354
|
+
organizationId,
|
|
355
|
+
startAt: zoneEpochProperty(properties, "start_at"),
|
|
356
|
+
};
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* coordsEqual compares two [lng, lat(, …)] positions by value, element by
|
|
361
|
+
* element. Two positions of a different length are unequal (a 2D vs 3D via).
|
|
362
|
+
*/
|
|
363
|
+
const coordsEqual = (a: Position, b: Position): boolean =>
|
|
364
|
+
a.length === b.length && a.every((value, index) => value === b[index]);
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* segmentSeedsEqual reports whether two segment-edit seeds are value-equal: the
|
|
368
|
+
* editable handle coordinates (seedVias) matched coordinate by coordinate and both
|
|
369
|
+
* pinned boundaries matched (or both absent). beginSegmentEdit compares an incoming
|
|
370
|
+
* re-arm against the last ARMED seed with it: SegmentDraftEngine, which the editing
|
|
371
|
+
* hook drives, arms the edit again whenever an arming input changes and hands the
|
|
372
|
+
* client a fresh copy of the seed each time, so an identity check would never hold
|
|
373
|
+
* even for an unchanged seed, and a working engine must not churn on a re-arm. Comparing
|
|
374
|
+
* against the armed seed (never the live draft) means a drag (which mutates the
|
|
375
|
+
* draft but not the session's seed) never re-triggers arming, while the co-pilot
|
|
376
|
+
* re-proposing new vias on the open edit does.
|
|
377
|
+
*/
|
|
378
|
+
const segmentSeedsEqual = (a: SegmentSeedRecord, b: SegmentSeedRecord): boolean => {
|
|
379
|
+
const aVias = a.seedVias ?? [];
|
|
380
|
+
const bVias = b.seedVias ?? [];
|
|
381
|
+
if (aVias.length !== bVias.length) {
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
for (const [index, via] of aVias.entries()) {
|
|
386
|
+
const other = bVias[index];
|
|
387
|
+
if (other === undefined || !coordsEqual(via, other)) {
|
|
388
|
+
return false;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
return (
|
|
393
|
+
pinsEqual(a.pinnedStart ?? null, b.pinnedStart ?? null) &&
|
|
394
|
+
pinsEqual(a.pinnedEnd ?? null, b.pinnedEnd ?? null)
|
|
395
|
+
);
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* SegmentSeedRecord is the arming seed {@link segmentSeedsEqual} compares: the
|
|
400
|
+
* editable handle coordinates plus the two optional pinned boundaries.
|
|
401
|
+
*/
|
|
402
|
+
interface SegmentSeedRecord {
|
|
403
|
+
pinnedEnd?: Position | null | undefined;
|
|
404
|
+
pinnedStart?: Position | null | undefined;
|
|
405
|
+
seedVias?: Position[] | undefined;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* pinsEqual compares two optional pinned boundary coordinates by value, treating
|
|
410
|
+
* an absent pin as equal only to another absent pin.
|
|
411
|
+
*/
|
|
412
|
+
const pinsEqual = (a: Position | null, b: Position | null): boolean =>
|
|
413
|
+
a === null || b === null ? a === null && b === null : coordsEqual(a, b);
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* HoverSubscription is one `onFeatureHover` caller: the layers it reads, which of their features
|
|
417
|
+
* it answers, the callbacks it fires, and whether the last hit-test found a feature it answers,
|
|
418
|
+
* which is what makes the next miss a leave.
|
|
419
|
+
*/
|
|
420
|
+
interface HoverSubscription {
|
|
421
|
+
readonly accepts: ((hit: FeatureHit) => boolean) | undefined;
|
|
422
|
+
readonly handlers: FeatureHoverHandlers;
|
|
423
|
+
inside: boolean;
|
|
424
|
+
readonly layerIds: ReadonlySet<string>;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* EditEngineSeams is what the client hands an edit engine it asks for: the map the engine draws
|
|
429
|
+
* on and the collaborators it shares with the client, so the engine's listeners, cursor writes
|
|
430
|
+
* and layers are torn down and stacked with the client's own.
|
|
431
|
+
*/
|
|
432
|
+
interface EditEngineSeams {
|
|
433
|
+
/** The cursor engine every edit pins and releases its cursor through. */
|
|
434
|
+
readonly cursor: CursorEngine;
|
|
435
|
+
/** The client's event scope, so the engine's listeners are swept with the client's. */
|
|
436
|
+
readonly events: MapEventEngine;
|
|
437
|
+
/** The MapLibre map the engine draws on. */
|
|
438
|
+
readonly map: MapLibreMap;
|
|
439
|
+
/** The map's one stacking registry, for an engine that adds a layer of its own. */
|
|
440
|
+
readonly placement: LayerPlacement;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/** WaypointEngineSeams adds what a waypoint edit reads beside {@link EditEngineSeams}. */
|
|
444
|
+
interface WaypointEngineSeams extends EditEngineSeams {
|
|
445
|
+
/** The glyph set and the canvas size the live cursor of a `point` edit is drawn with. */
|
|
446
|
+
readonly cursorOptions: WaypointCursorOptions;
|
|
447
|
+
/** The map reads a `poi-pick` edit makes: clicks, pointer moves and the POIs at a coordinate. */
|
|
448
|
+
readonly pick: MapClickQuery;
|
|
449
|
+
/** The active itinerary's lines a `point` edit snaps onto, read again on each click. */
|
|
450
|
+
readonly snapSegments: () => readonly Position[][];
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* AnyEditEngine is the engine of any edit family, as a base-map switch reads it:
|
|
455
|
+
* a library stopped before the swap and started again on the incoming style.
|
|
456
|
+
*/
|
|
457
|
+
type AnyEditEngine = BoundaryEditEngine | SegmentEditEngine | WaypointEditEngine | ZoneEditEngine;
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* EditEngineFactories builds the engine behind each edit family.
|
|
461
|
+
*
|
|
462
|
+
* It is a record the client is given and never imports. The engines stand on `terra-draw`, its
|
|
463
|
+
* MapLibre adapter and `@maplibre/maplibre-gl-directions`, and a client that named them would
|
|
464
|
+
* make every host of a map client install all three, a host that only shows a map included.
|
|
465
|
+
* {@link MapLibreViewClient} holds no record and refuses an edit, and `MapLibreClient` from
|
|
466
|
+
* `@mountaya/elements/editor` holds the one built from those engines.
|
|
467
|
+
*
|
|
468
|
+
* Each factory returns an engine that has attached and seeded itself, and each is handed the
|
|
469
|
+
* sink the engine reports its draft through.
|
|
470
|
+
*/
|
|
471
|
+
export interface EditEngineFactories {
|
|
472
|
+
/** Builds the engine of one boundary edit. */
|
|
473
|
+
readonly boundary: (
|
|
474
|
+
seams: EditEngineSeams,
|
|
475
|
+
options: BoundaryEditOptions,
|
|
476
|
+
emitDraft: EmitBoundaryDraft,
|
|
477
|
+
) => BoundaryEditEngine;
|
|
478
|
+
/** Refuses a boundary edit whose engine would refuse to be built, and builds nothing. */
|
|
479
|
+
readonly refuseBoundary: (options: BoundaryEditOptions) => void;
|
|
480
|
+
/**
|
|
481
|
+
* Refuses a segment edit whose engine would refuse to be built, and builds nothing.
|
|
482
|
+
*
|
|
483
|
+
* The client reads it, and its siblings, before it ends the edit a begin replaces, so a
|
|
484
|
+
* refused begin leaves that edit open and drawing.
|
|
485
|
+
*/
|
|
486
|
+
readonly refuseSegment: (options: SegmentEditOptions) => void;
|
|
487
|
+
/** Refuses a waypoint edit whose engine would refuse to be built, and builds nothing. */
|
|
488
|
+
readonly refuseWaypoint: (options: WaypointEditOptions) => void;
|
|
489
|
+
/** Refuses a zone edit whose engine would refuse to be built, and builds nothing. */
|
|
490
|
+
readonly refuseZone: (options: ZoneEditOptions) => void;
|
|
491
|
+
/** Builds the engine of one segment edit, for the mode `options` names. */
|
|
492
|
+
readonly segment: (
|
|
493
|
+
seams: EditEngineSeams,
|
|
494
|
+
options: SegmentEditOptions,
|
|
495
|
+
emitDraft: EmitSegmentDraft,
|
|
496
|
+
emitViaPrompt: EmitSegmentViaPrompt,
|
|
497
|
+
) => SegmentEditEngine;
|
|
498
|
+
/** Builds the engine of one waypoint edit, for the mode `options` names. */
|
|
499
|
+
readonly waypoint: (
|
|
500
|
+
seams: WaypointEngineSeams,
|
|
501
|
+
options: WaypointEditOptions,
|
|
502
|
+
emitDraftChange: EmitWaypointDraftChange,
|
|
503
|
+
) => WaypointEditEngine;
|
|
504
|
+
/** Builds the engine of one zone edit, for the mode `options` names. */
|
|
505
|
+
readonly zone: (
|
|
506
|
+
seams: EditEngineSeams,
|
|
507
|
+
options: ZoneEditOptions,
|
|
508
|
+
emitDraft: EmitZoneDraft,
|
|
509
|
+
) => ZoneEditEngine;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* The edit engine record bound to a client class's prototype, or to one client.
|
|
514
|
+
*
|
|
515
|
+
* It is a module-private table rather than a member a subclass overrides, so the declarations
|
|
516
|
+
* of the published clients name no record type: the engines are built in, and no host supplies
|
|
517
|
+
* one.
|
|
518
|
+
*/
|
|
519
|
+
const editEngineRecords = new WeakMap<object, EditEngineFactories>();
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* bindEditEngines gives a client the factories its edits are built with: a class's prototype,
|
|
523
|
+
* so every instance of the class edits, or one client.
|
|
524
|
+
*
|
|
525
|
+
* `MapLibreClient` binds its prototype in `editorClient.ts`, the one module that names the
|
|
526
|
+
* drawing engines.
|
|
527
|
+
*/
|
|
528
|
+
export const bindEditEngines = (
|
|
529
|
+
holder: MapLibreViewClient,
|
|
530
|
+
factories: EditEngineFactories,
|
|
531
|
+
): void => {
|
|
532
|
+
editEngineRecords.set(holder, factories);
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* MapLibreViewClient is the MapLibre implementation of {@link MapClient} that holds no edit
|
|
537
|
+
* engine: it draws, moves the camera, answers queries and drives a recording, and it refuses
|
|
538
|
+
* an edit.
|
|
539
|
+
*
|
|
540
|
+
* It is the client of a host that shows a map and never edits one, such as a fly-through over a
|
|
541
|
+
* line the host already holds, and `@mountaya/elements/view` publishes it
|
|
542
|
+
* (`@mountaya/elements/video` publishes it again beside the flight). Its import graph reaches none
|
|
543
|
+
* of `terra-draw`, `terra-draw-maplibre-gl-adapter` and `@maplibre/maplibre-gl-directions`, so that
|
|
544
|
+
* host installs none of them. `MapLibreClient` from `@mountaya/elements/editor` is this class with
|
|
545
|
+
* the edit engines built in, and every other member is the same.
|
|
546
|
+
*
|
|
547
|
+
* `beginSegmentEdit`, `beginWaypointEdit`, `beginZoneEdit` and `beginBoundaryEdit` throw a
|
|
548
|
+
* {@link MountayaElementsError} that names `@mountaya/elements/editor`, and leave the client as
|
|
549
|
+
* it was. A point pick draws nothing and works on both classes.
|
|
550
|
+
*
|
|
551
|
+
* Every listener the client attaches is held in a scope of its own over the map's events, so
|
|
552
|
+
* `dispose()` removes each one by reference and leaves the map's, and a new client over the same
|
|
553
|
+
* map listens. The always-on tile sources are tracked so a base-map switch replays them onto the
|
|
554
|
+
* fresh style.
|
|
555
|
+
*
|
|
556
|
+
* @example
|
|
557
|
+
* ```ts
|
|
558
|
+
* import type { MountayaMap } from "@mountaya/elements";
|
|
559
|
+
* import { MapLibreViewClient, VideoRunEngine } from "@mountaya/elements/video";
|
|
560
|
+
*
|
|
561
|
+
* declare const map: MountayaMap;
|
|
562
|
+
*
|
|
563
|
+
* const client = new MapLibreViewClient(map, {
|
|
564
|
+
* video: new VideoRunEngine(map.raw, map.events, () => map.loadOrganization()),
|
|
565
|
+
* });
|
|
566
|
+
* ```
|
|
567
|
+
*/
|
|
568
|
+
export class MapLibreViewClient implements MapClient {
|
|
569
|
+
// The MapLibre map underneath, held directly because nearly every seam below
|
|
570
|
+
// writes native style state MountayaMap does not wrap. Reaching for it is the
|
|
571
|
+
// escape hatch the map names `raw`; what must NOT come through it is a layer
|
|
572
|
+
// add or remove, because that steps outside the one rank registry: those go
|
|
573
|
+
// through MountayaMap, via the overlay renderer.
|
|
574
|
+
private readonly map: MapLibreMap;
|
|
575
|
+
// The scope every listener the client and its engines attach is held in: dispose()
|
|
576
|
+
// detaches those by reference and leaves the map's own, so the map outlives the client
|
|
577
|
+
// and a new client over it listens. What a base-map switch decides (afterStyleLoad,
|
|
578
|
+
// whenSettled, isStyleReloading) it reads from the map's engine, which announces every
|
|
579
|
+
// switch. It reads as disposed once the client or the map is.
|
|
580
|
+
private readonly events: MapEventEngine;
|
|
581
|
+
// The map's own event engine, which outlives the client: dispose() hands it the one write that
|
|
582
|
+
// must still land on a style that is loading, the indicator's removal.
|
|
583
|
+
private readonly mapEvents: MapEventEngine;
|
|
584
|
+
// Owns the canvas cursor and the lock an itinerary edit holds over it: every
|
|
585
|
+
// cursor write funnels through it so a feature-hover leave cannot clear a
|
|
586
|
+
// pinned edit cursor. Its mouseout re-assert listener is registered through
|
|
587
|
+
// the same event engine, so dispose sweeps it.
|
|
588
|
+
private readonly cursor: CursorEngine;
|
|
589
|
+
// The tile-overlay + itinerary render surface: it owns the desired tile
|
|
590
|
+
// sources, the drawn layer ids, the per-layer visibility, the deterministic
|
|
591
|
+
// stacking-rank working set, and the itinerary emphasis/exclusion/edit state,
|
|
592
|
+
// and exposes the commands that (re-)paint them. The itinerary is drawn by the
|
|
593
|
+
// tile layers, so tiles + itinerary rendering are one collaborator.
|
|
594
|
+
// Constructed with the map + the client's event scope; the missing-image resolver it
|
|
595
|
+
// installs is cleared by the scope's dispose().
|
|
596
|
+
private readonly overlay: OverlayRenderer;
|
|
597
|
+
// The one stacking registry, handed to every renderer and edit engine that adds a
|
|
598
|
+
// layer of its own. It is a callback pair over the overlay rather than the overlay
|
|
599
|
+
// itself: the borrowers are constructed before it, and they only ever call during a
|
|
600
|
+
// paint, by which point it exists.
|
|
601
|
+
private readonly placement: LayerPlacement;
|
|
602
|
+
// The last constraints applied via setConstraints. They are map-level (they
|
|
603
|
+
// survive setStyle), but are re-asserted at the end of setBaseTerrain so a
|
|
604
|
+
// terrain switch can never drop them.
|
|
605
|
+
private lastConstraints: MapConstraints | null = null;
|
|
606
|
+
// The active segment-edit engine (the directions SDK engine for a `directions`
|
|
607
|
+
// edit, the freehand TerraDraw engine for a `linestring` edit), built per
|
|
608
|
+
// edit on beginSegmentEdit and disposed on endSegmentEdit, so at most one
|
|
609
|
+
// segment engine is ever attached and a client that never edits never
|
|
610
|
+
// constructs either (nor pays their bundle). Null between edits.
|
|
611
|
+
private segmentEditEngine: SegmentEditEngine | null = null;
|
|
612
|
+
// The segment id and mode the active engine targets, tracked so beginSegmentEdit is idempotent
|
|
613
|
+
// for a re-call with the same {segmentId, mode}: SegmentDraftEngine arms the edit again whenever
|
|
614
|
+
// an arming input changes, and an unchanged session must NOT churn a working engine. A different
|
|
615
|
+
// segment or mode disposes the existing engine before constructing the next.
|
|
616
|
+
private segmentEditEngineSegmentId: string | null = null;
|
|
617
|
+
private segmentEditEngineMode: SegmentEditOptions["mode"] | null = null;
|
|
618
|
+
// The seed (editable handle coordinates + pinned boundaries) the active engine was
|
|
619
|
+
// ARMED with, tracked so beginSegmentEdit's idempotency check can value-compare
|
|
620
|
+
// it against a re-arm: an unchanged {segmentId, mode, seed} re-call leaves the
|
|
621
|
+
// engine in place (a re-render must not churn a working edit), while a CHANGED
|
|
622
|
+
// seed on the same segment + mode (the co-pilot re-proposing new vias on the
|
|
623
|
+
// open edit) disposes and rebuilds so the engine re-seeds. Held here rather
|
|
624
|
+
// than read off the live draft so a mid-edit drag (which mutates the draft, not
|
|
625
|
+
// the armed seed) never trips the re-seed. Null between edits.
|
|
626
|
+
private segmentEditEngineSeed: SegmentSeedRecord | null = null;
|
|
627
|
+
// The active waypoint-edit engine (the TerraDraw point engine for a `point`
|
|
628
|
+
// edit, the POI-pick engine for a `poi-pick` edit), built per edit on
|
|
629
|
+
// beginWaypointEdit and disposed on endWaypointEdit. Mirrors the segment
|
|
630
|
+
// family's lifecycle so the two engine groups read as parallel by
|
|
631
|
+
// construction; mutual exclusion across families is enforced one level up
|
|
632
|
+
// at the tool layer. Null between edits.
|
|
633
|
+
private waypointEditEngine: WaypointEditEngine | null = null;
|
|
634
|
+
// The waypoint id and mode the active waypoint engine targets, tracked for
|
|
635
|
+
// the same idempotency reason as the segment fields above.
|
|
636
|
+
private waypointEditEngineWaypointId: string | null = null;
|
|
637
|
+
private waypointEditEngineMode: WaypointEditOptions["mode"] | null = null;
|
|
638
|
+
// The segment-draft subscribers, held on the client (not the per-edit
|
|
639
|
+
// engine) so the seam survives an engine swap between modes and outlives an
|
|
640
|
+
// individual edit: the editor subscribes once for the whole session and
|
|
641
|
+
// every engine emits into this one set. Detached on dispose.
|
|
642
|
+
private readonly segmentDraftSubscribers = new Set<(draft: SegmentDraft) => void>();
|
|
643
|
+
// The segment via-prompt subscribers, held on the client for the same reason as
|
|
644
|
+
// the segment-draft subscribers. Fires discretely: once per gesture that landed
|
|
645
|
+
// on an existing handle, which the engine hands over instead of acting on.
|
|
646
|
+
private readonly segmentViaPromptSubscribers = new Set<(prompt: SegmentViaPromptEvent) => void>();
|
|
647
|
+
// The waypoint-draft-change subscribers, held on the client for the same
|
|
648
|
+
// reason as the segment-draft subscribers. Fires discretely (once per click
|
|
649
|
+
// that produces a change). See WaypointEngineDraftChange.
|
|
650
|
+
private readonly waypointDraftChangeSubscribers = new Set<
|
|
651
|
+
(change: WaypointEngineDraftChange) => void
|
|
652
|
+
>();
|
|
653
|
+
// The active point-pick engine: the generic "click the map to pick a
|
|
654
|
+
// coordinate" primitive built per pick on beginPointPick and disposed on
|
|
655
|
+
// endPointPick. Mirrors the segment/waypoint engine lifecycle so the three
|
|
656
|
+
// read as parallel by construction; mutual exclusion across families is
|
|
657
|
+
// enforced one level up at the tool layer. Null between picks. The pick has
|
|
658
|
+
// no id or mode to track (it is target-keyed only, and target rides on the
|
|
659
|
+
// begin call, not the engine), so unlike the segment/waypoint fields there is
|
|
660
|
+
// no idempotency key here: a repeated begin always replaces the prior pick.
|
|
661
|
+
private pointPickEngine: PointPickEngine | null = null;
|
|
662
|
+
// The point-pick-change subscribers, held on the client (not the per-pick
|
|
663
|
+
// engine) for the same reason as the segment-/waypoint-draft subscribers: the
|
|
664
|
+
// seam outlives an engine swap, so a caller subscribes once for the whole
|
|
665
|
+
// session. Fires discretely (once per armed click). See PointPickChange.
|
|
666
|
+
private readonly pointPickChangeSubscribers = new Set<(change: PointPickChange) => void>();
|
|
667
|
+
// The active zone-edit engine: the TerraDraw zone engine built per edit on
|
|
668
|
+
// beginZoneEdit and disposed on endZoneEdit, so at most one zone engine is ever
|
|
669
|
+
// attached. Mirrors the segment/waypoint engine lifecycle so the authoring
|
|
670
|
+
// families read as parallel by construction; mutual exclusion across families is
|
|
671
|
+
// enforced one level up at the tool layer. Null between edits.
|
|
672
|
+
private zoneEditEngine: ZoneEditEngine | null = null;
|
|
673
|
+
// The zone id and mode the active zone engine targets, tracked for the same
|
|
674
|
+
// idempotency reason as the segment/waypoint fields: the editing hook arms the
|
|
675
|
+
// edit on every (client, session) change, and an unchanged session must not
|
|
676
|
+
// churn a working engine. A different zone or mode disposes the active engine
|
|
677
|
+
// before constructing the next.
|
|
678
|
+
private zoneEditEngineZoneId: string | null = null;
|
|
679
|
+
private zoneEditEngineMode: ZoneEditOptions["mode"] | null = null;
|
|
680
|
+
// The colour the active zone engine draws in, so a begin that repeats the edit restyles it
|
|
681
|
+
// only when the colour it states is another.
|
|
682
|
+
private zoneEditEngineColor: string | null = null;
|
|
683
|
+
// The zone-draft subscribers, held on the client (not the per-edit engine) so
|
|
684
|
+
// the seam survives an engine swap and outlives an individual edit, the same
|
|
685
|
+
// posture as the segment-draft subscribers. Detached on dispose.
|
|
686
|
+
private readonly zoneDraftSubscribers = new Set<(draft: ZoneDraft) => void>();
|
|
687
|
+
// The active boundary-edit engine: the TerraDraw rectangle engine built per edit
|
|
688
|
+
// on beginBoundaryEdit and disposed on endBoundaryEdit, so at most one is ever
|
|
689
|
+
// attached. Mirrors the other authoring families' engine lifecycle. Null between
|
|
690
|
+
// edits.
|
|
691
|
+
private boundaryEditEngine: BoundaryEditEngine | null = null;
|
|
692
|
+
// The feature id the active boundary engine targets, tracked for the same
|
|
693
|
+
// idempotency reason as the other families: a re-arm for the same region must not
|
|
694
|
+
// churn a working engine, while a different region disposes it first.
|
|
695
|
+
private boundaryEditEngineFeatureId: string | null = null;
|
|
696
|
+
// The boundary-draft subscribers, held on the client (not the per-edit engine) so
|
|
697
|
+
// the seam survives an engine swap and outlives an individual edit. Detached on
|
|
698
|
+
// dispose.
|
|
699
|
+
private readonly boundaryDraftSubscribers = new Set<(draft: BoundaryDraft) => void>();
|
|
700
|
+
// The lock an authoring edit (any edit family, or a point pick) holds over the
|
|
701
|
+
// map: the base-map-switch block setBaseTerrain reads to refuse a terrain swap
|
|
702
|
+
// mid-edit so a swap cannot wipe the editable feature. Drag-pan is NOT part of
|
|
703
|
+
// it: each engine owns pan itself (panning empty map while editing, disabling
|
|
704
|
+
// only while dragging a handle). Every family acquires it on begin* and releases
|
|
705
|
+
// it on end* through the same guard, so the lock is provably identical across edits.
|
|
706
|
+
// Constructed with the map in the constructor.
|
|
707
|
+
private readonly lock: MapLockGuard;
|
|
708
|
+
// The base-map switch asked for while an edit held the lock, or null when none is held. An
|
|
709
|
+
// edit refuses the swap, which would wipe the feature being edited, and the last one asked
|
|
710
|
+
// for is applied when the edit ends, so the map and the terrain its caller chose agree again.
|
|
711
|
+
private heldBaseTerrain: BaseTerrainConfig | null = null;
|
|
712
|
+
// The edit engines whose replay is queued behind a style that is loading. An engine is in it
|
|
713
|
+
// from the moment its replay is queued until that replay runs, so one stopped for a swap is
|
|
714
|
+
// started again once, however many switches and begins asked for it meanwhile.
|
|
715
|
+
private readonly enginesAwaitingReplay = new Set<AnyEditEngine>();
|
|
716
|
+
// The single marker echoing the elevation profile's hovered position, moved as
|
|
717
|
+
// the chart cursor sweeps and removed when it leaves; held so a new position
|
|
718
|
+
// moves the one marker rather than stacking, and dispose removes it.
|
|
719
|
+
private profileMarker: Marker | null = null;
|
|
720
|
+
// The head descriptor the live marker was built with, reduced to a comparable
|
|
721
|
+
// key. A Marker cannot be restyled after construction, so this is what tells a
|
|
722
|
+
// move apart from a hand-off between the two surfaces that drive the marker (the
|
|
723
|
+
// elevation chart's activity pin and an armed gesture's own glyph).
|
|
724
|
+
private profileMarkerIconKey: string | null = null;
|
|
725
|
+
// The single bearing marker the Street View mini-map drops at the panorama
|
|
726
|
+
// position, rotated by the live panorama heading. Held so a new position moves
|
|
727
|
+
// the one marker rather than stacking, and the modal unmount + dispose remove
|
|
728
|
+
// it.
|
|
729
|
+
private miniBearingMarker: Marker | null = null;
|
|
730
|
+
// Counts the placements and clears of that marker asked for so far, so a first placement
|
|
731
|
+
// held behind the render can tell whether it is still the last thing its caller asked.
|
|
732
|
+
private miniBearingPlacement = 0;
|
|
733
|
+
// The transient search-result render (a place pin, a POI icon, or a way
|
|
734
|
+
// polyline / dashed bounds / pin fallback chain) the search seam paints when a
|
|
735
|
+
// user picks a result. It owns its own source/layers + place-pin marker and
|
|
736
|
+
// tears down the previous render on every set, so at most one highlight is on
|
|
737
|
+
// screen. Constructed with the map + event engine in the constructor; dispose
|
|
738
|
+
// sweeps a lingering one.
|
|
739
|
+
private readonly searchHighlight: SearchHighlightLayer;
|
|
740
|
+
// The read-only render of collaborators' in-flight edits: one glowing, pulsing
|
|
741
|
+
// line / ring / zone outline per peer draft, in the peer's color, with a name
|
|
742
|
+
// label + endpoint puck on a segment ghost. It never arms TerraDraw; it survives a
|
|
743
|
+
// base-map switch through its own replay below, and owns one shared rAF pulse loop.
|
|
744
|
+
private readonly peerDraft: PeerDraftLayer;
|
|
745
|
+
// The read-only overlay painting a NON-PERSISTED itinerary draft (an import
|
|
746
|
+
// preview). A persisted itinerary paints through the always-on vector tiles, so
|
|
747
|
+
// this layer carries the only on-map render a draft (which has no tiles yet)
|
|
748
|
+
// gets. It owns its own GeoJSON source + line/symbol layers and survives a
|
|
749
|
+
// base-map switch via replay() (registered in setBaseTerrain alongside the
|
|
750
|
+
// edit engines' replay-after-reload) so a terrain swap mid-preview keeps the
|
|
751
|
+
// draft on screen. Constructed with the map in the constructor.
|
|
752
|
+
private readonly itineraryPreview: ItineraryPreviewLayer;
|
|
753
|
+
// The single requestAnimationFrame loop that streams the dashes of the edit-view direction
|
|
754
|
+
// flow, the one animated direction layer the map draws (the tile view draws static chevrons).
|
|
755
|
+
// dispose stops the loop and detaches its visibility listener.
|
|
756
|
+
private readonly flowAnimator: DirectionFlowAnimator;
|
|
757
|
+
// The edit-view direction indicator: the animated flow + chevrons that follow a
|
|
758
|
+
// segment's DRAFT geometry while it is being edited (the persisted tile copy of
|
|
759
|
+
// both is hidden by the overlay's edit styling). Re-added after a base-map switch
|
|
760
|
+
// via replay() in setBaseTerrain, alongside the itinerary preview. Constructed with
|
|
761
|
+
// the map in the constructor.
|
|
762
|
+
private readonly editDirectionArrows: DirectionArrowLayer;
|
|
763
|
+
// The latest line a draft asked the indicator to follow, waiting for the frame that draws
|
|
764
|
+
// it, and that frame. A drag reports a draft on every pointer move, and a write re-tiles the
|
|
765
|
+
// line in the renderer's worker, so the indicator is rewritten once a frame at most.
|
|
766
|
+
private editArrowLine: Position[] | null = null;
|
|
767
|
+
private editArrowFrame: number | null = null;
|
|
768
|
+
// Whether the indicator stands on the map: its first line is drawn at once, so the layers
|
|
769
|
+
// stand up in the turn the edit's first draft arrives.
|
|
770
|
+
private editArrowsDrawn = false;
|
|
771
|
+
// The latest line held for a style that cannot take a source yet, and whether a wait for that
|
|
772
|
+
// style is open: a base-map switch, or the style MapLibre sets again as a lost WebGL context
|
|
773
|
+
// returns, refuses a source in MapLibre's own words until it has loaded.
|
|
774
|
+
private editArrowHeld: Position[] | null = null;
|
|
775
|
+
private editArrowAwaitingStyle = false;
|
|
776
|
+
// The restricted stretches of the route a segment edit has routed, striped over the live line
|
|
777
|
+
// (the saved stripes of the segment are hidden by the overlay's edit styling). Re-added after a
|
|
778
|
+
// base-map switch via replay() in setBaseTerrain, beside the direction indicator.
|
|
779
|
+
private readonly editRoadAccess: RoadAccessLineEngine;
|
|
780
|
+
// The route the live stretches were last drawn from, so a draft that carries the same route
|
|
781
|
+
// (a drag of a via before the re-route answers) writes nothing, and the stretches waiting for
|
|
782
|
+
// a style that can take a source, drawn once it has loaded.
|
|
783
|
+
private editRoadAccessRoute: SegmentRoute | null = null;
|
|
784
|
+
private editRoadAccessHeld:
|
|
785
|
+
| readonly Feature<LineString, { readonly kind: RoadAccessKind }>[]
|
|
786
|
+
| null = null;
|
|
787
|
+
// The video-run subsystem, when the host supplied one: orchestrates a preview/record
|
|
788
|
+
// flight over the map (camera snapshot + restore, abort-signal lifecycle, the moving
|
|
789
|
+
// "you are here" dot) and owns the in-flight run. Optional, because recording carries
|
|
790
|
+
// a video encoder and a map that only draws a route should not: absent, the
|
|
791
|
+
// recording methods report unsupported and everything else works unchanged.
|
|
792
|
+
private readonly video?: VideoSeam | undefined;
|
|
793
|
+
// The glyph set every sprite, marker and cursor on this map is drawn from, taken off
|
|
794
|
+
// the map the host constructed. One seam, read in one place: a host chooses its glyphs
|
|
795
|
+
// when it builds the map, and nothing downstream can be handed a different set.
|
|
796
|
+
private readonly icons: IconProvider;
|
|
797
|
+
// The pair the waypoint edit engine paints its live cursor from. DERIVED rather than
|
|
798
|
+
// taken as an option, because the cursor is a preview of the marker the next click will
|
|
799
|
+
// land (same glyph set, same canvas size) and a second option to supply would be a
|
|
800
|
+
// second chance to supply a different one.
|
|
801
|
+
private readonly waypointCursor: WaypointCursorOptions;
|
|
802
|
+
// Whether the map was constructed with a MapLibre `#view` hash on the URL: a genuine
|
|
803
|
+
// publisher default view, captured by MapView before the map writes its own `#view` on
|
|
804
|
+
// the first move. Exposed through hadInitialViewHash so the embed can defer its fit to
|
|
805
|
+
// a real captured view while ignoring the self-written hash.
|
|
806
|
+
private readonly initialViewHash: boolean;
|
|
807
|
+
// The animation frames a settled tile refresh is still waiting on, by handle, so dispose
|
|
808
|
+
// cancels them. The refresh's idle listener needs no entry here: it is held by the event
|
|
809
|
+
// manager, whose dispose detaches it.
|
|
810
|
+
private readonly settleFrames = new Set<number>();
|
|
811
|
+
// The feature-hover subscriptions, in the order they were made. They share one map-level
|
|
812
|
+
// mousemove and one hit-test per animation frame: MapLibre answers a layer-scoped listener
|
|
813
|
+
// with a query of its own on every mousemove, and a hover needs an enter, a move and a leave
|
|
814
|
+
// listener on each layer, so listening per layer costs a hit-test per listener, per layer,
|
|
815
|
+
// per move.
|
|
816
|
+
private readonly hoverSubscriptions = new Set<HoverSubscription>();
|
|
817
|
+
// Every layer a hover subscription reads, each named once, in subscription order. Kept
|
|
818
|
+
// beside the subscriptions so a frame's hit-test does not rebuild the union.
|
|
819
|
+
private hoverLayerIds: string[] = [];
|
|
820
|
+
// Detaches the map-level mousemove and mouseout listeners the hover seam holds, or null
|
|
821
|
+
// while nothing is subscribed.
|
|
822
|
+
private detachHoverListeners: (() => void) | null = null;
|
|
823
|
+
// The pointer's latest position, in container pixels, waiting for the frame that hit-tests
|
|
824
|
+
// it. Null once that frame has read it, and when the pointer leaves the canvas.
|
|
825
|
+
private hoverPoint: MapMouseEvent["point"] | null = null;
|
|
826
|
+
// The animation frame the next hover hit-test waits on, or null when none is scheduled.
|
|
827
|
+
private hoverFrame: number | null = null;
|
|
828
|
+
// Where the pointer last was over the canvas, in container pixels. It outlives the hit-test
|
|
829
|
+
// that read it, so a subscription made under a pointer at rest can be told what is under
|
|
830
|
+
// it. Null when the pointer left the canvas, and while the seam holds no listener.
|
|
831
|
+
private hoverRestingPoint: MapMouseEvent["point"] | null = null;
|
|
832
|
+
// The animation frame the seam's teardown waits on once its last subscription ended, or
|
|
833
|
+
// null when none is scheduled. A subscription made before the frame runs withdraws it.
|
|
834
|
+
private hoverTeardownFrame: number | null = null;
|
|
835
|
+
// Whether the hover seam's last cursor write asked for the pointer. Held on the client
|
|
836
|
+
// rather than on a subscription, so a pointer cursor outlives the subscription that asked
|
|
837
|
+
// for it and the next hit-test off every feature still puts the base cursor back.
|
|
838
|
+
private hoverPointer = false;
|
|
839
|
+
// The refusals of access that stand, by the source each came from and `null` for a refusal
|
|
840
|
+
// that names no source (accessStandingAfter). Kept by the client from its construction,
|
|
841
|
+
// subscribed to or not, so the standing answer is there for a host that is handed the client
|
|
842
|
+
// after a refusal landed.
|
|
843
|
+
private refusedSources: StandingRefusals = new Set();
|
|
844
|
+
// The subscribers told when the last standing refusal ends.
|
|
845
|
+
private readonly tilesAccessRestoredSubscribers = new Set<() => void>();
|
|
846
|
+
// Detaches each `pointerleave` listener a caller has on the canvas, one function a listener.
|
|
847
|
+
private readonly pointerLeaveDetachers = new Set<() => void>();
|
|
848
|
+
// Ends each wait held behind a queued slot write, one function a wait. A wait takes its own
|
|
849
|
+
// out when the write lands, and dispose calls what is left, so a wait held behind work that
|
|
850
|
+
// a torn-down map will never finish has something to end it and a wait that ended leaves
|
|
851
|
+
// nothing behind.
|
|
852
|
+
private readonly slotWriteWaits = new Set<() => void>();
|
|
853
|
+
|
|
854
|
+
/**
|
|
855
|
+
* Builds the client over a map the host owns. Every listener the client attaches is held in a
|
|
856
|
+
* scope of its own over the map's events, so `dispose()` takes off those alone.
|
|
857
|
+
*
|
|
858
|
+
* @param mountayaMap The map the client draws on. Its glyph set (`icons`) is the one every
|
|
859
|
+
* sprite, marker and cursor of the client is drawn from.
|
|
860
|
+
* @param options The recorder, and whether the page URL carried a `#view` hash.
|
|
861
|
+
* @throws {MountayaElementsError} When the map's `icons.viewBox` is not a finite number above
|
|
862
|
+
* 0, or its `icons.strokeWidth` is not a finite number (above 0 under `stroke`, 0 or above
|
|
863
|
+
* under `fill`). The client attaches nothing before it refuses.
|
|
864
|
+
*/
|
|
865
|
+
constructor(
|
|
866
|
+
private readonly mountayaMap: MountayaMap,
|
|
867
|
+
// What the host supplies beside the map: the recording subsystem (a video encoder) and
|
|
868
|
+
// whether the page URL carried a `#view` hash. Both optional, both degrading to a defined
|
|
869
|
+
// behavior rather than to a broken one.
|
|
870
|
+
options: MapLibreClientOptions = {},
|
|
871
|
+
) {
|
|
872
|
+
// A glyph set no sprite can be drawn with is refused before the client attaches anything.
|
|
873
|
+
// A constructor that throws hands back no client to dispose, so a listener attached first
|
|
874
|
+
// would stay on the map's event engine.
|
|
875
|
+
refuseUndrawableProvider(
|
|
876
|
+
this.editEngines() === null ? "MapLibreViewClient" : "MapLibreClient",
|
|
877
|
+
mountayaMap.icons,
|
|
878
|
+
);
|
|
879
|
+
this.initialViewHash = options.initialViewHash ?? false;
|
|
880
|
+
this.video = options.video;
|
|
881
|
+
this.icons = mountayaMap.icons;
|
|
882
|
+
this.waypointCursor = { provider: mountayaMap.icons, size: MARKER_SPRITE_PX };
|
|
883
|
+
|
|
884
|
+
// The MapLibre map the facade holds, kept as a field because the studio's own cartography is
|
|
885
|
+
// written against it: the camera cluster (zoomIn/zoomOut/resetNorth/
|
|
886
|
+
// jumpToPose/getCameraPose/project/unproject) plus fitBounds, tryGeolocate, the two scoped
|
|
887
|
+
// feature queries, zoneAtPoint, setConstraints and sampleTerrainElevation. Each was measured
|
|
888
|
+
// against the facade and stays here: each is a one-line forward with no state between them, or
|
|
889
|
+
// carries a channel the facade does not (`animate: false`, accuracy framing, active-overlay
|
|
890
|
+
// scoping, a re-asserted `lastConstraints`, a synchronous read against a Promise). Routing them
|
|
891
|
+
// through the facade would swap `this.map.zoomIn()` for its own `this.raw.zoomIn()`: no logic
|
|
892
|
+
// removed, no invariant unified, and more forwards for every map double to carry. The seams
|
|
893
|
+
// that DO hold state (the one rank registry, the shared event engine, the style swap, layer
|
|
894
|
+
// visibility and the label language) go through the facade, which is the line between the two.
|
|
895
|
+
const map = mountayaMap.raw;
|
|
896
|
+
this.map = map;
|
|
897
|
+
this.mapEvents = mapEventEngineOf(mountayaMap);
|
|
898
|
+
this.events = new MapEventScopeEngine(map, this.mapEvents);
|
|
899
|
+
this.trackTilesAccess();
|
|
900
|
+
this.redrawEditsAsContextReturns();
|
|
901
|
+
this.cursor = new CursorEngine(map, this.events);
|
|
902
|
+
this.lock = new MapLockGuard();
|
|
903
|
+
// Every renderer that adds a layer of its own borrows the one stacking registry
|
|
904
|
+
// rather than keeping its own, so each lands in its band instead of on top of
|
|
905
|
+
// everything, and so `featuresAt`, which queries exactly the layers the registry
|
|
906
|
+
// knows, can see them. The calls are wrapped rather than passed by reference
|
|
907
|
+
// because the overlay is built below and these only run during a paint.
|
|
908
|
+
this.placement = {
|
|
909
|
+
addLayerOrdered: (spec, rank) => this.overlay.addLayerOrdered(spec, rank),
|
|
910
|
+
forgetLayerRank: (layerId) => this.overlay.forgetLayerRank(layerId),
|
|
911
|
+
};
|
|
912
|
+
this.itineraryPreview = new ItineraryPreviewLayer(map, this.placement);
|
|
913
|
+
this.searchHighlight = new SearchHighlightLayer(map, this.placement, this.events, this.icons);
|
|
914
|
+
this.peerDraft = new PeerDraftLayer(map, this.placement, this.events);
|
|
915
|
+
// The shared direction-flow animator. The edit-view layer registers its flow layer with it
|
|
916
|
+
// on each segment edit.
|
|
917
|
+
this.flowAnimator = new DirectionFlowAnimator(map);
|
|
918
|
+
this.editDirectionArrows = new DirectionArrowLayer(map, this.placement);
|
|
919
|
+
this.editRoadAccess = new RoadAccessLineEngine(map, this.placement, this.icons);
|
|
920
|
+
// The tile-overlay + itinerary render surface. It registers the missing-image sprite
|
|
921
|
+
// resolver through the client's event scope (so the scope's `dispose()` clears it) and
|
|
922
|
+
// warms the marker-sprite registry on construction, so the first paint of an itinerary or
|
|
923
|
+
// POI overlay finds every bounded-vocabulary sprite present.
|
|
924
|
+
this.overlay = new OverlayRenderer(mountayaMap, this.events);
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
/**
|
|
928
|
+
* beginSegmentEdit attaches a per-mode edit engine (directions SDK or TerraDraw)
|
|
929
|
+
* for the targeted segment and paints the segment as a dual render: its tile
|
|
930
|
+
* copy stays on screen at 75% opacity with a dashed line, and the editable
|
|
931
|
+
* overlay the engine draws renders on top at full opacity. The user sees the
|
|
932
|
+
* saved version alongside the in-progress edit, so an inadvertent change is
|
|
933
|
+
* obvious against the original. The map refuses a base-map switch for the
|
|
934
|
+
* duration of the edit; drag-pan is left to the engine.
|
|
935
|
+
*/
|
|
936
|
+
beginSegmentEdit(options: SegmentEditOptions): void {
|
|
937
|
+
// A disposed client has let go of the map: it arms nothing on it.
|
|
938
|
+
if (this.events.disposed) {
|
|
939
|
+
return;
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
// A begin its engine would refuse is refused first: before the edit that stands is ended,
|
|
943
|
+
// and before a re-call for that edit returns, so a refusal reads the same whatever is armed.
|
|
944
|
+
this.requireEditEngines("beginSegmentEdit").refuseSegment(options);
|
|
945
|
+
|
|
946
|
+
// Idempotent for the same {segmentId, mode} AND an unchanged seed:
|
|
947
|
+
// SegmentDraftEngine arms the edit again whenever an arming input changes, so
|
|
948
|
+
// an unchanged session re-call must not churn a working engine. The seed is
|
|
949
|
+
// VALUE-compared (not by identity: buildSegmentEditOptions copies the seed on
|
|
950
|
+
// every arming) so a re-arm carrying the SAME handles + pinned start
|
|
951
|
+
// early-returns exactly as a pure re-arm should, while a CHANGED seed on the
|
|
952
|
+
// same segment + mode (the co-pilot re-proposing new vias on the open edit)
|
|
953
|
+
// falls through to the dispose + rebuild below so the engine re-seeds on the
|
|
954
|
+
// new proposal. A different segment or mode disposes the active engine before
|
|
955
|
+
// constructing the next (the same path endSegmentEdit runs) so at most one
|
|
956
|
+
// engine is ever attached.
|
|
957
|
+
if (
|
|
958
|
+
this.segmentEditEngine &&
|
|
959
|
+
this.segmentEditEngineSegmentId === options.featureId &&
|
|
960
|
+
this.segmentEditEngineMode === options.mode &&
|
|
961
|
+
this.segmentEditEngineSeed !== null &&
|
|
962
|
+
segmentSeedsEqual(this.segmentEditEngineSeed, options)
|
|
963
|
+
) {
|
|
964
|
+
return;
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
if (this.segmentEditEngine) {
|
|
968
|
+
this.teardownSegmentEdit();
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
// Build the engine for the mode: the directions SDK engine routes the
|
|
972
|
+
// vias and draws the routed line internally; the freehand TerraDraw
|
|
973
|
+
// engine shapes a linestring. Both emit through the client-owned
|
|
974
|
+
// subscriber sinks, so the draft seam is identical regardless of which
|
|
975
|
+
// engine is active. The engine attaches + seeds itself in its constructor.
|
|
976
|
+
const segmentEngine = this.armEditEngine("segment", () => this.buildSegmentEngine(options));
|
|
977
|
+
this.segmentEditEngine = segmentEngine;
|
|
978
|
+
this.replayIfStyleReloading(segmentEngine);
|
|
979
|
+
this.segmentEditEngineSegmentId = options.featureId;
|
|
980
|
+
this.segmentEditEngineMode = options.mode;
|
|
981
|
+
// Record the seed the engine was armed with so a later re-arm can value-compare
|
|
982
|
+
// against it: a matching seed is the idempotent no-op above, a changed one
|
|
983
|
+
// re-seeds.
|
|
984
|
+
this.segmentEditEngineSeed = {
|
|
985
|
+
pinnedEnd: options.pinnedEnd ?? null,
|
|
986
|
+
pinnedStart: options.pinnedStart ?? null,
|
|
987
|
+
seedVias: options.seedVias ?? [],
|
|
988
|
+
};
|
|
989
|
+
|
|
990
|
+
// De-emphasize the edited segment's tile copy (75% opacity + dashed) so the
|
|
991
|
+
// user sees the saved version alongside the editable overlay rendered on top
|
|
992
|
+
// at full opacity. The id is remembered so endSegmentEdit restores exactly
|
|
993
|
+
// this segment's normal paint rather than rebuilding every layer.
|
|
994
|
+
this.overlay.setEditedSegment(options.featureId);
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
beginWaypointEdit(options: WaypointEditOptions): void {
|
|
998
|
+
// A disposed client has let go of the map: it arms nothing on it.
|
|
999
|
+
if (this.events.disposed) {
|
|
1000
|
+
return;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
// A begin its engine would refuse is refused first, as the segment family's is.
|
|
1004
|
+
this.requireEditEngines("beginWaypointEdit").refuseWaypoint(options);
|
|
1005
|
+
|
|
1006
|
+
// Idempotent for the same {waypointId, mode}: mirrors the segment
|
|
1007
|
+
// family's behavior so a hook arming on every (client, session) change
|
|
1008
|
+
// does not churn a working engine.
|
|
1009
|
+
if (
|
|
1010
|
+
this.waypointEditEngine &&
|
|
1011
|
+
this.waypointEditEngineWaypointId === options.waypointId &&
|
|
1012
|
+
this.waypointEditEngineMode === options.mode
|
|
1013
|
+
) {
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
if (this.waypointEditEngine) {
|
|
1018
|
+
this.teardownWaypointEdit();
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
const waypointEngine = this.armEditEngine("waypoint", () => this.buildWaypointEngine(options));
|
|
1022
|
+
this.waypointEditEngine = waypointEngine;
|
|
1023
|
+
this.replayIfStyleReloading(waypointEngine);
|
|
1024
|
+
this.waypointEditEngineWaypointId = options.waypointId;
|
|
1025
|
+
this.waypointEditEngineMode = options.mode;
|
|
1026
|
+
|
|
1027
|
+
// Suppress the edited waypoint's committed tile copy so it stops painting under
|
|
1028
|
+
// the live DraftWaypointMarker: without this a custom-point waypoint double-renders
|
|
1029
|
+
// (once from the vector tile keyed by waypoint_id, once from the draft DOM marker).
|
|
1030
|
+
// The id is the waypoint UUID the point tile carries as its `waypoint_id` property;
|
|
1031
|
+
// for a not-yet-persisted point it is a harmless no-op, for a reposition it hides
|
|
1032
|
+
// the committed copy, the same posture beginZoneEdit's setEditedZone takes.
|
|
1033
|
+
// endWaypointEdit clears it (on both cancel and save) so the committed point
|
|
1034
|
+
// repaints at its new position.
|
|
1035
|
+
this.overlay.setEditedWaypoint(options.waypointId);
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
endWaypointEdit(): void {
|
|
1039
|
+
this.teardownWaypointEdit();
|
|
1040
|
+
this.applyHeldBaseTerrain();
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
/** teardownWaypointEdit is endWaypointEdit without the base-map switch the edit held. */
|
|
1044
|
+
private teardownWaypointEdit(): void {
|
|
1045
|
+
this.waypointEditEngine?.dispose();
|
|
1046
|
+
this.waypointEditEngine = null;
|
|
1047
|
+
this.waypointEditEngineWaypointId = null;
|
|
1048
|
+
this.waypointEditEngineMode = null;
|
|
1049
|
+
|
|
1050
|
+
// Restore the edited waypoint's committed tile copy: clearing the excluded id drops
|
|
1051
|
+
// the suppression filter so the persisted point repaints once the live draft marker
|
|
1052
|
+
// is gone. It runs on BOTH cancel (waypointEditCancel) and save (waypointEditCommit):
|
|
1053
|
+
// on cancel the committed point reappears in place, on save
|
|
1054
|
+
// refreshItineraryTilesWhenSettled then moves it to the new position. Mirrors
|
|
1055
|
+
// endZoneEdit clearing setEditedZone(null).
|
|
1056
|
+
this.overlay.setEditedWaypoint(null);
|
|
1057
|
+
|
|
1058
|
+
// Release the base-map-switch block even on a defensive call when no engine
|
|
1059
|
+
// was active, so an end*Edit always leaves the terrain lock down.
|
|
1060
|
+
this.lock.release("waypoint");
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
beginPointPick(_options: PointPickOptions): void {
|
|
1064
|
+
// A disposed client has let go of the map: it arms nothing on it.
|
|
1065
|
+
if (this.events.disposed) {
|
|
1066
|
+
return;
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
// `target` (a route endpoint, or the point a segment is split at) rides on
|
|
1070
|
+
// the options for symmetry with the begin/end edit families and for the
|
|
1071
|
+
// app-side cursor tooltip + telemetry; the map leaf is target-agnostic (it
|
|
1072
|
+
// just captures clicks) so the option is not read here. Adding a target is
|
|
1073
|
+
// therefore a type-level widening with no branch to follow it here.
|
|
1074
|
+
// A repeated begin always replaces the prior pick: there
|
|
1075
|
+
// is no idempotency key (a point pick is target-keyed only, and the target
|
|
1076
|
+
// lives on this call rather than the engine), so disposing first guarantees
|
|
1077
|
+
// at most one pick engine is ever armed and that its lock acquire/release
|
|
1078
|
+
// stay balanced across the swap.
|
|
1079
|
+
if (this.pointPickEngine) {
|
|
1080
|
+
this.teardownPointPick();
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
// The engine acquires the base-map-switch block in its constructor and
|
|
1084
|
+
// releases it on dispose, so the lock stays balanced with the engine's
|
|
1085
|
+
// lifetime here, unlike the segment/waypoint families, which acquire on
|
|
1086
|
+
// the client. Drag-pan stays enabled (the guard never touches pan) so the
|
|
1087
|
+
// user can roam the map to the pick target before clicking. The engine
|
|
1088
|
+
// emits each click through the client-owned change sink.
|
|
1089
|
+
// The pick's clicks are taken (takeMapClicks): a click is the pick's, and the line or the
|
|
1090
|
+
// marker under it is not also selected, opened or armed for an edit.
|
|
1091
|
+
this.pointPickEngine = new PointPickEngine(
|
|
1092
|
+
(change) => this.emitPointPickChange(change),
|
|
1093
|
+
{ onMapClick: (cb) => this.takeMapClicks(cb) },
|
|
1094
|
+
this.lock,
|
|
1095
|
+
);
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
endPointPick(): void {
|
|
1099
|
+
this.teardownPointPick();
|
|
1100
|
+
this.applyHeldBaseTerrain();
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
/** teardownPointPick is endPointPick without the base-map switch the pick held. */
|
|
1104
|
+
private teardownPointPick(): void {
|
|
1105
|
+
// Disposing the engine detaches its click subscription and releases the
|
|
1106
|
+
// base-map-switch block (the engine owns the lock for its lifetime). A
|
|
1107
|
+
// defensive call with no engine armed is a no-op: no point pick raised the
|
|
1108
|
+
// lock, so there is nothing to lower.
|
|
1109
|
+
this.pointPickEngine?.dispose();
|
|
1110
|
+
this.pointPickEngine = null;
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
beginZoneEdit(options: ZoneEditOptions): void {
|
|
1114
|
+
// A disposed client has let go of the map: it arms nothing on it.
|
|
1115
|
+
if (this.events.disposed) {
|
|
1116
|
+
return;
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
// A begin its engine would refuse is refused first, as the segment family's is: a re-key
|
|
1120
|
+
// below keeps the engine, and the colour it then paints is one this read accepts.
|
|
1121
|
+
this.requireEditEngines("beginZoneEdit").refuseZone(options);
|
|
1122
|
+
|
|
1123
|
+
// Idempotent for the same {zoneId, mode}: the editing hook arms the edit on
|
|
1124
|
+
// every (client, session) change, so an unchanged session re-call must not
|
|
1125
|
+
// churn a working engine, the same guard the segment/waypoint families use. A
|
|
1126
|
+
// re-call that states another colour restyles the engine it keeps, as a re-key
|
|
1127
|
+
// below does. A different zone or mode disposes the active engine before
|
|
1128
|
+
// constructing the next, so at most one zone engine is ever attached.
|
|
1129
|
+
if (
|
|
1130
|
+
this.zoneEditEngine &&
|
|
1131
|
+
this.zoneEditEngineZoneId === options.featureId &&
|
|
1132
|
+
this.zoneEditEngineMode === options.mode
|
|
1133
|
+
) {
|
|
1134
|
+
this.restyleZoneEdit(this.zoneEditEngine, options.color);
|
|
1135
|
+
|
|
1136
|
+
return;
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
// Re-key in place: a create→edit promotion (the first save of a new zone)
|
|
1140
|
+
// swaps the client-minted draft id for the server's persisted id while the
|
|
1141
|
+
// SAME shape stays on the map. When the mode is unchanged and the incoming
|
|
1142
|
+
// seed equals the live engine's current geometry, this is the same engine
|
|
1143
|
+
// under a new id: so retarget it (re-point the suppressed tile id) WITHOUT
|
|
1144
|
+
// disposing + rebuilding, which would flicker the draw and drop the in-flight
|
|
1145
|
+
// shape. The editing hook re-fires beginZoneEdit on the id change with the
|
|
1146
|
+
// session draft as the seed, so this branch absorbs that re-arm with no churn;
|
|
1147
|
+
// no camera move happens here (only openForEdit frames the camera). A genuine
|
|
1148
|
+
// zone/mode swap (a different shape, or a different mode) falls through to the
|
|
1149
|
+
// dispose + rebuild below.
|
|
1150
|
+
if (
|
|
1151
|
+
this.zoneEditEngine &&
|
|
1152
|
+
this.zoneEditEngineMode === options.mode &&
|
|
1153
|
+
this.zoneEditEngineZoneId !== options.featureId &&
|
|
1154
|
+
geometriesEqual(options.seedGeometry ?? null, this.zoneEditEngine.readDraft())
|
|
1155
|
+
) {
|
|
1156
|
+
this.zoneEditEngineZoneId = options.featureId;
|
|
1157
|
+
// The zone under its new id is drawn in the colour this begin states, as a rebuilt
|
|
1158
|
+
// engine would draw it.
|
|
1159
|
+
this.restyleZoneEdit(this.zoneEditEngine, options.color);
|
|
1160
|
+
// Re-point the tile suppression onto the new (now persisted) id so the saved
|
|
1161
|
+
// copy of the just-created zone stays hidden under the live draft.
|
|
1162
|
+
this.overlay.setEditedZone(options.featureId);
|
|
1163
|
+
|
|
1164
|
+
return;
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
if (this.zoneEditEngine) {
|
|
1168
|
+
this.teardownZoneEdit();
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
// Build the engine for the mode: it arms the matching TerraDraw draw mode +
|
|
1172
|
+
// the select mode and attaches + seeds itself in its constructor, emitting
|
|
1173
|
+
// through the client-owned draft sink so the seam is identical to the segment
|
|
1174
|
+
// family's.
|
|
1175
|
+
const zoneEngine = this.armEditEngine("zone", () => this.buildZoneEngine(options));
|
|
1176
|
+
this.zoneEditEngine = zoneEngine;
|
|
1177
|
+
this.replayIfStyleReloading(zoneEngine);
|
|
1178
|
+
this.zoneEditEngineZoneId = options.featureId;
|
|
1179
|
+
this.zoneEditEngineMode = options.mode;
|
|
1180
|
+
this.zoneEditEngineColor = options.color;
|
|
1181
|
+
|
|
1182
|
+
// Suppress the edited zone's persisted tile copy so it stops painting
|
|
1183
|
+
// underneath the live TerraDraw feature: without this the zone double-renders
|
|
1184
|
+
// (once from the vector tile, once from the editable draw). The id is the zone
|
|
1185
|
+
// UUID the tile carries as its `id` property; for a fresh create it is not in
|
|
1186
|
+
// the tile yet so the filter is a harmless no-op, and for a reshape it hides
|
|
1187
|
+
// the persisted copy, the same posture beginSegmentEdit's setEditedSegment
|
|
1188
|
+
// takes for a not-yet-persisted segment. endZoneEdit clears it so the saved
|
|
1189
|
+
// geometry repaints.
|
|
1190
|
+
this.overlay.setEditedZone(options.featureId);
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
endZoneEdit(): void {
|
|
1194
|
+
this.teardownZoneEdit();
|
|
1195
|
+
this.applyHeldBaseTerrain();
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
/** teardownZoneEdit is endZoneEdit without the base-map switch the edit held. */
|
|
1199
|
+
private teardownZoneEdit(): void {
|
|
1200
|
+
// Dispose the active engine: it removes its rendered layers + sources, detaches
|
|
1201
|
+
// its TerraDraw change listener (clear → stop), and pops any vertex-hover cursor
|
|
1202
|
+
// override it pushed. The base "+" lock is owned by the hook, which releases it
|
|
1203
|
+
// on its own teardown.
|
|
1204
|
+
this.zoneEditEngine?.dispose();
|
|
1205
|
+
this.zoneEditEngine = null;
|
|
1206
|
+
this.zoneEditEngineZoneId = null;
|
|
1207
|
+
this.zoneEditEngineMode = null;
|
|
1208
|
+
this.zoneEditEngineColor = null;
|
|
1209
|
+
|
|
1210
|
+
// Restore the edited zone's tile copy: clearing the excluded id drops the
|
|
1211
|
+
// suppression filter so the persisted geometry repaints once the live feature
|
|
1212
|
+
// is gone. It runs BEFORE the edit teardown's refreshZoneTiles bust: editCancel
|
|
1213
|
+
// and the cross-family teardown tear the edit down (this call) and only then
|
|
1214
|
+
// refetch the tiles, so a reshape saved during the still-armed edit repaints
|
|
1215
|
+
// against a layer whose filter is already back to the manifest base. Mirrors
|
|
1216
|
+
// endSegmentEdit clearing setEditedSegment(null).
|
|
1217
|
+
this.overlay.setEditedZone(null);
|
|
1218
|
+
|
|
1219
|
+
// Release the base-map-switch block even on a defensive call when no engine was
|
|
1220
|
+
// active, so an end*Edit always leaves the terrain lock down.
|
|
1221
|
+
this.lock.release("zone");
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
isZoneEditing(zoneId?: string): boolean {
|
|
1225
|
+
if (this.zoneEditEngine === null) {
|
|
1226
|
+
return false;
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
if (zoneId === undefined) {
|
|
1230
|
+
return true;
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
return this.zoneEditEngineZoneId === zoneId;
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
setZoneDraftStyle(style: { color: string }): void {
|
|
1237
|
+
if (this.zoneEditEngine) {
|
|
1238
|
+
this.restyleZoneEdit(this.zoneEditEngine, style.color);
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
/** restyleZoneEdit draws the zone under edit in `color`, and writes nothing when it already is. */
|
|
1243
|
+
private restyleZoneEdit(engine: ZoneEditEngine, color: string): void {
|
|
1244
|
+
if (this.zoneEditEngineColor === color) {
|
|
1245
|
+
return;
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
engine.setDraftStyle({ color });
|
|
1249
|
+
this.zoneEditEngineColor = color;
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
getZoneDraft(): ZoneDraft | null {
|
|
1253
|
+
// The engine's readDraft returns the geometry alone (the base contract's
|
|
1254
|
+
// TDraft); compose the wider ZoneDraft with the tracked mode here. The mode is
|
|
1255
|
+
// immutable for the session, so the tracked value always matches the drawn
|
|
1256
|
+
// shape's kind. A read is a snapshot, not an interactive edit, so it is flagged
|
|
1257
|
+
// programmatic: a history consumer reads it to record state, never to
|
|
1258
|
+
// originate a change. And it is settled, as every programmatic draft is: a
|
|
1259
|
+
// caller persisting it holds the shape as it stands, not a frame to replace.
|
|
1260
|
+
const geometry = this.zoneEditEngine?.readDraft();
|
|
1261
|
+
if (!geometry || this.zoneEditEngineMode === null) {
|
|
1262
|
+
return null;
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
return { geometry, mode: this.zoneEditEngineMode, phase: "settled", programmatic: true };
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
applyZoneDraft(geometry: Polygon): void {
|
|
1269
|
+
this.zoneEditEngine?.applyDraft(geometry);
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
onZoneDraftChange(cb: (draft: ZoneDraft) => void): () => void {
|
|
1273
|
+
// The subscriber registry lives on the client, not the per-edit engine, so the
|
|
1274
|
+
// seam survives an engine swap and outlives an individual edit, the same
|
|
1275
|
+
// posture as onSegmentDraftChange. CONTINUOUS: fires per geometry change.
|
|
1276
|
+
this.zoneDraftSubscribers.add(cb);
|
|
1277
|
+
|
|
1278
|
+
return () => {
|
|
1279
|
+
this.zoneDraftSubscribers.delete(cb);
|
|
1280
|
+
};
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
beginBoundaryEdit(options: BoundaryEditOptions): void {
|
|
1284
|
+
// A disposed client has let go of the map: it arms nothing on it.
|
|
1285
|
+
if (this.events.disposed) {
|
|
1286
|
+
return;
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
// A begin its engine would refuse is refused first, as the segment family's is.
|
|
1290
|
+
this.requireEditEngines("beginBoundaryEdit").refuseBoundary(options);
|
|
1291
|
+
|
|
1292
|
+
// Idempotent for the same region: the editing surface arms the edit whenever the
|
|
1293
|
+
// client lands, so an unchanged re-call must not churn a working engine, the same
|
|
1294
|
+
// guard the other authoring families use.
|
|
1295
|
+
if (this.boundaryEditEngine && this.boundaryEditEngineFeatureId === options.featureId) {
|
|
1296
|
+
return;
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
if (this.boundaryEditEngine) {
|
|
1300
|
+
this.teardownBoundaryEdit();
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
// The engine arms the rectangle + select modes and attaches + seeds itself in its
|
|
1304
|
+
// constructor, emitting through the client-owned draft sink so the seam is
|
|
1305
|
+
// identical to the other families'.
|
|
1306
|
+
const boundaryEngine = this.armEditEngine("boundary", () => this.buildBoundaryEngine(options));
|
|
1307
|
+
this.boundaryEditEngine = boundaryEngine;
|
|
1308
|
+
this.replayIfStyleReloading(boundaryEngine);
|
|
1309
|
+
this.boundaryEditEngineFeatureId = options.featureId;
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
endBoundaryEdit(): void {
|
|
1313
|
+
this.teardownBoundaryEdit();
|
|
1314
|
+
this.applyHeldBaseTerrain();
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
/** teardownBoundaryEdit is endBoundaryEdit without the base-map switch the edit held. */
|
|
1318
|
+
private teardownBoundaryEdit(): void {
|
|
1319
|
+
// Dispose the active engine: it removes its rendered layers + sources, detaches
|
|
1320
|
+
// its TerraDraw listeners, and releases the create-cursor lock it owns (unlike the
|
|
1321
|
+
// zone family, no hook above holds that lock).
|
|
1322
|
+
this.boundaryEditEngine?.dispose();
|
|
1323
|
+
this.boundaryEditEngine = null;
|
|
1324
|
+
this.boundaryEditEngineFeatureId = null;
|
|
1325
|
+
|
|
1326
|
+
// Release the base-map-switch block even on a defensive call when no engine was
|
|
1327
|
+
// active, so an end*Edit always leaves the terrain lock down.
|
|
1328
|
+
this.lock.release("boundary");
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
isBoundaryEditing(): boolean {
|
|
1332
|
+
return this.boundaryEditEngine !== null;
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
applyBoundaryDraft(bbox: BoundingBox): void {
|
|
1336
|
+
this.boundaryEditEngine?.applyDraft(bbox);
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
clearBoundaryDraft(): void {
|
|
1340
|
+
this.boundaryEditEngine?.clearDraft();
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
getBoundaryDraft(): BoundingBox | null {
|
|
1344
|
+
return this.boundaryEditEngine?.readDraft() ?? null;
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
onBoundaryDraftChange(cb: (draft: BoundaryDraft) => void): () => void {
|
|
1348
|
+
this.boundaryDraftSubscribers.add(cb);
|
|
1349
|
+
|
|
1350
|
+
return () => {
|
|
1351
|
+
this.boundaryDraftSubscribers.delete(cb);
|
|
1352
|
+
};
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
setZoneTimeReference(epochSeconds: number): void {
|
|
1356
|
+
this.overlay.setZoneTimeReference(epochSeconds);
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
isSegmentEditing(segmentId?: string): boolean {
|
|
1360
|
+
if (this.segmentEditEngine === null) {
|
|
1361
|
+
return false;
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
if (segmentId === undefined) {
|
|
1365
|
+
return true;
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
return this.segmentEditEngineSegmentId === segmentId;
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
isWaypointEditing(waypointId?: string): boolean {
|
|
1372
|
+
if (this.waypointEditEngine === null) {
|
|
1373
|
+
return false;
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
if (waypointId === undefined) {
|
|
1377
|
+
return true;
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
return this.waypointEditEngineWaypointId === waypointId;
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
ensureOverlayInZoomRange(overlay: OverlayZoomRange): void {
|
|
1384
|
+
this.overlay.ensureOverlayInZoomRange(overlay);
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
applyWaypointDraft(snapshot: WaypointDraftSnapshot): void {
|
|
1388
|
+
this.waypointEditEngine?.applyDraft(snapshot);
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
clearWaypointDraft(): void {
|
|
1392
|
+
this.waypointEditEngine?.clearDraft();
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
reseedWaypointEdit(lngLat: [number, number]): void {
|
|
1396
|
+
// Move the armed engine's marker to the new coordinate, keeping its current
|
|
1397
|
+
// icon + color. The waypoint editing hook holds the seed out of its arming
|
|
1398
|
+
// deps (a deps-driven rebuild would churn the engine mid-drag), so a re-begin
|
|
1399
|
+
// with a new position never re-arms: this seam re-seeds the position directly.
|
|
1400
|
+
// The current draft supplies the icon + color so a position-only re-seed
|
|
1401
|
+
// preserves the marker's look. A no-op when no engine is armed or nothing has
|
|
1402
|
+
// been placed yet (readDraft is null). applyDraft is a programmatic write, so
|
|
1403
|
+
// it does not loop back through onWaypointDraftChange.
|
|
1404
|
+
const current = this.waypointEditEngine?.readDraft();
|
|
1405
|
+
if (!current) {
|
|
1406
|
+
return;
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
this.waypointEditEngine?.applyDraft({ ...current, lngLat });
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
setWaypointDraftStyle(style: { color: string; icon: string }): void {
|
|
1413
|
+
this.waypointEditEngine?.setDraftStyle(style);
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
getWaypointDraft(): WaypointDraftSnapshot | null {
|
|
1417
|
+
return this.waypointEditEngine?.readDraft() ?? null;
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
setSearchHighlight(payload: SearchHighlight | null): void {
|
|
1421
|
+
this.searchHighlight.set(payload);
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
setPeerDraft(entity: PeerDraftEntity, geometry: Geometry, color: string, label?: string): void {
|
|
1425
|
+
this.peerDraft.set(entity, geometry, color, label);
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
clearPeerDraft(entity: PeerDraftEntity): void {
|
|
1429
|
+
this.peerDraft.clear(entity);
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
setProfileMarker(lngLat: [number, number] | null, icon: ProfileMarkerIcon | null = null): void {
|
|
1433
|
+
// A disposed client has let go of the map: a marker added now no dispose would take off.
|
|
1434
|
+
if (this.events.disposed) {
|
|
1435
|
+
return;
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
// Null clears the marker (the chart cursor left the profile); a coordinate
|
|
1439
|
+
// moves the existing marker in place, or creates it on first hover, so a sweep
|
|
1440
|
+
// across the chart never stacks markers.
|
|
1441
|
+
if (!lngLat) {
|
|
1442
|
+
this.profileMarker?.remove();
|
|
1443
|
+
this.profileMarker = null;
|
|
1444
|
+
this.profileMarkerIconKey = null;
|
|
1445
|
+
|
|
1446
|
+
return;
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
const center = new LngLat(lngLat[0], lngLat[1]);
|
|
1450
|
+
const key = profileMarkerIconKey(icon);
|
|
1451
|
+
|
|
1452
|
+
// The same pin moving is the hot path (a chart sweep runs it every frame) so
|
|
1453
|
+
// it is a coordinate write and nothing else. A different head means a different
|
|
1454
|
+
// surface now owns the marker (the chart handing off to an armed split pick, or
|
|
1455
|
+
// back), and the element is rebuilt: MapLibre's Marker takes its element at
|
|
1456
|
+
// construction, so there is no way to restyle one in place.
|
|
1457
|
+
if (this.profileMarker) {
|
|
1458
|
+
if (key === this.profileMarkerIconKey) {
|
|
1459
|
+
this.profileMarker.setLngLat(center);
|
|
1460
|
+
|
|
1461
|
+
return;
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
this.profileMarker.remove();
|
|
1465
|
+
this.profileMarker = null;
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
// Built with a bottom anchor, so the pin's tip marks the exact coordinate
|
|
1469
|
+
// rather than its center; the icon (when given) paints its glyph in the head.
|
|
1470
|
+
const element = buildProfileMarkerElement(icon, this.icons);
|
|
1471
|
+
this.profileMarkerIconKey = key;
|
|
1472
|
+
this.profileMarker = new Marker({ anchor: "bottom", element })
|
|
1473
|
+
.setLngLat(center)
|
|
1474
|
+
.addTo(this.map);
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
setVideoFocusMarker(lngLat: [number, number] | null): void {
|
|
1478
|
+
this.video?.setVideoFocusMarker(lngLat);
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
setSegmentDraftStyle(style: { color: string }): void {
|
|
1482
|
+
this.segmentEditEngine?.setDraftStyle(style);
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
getSegmentDraft(): Position[] | null {
|
|
1486
|
+
return this.segmentEditEngine?.readDraft() ?? null;
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
applySegmentDraft(vias: Position[]): void {
|
|
1490
|
+
this.segmentEditEngine?.applyDraft(vias);
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
setSegmentViaPromptPending(pending: boolean): void {
|
|
1494
|
+
this.segmentEditEngine?.setViaPromptPending(pending);
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
onSegmentDraftChange(cb: (draft: SegmentDraft) => void): () => void {
|
|
1498
|
+
// The subscriber registry lives on the client, not the per-edit engine,
|
|
1499
|
+
// so the seam survives an engine swap between modes and outlives an
|
|
1500
|
+
// individual edit. Whichever engine is active emits into this set
|
|
1501
|
+
// through the sink the client passes it. CONTINUOUS: fires per drag
|
|
1502
|
+
// frame.
|
|
1503
|
+
this.segmentDraftSubscribers.add(cb);
|
|
1504
|
+
|
|
1505
|
+
return () => {
|
|
1506
|
+
this.segmentDraftSubscribers.delete(cb);
|
|
1507
|
+
};
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
onSegmentViaPrompt(cb: (prompt: SegmentViaPromptEvent) => void): () => void {
|
|
1511
|
+
// The registry lives on the client for the same reason the draft one does:
|
|
1512
|
+
// the seam survives an engine swap between modes and outlives an individual
|
|
1513
|
+
// edit, so the editor subscribes once for the whole session. DISCRETE: fires
|
|
1514
|
+
// once per gesture that landed on an existing handle.
|
|
1515
|
+
this.segmentViaPromptSubscribers.add(cb);
|
|
1516
|
+
|
|
1517
|
+
return () => {
|
|
1518
|
+
this.segmentViaPromptSubscribers.delete(cb);
|
|
1519
|
+
};
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
onWaypointDraftChange(cb: (change: WaypointEngineDraftChange) => void): () => void {
|
|
1523
|
+
// Held on the client for the same reason as the segment-draft
|
|
1524
|
+
// subscribers; both waypoint engines emit into this set on each
|
|
1525
|
+
// interactive click. DISCRETE: fires once per change.
|
|
1526
|
+
this.waypointDraftChangeSubscribers.add(cb);
|
|
1527
|
+
|
|
1528
|
+
return () => {
|
|
1529
|
+
this.waypointDraftChangeSubscribers.delete(cb);
|
|
1530
|
+
};
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
onPointPickChange(cb: (change: PointPickChange) => void): () => void {
|
|
1534
|
+
// Held on the client for the same reason as the segment-/waypoint-draft
|
|
1535
|
+
// subscribers; the active pick engine emits into this set on each armed
|
|
1536
|
+
// click. DISCRETE: fires once per click.
|
|
1537
|
+
this.pointPickChangeSubscribers.add(cb);
|
|
1538
|
+
|
|
1539
|
+
return () => {
|
|
1540
|
+
this.pointPickChangeSubscribers.delete(cb);
|
|
1541
|
+
};
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
/**
|
|
1545
|
+
* endSegmentEdit tears the active edit engine down (removing its overlay
|
|
1546
|
+
* layers/sources and detaching its library-internal listeners) and restores
|
|
1547
|
+
* the edited segment's tile copy to its normal paint, so the dual render
|
|
1548
|
+
* resolves back to a single tile-rendered segment. The base-map-switch block is
|
|
1549
|
+
* released after the engine teardown so a terrain switch resumes.
|
|
1550
|
+
*/
|
|
1551
|
+
endSegmentEdit(): void {
|
|
1552
|
+
this.teardownSegmentEdit();
|
|
1553
|
+
this.applyHeldBaseTerrain();
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
/**
|
|
1557
|
+
* teardownSegmentEdit is endSegmentEdit without the base-map switch the edit held: the
|
|
1558
|
+
* teardown a re-arm on another segment or mode runs before it builds the next engine, where
|
|
1559
|
+
* a swap would wipe what that engine is about to draw.
|
|
1560
|
+
*/
|
|
1561
|
+
private teardownSegmentEdit(): void {
|
|
1562
|
+
// Dispose the active engine: it removes its rendered layers + sources
|
|
1563
|
+
// and detaches its library-internal listeners (TerraDraw: clear → stop;
|
|
1564
|
+
// the SDK: destroy). The client undoes its own cross-cutting concerns
|
|
1565
|
+
// after: restoring the tile copy paint and unlocking the map.
|
|
1566
|
+
this.segmentEditEngine?.dispose();
|
|
1567
|
+
this.segmentEditEngine = null;
|
|
1568
|
+
this.segmentEditEngineSegmentId = null;
|
|
1569
|
+
this.segmentEditEngineMode = null;
|
|
1570
|
+
this.segmentEditEngineSeed = null;
|
|
1571
|
+
|
|
1572
|
+
// Re-assert emphasis, exclusions, and edit styling in the same order
|
|
1573
|
+
// addTileSources runs them. The in-edit paint expressions on the itinerary
|
|
1574
|
+
// line and point layers are filter-folded with the emphasis + exclusion
|
|
1575
|
+
// expressions, so a teardown that only clears the edit override leaves the
|
|
1576
|
+
// other features painted against the in-edit fold until the next style
|
|
1577
|
+
// reload (a pan/zoom). Running all three rebuilds the paint from a clean
|
|
1578
|
+
// base so segments and waypoints outside the edit reappear immediately on
|
|
1579
|
+
// cancel or commit. reapplyItineraryPaint runs emphasis then exclusions;
|
|
1580
|
+
// setEditedSegment(null) clears the edit id and lays the styling on last.
|
|
1581
|
+
this.overlay.reapplyItineraryPaint();
|
|
1582
|
+
this.overlay.setEditedSegment(null);
|
|
1583
|
+
|
|
1584
|
+
// Tear down the live direction indicator and the live restricted stretches. The edited
|
|
1585
|
+
// segment's tile copy of both was restored to its emphasis paint by reapplyItineraryPaint
|
|
1586
|
+
// above, so the route's direction and its restrictions hand back to the tiles.
|
|
1587
|
+
this.clearSegmentEditArrows();
|
|
1588
|
+
this.clearSegmentEditRoadAccess();
|
|
1589
|
+
|
|
1590
|
+
// Release the base-map-switch block the segment edit held, even on a defensive
|
|
1591
|
+
// call when no engine was active, so an end always leaves the terrain lock down.
|
|
1592
|
+
this.lock.release("segment");
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1595
|
+
setTileLayerVisibility(layerId: string, visible: boolean): void {
|
|
1596
|
+
this.overlay.setTileLayerVisibility(layerId, visible);
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
addTileSources(sources: TileSchema.TileSource[]): void {
|
|
1600
|
+
this.overlay.addTileSources(sources);
|
|
1601
|
+
}
|
|
1602
|
+
|
|
1603
|
+
setCategoryOverlay(overlay: Overlay | null): void {
|
|
1604
|
+
this.overlay.setCategoryOverlay(overlay);
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
addEnrichmentOverlay(overlay: Overlay): void {
|
|
1608
|
+
this.overlay.addEnrichmentOverlay(overlay);
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1611
|
+
removeEnrichmentOverlay(slug: string): void {
|
|
1612
|
+
this.overlay.removeEnrichmentOverlay(slug);
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
removeTileSources(ids: string[]): void {
|
|
1616
|
+
this.overlay.removeTileSources(ids);
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1619
|
+
refreshItineraryTiles(bustToken?: string): void {
|
|
1620
|
+
this.overlay.refreshItineraryTiles(bustToken);
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
/**
|
|
1624
|
+
* refreshItineraryTilesWhenSettled busts the itinerary tile cache (the same
|
|
1625
|
+
* setTiles eviction refreshItineraryTiles drives) but only once the map has
|
|
1626
|
+
* SETTLED, never on the still-rendering frame an edit teardown leaves behind.
|
|
1627
|
+
* The edit-teardown paths reapply paint / dispose layers synchronously, so a
|
|
1628
|
+
* bust fired in the same tick lands while the map is mid-render, and
|
|
1629
|
+
* MapLibre's setTiles does not refetch the current-zoom tile until the view is
|
|
1630
|
+
* idle (the same constraint the zone teardown sidesteps by busting after
|
|
1631
|
+
* endZoneEdit). Deferring to a settled frame lets the freshly-persisted segment
|
|
1632
|
+
* or moved waypoint paint in place without a pan/zoom, and clears the stale
|
|
1633
|
+
* tile copy that otherwise lingers at the old position.
|
|
1634
|
+
*
|
|
1635
|
+
* The bust is guaranteed to run EXACTLY ONCE and can never hang: when the
|
|
1636
|
+
* teardown enqueued a render, MapLibre fires `idle` once it paints (the zone-
|
|
1637
|
+
* proven moment); when the map is already idle, `idle` never re-fires, so a
|
|
1638
|
+
* double requestAnimationFrame lands the settle signal on the next frame as a
|
|
1639
|
+
* fallback. Whichever settle signal fires first wins (the `scheduled` guard
|
|
1640
|
+
* absorbs the other) so the bust always lands and never double-busts.
|
|
1641
|
+
*
|
|
1642
|
+
* Whichever path wins does NOT bust synchronously: it schedules the actual
|
|
1643
|
+
* setTiles eviction on one further requestAnimationFrame. The idle callback runs
|
|
1644
|
+
* inside MapLibre's own idle dispatch (the segment teardown's synchronous
|
|
1645
|
+
* reapplyItineraryPaint + setEditedSegment(null) enqueue that render), and a bust
|
|
1646
|
+
* fired there evicts the tiles but does not refetch the current-zoom tile until
|
|
1647
|
+
* the next viewport change (the "zoom in/out to reappear" symptom). Deferring the
|
|
1648
|
+
* bust one frame past the settle signal lands setTiles on a fresh frame (the same
|
|
1649
|
+
* frame the double-rAF fallback already busts on) so the freshly-persisted segment
|
|
1650
|
+
* refetches and repaints in place with no pan/zoom.
|
|
1651
|
+
*
|
|
1652
|
+
* Nothing it schedules outlives the client. The idle listener is held by the event
|
|
1653
|
+
* manager and detaches itself on the first settle signal, and every frame is tracked
|
|
1654
|
+
* so {@link dispose} cancels the ones still pending: a bust landing after dispose
|
|
1655
|
+
* would re-point the tiles of a map the client has let go of.
|
|
1656
|
+
*/
|
|
1657
|
+
refreshItineraryTilesWhenSettled(bustToken?: string): void {
|
|
1658
|
+
let scheduled = false;
|
|
1659
|
+
let detachIdle = (): void => {};
|
|
1660
|
+
// Every frame this refresh asks for goes through here, so a dispose finds it.
|
|
1661
|
+
const onFrame = (callback: () => void): void => {
|
|
1662
|
+
const handle = requestAnimationFrame(() => {
|
|
1663
|
+
this.settleFrames.delete(handle);
|
|
1664
|
+
callback();
|
|
1665
|
+
});
|
|
1666
|
+
this.settleFrames.add(handle);
|
|
1667
|
+
};
|
|
1668
|
+
// The settle signal (idle OR the double-rAF fallback) only SCHEDULES the bust;
|
|
1669
|
+
// it never runs it in the same tick. Guarding on schedule (not on run) means the
|
|
1670
|
+
// idle and fallback paths never both queue a bust (the first to fire wins and the
|
|
1671
|
+
// other is absorbed) so the bust runs exactly once on a fresh frame.
|
|
1672
|
+
const scheduleBust = (): void => {
|
|
1673
|
+
if (scheduled) {
|
|
1674
|
+
return;
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1677
|
+
scheduled = true;
|
|
1678
|
+
detachIdle();
|
|
1679
|
+
onFrame(() => this.overlay.refreshItineraryTiles(bustToken));
|
|
1680
|
+
};
|
|
1681
|
+
|
|
1682
|
+
// `idle` fires after the teardown's enqueued render paints, the moment the zone
|
|
1683
|
+
// teardown relies on for a reliable setTiles refetch. Deferring one rAF past it
|
|
1684
|
+
// moves the bust off MapLibre's idle dispatch so setTiles lands on a fresh frame.
|
|
1685
|
+
// Held through the event engine rather than a raw one-shot, which MapLibre keeps
|
|
1686
|
+
// until it fires and nothing would take off at dispose.
|
|
1687
|
+
detachIdle = this.events.on("idle", scheduleBust);
|
|
1688
|
+
// When no render is pending, `idle` never re-fires; a double rAF still lands the
|
|
1689
|
+
// settle signal on the next frame. The `scheduled` guard absorbs whichever path
|
|
1690
|
+
// the first did not win, so the bust runs exactly once and never hangs.
|
|
1691
|
+
onFrame(() => onFrame(scheduleBust));
|
|
1692
|
+
}
|
|
1693
|
+
|
|
1694
|
+
refreshZoneTiles(): void {
|
|
1695
|
+
this.overlay.refreshZoneTiles();
|
|
1696
|
+
}
|
|
1697
|
+
|
|
1698
|
+
applyCamera(view: CameraPose): void {
|
|
1699
|
+
// Build the camera options from only the channels the view names, so an omitted
|
|
1700
|
+
// center/zoom/bearing/pitch is left untouched (passing undefined to easeTo/jumpTo
|
|
1701
|
+
// would still drive that channel to undefined on some SDK paths; building the
|
|
1702
|
+
// object keeps the call to exactly what changed).
|
|
1703
|
+
const options: {
|
|
1704
|
+
bearing?: number | undefined;
|
|
1705
|
+
center?: [number, number] | undefined;
|
|
1706
|
+
pitch?: number | undefined;
|
|
1707
|
+
zoom?: number | undefined;
|
|
1708
|
+
} = {};
|
|
1709
|
+
if (view.center !== undefined) {
|
|
1710
|
+
options.center = view.center;
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
if (view.zoom !== undefined) {
|
|
1714
|
+
options.zoom = view.zoom;
|
|
1715
|
+
}
|
|
1716
|
+
|
|
1717
|
+
if (view.bearing !== undefined) {
|
|
1718
|
+
options.bearing = view.bearing;
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1721
|
+
if (view.pitch !== undefined) {
|
|
1722
|
+
options.pitch = view.pitch;
|
|
1723
|
+
}
|
|
1724
|
+
|
|
1725
|
+
// Nothing to apply: avoid a no-op move (which would still fire move events) when
|
|
1726
|
+
// the view set no channel.
|
|
1727
|
+
if (Object.keys(options).length === 0) {
|
|
1728
|
+
return;
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1731
|
+
// A captured center is the full anchor the publisher framed, so JUMP to the whole
|
|
1732
|
+
// view at once: no fit-then-pan two-step, no easing toward a center the visitor
|
|
1733
|
+
// never picked. Without a center the view is an angle/zoom overlay on the current
|
|
1734
|
+
// center, so EASE it (a short animation matching fitBounds') so the adopt reads as
|
|
1735
|
+
// a deliberate framing rather than a jump-cut.
|
|
1736
|
+
if (options.center !== undefined) {
|
|
1737
|
+
this.map.jumpTo(options);
|
|
1738
|
+
|
|
1739
|
+
return;
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1742
|
+
this.map.easeTo(options);
|
|
1743
|
+
}
|
|
1744
|
+
|
|
1745
|
+
fitBounds(
|
|
1746
|
+
bounds: BoundingBox,
|
|
1747
|
+
padding?: FitBoundsPadding,
|
|
1748
|
+
maxZoom?: number,
|
|
1749
|
+
animate?: boolean,
|
|
1750
|
+
): void {
|
|
1751
|
+
// Flown as MapLibre flies its own fit. `animate: false` is the embed's cold-load framing
|
|
1752
|
+
// under its cover: the camera lands with no flight, so the first painted frame is already the
|
|
1753
|
+
// route, and every other call keeps the flight.
|
|
1754
|
+
const camera = this.fitCamera(bounds, padding, maxZoom, this.map.getMinZoom());
|
|
1755
|
+
if (camera !== null) {
|
|
1756
|
+
this.map.flyTo(animate === false ? { ...camera, animate } : camera);
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
|
|
1760
|
+
cameraForBounds(
|
|
1761
|
+
bounds: BoundingBox,
|
|
1762
|
+
padding?: FitBoundsPadding,
|
|
1763
|
+
maxZoom?: number,
|
|
1764
|
+
): MapViewport | null {
|
|
1765
|
+
// Held under the window's ceiling and not by its floor: the embed lowers its floor to the
|
|
1766
|
+
// zoom this answers, and a fit of the same box then lands on this camera.
|
|
1767
|
+
const camera = this.fitCamera(bounds, padding, maxZoom, MAP_ZOOM_FLOOR);
|
|
1768
|
+
|
|
1769
|
+
return camera === null ? null : { center: camera.center, zoom: camera.zoom };
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
/**
|
|
1773
|
+
* fitCamera answers the camera the contract's fit computes for a box on this map, held under its
|
|
1774
|
+
* zoom window's ceiling and the fit's, and down to the floor named.
|
|
1775
|
+
*
|
|
1776
|
+
* The box is read by its corners, as MapLibre reads one: a west edge east of the east one
|
|
1777
|
+
* crosses the antimeridian, which is how a caller writes such a box to the client.
|
|
1778
|
+
*
|
|
1779
|
+
* A box with an edge that is no number frames nothing, as one the padding leaves no room for: no
|
|
1780
|
+
* camera stands at it, and MapLibre throws for one.
|
|
1781
|
+
*/
|
|
1782
|
+
private fitCamera(
|
|
1783
|
+
bounds: BoundingBox,
|
|
1784
|
+
padding: FitBoundsPadding | undefined,
|
|
1785
|
+
maxZoom: number | undefined,
|
|
1786
|
+
floor: number,
|
|
1787
|
+
): BoundsCamera | null {
|
|
1788
|
+
if (!normalizeBoundingBox(bounds).every((edge) => Number.isFinite(edge))) {
|
|
1789
|
+
return null;
|
|
1790
|
+
}
|
|
1791
|
+
|
|
1792
|
+
const [west, south, east, north] = bounds;
|
|
1793
|
+
|
|
1794
|
+
return fitCameraOn(
|
|
1795
|
+
this.map,
|
|
1796
|
+
normalizeBoundingBox([west, south, west > east ? east + DEGREES_PER_TURN : east, north]),
|
|
1797
|
+
{ maxZoom, padding, window: { max: this.map.getMaxZoom(), min: floor } },
|
|
1798
|
+
);
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1801
|
+
hadInitialViewHash(): boolean {
|
|
1802
|
+
return this.initialViewHash;
|
|
1803
|
+
}
|
|
1804
|
+
|
|
1805
|
+
async prewarmTerrain(bounds: BoundingBox): Promise<void> {
|
|
1806
|
+
// Pad the route bounds generously: the camera eye and its sightline samples
|
|
1807
|
+
// sit well outside the route (a wide/back drone eye can be one to a few km
|
|
1808
|
+
// out), so a fit to the bare route would leave those samples on unloaded
|
|
1809
|
+
// tiles. Pad by the bbox span on each side (with a small degree floor for a
|
|
1810
|
+
// short or single-point-ish route) so the framed extent comfortably covers the
|
|
1811
|
+
// eye + sightline.
|
|
1812
|
+
//
|
|
1813
|
+
// The box is read in canonical form, so one drawn from its east corner is ordered and one
|
|
1814
|
+
// across the antimeridian is measured across the line. The padded box is put back into
|
|
1815
|
+
// that form: its latitudes are held inside the ones the renderer frames, which throws for
|
|
1816
|
+
// one past a pole, and a box padded to a turn or more is the whole world.
|
|
1817
|
+
const [west, south, east, north] = normalizeBoundingBox(bounds);
|
|
1818
|
+
const padLng = Math.max(east - west, TERRAIN_PREWARM_MIN_PAD_DEG);
|
|
1819
|
+
const padLat = Math.max(north - south, TERRAIN_PREWARM_MIN_PAD_DEG);
|
|
1820
|
+
const padded = normalizeBoundingBox([
|
|
1821
|
+
west - padLng,
|
|
1822
|
+
south - padLat,
|
|
1823
|
+
east + padLng,
|
|
1824
|
+
north + padLat,
|
|
1825
|
+
]);
|
|
1826
|
+
// A box with an edge at no finite coordinate frames nothing. The stated box is the one
|
|
1827
|
+
// read: an edge at an infinity pads to a finite box, the whole world or one held at the
|
|
1828
|
+
// latitude limit. The warm is best-effort, so it goes on to the wait and resolves, where
|
|
1829
|
+
// the renderer would throw for the box.
|
|
1830
|
+
if (bounds.every((edge) => Number.isFinite(edge))) {
|
|
1831
|
+
this.map.fitBounds(padded);
|
|
1832
|
+
}
|
|
1833
|
+
|
|
1834
|
+
// Await the render so the DEM tiles for the route and surroundings are loaded
|
|
1835
|
+
// and painted before the clearance pass samples them. Best-effort: waitForRender
|
|
1836
|
+
// resolves once the view settles even when no DEM is configured, so a terrain-
|
|
1837
|
+
// less map resolves immediately and the sampler simply returns null.
|
|
1838
|
+
await this.waitForRender();
|
|
1839
|
+
}
|
|
1840
|
+
|
|
1841
|
+
async warmPoses(poses: readonly RecordingCamera[], signal?: AbortSignal): Promise<void> {
|
|
1842
|
+
return warmPosesThrough(this.map, this.events, poses, signal);
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1845
|
+
sampleTerrainElevation(lngLat: [number, number]): number | null {
|
|
1846
|
+
return queryTerrainElevation(this.map, lngLat);
|
|
1847
|
+
}
|
|
1848
|
+
|
|
1849
|
+
getViewport(): MapViewport {
|
|
1850
|
+
const center = this.map.getCenter();
|
|
1851
|
+
|
|
1852
|
+
return { center: [center.lng, center.lat], zoom: this.map.getZoom() };
|
|
1853
|
+
}
|
|
1854
|
+
|
|
1855
|
+
getBearing(): number {
|
|
1856
|
+
return this.map.getBearing();
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
getCameraPose(): RecordingCamera {
|
|
1860
|
+
const center = this.map.getCenter();
|
|
1861
|
+
|
|
1862
|
+
return {
|
|
1863
|
+
bearing: this.map.getBearing(),
|
|
1864
|
+
center: [center.lng, center.lat],
|
|
1865
|
+
pitch: this.map.getPitch(),
|
|
1866
|
+
zoom: this.map.getZoom(),
|
|
1867
|
+
};
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1870
|
+
async previewPoses(
|
|
1871
|
+
poses: RecordingCamera[],
|
|
1872
|
+
options: {
|
|
1873
|
+
focusGlyphUrl?: string | undefined;
|
|
1874
|
+
markers?: [number, number][] | undefined;
|
|
1875
|
+
onProgress?: ((progress: VideoProgress) => void) | undefined;
|
|
1876
|
+
planDurationMs?: number | undefined;
|
|
1877
|
+
signal: AbortSignal;
|
|
1878
|
+
},
|
|
1879
|
+
): Promise<void> {
|
|
1880
|
+
// No recorder wired: the map does not fly, and the call resolves, since a host that
|
|
1881
|
+
// wants a preview flight is the one that supplies the seam.
|
|
1882
|
+
if (!this.video) {
|
|
1883
|
+
return;
|
|
1884
|
+
}
|
|
1885
|
+
|
|
1886
|
+
// The seam's promise is handed back as it is. A throw inside a frame rejects it once the
|
|
1887
|
+
// camera is restored, and a flight engine reads its failure off that rejection, so a
|
|
1888
|
+
// catch here would make a preview that failed read as one that finished.
|
|
1889
|
+
return this.video.previewPoses(poses, options);
|
|
1890
|
+
}
|
|
1891
|
+
|
|
1892
|
+
async recordPoses(
|
|
1893
|
+
poses: readonly RecordingCamera[],
|
|
1894
|
+
output: RecordOutput,
|
|
1895
|
+
options: {
|
|
1896
|
+
focusGlyphUrl?: string | undefined;
|
|
1897
|
+
markers?: [number, number][] | undefined;
|
|
1898
|
+
onProgress?: ((progress: VideoProgress) => void) | undefined;
|
|
1899
|
+
profile?: RecordProfile | undefined;
|
|
1900
|
+
signal: AbortSignal;
|
|
1901
|
+
/**
|
|
1902
|
+
* Whether the caller has just warmed these very poses' viewports, every frame's zoom and
|
|
1903
|
+
* pitch included, so no warm pass runs.
|
|
1904
|
+
*
|
|
1905
|
+
* @default false
|
|
1906
|
+
*/
|
|
1907
|
+
warmed?: boolean | undefined;
|
|
1908
|
+
},
|
|
1909
|
+
): Promise<VideoRecordingResult> {
|
|
1910
|
+
// No recorder wired: the run could not start, which nobody cancelled. The result keeps
|
|
1911
|
+
// the cancel's shape, so a caller that branches on `blob` needs no other branch, and
|
|
1912
|
+
// states the reason. recordPoses never rejects, and that holds here too.
|
|
1913
|
+
if (!this.video) {
|
|
1914
|
+
return {
|
|
1915
|
+
blob: null,
|
|
1916
|
+
cancelled: true,
|
|
1917
|
+
extension: containerExtension(output.format),
|
|
1918
|
+
reason: "unavailable",
|
|
1919
|
+
};
|
|
1920
|
+
}
|
|
1921
|
+
|
|
1922
|
+
return this.video.recordPoses(poses, output, options);
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1925
|
+
zoomIn(): void {
|
|
1926
|
+
this.map.zoomIn();
|
|
1927
|
+
}
|
|
1928
|
+
|
|
1929
|
+
zoomOut(): void {
|
|
1930
|
+
this.map.zoomOut();
|
|
1931
|
+
}
|
|
1932
|
+
|
|
1933
|
+
resetNorth(): void {
|
|
1934
|
+
// resetNorthPitch resets both bearing and pitch to 0 (true north, top-down);
|
|
1935
|
+
// resetNorth alone would leave a tilted pitch in place.
|
|
1936
|
+
this.map.resetNorthPitch();
|
|
1937
|
+
}
|
|
1938
|
+
|
|
1939
|
+
async tryGeolocate(): Promise<GeolocateResult> {
|
|
1940
|
+
// Geolocation is best-effort and arrives through the map's own seam: a denied permission, an
|
|
1941
|
+
// unavailable sensor and a missing API are three answers a surface reports differently, and
|
|
1942
|
+
// none of them throws. Where the fix comes FROM is the seam's business (the browser by
|
|
1943
|
+
// default, a native shell when a consumer wired one) so what is left here is the only part
|
|
1944
|
+
// that belongs to an editor: framing the camera on it.
|
|
1945
|
+
const fix = await this.mountayaMap.geolocation.locate();
|
|
1946
|
+
if (!fix.ok) {
|
|
1947
|
+
return { ok: false, reason: fix.reason };
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1950
|
+
// A fix that lands after the client let go of the map frames nothing: a disposed client
|
|
1951
|
+
// moves no camera.
|
|
1952
|
+
if (this.events.disposed) {
|
|
1953
|
+
return { ok: false, reason: "unavailable" };
|
|
1954
|
+
}
|
|
1955
|
+
|
|
1956
|
+
// Frame the box the accuracy spans so the camera both pans AND zooms to a level that matches
|
|
1957
|
+
// the fix precision (a coarse fix zooms out, a precise one in), capping the zoom so a pinpoint
|
|
1958
|
+
// fix does not slam to the maximum: a plain flyTo({ center }) would pan without ever changing
|
|
1959
|
+
// the zoom. The box and the fit are the map's own, so the client and the map frame one fix
|
|
1960
|
+
// alike.
|
|
1961
|
+
this.fitBounds(accuracyBounds(fix.position, fix.accuracyMeters), undefined, LOCATE_MAX_ZOOM);
|
|
1962
|
+
|
|
1963
|
+
return { ok: true };
|
|
1964
|
+
}
|
|
1965
|
+
setMiniBearingMarker(position: [number, number], headingDeg: number): void {
|
|
1966
|
+
// A disposed client has let go of the map: a marker added now no dispose would take off.
|
|
1967
|
+
if (this.events.disposed) {
|
|
1968
|
+
return;
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1971
|
+
const center = new LngLat(position[0], position[1]);
|
|
1972
|
+
// Every call is the latest word on where the marker is, whichever path lands it.
|
|
1973
|
+
this.miniBearingPlacement += 1;
|
|
1974
|
+
const placement = this.miniBearingPlacement;
|
|
1975
|
+
|
|
1976
|
+
// Fast path: the marker already exists, so heading + position updates write
|
|
1977
|
+
// straight through without any readiness deferral: a panorama heading sweep
|
|
1978
|
+
// is high-frequency and must not park itself behind an idle that already
|
|
1979
|
+
// fired.
|
|
1980
|
+
if (this.miniBearingMarker) {
|
|
1981
|
+
this.miniBearingMarker.setLngLat(center);
|
|
1982
|
+
this.rotateMiniBearingMarker(this.miniBearingMarker.getElement(), headingDeg);
|
|
1983
|
+
|
|
1984
|
+
return;
|
|
1985
|
+
}
|
|
1986
|
+
|
|
1987
|
+
const place = () => {
|
|
1988
|
+
// Re-check the marker field: a heading update that won the readiness race
|
|
1989
|
+
// already built it, and a second placement would stack a duplicate.
|
|
1990
|
+
if (this.miniBearingMarker) {
|
|
1991
|
+
this.miniBearingMarker.setLngLat(center);
|
|
1992
|
+
this.rotateMiniBearingMarker(this.miniBearingMarker.getElement(), headingDeg);
|
|
1993
|
+
|
|
1994
|
+
return;
|
|
1995
|
+
}
|
|
1996
|
+
|
|
1997
|
+
const element = buildMiniBearingMarkerElement();
|
|
1998
|
+
this.miniBearingMarker = new Marker({ anchor: "center", element })
|
|
1999
|
+
.setLngLat(center)
|
|
2000
|
+
.addTo(this.map);
|
|
2001
|
+
this.rotateMiniBearingMarker(element, headingDeg);
|
|
2002
|
+
};
|
|
2003
|
+
|
|
2004
|
+
// First placement may land before the initial style load resolves: a Marker
|
|
2005
|
+
// attached to a half-loaded map is dropped silently when the renderer
|
|
2006
|
+
// completes its first paint. Gate on waitForRender rather than style.load:
|
|
2007
|
+
// the mini-map opens with the same terrain url the main map cached, so no
|
|
2008
|
+
// setStyle reload fires after onClientReady: a style.load gate would park
|
|
2009
|
+
// forever in that case (the event the wait listens for never re-fires). The
|
|
2010
|
+
// render gate handles both states the readiness check can land in: when the
|
|
2011
|
+
// map already reports both loaded() and isStyleLoaded(), place runs
|
|
2012
|
+
// synchronously; otherwise it resolves on the next idle, which fires when a
|
|
2013
|
+
// pending source/tile load settles (no style.load required) and also when a
|
|
2014
|
+
// real reload completes (waitForRender defers to style.load internally for
|
|
2015
|
+
// that case via isStyleReloading()).
|
|
2016
|
+
if (this.map.loaded() && this.map.isStyleLoaded()) {
|
|
2017
|
+
place();
|
|
2018
|
+
|
|
2019
|
+
return;
|
|
2020
|
+
}
|
|
2021
|
+
|
|
2022
|
+
// The render gate also resolves on dispose, so that a wait held behind a style swap
|
|
2023
|
+
// cannot strand its caller. A continuation that WRITES has to re-check: a marker
|
|
2024
|
+
// attached to a torn-down client is one nothing will ever remove. It checks that it is
|
|
2025
|
+
// still the placement asked for last, too: a clear, or a later placement, that arrived
|
|
2026
|
+
// while this one waited withdraws it.
|
|
2027
|
+
void this.waitForRender().then(() => {
|
|
2028
|
+
if (!this.events.disposed && placement === this.miniBearingPlacement) {
|
|
2029
|
+
place();
|
|
2030
|
+
}
|
|
2031
|
+
});
|
|
2032
|
+
}
|
|
2033
|
+
|
|
2034
|
+
clearMiniBearingMarker(): void {
|
|
2035
|
+
// A placement still waiting for the render is withdrawn with the marker.
|
|
2036
|
+
this.miniBearingPlacement += 1;
|
|
2037
|
+
this.miniBearingMarker?.remove();
|
|
2038
|
+
this.miniBearingMarker = null;
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
setMiniCenter(position: [number, number]): void {
|
|
2042
|
+
// jumpTo with only `center` recenters at the current zoom, pitch, and
|
|
2043
|
+
// bearing, exactly the contract the mini-map needs (it stays at its
|
|
2044
|
+
// initial zoom, top-down, north-up framing for the life of the panorama).
|
|
2045
|
+
// No animation: a panorama walk step is small and continuous, so an eased
|
|
2046
|
+
// move would lag the marker's instantaneous setLngLat behind the camera.
|
|
2047
|
+
this.map.jumpTo({ center: position });
|
|
2048
|
+
}
|
|
2049
|
+
|
|
2050
|
+
/**
|
|
2051
|
+
* rotateMiniBearingMarker writes the heading rotation onto the dedicated child
|
|
2052
|
+
* rotator element so MapLibre's marker translate (written on the root each
|
|
2053
|
+
* frame) is never overwritten: the two transforms ride independent elements
|
|
2054
|
+
* and so cannot collide.
|
|
2055
|
+
*/
|
|
2056
|
+
private rotateMiniBearingMarker(root: HTMLElement, headingDeg: number): void {
|
|
2057
|
+
const rotator = root.querySelector<HTMLElement>(`[${MINI_BEARING_ROTATOR_DATA}]`);
|
|
2058
|
+
if (rotator) {
|
|
2059
|
+
rotator.style.transform = `rotate(${headingDeg}deg)`;
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
applyCursor(cursor: string): void {
|
|
2064
|
+
// Funnel through the cursor engine so a held lock wins: the feature-hover seam
|
|
2065
|
+
// calls this, and a leave clearing the cursor mid-edit is a no-op while an
|
|
2066
|
+
// edit cursor is pinned.
|
|
2067
|
+
this.cursor.apply(cursor);
|
|
2068
|
+
}
|
|
2069
|
+
|
|
2070
|
+
lockCursor(cursor: string): void {
|
|
2071
|
+
this.cursor.lock(cursor);
|
|
2072
|
+
}
|
|
2073
|
+
|
|
2074
|
+
unlockCursor(): void {
|
|
2075
|
+
this.cursor.unlock();
|
|
2076
|
+
}
|
|
2077
|
+
|
|
2078
|
+
waitForRender(): Promise<void> {
|
|
2079
|
+
// Resolves once the map has finished drawing what it was asked to draw (style
|
|
2080
|
+
// loaded, every requested tile painted, no transition in flight, and no resize of
|
|
2081
|
+
// the canvas on its way as the next frame reads it) or when the client is disposed,
|
|
2082
|
+
// because a map that no longer exists is not going to draw anything else. Never
|
|
2083
|
+
// rejects: most callers write `void waitForRender().then(…)`, and a rejection at
|
|
2084
|
+
// teardown would surface as an unhandled rejection rather than as anything anyone
|
|
2085
|
+
// could act on.
|
|
2086
|
+
//
|
|
2087
|
+
// The wait itself belongs to the event engine. Readiness across a style swap is
|
|
2088
|
+
// answerable only from the reload state IT holds, and the two ways a hand-rolled
|
|
2089
|
+
// version parks forever (reading `loaded()` inside the style.load drain, where it
|
|
2090
|
+
// is still false, and a dispose that drops the deferred queue un-invoked) are both
|
|
2091
|
+
// closed there rather than worked around here.
|
|
2092
|
+
//
|
|
2093
|
+
// A slot write still queued comes first. An overlay is drawn when its turn on the
|
|
2094
|
+
// renderer's tail comes, so until then the map is idle and holds none of it, and a wait
|
|
2095
|
+
// that read the map now would resolve before the overlay's sources exist. A write that
|
|
2096
|
+
// cannot land is not waited for past dispose, for the reason above.
|
|
2097
|
+
const writes = this.overlay.whenSlotWritesLand();
|
|
2098
|
+
if (writes === null || this.events.disposed) {
|
|
2099
|
+
return this.events.whenSettled();
|
|
2100
|
+
}
|
|
2101
|
+
|
|
2102
|
+
// The wait ends on the write or on dispose, whichever comes first. It is held as one
|
|
2103
|
+
// function in a set the client empties as waits end, not as a reaction on a promise the
|
|
2104
|
+
// client keeps for its lifetime, which would hold every wait ever made until dispose.
|
|
2105
|
+
return new Promise<void>((resolve) => {
|
|
2106
|
+
const end = (): void => {
|
|
2107
|
+
this.slotWriteWaits.delete(end);
|
|
2108
|
+
resolve();
|
|
2109
|
+
};
|
|
2110
|
+
this.slotWriteWaits.add(end);
|
|
2111
|
+
void writes.then(end);
|
|
2112
|
+
}).then(() => this.events.whenSettled());
|
|
2113
|
+
}
|
|
2114
|
+
|
|
2115
|
+
/**
|
|
2116
|
+
* waitForCategoryOverlay answers once the category overlay of the given slug is on the map:
|
|
2117
|
+
* `true` when it is drawn, at once when it already is, and `false` when the signal aborts or
|
|
2118
|
+
* the client is disposed first.
|
|
2119
|
+
*
|
|
2120
|
+
* It is the wait of a caller that selected an overlay and did not mount it. A studio tool
|
|
2121
|
+
* writes the selection to a store and a binding calls `setCategoryOverlay` in reaction, a
|
|
2122
|
+
* turn or more after the tool's own. Until then nothing is queued and nothing is in flight,
|
|
2123
|
+
* so `waitForRender` resolves within a frame over a map that holds none of the overlay. Wait
|
|
2124
|
+
* for the overlay first, then for the render of its tiles.
|
|
2125
|
+
*
|
|
2126
|
+
* The wait ends on the mount of that overlay and on no other: another overlay drawn in the
|
|
2127
|
+
* slot meanwhile, a clear, and an enrichment of the same slug leave it waiting. It never
|
|
2128
|
+
* rejects, and it runs no timer of its own: pass a signal to bound it.
|
|
2129
|
+
*
|
|
2130
|
+
* The answer is read once every overlay write asked for so far has run. A wait asked while a
|
|
2131
|
+
* clear or another overlay is queued over the one drawn is answered by what the map holds
|
|
2132
|
+
* after them, and a mount with a clear queued behind it answers nobody. A disposed client
|
|
2133
|
+
* answers `false`, whatever it had drawn.
|
|
2134
|
+
*
|
|
2135
|
+
* The answer is read off the category slot and never off the style. A base-map switch in
|
|
2136
|
+
* flight keeps the slot and draws the overlay again on the style it brings, so a wait asked
|
|
2137
|
+
* meanwhile answers `true` while the map holds none of the overlay's sources yet. The
|
|
2138
|
+
* `waitForRender` made next waits for the switch and for what it draws again.
|
|
2139
|
+
*
|
|
2140
|
+
* @param slug The slug of the overlay awaited, as its manifest entry states it.
|
|
2141
|
+
* @param options.signal Ends the wait when it aborts, with `false`.
|
|
2142
|
+
* @returns `true` once the category slot holds the overlay, `false` when the wait ended first.
|
|
2143
|
+
* @example
|
|
2144
|
+
* ```ts
|
|
2145
|
+
* import type { MapLibreClient } from "@mountaya/elements/editor";
|
|
2146
|
+
*
|
|
2147
|
+
* declare const client: MapLibreClient;
|
|
2148
|
+
*
|
|
2149
|
+
* if (await client.waitForCategoryOverlay("aspectslope", { signal: AbortSignal.timeout(5_000) })) {
|
|
2150
|
+
* await client.waitForRender();
|
|
2151
|
+
* client.queryOverlayFeaturesAt([6.86, 45.83]);
|
|
2152
|
+
* }
|
|
2153
|
+
* ```
|
|
2154
|
+
*/
|
|
2155
|
+
waitForCategoryOverlay(
|
|
2156
|
+
slug: string,
|
|
2157
|
+
options: { signal?: AbortSignal | undefined } = {},
|
|
2158
|
+
): Promise<boolean> {
|
|
2159
|
+
return this.overlay.whenCategoryOverlayMounted(slug, options.signal);
|
|
2160
|
+
}
|
|
2161
|
+
|
|
2162
|
+
unproject(point: [number, number]): [number, number] {
|
|
2163
|
+
return this.map.unproject(point).toArray();
|
|
2164
|
+
}
|
|
2165
|
+
|
|
2166
|
+
project(lngLat: [number, number]): [number, number] {
|
|
2167
|
+
const projected = this.map.project(lngLat);
|
|
2168
|
+
|
|
2169
|
+
return [projected.x, projected.y];
|
|
2170
|
+
}
|
|
2171
|
+
|
|
2172
|
+
/**
|
|
2173
|
+
* onShownCopy writes a place on the copy of the world the camera shows. A map panned across
|
|
2174
|
+
* the antimeridian shows a copy where the meridian at -170 reads 190, and the renderer holds
|
|
2175
|
+
* the pixels and the terrain of that copy alone, so a place handed back inside [-180, 180] is
|
|
2176
|
+
* moved whole turns to it, and by none on a map that shows the world it is written in.
|
|
2177
|
+
*/
|
|
2178
|
+
private onShownCopy([lng, lat]: [number, number]): [number, number] {
|
|
2179
|
+
const turns = Math.round((this.map.getCenter().lng - lng) / DEGREES_PER_TURN);
|
|
2180
|
+
|
|
2181
|
+
return [lng + DEGREES_PER_TURN * turns, lat];
|
|
2182
|
+
}
|
|
2183
|
+
|
|
2184
|
+
/** projectOnShownCopy reads the pixel a place is drawn at on the copy the camera shows. */
|
|
2185
|
+
private projectOnShownCopy(lngLat: [number, number]): ReturnType<MapLibreMap["project"]> {
|
|
2186
|
+
return this.map.project(this.onShownCopy(lngLat));
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2189
|
+
queryOverlayFeaturesAt(lngLat: [number, number]): OverlayFeature[] {
|
|
2190
|
+
// The overlay owns the query scope (the active overlay's vector layers); the
|
|
2191
|
+
// picking lives here because it composes with the POI/terrain readouts.
|
|
2192
|
+
const overlayQueryLayerIds = this.overlay.getOverlayQueryLayerIds();
|
|
2193
|
+
// No overlay query layers set (a raster overlay or no overlay) makes this a
|
|
2194
|
+
// clean no-op: an unscoped queryRenderedFeatures would return every rendered
|
|
2195
|
+
// feature, so guard before querying rather than filter a broad result.
|
|
2196
|
+
if (overlayQueryLayerIds.length === 0) {
|
|
2197
|
+
return [];
|
|
2198
|
+
}
|
|
2199
|
+
|
|
2200
|
+
// Project the coordinate to a pixel so a coordinate-driven query (an
|
|
2201
|
+
// agent-issued open carries no pixel) hits the same renderer path a
|
|
2202
|
+
// right-click there would, scoped to the active overlay's layers.
|
|
2203
|
+
const point = this.projectOnShownCopy(lngLat);
|
|
2204
|
+
const features = this.map.queryRenderedFeatures(point, { layers: overlayQueryLayerIds });
|
|
2205
|
+
|
|
2206
|
+
const overlayFeatures: OverlayFeature[] = [];
|
|
2207
|
+
// De-dupe identical property sets: an overlay can stack a fill and a symbol
|
|
2208
|
+
// for the same cell, so the raw query can return the same properties twice.
|
|
2209
|
+
const seen = new Set<string>();
|
|
2210
|
+
for (const feature of features) {
|
|
2211
|
+
const overlayFeature = featureToOverlayFeature(feature);
|
|
2212
|
+
if (!overlayFeature) {
|
|
2213
|
+
continue;
|
|
2214
|
+
}
|
|
2215
|
+
|
|
2216
|
+
const key = JSON.stringify(overlayFeature);
|
|
2217
|
+
if (seen.has(key)) {
|
|
2218
|
+
continue;
|
|
2219
|
+
}
|
|
2220
|
+
|
|
2221
|
+
seen.add(key);
|
|
2222
|
+
overlayFeatures.push(overlayFeature);
|
|
2223
|
+
}
|
|
2224
|
+
|
|
2225
|
+
return overlayFeatures;
|
|
2226
|
+
}
|
|
2227
|
+
|
|
2228
|
+
sampleOverlayAt(lngLat: [number, number]): OverlayFeature | null {
|
|
2229
|
+
// The studio bakes 3D terrain into every session, so MapLibre's
|
|
2230
|
+
// queryTerrainElevation pipeline answers every right-click: the readout
|
|
2231
|
+
// is unconditional on which overlay (if any) is active. Elevation, slope,
|
|
2232
|
+
// and aspect always show; the contextmenu tool layers any overlay-specific
|
|
2233
|
+
// classification (steepness) on top after consulting the active
|
|
2234
|
+
// overlay slug. The terrain is read on the copy of the world the camera shows, the one
|
|
2235
|
+
// whose tiles the renderer holds.
|
|
2236
|
+
const sample = sampleTerrainAt(this.map, this.onShownCopy(lngLat));
|
|
2237
|
+
if (!sample) {
|
|
2238
|
+
return null;
|
|
2239
|
+
}
|
|
2240
|
+
|
|
2241
|
+
const readout: OverlayFeature = {
|
|
2242
|
+
elevation: Math.round(sample.elevation),
|
|
2243
|
+
slope: Math.round(sample.slope),
|
|
2244
|
+
};
|
|
2245
|
+
// Flat ground falls in no direction, and the sample says so with a null. The member is
|
|
2246
|
+
// left out, since a rounded null is 0 and an aspect of 0 is a north-facing slope.
|
|
2247
|
+
if (sample.aspect !== null) {
|
|
2248
|
+
// A bearing within half a degree of a whole turn rounds to the turn, which is north: it
|
|
2249
|
+
// is written 0, so the whole number stays inside the range the sample states.
|
|
2250
|
+
readout.aspect = Math.round(sample.aspect) % DEGREES_PER_TURN;
|
|
2251
|
+
}
|
|
2252
|
+
|
|
2253
|
+
return readout;
|
|
2254
|
+
}
|
|
2255
|
+
|
|
2256
|
+
queryPoisAt(lngLat: [number, number]): PoiInfo[] {
|
|
2257
|
+
// Only the shared POI source-layers carry place names, so the hit-test names the layers
|
|
2258
|
+
// that draw one and no other: water, landuse and the route lines are never walked. A POI
|
|
2259
|
+
// pick asks once a frame while the pointer moves, and an unscoped query walks every layer
|
|
2260
|
+
// the style renders at the pixel. The published set names the OpenMapTiles layers the
|
|
2261
|
+
// vector base styles carry as well as the `pois` overlay, so the query resolves names on
|
|
2262
|
+
// topo, winter and hybrid and not only where the overlay is active. The layers are read
|
|
2263
|
+
// off the style as it stands, so a base-map switch or an overlay toggled since the last
|
|
2264
|
+
// query is already counted. A style that draws none yields no POIs, the coordinate-only
|
|
2265
|
+
// floor, and is not queried.
|
|
2266
|
+
const layers = this.map
|
|
2267
|
+
.getLayersOrder()
|
|
2268
|
+
.filter((layerId) => poiSourceLayers.has(this.map.getLayer(layerId)?.sourceLayer ?? ""));
|
|
2269
|
+
if (layers.length === 0) {
|
|
2270
|
+
return [];
|
|
2271
|
+
}
|
|
2272
|
+
|
|
2273
|
+
// Project the coordinate to a pixel so a coordinate-driven query (an
|
|
2274
|
+
// agent-issued open carries no pixel) hits the same renderer path a
|
|
2275
|
+
// right-click there would.
|
|
2276
|
+
const point = this.projectOnShownCopy(lngLat);
|
|
2277
|
+
const features = this.map.queryRenderedFeatures(point, { layers });
|
|
2278
|
+
|
|
2279
|
+
const pois: PoiInfo[] = [];
|
|
2280
|
+
// De-dupe by name+category: the POI layers stack a fill and a symbol for the
|
|
2281
|
+
// same place (e.g. a parking polygon and its icon), so the raw query can
|
|
2282
|
+
// return the feature twice.
|
|
2283
|
+
const seen = new Set<string>();
|
|
2284
|
+
for (const feature of features) {
|
|
2285
|
+
const poi = featureToPoi(feature);
|
|
2286
|
+
if (!poi) {
|
|
2287
|
+
continue;
|
|
2288
|
+
}
|
|
2289
|
+
|
|
2290
|
+
const key = `${poi.name ?? ""}${poi.category}`;
|
|
2291
|
+
if (seen.has(key)) {
|
|
2292
|
+
continue;
|
|
2293
|
+
}
|
|
2294
|
+
|
|
2295
|
+
seen.add(key);
|
|
2296
|
+
pois.push(poi);
|
|
2297
|
+
}
|
|
2298
|
+
|
|
2299
|
+
return pois;
|
|
2300
|
+
}
|
|
2301
|
+
|
|
2302
|
+
zoneAtPoint(lngLat: [number, number]): ContextMenuZone | null {
|
|
2303
|
+
// The overlay owns the zone layer scope, derived fresh from the live manifest
|
|
2304
|
+
// (the zone geometry layers' unstable ids resolved by their stable
|
|
2305
|
+
// source-layer). The picking lives here because it composes with the POI /
|
|
2306
|
+
// overlay / terrain readouts the context menu also resolves.
|
|
2307
|
+
const zoneLayerIds = this.overlay.getZoneQueryLayerIds();
|
|
2308
|
+
// No zone tile source mounted (or none at this zoom) makes this a clean no-op:
|
|
2309
|
+
// an unscoped queryRenderedFeatures would return every rendered feature, so
|
|
2310
|
+
// guard before querying rather than filter a broad result.
|
|
2311
|
+
if (zoneLayerIds.length === 0) {
|
|
2312
|
+
return null;
|
|
2313
|
+
}
|
|
2314
|
+
|
|
2315
|
+
// Project the coordinate to a pixel so a coordinate-driven query (an
|
|
2316
|
+
// agent-issued open carries no pixel) hits the same renderer path a right-click
|
|
2317
|
+
// there would, scoped to the zone geometry layers.
|
|
2318
|
+
const point = this.projectOnShownCopy(lngLat);
|
|
2319
|
+
const features = this.map.queryRenderedFeatures(point, { layers: zoneLayerIds });
|
|
2320
|
+
|
|
2321
|
+
// The renderer lists features topmost-first; return the first that resolves to
|
|
2322
|
+
// a zone so an overlapping stack shows the one on top, matching the single-zone
|
|
2323
|
+
// readout the popup renders (and the single-place POI readout).
|
|
2324
|
+
for (const feature of features) {
|
|
2325
|
+
const zone = featureToContextMenuZone(feature);
|
|
2326
|
+
if (zone) {
|
|
2327
|
+
return zone;
|
|
2328
|
+
}
|
|
2329
|
+
}
|
|
2330
|
+
|
|
2331
|
+
return null;
|
|
2332
|
+
}
|
|
2333
|
+
|
|
2334
|
+
onFeatureClick(
|
|
2335
|
+
layerIds: string[],
|
|
2336
|
+
cb: (hit: FeatureHit) => void,
|
|
2337
|
+
options?: FeatureSubscriptionOptions,
|
|
2338
|
+
): () => void {
|
|
2339
|
+
// An empty list is a subscription that does nothing, and registers nothing.
|
|
2340
|
+
if (layerIds.length === 0) {
|
|
2341
|
+
return () => {};
|
|
2342
|
+
}
|
|
2343
|
+
|
|
2344
|
+
let subscribed = true;
|
|
2345
|
+
const handler = (event: MapMouseEvent) => {
|
|
2346
|
+
// One hit-test across every layer of the subscription, where a listener scoped to each
|
|
2347
|
+
// layer would be answered once per layer with a feature under the click: a waypoint on
|
|
2348
|
+
// its route would report the point, the line and the line's casing. A layer the style
|
|
2349
|
+
// does not hold is left out, since the renderer refuses a query that names one and a
|
|
2350
|
+
// base-map switch wipes every layer for a beat.
|
|
2351
|
+
const layers = layerIds.filter((layerId) => this.map.getLayer(layerId) !== undefined);
|
|
2352
|
+
if (layers.length === 0) {
|
|
2353
|
+
return;
|
|
2354
|
+
}
|
|
2355
|
+
|
|
2356
|
+
// The renderer lists the features under the click topmost-first, so the first the
|
|
2357
|
+
// subscription answers is the one the user meant: a feature it refuses, drawn over one it
|
|
2358
|
+
// answers, never hides it. A click that found none it answers is dropped.
|
|
2359
|
+
const accepts = options?.accepts;
|
|
2360
|
+
const hit = this.map
|
|
2361
|
+
.queryRenderedFeatures(event.point, { layers })
|
|
2362
|
+
.map(featureToHit)
|
|
2363
|
+
.find((candidate) => accepts === undefined || accepts(candidate));
|
|
2364
|
+
if (hit === undefined) {
|
|
2365
|
+
return;
|
|
2366
|
+
}
|
|
2367
|
+
|
|
2368
|
+
// The browser's count of the clicks made in a row on this spot, so a caller tells the
|
|
2369
|
+
// second click of a double-click from a click of its own. A click that counts none (one a
|
|
2370
|
+
// keyboard or a script made) reports no count.
|
|
2371
|
+
const clicks = event.originalEvent?.detail;
|
|
2372
|
+
const clicked =
|
|
2373
|
+
typeof clicks === "number" && clicks > 0 ? { ...hit, clickCount: clicks } : hit;
|
|
2374
|
+
|
|
2375
|
+
// Reported once the click has been dispatched to every listener, for the reason
|
|
2376
|
+
// onContextMenu gives: an edit that turns the click into a vertex of its line marks it
|
|
2377
|
+
// from a listener attached after this one, and a click it took selects nothing.
|
|
2378
|
+
queueMicrotask(() => {
|
|
2379
|
+
if (subscribed && !this.events.disposed && !event.defaultPrevented) {
|
|
2380
|
+
cb(clicked);
|
|
2381
|
+
}
|
|
2382
|
+
});
|
|
2383
|
+
};
|
|
2384
|
+
|
|
2385
|
+
// One map-level listener, tracked by the event engine so the returned unsubscribe
|
|
2386
|
+
// detaches it and dispose() sweeps one a caller forgot. The engine re-attaches nothing
|
|
2387
|
+
// on a restyle, so a base-map switch leaves it firing.
|
|
2388
|
+
const detach = this.events.on("click", handler);
|
|
2389
|
+
|
|
2390
|
+
return () => {
|
|
2391
|
+
subscribed = false;
|
|
2392
|
+
detach();
|
|
2393
|
+
};
|
|
2394
|
+
}
|
|
2395
|
+
|
|
2396
|
+
onFeatureHover(
|
|
2397
|
+
layerIds: string[],
|
|
2398
|
+
handlers: FeatureHoverHandlers,
|
|
2399
|
+
options?: FeatureSubscriptionOptions,
|
|
2400
|
+
): () => void {
|
|
2401
|
+
// An empty list is a subscription that does nothing. So is one made on a disposed client:
|
|
2402
|
+
// the event engine sweeps its listeners once, at dispose, and one attached afterwards
|
|
2403
|
+
// would sit on the map with nothing left to take it off.
|
|
2404
|
+
if (layerIds.length === 0 || this.events.disposed) {
|
|
2405
|
+
return () => {};
|
|
2406
|
+
}
|
|
2407
|
+
|
|
2408
|
+
const subscription: HoverSubscription = {
|
|
2409
|
+
accepts: options?.accepts,
|
|
2410
|
+
handlers,
|
|
2411
|
+
inside: false,
|
|
2412
|
+
layerIds: new Set(layerIds),
|
|
2413
|
+
};
|
|
2414
|
+
this.hoverSubscriptions.add(subscription);
|
|
2415
|
+
this.refreshHoverLayerIds();
|
|
2416
|
+
// The seam has a subscriber again, so a teardown still waiting on its frame is withdrawn
|
|
2417
|
+
// and the listeners it would have taken stay.
|
|
2418
|
+
this.cancelHoverTeardown();
|
|
2419
|
+
this.attachHoverListeners();
|
|
2420
|
+
// A pointer at rest sends no move, so the subscription is told what is under it from the
|
|
2421
|
+
// position the seam still holds. A hook that remakes its subscription under a resting
|
|
2422
|
+
// pointer hears its enter this way, and the pointer cursor is never dropped in between.
|
|
2423
|
+
if (this.hoverRestingPoint !== null) {
|
|
2424
|
+
this.hoverPoint = this.hoverRestingPoint;
|
|
2425
|
+
this.requestHoverFrame();
|
|
2426
|
+
}
|
|
2427
|
+
|
|
2428
|
+
return () => {
|
|
2429
|
+
if (!this.hoverSubscriptions.delete(subscription)) {
|
|
2430
|
+
return;
|
|
2431
|
+
}
|
|
2432
|
+
|
|
2433
|
+
this.refreshHoverLayerIds();
|
|
2434
|
+
// The last subscription takes any waiting hit-test with it, and no leave is reported:
|
|
2435
|
+
// the caller clears what it had lit. The listeners and the cursor wait one frame.
|
|
2436
|
+
if (this.hoverSubscriptions.size === 0) {
|
|
2437
|
+
this.cancelHoverFrame();
|
|
2438
|
+
this.scheduleHoverTeardown();
|
|
2439
|
+
}
|
|
2440
|
+
};
|
|
2441
|
+
}
|
|
2442
|
+
|
|
2443
|
+
/**
|
|
2444
|
+
* scheduleHoverTeardown ends the hover seam one animation frame after its last subscription
|
|
2445
|
+
* did: it puts the base cursor back when the seam had asked for the pointer, detaches the
|
|
2446
|
+
* two listeners and forgets where the pointer was.
|
|
2447
|
+
*
|
|
2448
|
+
* The frame is what tells a seam nobody reads any more from a subscription being remade. A
|
|
2449
|
+
* hook that ends its subscription and makes the next one in the same task finds the
|
|
2450
|
+
* teardown withdrawn, so the pointer cursor never flickers through the base one. With no
|
|
2451
|
+
* subscription made again, nothing would hit-test the pointer and clear the cursor, so the
|
|
2452
|
+
* teardown does. The write goes through the cursor seam, so under an edit's lock it sets
|
|
2453
|
+
* the base the lock releases to and leaves the pinned cursor.
|
|
2454
|
+
*/
|
|
2455
|
+
private scheduleHoverTeardown(): void {
|
|
2456
|
+
if (this.hoverTeardownFrame !== null) {
|
|
2457
|
+
return;
|
|
2458
|
+
}
|
|
2459
|
+
|
|
2460
|
+
this.hoverTeardownFrame = requestAnimationFrame(() => {
|
|
2461
|
+
this.hoverTeardownFrame = null;
|
|
2462
|
+
if (this.hoverPointer) {
|
|
2463
|
+
this.applyCursor("");
|
|
2464
|
+
this.hoverPointer = false;
|
|
2465
|
+
}
|
|
2466
|
+
|
|
2467
|
+
this.cancelHoverFrame();
|
|
2468
|
+
this.detachHoverListeners?.();
|
|
2469
|
+
this.detachHoverListeners = null;
|
|
2470
|
+
this.hoverRestingPoint = null;
|
|
2471
|
+
});
|
|
2472
|
+
}
|
|
2473
|
+
|
|
2474
|
+
/** cancelHoverTeardown withdraws the teardown waiting on its frame, when one is. */
|
|
2475
|
+
private cancelHoverTeardown(): void {
|
|
2476
|
+
if (this.hoverTeardownFrame !== null) {
|
|
2477
|
+
cancelAnimationFrame(this.hoverTeardownFrame);
|
|
2478
|
+
this.hoverTeardownFrame = null;
|
|
2479
|
+
}
|
|
2480
|
+
}
|
|
2481
|
+
|
|
2482
|
+
/** requestHoverFrame asks for the frame that hit-tests the waiting position, once. */
|
|
2483
|
+
private requestHoverFrame(): void {
|
|
2484
|
+
if (this.hoverFrame === null) {
|
|
2485
|
+
this.hoverFrame = requestAnimationFrame(() => {
|
|
2486
|
+
this.hoverFrame = null;
|
|
2487
|
+
this.hitTestHover();
|
|
2488
|
+
});
|
|
2489
|
+
}
|
|
2490
|
+
}
|
|
2491
|
+
|
|
2492
|
+
/**
|
|
2493
|
+
* attachHoverListeners registers the hover seam's two map-level listeners, once, however
|
|
2494
|
+
* many subscriptions share them.
|
|
2495
|
+
*
|
|
2496
|
+
* The mousemove only records where the pointer is and asks for a frame, so a burst of moves
|
|
2497
|
+
* inside one frame costs one hit-test, taken at the position the pointer ended on. The
|
|
2498
|
+
* mouseout is the leave a layer-scoped listener reports when the pointer exits the canvas
|
|
2499
|
+
* over a feature, which no mousemove follows.
|
|
2500
|
+
*/
|
|
2501
|
+
private attachHoverListeners(): void {
|
|
2502
|
+
if (this.detachHoverListeners !== null) {
|
|
2503
|
+
return;
|
|
2504
|
+
}
|
|
2505
|
+
|
|
2506
|
+
const detachMove = this.events.on("mousemove", (event: MapMouseEvent) => {
|
|
2507
|
+
this.hoverPoint = event.point;
|
|
2508
|
+
this.hoverRestingPoint = event.point;
|
|
2509
|
+
this.requestHoverFrame();
|
|
2510
|
+
});
|
|
2511
|
+
const detachOut = this.events.on("mouseout", () => {
|
|
2512
|
+
// Nothing is under a pointer that left, and a hit-test still waiting on its frame would
|
|
2513
|
+
// answer for a position the pointer no longer holds.
|
|
2514
|
+
this.cancelHoverFrame();
|
|
2515
|
+
this.hoverRestingPoint = null;
|
|
2516
|
+
this.reportHover([]);
|
|
2517
|
+
});
|
|
2518
|
+
|
|
2519
|
+
this.detachHoverListeners = () => {
|
|
2520
|
+
detachMove();
|
|
2521
|
+
detachOut();
|
|
2522
|
+
};
|
|
2523
|
+
}
|
|
2524
|
+
|
|
2525
|
+
/** refreshHoverLayerIds rebuilds the union of the layers the hover subscriptions read. */
|
|
2526
|
+
private refreshHoverLayerIds(): void {
|
|
2527
|
+
const union = new Set<string>();
|
|
2528
|
+
for (const subscription of this.hoverSubscriptions) {
|
|
2529
|
+
for (const layerId of subscription.layerIds) {
|
|
2530
|
+
union.add(layerId);
|
|
2531
|
+
}
|
|
2532
|
+
}
|
|
2533
|
+
|
|
2534
|
+
this.hoverLayerIds = [...union];
|
|
2535
|
+
}
|
|
2536
|
+
|
|
2537
|
+
/** cancelHoverFrame drops the waiting hover hit-test and the position it would have read. */
|
|
2538
|
+
private cancelHoverFrame(): void {
|
|
2539
|
+
if (this.hoverFrame !== null) {
|
|
2540
|
+
cancelAnimationFrame(this.hoverFrame);
|
|
2541
|
+
this.hoverFrame = null;
|
|
2542
|
+
}
|
|
2543
|
+
|
|
2544
|
+
this.hoverPoint = null;
|
|
2545
|
+
}
|
|
2546
|
+
|
|
2547
|
+
/**
|
|
2548
|
+
* hitTestHover asks the renderer once what is under the pointer, across every layer a hover
|
|
2549
|
+
* subscription reads, and reports the answer to each of them.
|
|
2550
|
+
*/
|
|
2551
|
+
private hitTestHover(): void {
|
|
2552
|
+
const point = this.hoverPoint;
|
|
2553
|
+
this.hoverPoint = null;
|
|
2554
|
+
if (point === null || this.hoverSubscriptions.size === 0) {
|
|
2555
|
+
return;
|
|
2556
|
+
}
|
|
2557
|
+
|
|
2558
|
+
// A layer the style does not hold is left out: the renderer refuses a query that names
|
|
2559
|
+
// one, and a base-map switch wipes every layer for a beat. With none live there is
|
|
2560
|
+
// nothing to ask, and every subscription reads as left.
|
|
2561
|
+
const layers = this.hoverLayerIds.filter((layerId) => this.map.getLayer(layerId) !== undefined);
|
|
2562
|
+
|
|
2563
|
+
this.reportHover(layers.length === 0 ? [] : this.map.queryRenderedFeatures(point, { layers }));
|
|
2564
|
+
}
|
|
2565
|
+
|
|
2566
|
+
/**
|
|
2567
|
+
* reportHover tells each hover subscription what one hit-test found: the topmost feature on
|
|
2568
|
+
* its own layers as an enter, or a leave when it had one and has none now.
|
|
2569
|
+
*
|
|
2570
|
+
* An enter is told again on every hit-test that still finds a feature, which is what makes
|
|
2571
|
+
* the seam report a feature and not a layer: sliding along a continuous route from one
|
|
2572
|
+
* segment onto the next never leaves the layer, and the consumer still has to hear the
|
|
2573
|
+
* second segment. So a consumer that acts on an enter must be idempotent.
|
|
2574
|
+
*/
|
|
2575
|
+
private reportHover(features: MapGeoJSONFeature[]): void {
|
|
2576
|
+
// Read before anything is told, so a handler that ends a subscription or writes the
|
|
2577
|
+
// cursor cannot change what the others hear about this hit-test.
|
|
2578
|
+
const hits = [...this.hoverSubscriptions].map((subscription) => {
|
|
2579
|
+
// The renderer lists the features topmost-first, so the first on a subscription's
|
|
2580
|
+
// layers that it answers is the one the pointer is on for it. Each feature is read as a
|
|
2581
|
+
// hit once, whether the subscription filters or not, and that one hit is what it hears.
|
|
2582
|
+
const { accepts } = subscription;
|
|
2583
|
+
for (const candidate of features) {
|
|
2584
|
+
if (!subscription.layerIds.has(candidate.layer.id)) {
|
|
2585
|
+
continue;
|
|
2586
|
+
}
|
|
2587
|
+
|
|
2588
|
+
const hit = featureToHit(candidate);
|
|
2589
|
+
if (accepts === undefined || accepts(hit)) {
|
|
2590
|
+
return { hit, subscription };
|
|
2591
|
+
}
|
|
2592
|
+
}
|
|
2593
|
+
|
|
2594
|
+
return { hit: undefined, subscription };
|
|
2595
|
+
});
|
|
2596
|
+
|
|
2597
|
+
// The cursor goes through applyCursor, not the canvas directly, so an active edit's
|
|
2598
|
+
// pinned cursor lock is honored. It is the pointer while any subscription has a feature
|
|
2599
|
+
// and the base cursor once none has, so one subscription leaving while another still has
|
|
2600
|
+
// a feature never drops it.
|
|
2601
|
+
if (hits.some(({ hit }) => hit !== undefined)) {
|
|
2602
|
+
this.applyCursor("pointer");
|
|
2603
|
+
this.hoverPointer = true;
|
|
2604
|
+
} else if (this.hoverPointer) {
|
|
2605
|
+
this.applyCursor("");
|
|
2606
|
+
this.hoverPointer = false;
|
|
2607
|
+
}
|
|
2608
|
+
|
|
2609
|
+
// Leaves before enters. Two subscriptions sharing one "what is hovered" slot clear it on
|
|
2610
|
+
// a leave and fill it on an enter, and sliding off a waypoint onto the leg beneath it is
|
|
2611
|
+
// both in one hit-test: a leave told last would empty the slot the enter had just filled.
|
|
2612
|
+
// Each handler is called only while its subscription still stands, since one told earlier
|
|
2613
|
+
// in this report may have ended it.
|
|
2614
|
+
for (const { hit, subscription } of hits) {
|
|
2615
|
+
if (hit === undefined && subscription.inside) {
|
|
2616
|
+
subscription.inside = false;
|
|
2617
|
+
if (this.hoverSubscriptions.has(subscription)) {
|
|
2618
|
+
notifyListeners([() => subscription.handlers.onLeave()]);
|
|
2619
|
+
}
|
|
2620
|
+
}
|
|
2621
|
+
}
|
|
2622
|
+
|
|
2623
|
+
for (const { hit, subscription } of hits) {
|
|
2624
|
+
if (hit !== undefined && this.hoverSubscriptions.has(subscription)) {
|
|
2625
|
+
subscription.inside = true;
|
|
2626
|
+
notifyListeners([() => subscription.handlers.onEnter(hit)]);
|
|
2627
|
+
}
|
|
2628
|
+
}
|
|
2629
|
+
}
|
|
2630
|
+
|
|
2631
|
+
onContextMenu(cb: (event: MapContextMenuEvent) => void): () => void {
|
|
2632
|
+
let subscribed = true;
|
|
2633
|
+
const handler = (event: MapMouseEvent) => {
|
|
2634
|
+
// The renderer calls every listener of a right-click whatever one of them prevents, in
|
|
2635
|
+
// the order they were attached, and a host subscribes here before an edit attaches its
|
|
2636
|
+
// own. An edit engine that takes a right-click, one on a handle of its line, marks it
|
|
2637
|
+
// with preventDefault from that later listener. So the mark is read once the dispatch
|
|
2638
|
+
// is over: a microtask later, still inside the task the gesture arrived in.
|
|
2639
|
+
//
|
|
2640
|
+
// This listener leaves no mark of its own. The renderer suppresses the browser's menu
|
|
2641
|
+
// for as long as a right-click listener stands, and a mark here would tell every
|
|
2642
|
+
// reader after this one that the gesture was taken.
|
|
2643
|
+
queueMicrotask(() => {
|
|
2644
|
+
// A subscription ended, or a client disposed, while the gesture was being
|
|
2645
|
+
// dispatched hears nothing of it.
|
|
2646
|
+
if (!subscribed || this.events.disposed || event.defaultPrevented) {
|
|
2647
|
+
return;
|
|
2648
|
+
}
|
|
2649
|
+
|
|
2650
|
+
// The meridian as the range names it, as onMapClick hands it.
|
|
2651
|
+
cb({
|
|
2652
|
+
lngLat: [wrapLongitudePastRange(event.lngLat.lng), event.lngLat.lat],
|
|
2653
|
+
point: [event.point.x, event.point.y],
|
|
2654
|
+
});
|
|
2655
|
+
});
|
|
2656
|
+
};
|
|
2657
|
+
|
|
2658
|
+
// Attach through the manager so the handler tracks under a unique key: the
|
|
2659
|
+
// returned unsubscribe detaches this listener, and dispose() sweeps it even
|
|
2660
|
+
// if a caller never unsubscribes. Multiple right-click listeners coexist,
|
|
2661
|
+
// each keyed on its own.
|
|
2662
|
+
const detach = this.events.on("contextmenu", handler);
|
|
2663
|
+
|
|
2664
|
+
return () => {
|
|
2665
|
+
subscribed = false;
|
|
2666
|
+
detach();
|
|
2667
|
+
};
|
|
2668
|
+
}
|
|
2669
|
+
|
|
2670
|
+
onMapClick(cb: (lngLat: [number, number]) => void): () => void {
|
|
2671
|
+
const handler = (event: MapMouseEvent) => {
|
|
2672
|
+
// The map keeps counting over a copy of the world, where the meridian at -170 reads 190.
|
|
2673
|
+
// The subscriber is handed the meridian as the range names it, the one a place is saved
|
|
2674
|
+
// and sent under, and {@link queryPoisAt} finds the copy again for its hit-test.
|
|
2675
|
+
notifyListeners([cb], [wrapLongitudePastRange(event.lngLat.lng), event.lngLat.lat]);
|
|
2676
|
+
};
|
|
2677
|
+
|
|
2678
|
+
// Attach through the manager so the handler tracks under a unique key:
|
|
2679
|
+
// the returned unsubscribe detaches it, dispose() sweeps it. It mirrors
|
|
2680
|
+
// onContextMenu but listens to the left-click `click` event the
|
|
2681
|
+
// waypoint-from-POI flow drives, the seam an unscoped click subscriber
|
|
2682
|
+
// reads to query POIs at the clicked coordinate.
|
|
2683
|
+
return this.events.on("click", handler);
|
|
2684
|
+
}
|
|
2685
|
+
|
|
2686
|
+
/**
|
|
2687
|
+
* takeMapClicks hands `cb` every left-click on the map, as {@link onMapClick} does, and marks
|
|
2688
|
+
* each one taken with `preventDefault`, so a feature-click subscriber (onFeatureClick) hears
|
|
2689
|
+
* none of them.
|
|
2690
|
+
*
|
|
2691
|
+
* It is what a point pick listens through. A pick's click is aimed at a place, often a line
|
|
2692
|
+
* because the place is on it: a split goes where the click projects onto the segment, a route
|
|
2693
|
+
* starts or ends where it lands. Untaken, the same click would also reach the host's selection,
|
|
2694
|
+
* which would select the segment under it and arm its edit, or open the details of the marker
|
|
2695
|
+
* there. The pick's listener is attached after the host's, and a feature click reads the mark
|
|
2696
|
+
* once the click has been dispatched to every listener, so the mark holds whichever came first.
|
|
2697
|
+
*/
|
|
2698
|
+
private takeMapClicks(cb: (lngLat: [number, number]) => void): () => void {
|
|
2699
|
+
return this.events.on("click", (event: MapMouseEvent) => {
|
|
2700
|
+
event.preventDefault();
|
|
2701
|
+
notifyListeners([cb], [wrapLongitudePastRange(event.lngLat.lng), event.lngLat.lat]);
|
|
2702
|
+
});
|
|
2703
|
+
}
|
|
2704
|
+
|
|
2705
|
+
onPointerMove(cb: (move: MapPointerMove) => void): () => void {
|
|
2706
|
+
const handler = (event: MapMouseEvent) => {
|
|
2707
|
+
// The meridian as the range names it, as onMapClick hands it; the pixel as read.
|
|
2708
|
+
notifyListeners([cb], {
|
|
2709
|
+
lngLat: [wrapLongitudePastRange(event.lngLat.lng), event.lngLat.lat],
|
|
2710
|
+
point: [event.point.x, event.point.y],
|
|
2711
|
+
});
|
|
2712
|
+
};
|
|
2713
|
+
|
|
2714
|
+
// Attach through the manager so the handler tracks under a unique key (the
|
|
2715
|
+
// returned unsubscribe detaches it, dispose() sweeps it). It mirrors
|
|
2716
|
+
// onContextMenu; "mousemove" is the high-frequency move the editing tooltip
|
|
2717
|
+
// follows, so a consumer keeps the position in a ref rather than state.
|
|
2718
|
+
return this.events.on("mousemove", handler);
|
|
2719
|
+
}
|
|
2720
|
+
|
|
2721
|
+
onPointerLeave(cb: () => void): () => void {
|
|
2722
|
+
// A disposed client has let go of the map: a listener put on its canvas now no dispose would
|
|
2723
|
+
// take off.
|
|
2724
|
+
if (this.events.disposed) {
|
|
2725
|
+
return () => {};
|
|
2726
|
+
}
|
|
2727
|
+
|
|
2728
|
+
// The canvas, not the map container, is what the pointer actually rides;
|
|
2729
|
+
// attaching to the container would fire on every panel that overlays the
|
|
2730
|
+
// map (the floating layers panel, the elevation chart, the sidenav). The
|
|
2731
|
+
// canvas's own pointerleave is the single signal that the pointer truly
|
|
2732
|
+
// left the map surface, so a cursor-following overlay hides exactly when
|
|
2733
|
+
// the pointer enters another surface or exits the studio.
|
|
2734
|
+
const canvas = this.map.getCanvas();
|
|
2735
|
+
canvas.addEventListener("pointerleave", cb);
|
|
2736
|
+
// A listener on the canvas is outside the event engine, which holds the map's own events,
|
|
2737
|
+
// so it is kept here for dispose to take off one a caller never unsubscribed.
|
|
2738
|
+
const detach = (): void => {
|
|
2739
|
+
canvas.removeEventListener("pointerleave", cb);
|
|
2740
|
+
this.pointerLeaveDetachers.delete(detach);
|
|
2741
|
+
};
|
|
2742
|
+
this.pointerLeaveDetachers.add(detach);
|
|
2743
|
+
|
|
2744
|
+
return detach;
|
|
2745
|
+
}
|
|
2746
|
+
|
|
2747
|
+
onViewportChange(cb: (viewport: MapViewportChange) => void): () => void {
|
|
2748
|
+
const handler = () => {
|
|
2749
|
+
const center = this.map.getCenter();
|
|
2750
|
+
notifyListeners([cb], {
|
|
2751
|
+
bearing: this.map.getBearing(),
|
|
2752
|
+
center: [center.lng, center.lat],
|
|
2753
|
+
zoom: this.map.getZoom(),
|
|
2754
|
+
});
|
|
2755
|
+
};
|
|
2756
|
+
|
|
2757
|
+
// Attach through the manager so the handler tracks under a unique key: the
|
|
2758
|
+
// returned unsubscribe detaches this listener, and dispose() sweeps it even
|
|
2759
|
+
// if a caller never unsubscribes. Several passive viewport readouts may
|
|
2760
|
+
// subscribe to "move" at once, each keyed on its own.
|
|
2761
|
+
return this.events.on("move", handler);
|
|
2762
|
+
}
|
|
2763
|
+
|
|
2764
|
+
onViewportSettle(cb: (viewport: MapViewportChange) => void): () => void {
|
|
2765
|
+
const handler = () => {
|
|
2766
|
+
const center = this.map.getCenter();
|
|
2767
|
+
notifyListeners([cb], {
|
|
2768
|
+
bearing: this.map.getBearing(),
|
|
2769
|
+
center: [center.lng, center.lat],
|
|
2770
|
+
zoom: this.map.getZoom(),
|
|
2771
|
+
});
|
|
2772
|
+
};
|
|
2773
|
+
|
|
2774
|
+
// Through the manager, as `onViewportChange` attaches: the unsubscribe detaches this
|
|
2775
|
+
// listener, and dispose() sweeps one a caller never unsubscribed.
|
|
2776
|
+
return this.events.on("moveend", handler);
|
|
2777
|
+
}
|
|
2778
|
+
|
|
2779
|
+
onResize(cb: () => void): () => void {
|
|
2780
|
+
// Through the manager, as the viewport seams attach: the unsubscribe detaches this
|
|
2781
|
+
// listener, and dispose() sweeps one a caller never unsubscribed.
|
|
2782
|
+
return this.events.on("resize", () => notifyListeners([cb]));
|
|
2783
|
+
}
|
|
2784
|
+
|
|
2785
|
+
onTilesAccessRequired(cb: () => void): () => void {
|
|
2786
|
+
const handler = (event: ErrorEvent) => {
|
|
2787
|
+
// The renderer sends every failure through this one "error" stream: a style that does
|
|
2788
|
+
// not parse, a layer assertion, a dropped tile, a 404, a 5xx. A refusal of access is the
|
|
2789
|
+
// one among them that is product state, and it is read by the definition the map's own
|
|
2790
|
+
// `accessrequired` event reads, so the two never disagree about one request. A failure
|
|
2791
|
+
// with no status, a status that refuses nothing, and a refusal the map tells nobody of,
|
|
2792
|
+
// of a credential it has replaced since, leave the signal down.
|
|
2793
|
+
if (accessRefusalStatus(event.error) !== null && !isToldToNobody(event.error)) {
|
|
2794
|
+
notifyListeners([cb]);
|
|
2795
|
+
}
|
|
2796
|
+
};
|
|
2797
|
+
|
|
2798
|
+
// Attach through the manager like the other map-level subscriptions: the
|
|
2799
|
+
// returned unsubscribe detaches this listener, dispose() sweeps it if a
|
|
2800
|
+
// caller never unsubscribes, and a base-map switch leaves it firing (setStyle
|
|
2801
|
+
// does not drop it), so the signal survives a terrain swap.
|
|
2802
|
+
return this.events.on("error", handler);
|
|
2803
|
+
}
|
|
2804
|
+
|
|
2805
|
+
onTilesAccessRestored(cb: () => void): () => void {
|
|
2806
|
+
// The refusals are the client's own standing set, so a subscription made while one stands
|
|
2807
|
+
// is told when it ends, whether or not it heard it begin.
|
|
2808
|
+
this.tilesAccessRestoredSubscribers.add(cb);
|
|
2809
|
+
|
|
2810
|
+
return () => {
|
|
2811
|
+
this.tilesAccessRestoredSubscribers.delete(cb);
|
|
2812
|
+
};
|
|
2813
|
+
}
|
|
2814
|
+
|
|
2815
|
+
isTilesAccessRequired(): boolean {
|
|
2816
|
+
return this.refusedSources.size > 0;
|
|
2817
|
+
}
|
|
2818
|
+
|
|
2819
|
+
/**
|
|
2820
|
+
* trackTilesAccess keeps the refusals of access that stand, from the streams that raise
|
|
2821
|
+
* one and answer one.
|
|
2822
|
+
*
|
|
2823
|
+
* It runs once, at construction, and its listeners are held by the event engine, so they
|
|
2824
|
+
* are attached before any subscriber's and are swept on dispose. A refusal is read by the
|
|
2825
|
+
* definition {@link MapLibreViewClient.onTilesAccessRequired} reads, so a failure that
|
|
2826
|
+
* raises that signal is one that stands here, and a refusal the map tells nobody of stands
|
|
2827
|
+
* for nothing.
|
|
2828
|
+
*/
|
|
2829
|
+
private trackTilesAccess(): void {
|
|
2830
|
+
this.events.on("error", (event: ErrorEvent) => {
|
|
2831
|
+
if (accessRefusalStatus(event.error) !== null && !isToldToNobody(event.error)) {
|
|
2832
|
+
this.answerTilesAccess({ kind: "refused", source: accessRefusalSource(event) });
|
|
2833
|
+
}
|
|
2834
|
+
});
|
|
2835
|
+
|
|
2836
|
+
this.events.on("sourcedata", (event: MapSourceDataEvent) => {
|
|
2837
|
+
// This stream also carries a source's description and its visibility: a tile that loaded
|
|
2838
|
+
// is the one event among them that answers a refusal.
|
|
2839
|
+
if (event.tile !== undefined) {
|
|
2840
|
+
this.answerTilesAccess({ kind: "tile", source: event.sourceId });
|
|
2841
|
+
}
|
|
2842
|
+
});
|
|
2843
|
+
|
|
2844
|
+
// A style and a sprite are requested once per style, so the next style to load is what
|
|
2845
|
+
// answers a refusal of either.
|
|
2846
|
+
this.events.on("style.load", () => this.answerTilesAccess({ kind: "style" }));
|
|
2847
|
+
}
|
|
2848
|
+
|
|
2849
|
+
/**
|
|
2850
|
+
* redrawEditsAsContextReturns draws each live edit again once the style MapLibre sets again
|
|
2851
|
+
* as a lost WebGL context returns has loaded.
|
|
2852
|
+
*
|
|
2853
|
+
* MapLibre holds no style while the context is lost, so what an edit engine's library wrote
|
|
2854
|
+
* meanwhile reached none: a draft applied then, an undo, a peer's change. The style that
|
|
2855
|
+
* returns is the one kept aside at the loss, the edit's sources and layers included, as they
|
|
2856
|
+
* read then. So each engine armed as that style loads is stopped on it and started again,
|
|
2857
|
+
* the pair a base-map switch runs ({@link setBaseTerrain}), and draws what it holds now. An
|
|
2858
|
+
* engine a base-map switch already queued for replay is left to that replay.
|
|
2859
|
+
*
|
|
2860
|
+
* It runs once, at construction, and its listener is held by the event engine.
|
|
2861
|
+
*/
|
|
2862
|
+
private redrawEditsAsContextReturns(): void {
|
|
2863
|
+
this.events.on("webglcontextrestored", () => {
|
|
2864
|
+
// The engines armed as the context returns. One a base-map switch stopped has its replay
|
|
2865
|
+
// queued behind this same style, and one armed from here on is put on it as it is built
|
|
2866
|
+
// ({@link replayIfStyleReloading}).
|
|
2867
|
+
const armed = [
|
|
2868
|
+
this.segmentEditEngine,
|
|
2869
|
+
this.waypointEditEngine,
|
|
2870
|
+
this.zoneEditEngine,
|
|
2871
|
+
this.boundaryEditEngine,
|
|
2872
|
+
].filter(
|
|
2873
|
+
(engine): engine is AnyEditEngine =>
|
|
2874
|
+
engine !== null && !this.enginesAwaitingReplay.has(engine),
|
|
2875
|
+
);
|
|
2876
|
+
|
|
2877
|
+
// MapLibre has set the style again by now, so this waits for it to load: an engine's
|
|
2878
|
+
// own layers are on that style, to take off, only once it has.
|
|
2879
|
+
this.events.afterStyleLoad(() => {
|
|
2880
|
+
for (const engine of armed) {
|
|
2881
|
+
if (this.isLiveEditEngine(engine) && !this.enginesAwaitingReplay.has(engine)) {
|
|
2882
|
+
engine.detachBeforeStyleReload();
|
|
2883
|
+
engine.replayAfterStyleReload();
|
|
2884
|
+
}
|
|
2885
|
+
}
|
|
2886
|
+
});
|
|
2887
|
+
});
|
|
2888
|
+
}
|
|
2889
|
+
|
|
2890
|
+
/**
|
|
2891
|
+
* answerTilesAccess moves the refusals that stand by what the map heard
|
|
2892
|
+
* ({@link accessStandingAfter}): a refusal stands, and an answer ends the refusal it answers and
|
|
2893
|
+
* that of every source that left the style, which can never load a tile again. It tells the
|
|
2894
|
+
* restored subscribers when that leaves none standing.
|
|
2895
|
+
*/
|
|
2896
|
+
private answerTilesAccess(answer: AccessAnswer): void {
|
|
2897
|
+
const { restored, standing } = accessStandingAfter(
|
|
2898
|
+
this.refusedSources,
|
|
2899
|
+
answer,
|
|
2900
|
+
(id) => this.map.getSource(id) !== undefined,
|
|
2901
|
+
);
|
|
2902
|
+
this.refusedSources = standing;
|
|
2903
|
+
|
|
2904
|
+
if (restored) {
|
|
2905
|
+
// Copied before anyone is told, so a subscription made while the others are told hears
|
|
2906
|
+
// nothing of this one. One ended by a subscriber told before it hears nothing either.
|
|
2907
|
+
notifyListeners(
|
|
2908
|
+
[...this.tilesAccessRestoredSubscribers].map((cb) => (): void => {
|
|
2909
|
+
if (this.tilesAccessRestoredSubscribers.has(cb)) {
|
|
2910
|
+
cb();
|
|
2911
|
+
}
|
|
2912
|
+
}),
|
|
2913
|
+
);
|
|
2914
|
+
}
|
|
2915
|
+
}
|
|
2916
|
+
|
|
2917
|
+
setConstraints(constraints: MapConstraints): void {
|
|
2918
|
+
// Read before anything is stored or applied, so a pan lock MapLibre cannot hold is refused
|
|
2919
|
+
// with the zoom limits of the same call unapplied, and a base-map switch never asserts a
|
|
2920
|
+
// refused lock again from inside its style reload.
|
|
2921
|
+
if (constraints.maxBounds != null) {
|
|
2922
|
+
this.toMaxBounds(constraints.maxBounds);
|
|
2923
|
+
}
|
|
2924
|
+
|
|
2925
|
+
// Merge into the stored constraints so a partial update (e.g. only maxBounds)
|
|
2926
|
+
// does not erase a previously-applied minZoom/maxZoom on the next re-assert.
|
|
2927
|
+
const next: MapConstraints = { ...this.lastConstraints, ...constraints };
|
|
2928
|
+
// The zoom window is read as the call leaves it, before anything is stored or applied:
|
|
2929
|
+
// a window the renderer cannot hold would otherwise be asserted again, and thrown again,
|
|
2930
|
+
// from inside every later base-map switch.
|
|
2931
|
+
this.refuseZoomWindow(constraints, next);
|
|
2932
|
+
|
|
2933
|
+
const previous = this.lastConstraints;
|
|
2934
|
+
this.lastConstraints = next;
|
|
2935
|
+
try {
|
|
2936
|
+
this.applyConstraints(constraints);
|
|
2937
|
+
} catch (cause) {
|
|
2938
|
+
// What is left is a limit the renderer refuses for a reason of its own, such as a zoom
|
|
2939
|
+
// outside the range it draws. The window in force before the call is the one a base-map
|
|
2940
|
+
// switch asserts, and the refusal leaves in the package's family.
|
|
2941
|
+
this.lastConstraints = previous;
|
|
2942
|
+
throw new MountayaElementsError(
|
|
2943
|
+
`MapClient.setConstraints: the renderer refused minZoom ${String(constraints.minZoom)} ` +
|
|
2944
|
+
`and maxZoom ${String(constraints.maxZoom)}. Pass zooms inside the range the map draws.`,
|
|
2945
|
+
{ cause },
|
|
2946
|
+
);
|
|
2947
|
+
}
|
|
2948
|
+
}
|
|
2949
|
+
|
|
2950
|
+
/**
|
|
2951
|
+
* refuseZoomWindow refuses a zoom window the renderer cannot hold, naming the limit at fault.
|
|
2952
|
+
*
|
|
2953
|
+
* `stated` is what the call names and `window` what it leaves: its limits over the ones in
|
|
2954
|
+
* force. A limit the window does not state is the map's own, so a lone minimum is held
|
|
2955
|
+
* against the maximum the map has and a lone maximum against its minimum. A limit stated as
|
|
2956
|
+
* `null` is released, and is read as the limit a map is built with when it is given none.
|
|
2957
|
+
*
|
|
2958
|
+
* @throws {MountayaElementsError} When a stated limit is neither `null` nor a finite number,
|
|
2959
|
+
* or the window's minimum is above its maximum.
|
|
2960
|
+
*/
|
|
2961
|
+
private refuseZoomWindow(stated: MapConstraints, window: MapConstraints): void {
|
|
2962
|
+
for (const limit of ["minZoom", "maxZoom"] as const) {
|
|
2963
|
+
const zoom = stated[limit];
|
|
2964
|
+
if (zoom !== undefined && zoom !== null && !Number.isFinite(zoom)) {
|
|
2965
|
+
throw new MountayaElementsError(
|
|
2966
|
+
`MapClient.setConstraints: ${limit} is ${String(zoom)}. Pass a finite zoom, null to ` +
|
|
2967
|
+
"release the limit, or leave it out to keep the one in force.",
|
|
2968
|
+
);
|
|
2969
|
+
}
|
|
2970
|
+
}
|
|
2971
|
+
|
|
2972
|
+
if (stated.minZoom === undefined && stated.maxZoom === undefined) {
|
|
2973
|
+
return;
|
|
2974
|
+
}
|
|
2975
|
+
|
|
2976
|
+
const minZoom =
|
|
2977
|
+
window.minZoom === null ? MAP_ZOOM_FLOOR : (window.minZoom ?? this.map.getMinZoom());
|
|
2978
|
+
const maxZoom =
|
|
2979
|
+
window.maxZoom === null
|
|
2980
|
+
? MAP_ZOOM_DEFAULT_CEILING
|
|
2981
|
+
: (window.maxZoom ?? this.map.getMaxZoom());
|
|
2982
|
+
if (minZoom > maxZoom) {
|
|
2983
|
+
// The limit the call states is the one named. A call that states both names the minimum.
|
|
2984
|
+
const named = stated.minZoom !== undefined ? "minZoom" : "maxZoom";
|
|
2985
|
+
throw new MountayaElementsError(
|
|
2986
|
+
`MapClient.setConstraints: ${named} is ${String(stated[named])}, which leaves a zoom ` +
|
|
2987
|
+
`window from ${String(minZoom)} to ${String(maxZoom)} that holds no zoom. Pass a ` +
|
|
2988
|
+
"minZoom at or below the maxZoom, stating both when the window moves.",
|
|
2989
|
+
);
|
|
2990
|
+
}
|
|
2991
|
+
}
|
|
2992
|
+
|
|
2993
|
+
setBaseTerrain(config: BaseTerrainConfig): void {
|
|
2994
|
+
// A disposed client has let go of the map: it swaps no style on it, and it holds no switch
|
|
2995
|
+
// for an end call that arrives after the dispose to apply.
|
|
2996
|
+
if (this.events.disposed) {
|
|
2997
|
+
return;
|
|
2998
|
+
}
|
|
2999
|
+
|
|
3000
|
+
// A base-map switch is blocked while any authoring edit or point pick is
|
|
3001
|
+
// active: setStyle wipes the style, which would tear the editable feature
|
|
3002
|
+
// out from under the user mid-edit. The terrain-edit lock (raised by every
|
|
3003
|
+
// begin*Edit call and by beginPointPick) refuses the switch rather than
|
|
3004
|
+
// corrupting the edit.
|
|
3005
|
+
if (this.lock.isLocked()) {
|
|
3006
|
+
// Held and not dropped: the last switch asked for mid-edit is applied when the edit
|
|
3007
|
+
// ends, so the caller, which cannot tell a held switch from an applied one, never ends
|
|
3008
|
+
// an edit on a map that disagrees with the terrain it chose.
|
|
3009
|
+
this.heldBaseTerrain = config;
|
|
3010
|
+
|
|
3011
|
+
return;
|
|
3012
|
+
}
|
|
3013
|
+
|
|
3014
|
+
// This switch is the one that stands, so an earlier one still held is superseded.
|
|
3015
|
+
this.heldBaseTerrain = null;
|
|
3016
|
+
|
|
3017
|
+
// setStyle() replaces the style (sources, layers, sprites, terrain) but
|
|
3018
|
+
// leaves the map's event listeners in place, so the manager is untouched
|
|
3019
|
+
// here: the contextmenu and move handlers and the missing-image resolver keep
|
|
3020
|
+
// working on the new style.
|
|
3021
|
+
|
|
3022
|
+
// Stop every live edit engine's rendering library BEFORE the swap. This is the
|
|
3023
|
+
// first half of a pair whose second half is the `replayAfterStyleReload` calls at
|
|
3024
|
+
// the foot of this method, and WITHOUT IT THOSE REPLAYS DO NOTHING: each engine
|
|
3025
|
+
// delegates its rendering to a library guarded on an "already running" flag that
|
|
3026
|
+
// only a stop lowers, so the replay's `start()` returns before re-registering
|
|
3027
|
+
// anything and re-seeds a feature into sources the swap removed.
|
|
3028
|
+
//
|
|
3029
|
+
// It runs here (after the lock guard, before setStyle) because the teardown each
|
|
3030
|
+
// engine performs is unguarded. On the OUTGOING style every layer and source it
|
|
3031
|
+
// removes is still present and the removal is silent; after the swap, `removeLayer`
|
|
3032
|
+
// on a missing layer fires an `ErrorEvent` that reaches any consumer who wired
|
|
3033
|
+
// `onError` and `removeSource` on a missing source throws outright.
|
|
3034
|
+
//
|
|
3035
|
+
// Refused switches detach nothing: the lock guard above returned already. A swap
|
|
3036
|
+
// that FAILS re-attaches rather than stranding the edit: the event engine ends
|
|
3037
|
+
// the reload on both failure paths (a synchronous refusal through
|
|
3038
|
+
// `cancelStyleReload`, an asynchronous one through its error-then-idle pair), and
|
|
3039
|
+
// every replay below runs against the style that is still installed.
|
|
3040
|
+
this.segmentEditEngine?.detachBeforeStyleReload();
|
|
3041
|
+
this.waypointEditEngine?.detachBeforeStyleReload();
|
|
3042
|
+
this.zoneEditEngine?.detachBeforeStyleReload();
|
|
3043
|
+
this.boundaryEditEngine?.detachBeforeStyleReload();
|
|
3044
|
+
|
|
3045
|
+
// Load the variant's vector style wholesale, baking the always-on 3D relief
|
|
3046
|
+
// into the freshly-fetched style document via transformStyle. The raster-dem
|
|
3047
|
+
// source + root terrain block ride along with every setStyle, so a base-map
|
|
3048
|
+
// switch restores (or, for a no-DEM variant, drops) the relief automatically:
|
|
3049
|
+
// there is no imperative terrain re-apply to replay.
|
|
3050
|
+
const demUrl = config.demUrl;
|
|
3051
|
+
// Through MountayaMap rather than the raw map, because the swap sequence is
|
|
3052
|
+
// the registry's own: it empties the rank registry (which describes the layers
|
|
3053
|
+
// about to be wiped) and marks the reload BEFORE handing the style to MapLibre.
|
|
3054
|
+
// The mark matters because until the new style loads isStyleLoaded() still
|
|
3055
|
+
// reports the old one, so it keeps the tile replay below (and any
|
|
3056
|
+
// afterStyleLoad work racing in from a sibling hook) waiting for the new style
|
|
3057
|
+
// rather than painting onto the one being replaced. Those three steps run
|
|
3058
|
+
// synchronously; the promise settles later, once the new style has loaded, and
|
|
3059
|
+
// this surface has nothing to do at that point.
|
|
3060
|
+
//
|
|
3061
|
+
// A map that has lost its WebGL context is handed no style in this step: it makes the
|
|
3062
|
+
// switch once the context is back. It marks the reload in this step all the same, and
|
|
3063
|
+
// keeps it open until the style of the switch has loaded, so everything queued below
|
|
3064
|
+
// waits for that style and never runs on the one the context brings back.
|
|
3065
|
+
//
|
|
3066
|
+
// It does have something to do if the swap FAILS. The promise rejects when MapLibre
|
|
3067
|
+
// refuses the style outright or the replay onto it throws, and a rejection nobody
|
|
3068
|
+
// catches is an unhandled rejection rather than a symptom anyone can act on, so it
|
|
3069
|
+
// goes to the map's own error stream, where a tile 404 and a style parse failure
|
|
3070
|
+
// already arrive and where the application's listeners are already looking.
|
|
3071
|
+
this.mountayaMap
|
|
3072
|
+
.setStyle(config.styleUrl, {
|
|
3073
|
+
transformStyle: (_previous, next) => bakeTerrain(next, demUrl),
|
|
3074
|
+
})
|
|
3075
|
+
.catch((cause: unknown) => {
|
|
3076
|
+
this.map.fire("error", {
|
|
3077
|
+
error: errorFrom(
|
|
3078
|
+
cause,
|
|
3079
|
+
"The base-map switch failed. Check what the style request rejects with.",
|
|
3080
|
+
),
|
|
3081
|
+
});
|
|
3082
|
+
});
|
|
3083
|
+
|
|
3084
|
+
// Re-warm the marker-sprite registry on the fresh style. setStyle discards
|
|
3085
|
+
// the map's image registry entirely, so every prebaked id is gone: without
|
|
3086
|
+
// this, the first paint of the replayed itinerary tiles would log
|
|
3087
|
+
// `Image "section-icon-…" could not be loaded` for every sprite until the
|
|
3088
|
+
// missing-image resolver catches up. The module-level bitmap cache is
|
|
3089
|
+
// hot from the constructor-time prebake, so the rasterization cost is paid
|
|
3090
|
+
// once for the life of the page; this replay is a fan-out of synchronous
|
|
3091
|
+
// map writes. Queued through afterStyleLoad so it lands on the new style.
|
|
3092
|
+
this.events.afterStyleLoad(() => {
|
|
3093
|
+
void prebakeMarkerIcons(this.map, this.icons);
|
|
3094
|
+
});
|
|
3095
|
+
|
|
3096
|
+
// The tile overlays need no re-draw here. Each manifest source holds a facade slot of
|
|
3097
|
+
// its own, and the swap above resets the registry, loads the new style, waits for it,
|
|
3098
|
+
// redraws every slot and re-runs each one's onMounted, which is where the renderer
|
|
3099
|
+
// re-attaches its companion layers and re-asserts the itinerary emphasis, exclusions,
|
|
3100
|
+
// edit styling and hillshade illumination. The itinerary geometry IS those tile sources
|
|
3101
|
+
// (the lines/points layers), so the whole itinerary rides that replay and there is no
|
|
3102
|
+
// separate per-segment redraw.
|
|
3103
|
+
|
|
3104
|
+
// Re-render every live peer-draft ghost onto the fresh style: setStyle wiped
|
|
3105
|
+
// the overlay's sources/layers, so a collaborator's in-flight ghost would
|
|
3106
|
+
// vanish on a base-map/terrain switch without this replay, the same durability
|
|
3107
|
+
// the tile overlays get above. Waits on the new style via afterStyleLoad.
|
|
3108
|
+
this.peerDraft.replay();
|
|
3109
|
+
|
|
3110
|
+
// The map label language needs no re-assertion here: the façade re-applies it on every
|
|
3111
|
+
// style load, which is the one place that knows the new style's symbol layers exist.
|
|
3112
|
+
|
|
3113
|
+
// Re-assert the stored camera constraints so a terrain switch never drops the
|
|
3114
|
+
// organization's zoom/bounds restrictions.
|
|
3115
|
+
if (this.lastConstraints) {
|
|
3116
|
+
this.applyConstraints(this.lastConstraints);
|
|
3117
|
+
}
|
|
3118
|
+
|
|
3119
|
+
this.queueReplaysAfterStyleLoad();
|
|
3120
|
+
}
|
|
3121
|
+
|
|
3122
|
+
/**
|
|
3123
|
+
* queueReplaysAfterStyleLoad queues, behind the style a base-map switch just asked for, the
|
|
3124
|
+
* replay of everything the client draws outside the map's own slots: each live edit engine,
|
|
3125
|
+
* the import preview, the search highlight and the edit-view direction indicator.
|
|
3126
|
+
*
|
|
3127
|
+
* It is the second half of {@link setBaseTerrain}, a method of its own so each half reads
|
|
3128
|
+
* whole. The first half stops each engine's library on the outgoing style, and each replay
|
|
3129
|
+
* here starts it again on the incoming one.
|
|
3130
|
+
*/
|
|
3131
|
+
private queueReplaysAfterStyleLoad(): void {
|
|
3132
|
+
// Replay an active segment edit onto the fresh style once it loads.
|
|
3133
|
+
// setStyle wipes the engine's sources/layers (TerraDraw's, or the
|
|
3134
|
+
// SDK's), so the engine re-attaches + re-seeds its feature after
|
|
3135
|
+
// style.load. The edit lock normally refuses a switch mid-edit, so this
|
|
3136
|
+
// is the safety net for a restyle that races past the lock: it keeps
|
|
3137
|
+
// the editable feature on screen rather than silently dropping it.
|
|
3138
|
+
if (this.segmentEditEngine) {
|
|
3139
|
+
this.queueEngineReplay(this.segmentEditEngine);
|
|
3140
|
+
}
|
|
3141
|
+
|
|
3142
|
+
// Replay an active waypoint edit onto the fresh style. The shared draft
|
|
3143
|
+
// marker re-adds its source + symbol layer onto the fresh style and
|
|
3144
|
+
// re-seeds the last known draft, so a base-map switch mid-session
|
|
3145
|
+
// survives.
|
|
3146
|
+
if (this.waypointEditEngine) {
|
|
3147
|
+
this.queueEngineReplay(this.waypointEditEngine);
|
|
3148
|
+
}
|
|
3149
|
+
|
|
3150
|
+
// Replay an active zone edit onto the fresh style. setStyle wiped the engine's
|
|
3151
|
+
// TerraDraw sources/layers, so it re-starts, re-seeds the drawn shape, re-applies
|
|
3152
|
+
// the level color, and re-attaches its vertex-hover cursor after style.load,
|
|
3153
|
+
// the same post-reload survival the segment/waypoint engines get.
|
|
3154
|
+
if (this.zoneEditEngine) {
|
|
3155
|
+
this.queueEngineReplay(this.zoneEditEngine);
|
|
3156
|
+
}
|
|
3157
|
+
|
|
3158
|
+
// Replay an active boundary edit onto the fresh style, for the same reason: the
|
|
3159
|
+
// switch wiped the engine's TerraDraw sources/layers, so it re-starts, re-seeds
|
|
3160
|
+
// the drawn box, re-applies its color, and re-attaches its cursor overrides after
|
|
3161
|
+
// style.load.
|
|
3162
|
+
if (this.boundaryEditEngine) {
|
|
3163
|
+
this.queueEngineReplay(this.boundaryEditEngine);
|
|
3164
|
+
}
|
|
3165
|
+
|
|
3166
|
+
// An armed point pick needs no replay: it renders nothing of its own (the
|
|
3167
|
+
// start/end pins paint through the itinerary preview, replayed below), so a
|
|
3168
|
+
// restyle leaves it nothing to restore. The pick's lock refuses a base-map
|
|
3169
|
+
// switch for its duration anyway (the isLocked guard at the top of this
|
|
3170
|
+
// method returns early), so this is reached only for a switch that the
|
|
3171
|
+
// app drives around the lock, and even then the pick's click capture
|
|
3172
|
+
// survives untouched (its listener is map-level, like the segment/waypoint
|
|
3173
|
+
// click seams, so setStyle does not drop it).
|
|
3174
|
+
|
|
3175
|
+
// Replay the non-persisted itinerary preview onto the fresh style. setStyle
|
|
3176
|
+
// wiped the preview's source + layers, so it re-adds them and re-seeds the
|
|
3177
|
+
// last preview after style.load, the same post-reload survival the edit
|
|
3178
|
+
// engines above get. A no-op when no preview is held.
|
|
3179
|
+
this.events.afterStyleLoad(() => {
|
|
3180
|
+
this.itineraryPreview.replay();
|
|
3181
|
+
});
|
|
3182
|
+
|
|
3183
|
+
// Replay the transient search highlight for the same reason. Every write it makes is gated
|
|
3184
|
+
// on afterStyleLoad, which answers whether the style can TAKE a layer and not whether the
|
|
3185
|
+
// switch removed one, so without this replay the answer to what the user just searched for
|
|
3186
|
+
// would come off the map with nothing saying so. A no-op when nothing is highlighted.
|
|
3187
|
+
this.events.afterStyleLoad(() => {
|
|
3188
|
+
this.searchHighlight.replay();
|
|
3189
|
+
});
|
|
3190
|
+
|
|
3191
|
+
// Replay the live edit-view direction indicator onto the fresh style. setStyle
|
|
3192
|
+
// wiped its source + layers, so it re-adds them and re-seeds the last draft line
|
|
3193
|
+
// after style.load, the same post-reload survival the preview above gets. When a
|
|
3194
|
+
// segment edit is active its flow id is re-registered with the animator (replay
|
|
3195
|
+
// re-creates the layer, but the animator only re-registers on an apply, not on a
|
|
3196
|
+
// bare replay), so the flow keeps streaming across the switch. The tile-view
|
|
3197
|
+
// direction layers re-add through each manifest slot's own onMounted. A no-op when
|
|
3198
|
+
// no segment edit is held.
|
|
3199
|
+
this.events.afterStyleLoad(() => {
|
|
3200
|
+
this.editDirectionArrows.replay();
|
|
3201
|
+
if (this.segmentEditEngine) {
|
|
3202
|
+
this.flowAnimator.register(this.editDirectionArrows.flowLayerId());
|
|
3203
|
+
}
|
|
3204
|
+
// The live restricted stretches come back with it, over the line the edit engines'
|
|
3205
|
+
// replay has drawn again.
|
|
3206
|
+
this.editRoadAccess.replay();
|
|
3207
|
+
});
|
|
3208
|
+
}
|
|
3209
|
+
|
|
3210
|
+
/**
|
|
3211
|
+
* applyHeldBaseTerrain asks again for the base-map switch an edit held, once the edit that
|
|
3212
|
+
* held it has ended, and does nothing when none was asked for.
|
|
3213
|
+
*
|
|
3214
|
+
* {@link setBaseTerrain} decides what becomes of it, as for any switch: it applies the
|
|
3215
|
+
* switch and lets go of it, holds it again while another edit or a point pick still holds
|
|
3216
|
+
* the lock, and does nothing on a disposed client.
|
|
3217
|
+
*/
|
|
3218
|
+
private applyHeldBaseTerrain(): void {
|
|
3219
|
+
if (this.heldBaseTerrain !== null) {
|
|
3220
|
+
this.setBaseTerrain(this.heldBaseTerrain);
|
|
3221
|
+
}
|
|
3222
|
+
}
|
|
3223
|
+
|
|
3224
|
+
/**
|
|
3225
|
+
* armEditEngine locks the map for an edit that is beginning and builds its engine, and
|
|
3226
|
+
* applies the base-map switch a replaced edit held when the engine cannot be built.
|
|
3227
|
+
*
|
|
3228
|
+
* The family's hold on the map is raised before the build, and stands until the edit's end
|
|
3229
|
+
* releases it. An engine seeds itself as it is built and reports the seed as a draft, so a
|
|
3230
|
+
* host that asks for a base-map switch from that draft asks while the engine is half built:
|
|
3231
|
+
* the switch is held like any other asked for mid-edit, where a hold raised after the build
|
|
3232
|
+
* would let it wipe the style under the engine. Drag-pan is no part of the hold: each engine
|
|
3233
|
+
* disables pan only while one of its own handles is dragged.
|
|
3234
|
+
*
|
|
3235
|
+
* A begin on another target tears down the edit it replaces first. That lowers the hold and
|
|
3236
|
+
* leaves the switch the edit held for the next engine's end to apply, since a swap between
|
|
3237
|
+
* the teardown and the build would wipe what the next engine draws. When the build throws
|
|
3238
|
+
* there is no next engine and no end to come: the edit has ended, so the hold is released and
|
|
3239
|
+
* the switch is applied here, as its end would have applied it. It stays held while another
|
|
3240
|
+
* family or a point pick still holds the lock.
|
|
3241
|
+
*
|
|
3242
|
+
* @throws Whatever `build` throws, after the hold is released and the held switch is applied.
|
|
3243
|
+
*/
|
|
3244
|
+
private armEditEngine<TEngine>(holder: MapLockHolder, build: () => TEngine): TEngine {
|
|
3245
|
+
this.lock.acquire(holder);
|
|
3246
|
+
try {
|
|
3247
|
+
return build();
|
|
3248
|
+
} catch (cause) {
|
|
3249
|
+
this.lock.release(holder);
|
|
3250
|
+
this.applyHeldBaseTerrain();
|
|
3251
|
+
|
|
3252
|
+
throw cause;
|
|
3253
|
+
}
|
|
3254
|
+
}
|
|
3255
|
+
|
|
3256
|
+
/**
|
|
3257
|
+
* replayIfStyleReloading puts an engine built while a base-map switch's style is loading onto
|
|
3258
|
+
* the incoming style: it stops the engine's library on the outgoing style and queues its
|
|
3259
|
+
* replay behind the incoming one, the pair {@link setBaseTerrain} runs over the engines live
|
|
3260
|
+
* when a switch is asked for. It does nothing when no switch is in flight.
|
|
3261
|
+
*
|
|
3262
|
+
* An engine attaches itself as it is built, and until the incoming style lands the one
|
|
3263
|
+
* installed is the outgoing one, which the swap wipes. The switch queued a replay for the
|
|
3264
|
+
* engines live when it was asked for and for no other, so an edit begun after it would lose
|
|
3265
|
+
* what it drew with nothing to draw it again: the begin that follows an end which applied a
|
|
3266
|
+
* held switch, or a switch and a begin issued in one turn.
|
|
3267
|
+
*/
|
|
3268
|
+
private replayIfStyleReloading(engine: AnyEditEngine): void {
|
|
3269
|
+
if (!this.events.isStyleReloading()) {
|
|
3270
|
+
return;
|
|
3271
|
+
}
|
|
3272
|
+
|
|
3273
|
+
engine.detachBeforeStyleReload();
|
|
3274
|
+
this.queueEngineReplay(engine);
|
|
3275
|
+
}
|
|
3276
|
+
|
|
3277
|
+
/**
|
|
3278
|
+
* queueEngineReplay queues, behind the style that is loading, the replay of an edit engine
|
|
3279
|
+
* stopped for the swap.
|
|
3280
|
+
*
|
|
3281
|
+
* An engine whose replay is already queued is not queued again, so it is started once
|
|
3282
|
+
* however many switches and begins asked for it before the style landed. A replay attaches
|
|
3283
|
+
* the engine's listeners again, and a second one with no stop between them would stack them.
|
|
3284
|
+
* A replay that finds its engine ended or re-armed meanwhile does nothing: that engine is
|
|
3285
|
+
* disposed, and the one armed in its place has a replay of its own.
|
|
3286
|
+
*/
|
|
3287
|
+
private queueEngineReplay(engine: AnyEditEngine): void {
|
|
3288
|
+
if (this.enginesAwaitingReplay.has(engine)) {
|
|
3289
|
+
return;
|
|
3290
|
+
}
|
|
3291
|
+
|
|
3292
|
+
this.enginesAwaitingReplay.add(engine);
|
|
3293
|
+
this.events.afterStyleLoad(() => {
|
|
3294
|
+
this.enginesAwaitingReplay.delete(engine);
|
|
3295
|
+
if (this.isLiveEditEngine(engine)) {
|
|
3296
|
+
engine.replayAfterStyleReload();
|
|
3297
|
+
}
|
|
3298
|
+
});
|
|
3299
|
+
}
|
|
3300
|
+
|
|
3301
|
+
/** isLiveEditEngine answers whether an engine is the one its edit family has armed. */
|
|
3302
|
+
private isLiveEditEngine(engine: AnyEditEngine): boolean {
|
|
3303
|
+
return (
|
|
3304
|
+
engine === this.segmentEditEngine ||
|
|
3305
|
+
engine === this.waypointEditEngine ||
|
|
3306
|
+
engine === this.zoneEditEngine ||
|
|
3307
|
+
engine === this.boundaryEditEngine
|
|
3308
|
+
);
|
|
3309
|
+
}
|
|
3310
|
+
|
|
3311
|
+
jumpToPose(pose: RecordingCamera): void {
|
|
3312
|
+
// jumpTo accepts the full pose ({ center, zoom, pitch, bearing }) (the same
|
|
3313
|
+
// call the preview/record loops make per frame) so a one-off seek lands every
|
|
3314
|
+
// channel, not just the center+zoom setViewport carries.
|
|
3315
|
+
this.map.jumpTo(pose);
|
|
3316
|
+
}
|
|
3317
|
+
|
|
3318
|
+
setViewport(viewport: MapViewport): void {
|
|
3319
|
+
this.map.jumpTo({ center: viewport.center, zoom: viewport.zoom });
|
|
3320
|
+
}
|
|
3321
|
+
|
|
3322
|
+
setSourceTiles(sourceId: string, tiles: string[]): void {
|
|
3323
|
+
this.overlay.setSourceTiles(sourceId, tiles);
|
|
3324
|
+
}
|
|
3325
|
+
|
|
3326
|
+
setStreetviewCoverage(visible: boolean): void {
|
|
3327
|
+
// Delegated. The façade owns the source id, the layer id, the keyless Google tile URL,
|
|
3328
|
+
// the rank band, the removal order MapLibre insists on, the duplicate-add guard and the
|
|
3329
|
+
// pinned `raster-fade-duration`.
|
|
3330
|
+
//
|
|
3331
|
+
// The hue rotation is the one thing that is ours: the studio tints its base map on the
|
|
3332
|
+
// dark scheme, and the keyless coverage glares against it. It rides the published `paint`
|
|
3333
|
+
// override rather than a fork, because the layer is added inside a deferred callback and
|
|
3334
|
+
// there is no moment at which setPaintProperty could reach it from out here.
|
|
3335
|
+
this.mountayaMap.setStreetviewCoverage(
|
|
3336
|
+
visible,
|
|
3337
|
+
visible ? { "raster-hue-rotate": this.themeHueRotation() } : {},
|
|
3338
|
+
);
|
|
3339
|
+
}
|
|
3340
|
+
|
|
3341
|
+
setStreetviewCorridor(lines: [number, number][][] | null, radiusMeters: number): void {
|
|
3342
|
+
const clears = !lines || lines.length === 0;
|
|
3343
|
+
// Read before anything is deferred or drawn, so a radius no band can be drawn at is
|
|
3344
|
+
// refused where it was passed and leaves nothing on the map for the next draw to meet.
|
|
3345
|
+
if (!clears && !(Number.isFinite(radiusMeters) && radiusMeters > 0)) {
|
|
3346
|
+
throw new MountayaElementsError(
|
|
3347
|
+
`MapClient.setStreetviewCorridor: radiusMeters is ${String(radiusMeters)}. The band is ` +
|
|
3348
|
+
"drawn that many meters of ground on each side of the route: pass a finite number " +
|
|
3349
|
+
"above 0, or null lines to clear the band.",
|
|
3350
|
+
);
|
|
3351
|
+
}
|
|
3352
|
+
|
|
3353
|
+
this.events.afterStyleLoad(() => {
|
|
3354
|
+
if (!lines || lines.length === 0) {
|
|
3355
|
+
// Layer before source: MapLibre rejects removing a source a layer still references.
|
|
3356
|
+
//
|
|
3357
|
+
// Through the overlay rather than through the raw map, which is the rule this class
|
|
3358
|
+
// states about its own escape hatch: a layer add or remove that goes around the
|
|
3359
|
+
// façade steps outside the one rank registry. `forgetLayerRank` IS that removal: it
|
|
3360
|
+
// drops the layer if it is there and forgets its rank either way, so a cleared band
|
|
3361
|
+
// stops anchoring later inserts.
|
|
3362
|
+
this.overlay.forgetLayerRank(SV_CORRIDOR_LAYER);
|
|
3363
|
+
|
|
3364
|
+
if (this.map.getSource(SV_CORRIDOR_SOURCE)) {
|
|
3365
|
+
this.map.removeSource(SV_CORRIDOR_SOURCE);
|
|
3366
|
+
}
|
|
3367
|
+
|
|
3368
|
+
return;
|
|
3369
|
+
}
|
|
3370
|
+
|
|
3371
|
+
const data: FeatureCollection = {
|
|
3372
|
+
features: lines.map((coordinates) => ({
|
|
3373
|
+
geometry: { coordinates, type: "LineString" },
|
|
3374
|
+
properties: {},
|
|
3375
|
+
type: "Feature",
|
|
3376
|
+
})),
|
|
3377
|
+
type: "FeatureCollection",
|
|
3378
|
+
};
|
|
3379
|
+
|
|
3380
|
+
// A draw over a band already on the map replaces it in place: the source takes the new
|
|
3381
|
+
// lines and the layer the new width, so a caller that redraws on a moved route or a
|
|
3382
|
+
// changed radius needs no clear in between.
|
|
3383
|
+
const source = this.map.getSource(SV_CORRIDOR_SOURCE);
|
|
3384
|
+
if (isGeoJsonSource(source)) {
|
|
3385
|
+
source.setData(data);
|
|
3386
|
+
} else {
|
|
3387
|
+
this.map.addSource(SV_CORRIDOR_SOURCE, { data, type: "geojson" });
|
|
3388
|
+
}
|
|
3389
|
+
|
|
3390
|
+
// Draw the band at the corridor's TRUE ground width: the drop-gate radius on each
|
|
3391
|
+
// side of the route (so 2x the radius across), so the highlight is exactly where a
|
|
3392
|
+
// drop is accepted. line-width is in screen pixels, so it is sized per zoom (an
|
|
3393
|
+
// exponential-base-2 interpolation doubles the width each zoom level, which is how
|
|
3394
|
+
// a fixed ground distance grows on screen) anchored from its z0 pixel size at the
|
|
3395
|
+
// route's mid-latitude, where groundMetersPerPixel gives the ground a pixel spans.
|
|
3396
|
+
let latitudeSum = 0;
|
|
3397
|
+
let coordinateCount = 0;
|
|
3398
|
+
for (const line of lines) {
|
|
3399
|
+
for (const coordinate of line) {
|
|
3400
|
+
latitudeSum += coordinate[1];
|
|
3401
|
+
coordinateCount += 1;
|
|
3402
|
+
}
|
|
3403
|
+
}
|
|
3404
|
+
|
|
3405
|
+
const centerLatitude = coordinateCount > 0 ? latitudeSum / coordinateCount : 0;
|
|
3406
|
+
const widthPxAtZ0 = (2 * radiusMeters) / groundMetersPerPixel(0, centerLatitude);
|
|
3407
|
+
const widthByZoom: ExpressionSpecification = [
|
|
3408
|
+
"interpolate",
|
|
3409
|
+
["exponential", 2],
|
|
3410
|
+
["zoom"],
|
|
3411
|
+
0,
|
|
3412
|
+
widthPxAtZ0,
|
|
3413
|
+
24,
|
|
3414
|
+
widthPxAtZ0 * 2 ** 24,
|
|
3415
|
+
];
|
|
3416
|
+
|
|
3417
|
+
if (this.map.getLayer(SV_CORRIDOR_LAYER)) {
|
|
3418
|
+
this.map.setPaintProperty(SV_CORRIDOR_LAYER, "line-width", widthByZoom);
|
|
3419
|
+
|
|
3420
|
+
return;
|
|
3421
|
+
}
|
|
3422
|
+
|
|
3423
|
+
// The band reads as a soft droppable-zone highlight along the route, drawn over the
|
|
3424
|
+
// route and the Street View coverage tiles (which mark where imagery exists) so a
|
|
3425
|
+
// visitor sees both where they may drop and where Street View is, yet below the POI
|
|
3426
|
+
// and itinerary point symbols so those stay legible mid-drag.
|
|
3427
|
+
this.overlay.addLayerOrdered(
|
|
3428
|
+
{
|
|
3429
|
+
id: SV_CORRIDOR_LAYER,
|
|
3430
|
+
layout: { "line-cap": "round", "line-join": "round" },
|
|
3431
|
+
paint: {
|
|
3432
|
+
"line-blur": 2,
|
|
3433
|
+
// The default accent, the one the bearing disc falls back to.
|
|
3434
|
+
"line-color": DEFAULT_ACCENT,
|
|
3435
|
+
"line-opacity": 0.2,
|
|
3436
|
+
"line-width": widthByZoom,
|
|
3437
|
+
},
|
|
3438
|
+
source: SV_CORRIDOR_SOURCE,
|
|
3439
|
+
type: "line",
|
|
3440
|
+
},
|
|
3441
|
+
LayerRank.STREETVIEW_CORRIDOR,
|
|
3442
|
+
);
|
|
3443
|
+
});
|
|
3444
|
+
}
|
|
3445
|
+
|
|
3446
|
+
setHillshadeIllumination(direction: number): void {
|
|
3447
|
+
this.overlay.setHillshadeIllumination(direction);
|
|
3448
|
+
}
|
|
3449
|
+
|
|
3450
|
+
prewarmItineraryIcons(icons: { color: string; icon: string }[]): void {
|
|
3451
|
+
this.overlay.prewarmItineraryIcons(icons);
|
|
3452
|
+
}
|
|
3453
|
+
|
|
3454
|
+
setItineraryEmphasis(target: ItineraryEmphasis): void {
|
|
3455
|
+
this.overlay.setItineraryEmphasis(target);
|
|
3456
|
+
}
|
|
3457
|
+
|
|
3458
|
+
setItineraryExclusions(exclusions: ItineraryExclusions): void {
|
|
3459
|
+
this.overlay.setItineraryExclusions(exclusions);
|
|
3460
|
+
}
|
|
3461
|
+
|
|
3462
|
+
setItinerarySegmentColor(color: string | null): void {
|
|
3463
|
+
this.overlay.setItinerarySegmentColor(color);
|
|
3464
|
+
}
|
|
3465
|
+
|
|
3466
|
+
setAccessRestrictionsVisibility(visible: boolean): void {
|
|
3467
|
+
this.overlay.setAccessRestrictionsVisibility(visible);
|
|
3468
|
+
}
|
|
3469
|
+
|
|
3470
|
+
setItineraryPreview(preview: ItineraryPreviewRender | null): void {
|
|
3471
|
+
// Gate the render on afterStyleLoad for the same reason setSearchHighlight
|
|
3472
|
+
// does: a setStyle in flight (a terrain switch) has the previous style
|
|
3473
|
+
// mid-teardown, so an addSource/addLayer landing now would attach to a style
|
|
3474
|
+
// about to be replaced. The gate batches the write into the next style.load;
|
|
3475
|
+
// the preview layer is idempotent, so a clear that races the reload reduces
|
|
3476
|
+
// to the teardown alone. The layer holds the last preview itself and is
|
|
3477
|
+
// replayed from setBaseTerrain, so a real terrain switch re-paints it.
|
|
3478
|
+
this.events.afterStyleLoad(() => {
|
|
3479
|
+
if (!preview) {
|
|
3480
|
+
this.itineraryPreview.clear();
|
|
3481
|
+
|
|
3482
|
+
return;
|
|
3483
|
+
}
|
|
3484
|
+
|
|
3485
|
+
this.itineraryPreview.apply(preview);
|
|
3486
|
+
});
|
|
3487
|
+
}
|
|
3488
|
+
|
|
3489
|
+
setActiveItinerarySegments(lines: readonly Position[][]): void {
|
|
3490
|
+
this.overlay.setActiveItinerarySegments(lines);
|
|
3491
|
+
}
|
|
3492
|
+
|
|
3493
|
+
/**
|
|
3494
|
+
* getActiveItinerarySegments answers the active itinerary's segment geometries as the last
|
|
3495
|
+
* `setActiveItinerarySegments` call set them: the lines a `point` waypoint edit snaps onto.
|
|
3496
|
+
* An empty list when no itinerary is active.
|
|
3497
|
+
*/
|
|
3498
|
+
getActiveItinerarySegments(): readonly Position[][] {
|
|
3499
|
+
return this.overlay.getActiveItinerarySegments();
|
|
3500
|
+
}
|
|
3501
|
+
|
|
3502
|
+
setMapLanguage(language: string): void {
|
|
3503
|
+
// The façade holds the language and re-applies it on every style load, so a base-map
|
|
3504
|
+
// switch keeps it without this surface re-asserting anything: setStyle loads a fresh
|
|
3505
|
+
// style document whose symbol layers all carry the default `name` text-field.
|
|
3506
|
+
this.mountayaMap.setLanguage(language);
|
|
3507
|
+
}
|
|
3508
|
+
|
|
3509
|
+
setOverlayQueryLayers(layerIds: string[]): void {
|
|
3510
|
+
this.overlay.setOverlayQueryLayers(layerIds);
|
|
3511
|
+
}
|
|
3512
|
+
|
|
3513
|
+
/**
|
|
3514
|
+
* editEngines answers the factories this client builds its edit engines with, or `null`
|
|
3515
|
+
* when it holds none: the record bound to the instance, or else to the nearest class of its
|
|
3516
|
+
* prototype chain ({@link bindEditEngines}).
|
|
3517
|
+
*/
|
|
3518
|
+
private editEngines(): EditEngineFactories | null {
|
|
3519
|
+
for (
|
|
3520
|
+
// oxlint-disable-next-line unicorn/no-this-assignment -- the walk starts at the instance and climbs its prototypes.
|
|
3521
|
+
let holder: object | null = this;
|
|
3522
|
+
holder !== null;
|
|
3523
|
+
holder = Object.getPrototypeOf(holder)
|
|
3524
|
+
) {
|
|
3525
|
+
const record = editEngineRecords.get(holder);
|
|
3526
|
+
if (record !== undefined) {
|
|
3527
|
+
return record;
|
|
3528
|
+
}
|
|
3529
|
+
}
|
|
3530
|
+
|
|
3531
|
+
return null;
|
|
3532
|
+
}
|
|
3533
|
+
|
|
3534
|
+
/**
|
|
3535
|
+
* requireEditEngines answers the factories an edit is built with, and refuses the edit by
|
|
3536
|
+
* name when the client holds none.
|
|
3537
|
+
*
|
|
3538
|
+
* It is read before anything of the edit is stored, so a refused edit leaves the client as
|
|
3539
|
+
* it was: no engine, no edit styling and no base-map lock.
|
|
3540
|
+
*
|
|
3541
|
+
* @throws {MountayaElementsError} When the client holds no edit engine. The message names
|
|
3542
|
+
* the method called and `@mountaya/elements/editor`, where the client that edits is.
|
|
3543
|
+
*/
|
|
3544
|
+
private requireEditEngines(method: string): EditEngineFactories {
|
|
3545
|
+
const engines = this.editEngines();
|
|
3546
|
+
if (engines === null) {
|
|
3547
|
+
throw new MountayaElementsError(
|
|
3548
|
+
`MapLibreViewClient.${method}: this client holds no edit engine, so it cannot start an ` +
|
|
3549
|
+
'edit. Construct MapLibreClient from "@mountaya/elements/editor" to edit on the map.',
|
|
3550
|
+
);
|
|
3551
|
+
}
|
|
3552
|
+
|
|
3553
|
+
return engines;
|
|
3554
|
+
}
|
|
3555
|
+
|
|
3556
|
+
/** editEngineSeams gathers what every edit engine is built over. */
|
|
3557
|
+
private editEngineSeams(): EditEngineSeams {
|
|
3558
|
+
return { cursor: this.cursor, events: this.events, map: this.map, placement: this.placement };
|
|
3559
|
+
}
|
|
3560
|
+
|
|
3561
|
+
/**
|
|
3562
|
+
* buildSegmentEngine has the client's factories build the segment-edit engine for the
|
|
3563
|
+
* edit's mode, passing the client-owned draft sink so whichever engine is built emits into
|
|
3564
|
+
* the same subscriber registry. The engine shares the client's event engine and cursor
|
|
3565
|
+
* engine, so its listeners and any cursor override tear down with the client's on dispose.
|
|
3566
|
+
* The engine attaches and seeds itself as it is built.
|
|
3567
|
+
*
|
|
3568
|
+
* @throws {MountayaElementsError} When the client holds no edit engine.
|
|
3569
|
+
*/
|
|
3570
|
+
private buildSegmentEngine(options: SegmentEditOptions): SegmentEditEngine {
|
|
3571
|
+
const engines = this.requireEditEngines("beginSegmentEdit");
|
|
3572
|
+
|
|
3573
|
+
// Wrap the draft sink so every draft both updates the live direction indicator
|
|
3574
|
+
// (chevrons + flow following the drawn geometry) and fans out to the segment-
|
|
3575
|
+
// draft subscribers. The indicator update runs first so the on-map render tracks
|
|
3576
|
+
// the drag before any subscriber-driven re-route lands.
|
|
3577
|
+
const emitDraft = (draft: SegmentDraft) => {
|
|
3578
|
+
this.updateSegmentEditArrows(draft);
|
|
3579
|
+
this.updateSegmentEditRoadAccess(draft);
|
|
3580
|
+
this.emitSegmentDraft(draft);
|
|
3581
|
+
};
|
|
3582
|
+
|
|
3583
|
+
// The ask-the-user sink fans straight out: a prompt changes no geometry, so
|
|
3584
|
+
// there is nothing to re-paint until the app resolves it.
|
|
3585
|
+
const emitViaPrompt = (prompt: SegmentViaPromptEvent) => this.emitSegmentViaPrompt(prompt);
|
|
3586
|
+
|
|
3587
|
+
return engines.segment(this.editEngineSeams(), options, emitDraft, emitViaPrompt);
|
|
3588
|
+
}
|
|
3589
|
+
|
|
3590
|
+
/**
|
|
3591
|
+
* updateSegmentEditArrows re-paints the live direction indicator for the segment under edit
|
|
3592
|
+
* from the latest draft: the routed curve when the directions engine has resolved one, else
|
|
3593
|
+
* the editable handle vias (the freehand vertices, or the directions vias mid-reroute). With
|
|
3594
|
+
* two or more coordinates it draws the line on the edit-view DirectionArrowLayer and registers
|
|
3595
|
+
* its flow id with the shared animator (idempotent); below the two-point floor it clears the
|
|
3596
|
+
* overlay at once and unregisters the flow id, since a single point carries no direction.
|
|
3597
|
+
*
|
|
3598
|
+
* The first line is drawn as soon as the style can take a source, so the indicator stands up
|
|
3599
|
+
* with the edit's first draft on a loaded style. A later line waits for the next animation
|
|
3600
|
+
* frame and only the latest is drawn: a drag reports a
|
|
3601
|
+
* draft on every pointer move, and each write re-tiles the line in the renderer's worker. The
|
|
3602
|
+
* edited segment's tile copy of the indicator is hidden by the overlay's edit styling, so this
|
|
3603
|
+
* live overlay is the only direction render for the segment while the edit is open.
|
|
3604
|
+
*/
|
|
3605
|
+
private updateSegmentEditArrows(draft: SegmentDraft): void {
|
|
3606
|
+
const coordinates = lineFromSegmentDraft(draft);
|
|
3607
|
+
if (coordinates.length < 2) {
|
|
3608
|
+
this.clearSegmentEditArrows();
|
|
3609
|
+
|
|
3610
|
+
return;
|
|
3611
|
+
}
|
|
3612
|
+
|
|
3613
|
+
this.flowAnimator.register(this.editDirectionArrows.flowLayerId());
|
|
3614
|
+
if (!this.editArrowsDrawn) {
|
|
3615
|
+
this.editArrowsDrawn = true;
|
|
3616
|
+
this.paintSegmentEditArrows(coordinates);
|
|
3617
|
+
|
|
3618
|
+
return;
|
|
3619
|
+
}
|
|
3620
|
+
|
|
3621
|
+
this.editArrowLine = coordinates;
|
|
3622
|
+
if (this.editArrowFrame === null) {
|
|
3623
|
+
this.editArrowFrame = requestAnimationFrame(() => {
|
|
3624
|
+
this.editArrowFrame = null;
|
|
3625
|
+
const line = this.editArrowLine;
|
|
3626
|
+
this.editArrowLine = null;
|
|
3627
|
+
if (line !== null) {
|
|
3628
|
+
this.paintSegmentEditArrows(line);
|
|
3629
|
+
}
|
|
3630
|
+
});
|
|
3631
|
+
}
|
|
3632
|
+
}
|
|
3633
|
+
|
|
3634
|
+
/**
|
|
3635
|
+
* paintSegmentEditArrows draws a line on the live direction indicator once the style can take
|
|
3636
|
+
* its source: at once on a loaded style, and on the style a base-map switch or a returning
|
|
3637
|
+
* WebGL context brings once it has loaded, where only the latest line held meanwhile is drawn.
|
|
3638
|
+
*/
|
|
3639
|
+
private paintSegmentEditArrows(line: Position[]): void {
|
|
3640
|
+
this.editArrowHeld = line;
|
|
3641
|
+
if (this.editArrowAwaitingStyle) {
|
|
3642
|
+
return;
|
|
3643
|
+
}
|
|
3644
|
+
|
|
3645
|
+
this.editArrowAwaitingStyle = true;
|
|
3646
|
+
this.events.afterStyleLoad(this.drawHeldSegmentEditArrows);
|
|
3647
|
+
}
|
|
3648
|
+
|
|
3649
|
+
// Draws the line held for the style, built once so a drag frame allocates no closure of the
|
|
3650
|
+
// client's for it.
|
|
3651
|
+
private readonly drawHeldSegmentEditArrows = (): void => {
|
|
3652
|
+
this.editArrowAwaitingStyle = false;
|
|
3653
|
+
const held = this.editArrowHeld;
|
|
3654
|
+
this.editArrowHeld = null;
|
|
3655
|
+
if (held !== null) {
|
|
3656
|
+
this.editDirectionArrows.apply(held);
|
|
3657
|
+
}
|
|
3658
|
+
};
|
|
3659
|
+
|
|
3660
|
+
/**
|
|
3661
|
+
* clearSegmentEditArrows takes the live direction indicator off the map: the frame still
|
|
3662
|
+
* waiting is dropped with the line it would draw, the layer forgets its line so no replay draws
|
|
3663
|
+
* it again, the flow id is unregistered (which pauses the animator's loop once no other flow
|
|
3664
|
+
* layer remains), and the source and layers are removed from the style that can be read.
|
|
3665
|
+
*
|
|
3666
|
+
* @param events The engine the removal waits on: the client's scope, or the map's own engine
|
|
3667
|
+
* when the client is being disposed, since the scope's sweep drops what it holds.
|
|
3668
|
+
*/
|
|
3669
|
+
private clearSegmentEditArrows(events: MapEventEngine = this.events): void {
|
|
3670
|
+
if (this.editArrowFrame !== null) {
|
|
3671
|
+
cancelAnimationFrame(this.editArrowFrame);
|
|
3672
|
+
this.editArrowFrame = null;
|
|
3673
|
+
}
|
|
3674
|
+
this.editArrowLine = null;
|
|
3675
|
+
this.editArrowHeld = null;
|
|
3676
|
+
this.editArrowsDrawn = false;
|
|
3677
|
+
this.editDirectionArrows.forgetLine();
|
|
3678
|
+
this.flowAnimator.unregister(this.editDirectionArrows.flowLayerId());
|
|
3679
|
+
// Taken off the style that can be read: at once on a loaded one, and on the style a switch
|
|
3680
|
+
// or a returning context brings, which may carry the indicator as it stood before, unless a
|
|
3681
|
+
// line has been drawn again meanwhile.
|
|
3682
|
+
events.afterStyleLoad(() => {
|
|
3683
|
+
if (!this.editArrowsDrawn) {
|
|
3684
|
+
this.editDirectionArrows.clear();
|
|
3685
|
+
}
|
|
3686
|
+
});
|
|
3687
|
+
}
|
|
3688
|
+
|
|
3689
|
+
/**
|
|
3690
|
+
* updateSegmentEditRoadAccess draws the restricted stretches of the route the latest draft
|
|
3691
|
+
* carries over the live line: the stretches the router reported, cut out of the routed
|
|
3692
|
+
* geometry and grouped into the kind each is shown as. A draft with no route, or a route that
|
|
3693
|
+
* crosses none, takes them off.
|
|
3694
|
+
*
|
|
3695
|
+
* A draft that carries the route already drawn writes nothing: an engine hands its last route
|
|
3696
|
+
* on every draft until a new one answers, and a drag reports a draft on every pointer move.
|
|
3697
|
+
* The stretches are drawn once the style can take a source, and only the latest held
|
|
3698
|
+
* meanwhile is drawn.
|
|
3699
|
+
*/
|
|
3700
|
+
private updateSegmentEditRoadAccess(draft: SegmentDraft): void {
|
|
3701
|
+
const route = draft.route ?? null;
|
|
3702
|
+
if (route === this.editRoadAccessRoute) {
|
|
3703
|
+
return;
|
|
3704
|
+
}
|
|
3705
|
+
|
|
3706
|
+
this.editRoadAccessRoute = route;
|
|
3707
|
+
this.editRoadAccessHeld = roadAccessFeatures(route?.geometry, route?.roadAccessInfo);
|
|
3708
|
+
this.events.afterStyleLoad(() => {
|
|
3709
|
+
const held = this.editRoadAccessHeld;
|
|
3710
|
+
this.editRoadAccessHeld = null;
|
|
3711
|
+
if (held !== null) {
|
|
3712
|
+
this.editRoadAccess.apply(held);
|
|
3713
|
+
}
|
|
3714
|
+
});
|
|
3715
|
+
}
|
|
3716
|
+
|
|
3717
|
+
/**
|
|
3718
|
+
* clearSegmentEditRoadAccess takes the live restricted stretches off the map: what was held
|
|
3719
|
+
* for a style still loading is dropped, the engine forgets its stretches so no replay draws
|
|
3720
|
+
* them again, and the source and layers are removed from the style that can be read, unless a
|
|
3721
|
+
* route has been drawn again meanwhile.
|
|
3722
|
+
*
|
|
3723
|
+
* @param events The engine the removal waits on: the client's scope, or the map's own engine
|
|
3724
|
+
* when the client is being disposed, since the scope's sweep drops what it holds.
|
|
3725
|
+
*/
|
|
3726
|
+
private clearSegmentEditRoadAccess(events: MapEventEngine = this.events): void {
|
|
3727
|
+
this.editRoadAccessRoute = null;
|
|
3728
|
+
this.editRoadAccessHeld = null;
|
|
3729
|
+
this.editRoadAccess.forgetFeatures();
|
|
3730
|
+
events.afterStyleLoad(() => {
|
|
3731
|
+
if (this.editRoadAccessRoute === null) {
|
|
3732
|
+
this.editRoadAccess.clear();
|
|
3733
|
+
}
|
|
3734
|
+
});
|
|
3735
|
+
}
|
|
3736
|
+
|
|
3737
|
+
/**
|
|
3738
|
+
* buildWaypointEngine has the client's factories build the waypoint-edit engine for the
|
|
3739
|
+
* edit's mode, passing the client-owned draft-change sink. Beside the shared seams the
|
|
3740
|
+
* engine is handed what its two modes read: the active itinerary's lines a `point` edit
|
|
3741
|
+
* snaps onto, the glyph set and canvas size its live cursor is drawn with, and the map
|
|
3742
|
+
* reads a `poi-pick` edit makes.
|
|
3743
|
+
*
|
|
3744
|
+
* @throws {MountayaElementsError} When the client holds no edit engine.
|
|
3745
|
+
*/
|
|
3746
|
+
private buildWaypointEngine(options: WaypointEditOptions): WaypointEditEngine {
|
|
3747
|
+
const engines = this.requireEditEngines("beginWaypointEdit");
|
|
3748
|
+
|
|
3749
|
+
return engines.waypoint(
|
|
3750
|
+
{
|
|
3751
|
+
...this.editEngineSeams(),
|
|
3752
|
+
// The glyph set and canvas size the visible cursor is drawn with, taken off the map
|
|
3753
|
+
// the host built. An engine with no glyphs shows the OS cursor.
|
|
3754
|
+
cursorOptions: this.waypointCursor,
|
|
3755
|
+
pick: {
|
|
3756
|
+
onMapClick: (cb) => this.onMapClick(cb),
|
|
3757
|
+
onPointerMove: (cb) => this.onPointerMove(cb),
|
|
3758
|
+
queryPoisAt: (lngLat) => this.queryPoisAt(lngLat),
|
|
3759
|
+
},
|
|
3760
|
+
// A thunk over the client-held lines, so the engine reads the latest list on each
|
|
3761
|
+
// click and a fresh edit lands on the geometry just updated, with no re-arming.
|
|
3762
|
+
snapSegments: () => this.getActiveItinerarySegments(),
|
|
3763
|
+
},
|
|
3764
|
+
options,
|
|
3765
|
+
(change) => this.emitWaypointDraftChange(change),
|
|
3766
|
+
);
|
|
3767
|
+
}
|
|
3768
|
+
|
|
3769
|
+
/** emitSegmentDraft fans a draft from the active engine out to every segment-draft subscriber held on the client. */
|
|
3770
|
+
private emitSegmentDraft(draft: SegmentDraft): void {
|
|
3771
|
+
notifyListeners(this.segmentDraftSubscribers, draft);
|
|
3772
|
+
}
|
|
3773
|
+
|
|
3774
|
+
/** emitSegmentViaPrompt fans an ask-the-user prompt from the active engine out to every via-prompt subscriber held on the client. */
|
|
3775
|
+
private emitSegmentViaPrompt(prompt: SegmentViaPromptEvent): void {
|
|
3776
|
+
notifyListeners(this.segmentViaPromptSubscribers, prompt);
|
|
3777
|
+
}
|
|
3778
|
+
|
|
3779
|
+
/**
|
|
3780
|
+
* buildZoneEngine has the client's factories build the zone-edit engine for the edit's
|
|
3781
|
+
* mode, passing the client-owned draft sink so it emits into the subscriber registry the
|
|
3782
|
+
* seam reads. The engine shares the client's event engine and cursor engine, so its
|
|
3783
|
+
* vertex-hover override tears down with the client on dispose, and it attaches and seeds
|
|
3784
|
+
* itself as it is built.
|
|
3785
|
+
*
|
|
3786
|
+
* @throws {MountayaElementsError} When the client holds no edit engine.
|
|
3787
|
+
*/
|
|
3788
|
+
private buildZoneEngine(options: ZoneEditOptions): ZoneEditEngine {
|
|
3789
|
+
const engines = this.requireEditEngines("beginZoneEdit");
|
|
3790
|
+
|
|
3791
|
+
return engines.zone(this.editEngineSeams(), options, (draft) => this.emitZoneDraft(draft));
|
|
3792
|
+
}
|
|
3793
|
+
|
|
3794
|
+
/** emitZoneDraft fans a draft from the active zone engine out to every zone-draft subscriber held on the client. */
|
|
3795
|
+
private emitZoneDraft(draft: ZoneDraft): void {
|
|
3796
|
+
notifyListeners(this.zoneDraftSubscribers, draft);
|
|
3797
|
+
}
|
|
3798
|
+
|
|
3799
|
+
/**
|
|
3800
|
+
* buildBoundaryEngine has the client's factories build the engine of one boundary edit,
|
|
3801
|
+
* passing the client-owned draft sink with the shared event engine and cursor engine, so
|
|
3802
|
+
* the engine's overrides, and the create-cursor lock it owns itself, tear down with the
|
|
3803
|
+
* client on dispose. The engine attaches and seeds itself as it is built.
|
|
3804
|
+
*
|
|
3805
|
+
* @throws {MountayaElementsError} When the client holds no edit engine.
|
|
3806
|
+
*/
|
|
3807
|
+
private buildBoundaryEngine(options: BoundaryEditOptions): BoundaryEditEngine {
|
|
3808
|
+
const engines = this.requireEditEngines("beginBoundaryEdit");
|
|
3809
|
+
|
|
3810
|
+
return engines.boundary(this.editEngineSeams(), options, (draft) =>
|
|
3811
|
+
this.emitBoundaryDraft(draft),
|
|
3812
|
+
);
|
|
3813
|
+
}
|
|
3814
|
+
|
|
3815
|
+
/** emitBoundaryDraft fans a draft from the active boundary engine out to every boundary-draft subscriber held on the client. */
|
|
3816
|
+
private emitBoundaryDraft(draft: BoundaryDraft): void {
|
|
3817
|
+
notifyListeners(this.boundaryDraftSubscribers, draft);
|
|
3818
|
+
}
|
|
3819
|
+
|
|
3820
|
+
/** emitWaypointDraftChange fans a draft change from the active waypoint engine out to every change subscriber. */
|
|
3821
|
+
private emitWaypointDraftChange(change: WaypointEngineDraftChange): void {
|
|
3822
|
+
notifyListeners(this.waypointDraftChangeSubscribers, change);
|
|
3823
|
+
}
|
|
3824
|
+
|
|
3825
|
+
/** emitPointPickChange fans a captured coordinate from the active point pick out to every change subscriber. */
|
|
3826
|
+
private emitPointPickChange(change: PointPickChange): void {
|
|
3827
|
+
notifyListeners(this.pointPickChangeSubscribers, change);
|
|
3828
|
+
}
|
|
3829
|
+
|
|
3830
|
+
/**
|
|
3831
|
+
* applyConstraints pushes the given fields onto the map, setting only those
|
|
3832
|
+
* present. A `maxBounds` box is handed over as `toMaxBounds` writes it, and null
|
|
3833
|
+
* clears a bound set earlier.
|
|
3834
|
+
*
|
|
3835
|
+
* The zoom window is written through the façade's `setConstraints`, which writes it in the
|
|
3836
|
+
* order the renderer takes (the far limit first when the window moves past the one in force)
|
|
3837
|
+
* and tells the map's listeners a window that moved (`zoomlimitschange`): a zoom control greys
|
|
3838
|
+
* its buttons at the limits from it, whichever of the map and the client set them.
|
|
3839
|
+
*
|
|
3840
|
+
* A zoom limit stated as `null` is released: it is written as the limit a map is built with
|
|
3841
|
+
* when it is given none, `MAP_ZOOM_FLOOR` for the floor and `MAP_ZOOM_DEFAULT_CEILING` for the
|
|
3842
|
+
* ceiling. The release is what the stored constraints keep, so a base-map switch asserts it
|
|
3843
|
+
* again.
|
|
3844
|
+
*/
|
|
3845
|
+
private applyConstraints(constraints: MapConstraints): void {
|
|
3846
|
+
const minZoom = constraints.minZoom === null ? MAP_ZOOM_FLOOR : constraints.minZoom;
|
|
3847
|
+
const maxZoom = constraints.maxZoom === null ? MAP_ZOOM_DEFAULT_CEILING : constraints.maxZoom;
|
|
3848
|
+
if (minZoom !== undefined || maxZoom !== undefined) {
|
|
3849
|
+
this.mountayaMap.setConstraints({
|
|
3850
|
+
zoom: {
|
|
3851
|
+
...(maxZoom === undefined ? {} : { max: maxZoom }),
|
|
3852
|
+
...(minZoom === undefined ? {} : { min: minZoom }),
|
|
3853
|
+
},
|
|
3854
|
+
});
|
|
3855
|
+
}
|
|
3856
|
+
|
|
3857
|
+
if (constraints.maxBounds !== undefined) {
|
|
3858
|
+
this.map.setMaxBounds(
|
|
3859
|
+
constraints.maxBounds === null ? null : this.toMaxBounds(constraints.maxBounds),
|
|
3860
|
+
);
|
|
3861
|
+
}
|
|
3862
|
+
}
|
|
3863
|
+
|
|
3864
|
+
/**
|
|
3865
|
+
* toMaxBounds writes a pan lock as `setMaxBounds` takes it, and refuses one MapLibre cannot
|
|
3866
|
+
* hold, by the one rule every surface of the package locks a camera by ({@link readBoxLock}):
|
|
3867
|
+
* a box drawn from its north-east corner is ordered, one crossing the antimeridian is locked
|
|
3868
|
+
* across the line, and one a turn or more wide becomes the whole world a hair under a turn
|
|
3869
|
+
* wide. So one lock reaches MapLibre with the same edges, and is refused in the same words,
|
|
3870
|
+
* whether the map or its client writes it.
|
|
3871
|
+
*
|
|
3872
|
+
* @throws {MountayaElementsError} When the lock has an edge at no finite coordinate, no width
|
|
3873
|
+
* or no height.
|
|
3874
|
+
*/
|
|
3875
|
+
private toMaxBounds(bounds: BoundingBox): BoundingBox {
|
|
3876
|
+
return readBoxLock(bounds);
|
|
3877
|
+
}
|
|
3878
|
+
|
|
3879
|
+
/**
|
|
3880
|
+
* themeHueRotation computes the hue rotation that shifts Google's coverage
|
|
3881
|
+
* blue (hue 217) toward the host's accent, the `--mtya-accent` custom property
|
|
3882
|
+
* as the map's container inherits it, read as `#rrggbb` whatever form the host
|
|
3883
|
+
* wrote it in. With no accent in effect it rotates toward the token's default,
|
|
3884
|
+
* the colour the bearing disc paints then, and it returns 0 when the accent is
|
|
3885
|
+
* achromatic, leaving the tiles in Google's blue.
|
|
3886
|
+
*
|
|
3887
|
+
* Read at the container rather than at the document root, because this package
|
|
3888
|
+
* never writes a token to `:root`: the accent in effect where the map is mounted
|
|
3889
|
+
* is the one a studio root, or a host's ancestor of the map, declares.
|
|
3890
|
+
*/
|
|
3891
|
+
private themeHueRotation(): number {
|
|
3892
|
+
const hex = accentHexAt(this.map.getContainer()).replace("#", "");
|
|
3893
|
+
const r = Number.parseInt(hex.substring(0, 2), 16) / 255;
|
|
3894
|
+
const g = Number.parseInt(hex.substring(2, 4), 16) / 255;
|
|
3895
|
+
const b = Number.parseInt(hex.substring(4, 6), 16) / 255;
|
|
3896
|
+
|
|
3897
|
+
// A non-hex resolve (rgb(...), a 3-digit hex, an unexpected format) yields NaN;
|
|
3898
|
+
// bail to no rotation rather than feeding NaN to the paint property.
|
|
3899
|
+
if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) {
|
|
3900
|
+
return 0;
|
|
3901
|
+
}
|
|
3902
|
+
|
|
3903
|
+
const max = Math.max(r, g, b);
|
|
3904
|
+
const min = Math.min(r, g, b);
|
|
3905
|
+
const delta = max - min;
|
|
3906
|
+
|
|
3907
|
+
if (delta === 0) {
|
|
3908
|
+
return 0;
|
|
3909
|
+
}
|
|
3910
|
+
|
|
3911
|
+
let hue = 0;
|
|
3912
|
+
if (max === r) {
|
|
3913
|
+
hue = ((g - b) / delta) % 6;
|
|
3914
|
+
} else if (max === g) {
|
|
3915
|
+
hue = (b - r) / delta + 2;
|
|
3916
|
+
} else {
|
|
3917
|
+
hue = (r - g) / delta + 4;
|
|
3918
|
+
}
|
|
3919
|
+
|
|
3920
|
+
hue = Math.round(hue * 60);
|
|
3921
|
+
if (hue < 0) {
|
|
3922
|
+
hue += 360;
|
|
3923
|
+
}
|
|
3924
|
+
|
|
3925
|
+
return hue - GOOGLE_BLUE_HUE;
|
|
3926
|
+
}
|
|
3927
|
+
|
|
3928
|
+
// Whether dispose has run. The client's event scope cannot answer it: the scope reads as
|
|
3929
|
+
// disposed once the map's own events are, and a client over a map destroyed first still holds
|
|
3930
|
+
// its edits and its markers to release.
|
|
3931
|
+
private released = false;
|
|
3932
|
+
|
|
3933
|
+
/**
|
|
3934
|
+
* dispose tears the client down: it first disposes the active segment-edit
|
|
3935
|
+
* engine and the active waypoint-edit engine (each removing its rendered
|
|
3936
|
+
* layers + sources and detaching its own listeners) so those map writes
|
|
3937
|
+
* land while the client's listeners are still attached, then the client's
|
|
3938
|
+
* event scope detaches every listener it holds (any live contextmenu, move
|
|
3939
|
+
* and edit subscription) by reference and clears the missing-image resolver, and
|
|
3940
|
+
* the profile, search, and Street View mini-bearing markers are removed.
|
|
3941
|
+
* Ordering engine teardown before the listener sweep keeps the cursor
|
|
3942
|
+
* unlock + the SDK/TerraDraw teardown ahead of the scope's dispose, so a
|
|
3943
|
+
* StrictMode unmount leaves the map clean. Detaching here is deterministic:
|
|
3944
|
+
* it does not rely on map.remove() to sweep listeners, and it leaves the
|
|
3945
|
+
* map's own, so a client is disposed independently of the map.
|
|
3946
|
+
*
|
|
3947
|
+
* A map that outlives its client is handed back as the client's own commands left none of
|
|
3948
|
+
* it: the import preview, the corridor band, the direction indicator and the styling of an
|
|
3949
|
+
* edit still open are taken off, and so is every `pointerleave` listener on the canvas. The
|
|
3950
|
+
* tile sources and the overlays stay, since they are slots of the map and its to replay.
|
|
3951
|
+
*
|
|
3952
|
+
* It never throws. Each part is released in a step of its own, so a part whose teardown
|
|
3953
|
+
* fails, an edit's drawing library writing to a map that holds no style while its WebGL
|
|
3954
|
+
* context is lost among them, keeps none of the others from being released: the listeners,
|
|
3955
|
+
* every other edit, the overlay renderer and the markers. Each such failure is handed to the
|
|
3956
|
+
* runtime as an uncaught error, on a microtask, as a listener's own fault is. A second call
|
|
3957
|
+
* finds nothing left to release and does nothing.
|
|
3958
|
+
*/
|
|
3959
|
+
dispose(): void {
|
|
3960
|
+
if (this.released) {
|
|
3961
|
+
return;
|
|
3962
|
+
}
|
|
3963
|
+
|
|
3964
|
+
this.released = true;
|
|
3965
|
+
|
|
3966
|
+
// release runs one part's teardown, and hands what it throws to the runtime rather than
|
|
3967
|
+
// through this method, so the parts after it are released all the same.
|
|
3968
|
+
const release = (step: () => void): void => {
|
|
3969
|
+
try {
|
|
3970
|
+
step();
|
|
3971
|
+
} catch (fault) {
|
|
3972
|
+
surfaceFault(fault);
|
|
3973
|
+
}
|
|
3974
|
+
};
|
|
3975
|
+
|
|
3976
|
+
// Tear down the video run before the listener sweep, mirroring how the edit
|
|
3977
|
+
// engines are torn down first: it aborts an in-flight run, restores the
|
|
3978
|
+
// pre-run camera + renderer clock, and removes a lingering focus dot. The
|
|
3979
|
+
// recorder's render-wait listener is held by the event engine, so aborting
|
|
3980
|
+
// here lets its loop bail and its finally restore the clock before dispose
|
|
3981
|
+
// detaches the render listener below.
|
|
3982
|
+
release(() => this.video?.dispose());
|
|
3983
|
+
|
|
3984
|
+
// A client disposed mid-edit hands back the tile layers as it found them. Each edit laid
|
|
3985
|
+
// its own styling over the persisted copy of what it edits (a ghost and a dash on the
|
|
3986
|
+
// segment, a filter on the zone or the waypoint), and a map that outlives the client
|
|
3987
|
+
// would keep drawing it for an edit nobody holds.
|
|
3988
|
+
if (this.segmentEditEngine) {
|
|
3989
|
+
release(() => this.overlay.setEditedSegment(null));
|
|
3990
|
+
}
|
|
3991
|
+
|
|
3992
|
+
if (this.waypointEditEngine) {
|
|
3993
|
+
release(() => this.overlay.setEditedWaypoint(null));
|
|
3994
|
+
}
|
|
3995
|
+
|
|
3996
|
+
if (this.zoneEditEngine) {
|
|
3997
|
+
release(() => this.overlay.setEditedZone(null));
|
|
3998
|
+
}
|
|
3999
|
+
|
|
4000
|
+
// Each engine is let go of whether or not its own teardown finishes: an edit whose library
|
|
4001
|
+
// failed to stop is not one a later call could end.
|
|
4002
|
+
release(() => this.segmentEditEngine?.dispose());
|
|
4003
|
+
this.segmentEditEngine = null;
|
|
4004
|
+
this.segmentEditEngineSegmentId = null;
|
|
4005
|
+
this.segmentEditEngineMode = null;
|
|
4006
|
+
this.segmentEditEngineSeed = null;
|
|
4007
|
+
release(() => this.waypointEditEngine?.dispose());
|
|
4008
|
+
this.waypointEditEngine = null;
|
|
4009
|
+
this.waypointEditEngineWaypointId = null;
|
|
4010
|
+
this.waypointEditEngineMode = null;
|
|
4011
|
+
// Tear down an active zone edit before the listener sweep, mirroring the
|
|
4012
|
+
// segment/waypoint engines: its dispose removes the TerraDraw layers + sources,
|
|
4013
|
+
// detaches its change listener, and pops any vertex-hover override, so those
|
|
4014
|
+
// map writes + the cursor revert land while the shared listeners are still
|
|
4015
|
+
// attached.
|
|
4016
|
+
release(() => this.zoneEditEngine?.dispose());
|
|
4017
|
+
this.zoneEditEngine = null;
|
|
4018
|
+
this.zoneEditEngineZoneId = null;
|
|
4019
|
+
this.zoneEditEngineMode = null;
|
|
4020
|
+
// Tear down an active boundary edit before the listener sweep, for the same
|
|
4021
|
+
// reason: its dispose removes the TerraDraw layers + sources, detaches its
|
|
4022
|
+
// listeners, and releases the create-cursor lock it owns, so those map writes and
|
|
4023
|
+
// the cursor revert land while the shared listeners are still attached.
|
|
4024
|
+
release(() => this.boundaryEditEngine?.dispose());
|
|
4025
|
+
this.boundaryEditEngine = null;
|
|
4026
|
+
this.boundaryEditEngineFeatureId = null;
|
|
4027
|
+
// Tear down an armed point pick before the listener sweep, mirroring the
|
|
4028
|
+
// edit engines above: its dispose detaches the click subscription and
|
|
4029
|
+
// releases the base-map-switch block, so the lock lands down on a client
|
|
4030
|
+
// dispose mid-pick.
|
|
4031
|
+
release(() => this.pointPickEngine?.dispose());
|
|
4032
|
+
this.pointPickEngine = null;
|
|
4033
|
+
// What the client's own commands drew goes with it too: the import preview, the live
|
|
4034
|
+
// direction indicator of a segment edit and the Street View corridor band. Each owns a
|
|
4035
|
+
// source and its layers, removed layer first, and each removal finds nothing when the
|
|
4036
|
+
// command never ran.
|
|
4037
|
+
release(() => this.itineraryPreview.clear());
|
|
4038
|
+
release(() => this.clearSegmentEditArrows(this.mapEvents));
|
|
4039
|
+
release(() => this.clearSegmentEditRoadAccess(this.mapEvents));
|
|
4040
|
+
release(() => {
|
|
4041
|
+
this.overlay.forgetLayerRank(SV_CORRIDOR_LAYER);
|
|
4042
|
+
if (this.map.getSource(SV_CORRIDOR_SOURCE)) {
|
|
4043
|
+
this.map.removeSource(SV_CORRIDOR_SOURCE);
|
|
4044
|
+
}
|
|
4045
|
+
});
|
|
4046
|
+
|
|
4047
|
+
for (const detach of [...this.pointerLeaveDetachers]) {
|
|
4048
|
+
release(detach);
|
|
4049
|
+
}
|
|
4050
|
+
|
|
4051
|
+
release(() => this.events.dispose());
|
|
4052
|
+
for (const end of [...this.slotWriteWaits]) {
|
|
4053
|
+
release(end);
|
|
4054
|
+
}
|
|
4055
|
+
// The sprite warm pass the renderer put off to a later turn is withdrawn, so it never
|
|
4056
|
+
// reads the registry of a map the client let go of.
|
|
4057
|
+
release(() => this.overlay.dispose());
|
|
4058
|
+
// The streams that would answer a standing refusal went with the sweep above, so it is
|
|
4059
|
+
// forgotten with them, and nobody is left to tell.
|
|
4060
|
+
this.refusedSources = new Set();
|
|
4061
|
+
this.tilesAccessRestoredSubscribers.clear();
|
|
4062
|
+
release(() => this.profileMarker?.remove());
|
|
4063
|
+
this.profileMarker = null;
|
|
4064
|
+
this.profileMarkerIconKey = null;
|
|
4065
|
+
release(() => this.searchHighlight.dispose());
|
|
4066
|
+
// Sweep every peer-draft ghost so a client teardown leaves no orphaned source
|
|
4067
|
+
// or layer behind (synchronous, like searchHighlight's own dispose).
|
|
4068
|
+
release(() => this.peerDraft.dispose());
|
|
4069
|
+
// Stop the shared direction-flow rAF loop and detach its visibility listener, so
|
|
4070
|
+
// a client teardown leaves no frame scheduled and no listener leaked.
|
|
4071
|
+
release(() => this.flowAnimator.dispose());
|
|
4072
|
+
// Cancel the frames a settled tile refresh is still waiting on, for the same reason.
|
|
4073
|
+
// Its idle listener already went with the event engine's sweep above.
|
|
4074
|
+
for (const handle of this.settleFrames) {
|
|
4075
|
+
cancelAnimationFrame(handle);
|
|
4076
|
+
}
|
|
4077
|
+
this.settleFrames.clear();
|
|
4078
|
+
// The hover seam's two listeners went with the same sweep. Its waiting hit-test and its
|
|
4079
|
+
// subscriptions go here, so no frame queries a map that is gone and a late unsubscribe
|
|
4080
|
+
// finds nothing to end.
|
|
4081
|
+
release(() => this.cancelHoverFrame());
|
|
4082
|
+
release(() => this.cancelHoverTeardown());
|
|
4083
|
+
this.hoverSubscriptions.clear();
|
|
4084
|
+
this.hoverLayerIds = [];
|
|
4085
|
+
this.detachHoverListeners = null;
|
|
4086
|
+
this.hoverPointer = false;
|
|
4087
|
+
this.hoverRestingPoint = null;
|
|
4088
|
+
release(() => this.miniBearingMarker?.remove());
|
|
4089
|
+
this.miniBearingMarker = null;
|
|
4090
|
+
}
|
|
4091
|
+
}
|