feat(globe): render the tilt and north-up buttons from the globe actions store

The camera orientation controls publish whether the map is tilted and the
camera's whole-degree heading instead of writing the buttons' attributes,
and answer tilt and north-up through the globe actions store. The new
GlobeCompass renders the heading, so a rotating camera re-renders only the
compass. The store drops an unchanged camera state and keeps each clear
owner's busy state, so the buttons show the shell that answers them: a
shell replaced by a newer one, or disposed mid-clear, leaves the live
shell's state alone, and an older shell that answers again shows its own.
createOwners gains owns() and ownerOf().
This commit is contained in:
Sameh Khamis committed 2026-11-01 13:37:06 -08:00
1 parent 7edf8a577e
commit eccaeea0c4
15 files changed
+495 -180

No files matched your search

+70 -10
View File
@@ -1,22 +1,82 @@
import { defineStore } from 'pinia';
import { ref } from 'vue';
import { computed, ref, shallowReactive } from 'vue';
import { createOwners } from './owners.js';
/**
* The top-center globe actions as their view renders them. The shell
* publishes whether a clear of the selected data layers is under way, and
* answers the clear and share buttons through act().
* publishes whether a clear of the selected data layers is under way and the
* camera's tilt and heading, and answers the buttons through act().
*/
export const useGlobeActionsStore = defineStore('gev-globe-actions', () => {
/** Whether a clear is under way; null until the shell first says. */
const clearBusy = ref(null);
const owners = createOwners();
// Who answers which action, as the computed state below reads it.
const ownership = ref(0);
/** Each clear owner's clear under way, by its token. */
const busyBy = shallowReactive(new Map());
/** @param {boolean | null} busy null when no shell answers the clear. */
function publishClearBusy(busy) {
clearBusy.value = busy == null ? null : Boolean(busy);
/**
* Whether the clear owner's clear is under way; null until it says. Each
* owner keeps its own, so the button shows the one that answers it.
*/
const clearBusy = computed(() => {
void ownership.value;
return busyBy.get(owners.ownerOf('clear')) ?? null;
});
/**
* @param {object} token The clear owner's, from connect().
* @param {boolean} busy
*/
function publishClearBusy(token, busy) {
busyBy.set(token, Boolean(busy));
}
const { connect, detach, act } = createOwners();
/**
* Whether the map reads as tilted and the camera's whole-degree heading;
* null until the camera controls first say.
* @type {import('vue').Ref<{ tilted: boolean, heading: number } | null>}
*/
const camera = ref(null);
return { clearBusy, publishClearBusy, connect, detach, act };
/**
* Take the camera's state; the same state again changes nothing, so its
* owner can publish it on every frame the camera draws.
* @param {{ tilted: boolean, heading: number } | null} state
*/
function publishCamera(state) {
const current = camera.value;
if (!state) {
camera.value = null;
return;
}
const tilted = Boolean(state.tilted);
if (current?.tilted === tilted && current.heading === state.heading) return;
camera.value = { tilted, heading: state.heading };
}
/** @param {Record<string, Function>} actions */
function connect(actions) {
const token = owners.connect(actions);
ownership.value += 1;
return token;
}
function detach(token) {
owners.detach(token);
busyBy.delete(token);
ownership.value += 1;
}
const { act, owns } = owners;
return {
clearBusy,
publishClearBusy,
camera,
publishCamera,
connect,
detach,
act,
owns,
};
});