Put a globe in a page
npm install @mark1russell7/visuals three
import { GLOBE_POLAR, createGlobe, globeView } from "@mark1russell7/visuals/globe";
import { createStage } from "@mark1russell7/visuals/three";
const globe = createGlobe({
areas: [
{ record: "storm", kind: "warning", value: "A storm warning", region },
],
points: [
{ record: "city", kind: "city", value: "A city", place: { lat: 32.8, lon: -96.8 } },
],
});
const stage = createStage(document.querySelector("#globe"), {
content: globe,
theme,
label: "The Earth with one storm warning",
views: { earth: globeView({ lat: 35, lon: -95 }) },
home: "earth",
polar: GLOBE_POLAR,
pan: false,
onSelect: (value) => console.log(value),
});
- A stage is one canvas with a camera that a person moves. It has views by name, picking and themes.
- A globe shows areas and points on the Earth. It uses no map tiles and no service.
- An area is a
Polygonor aMultiPolygonof GeoJSON. The theme has a style for each kind. createStagegivesundefinedin a browser with no WebGL 2. This page then shows a flat map.
Replay a history
import { changeTimes, isLive, replayOf } from "@mark1russell7/visuals";
import { createScrubber } from "@mark1russell7/visuals/scrubber";
import "@mark1russell7/visuals/scrubber.css";
// The value of each part of the globe is its time in the picture, in hours.
const lives = [{ from: 6, to: 18 }, { from: 12 }];
createScrubber(document.querySelector("#time"), {
label: "Time of the picture",
replay: replayOf({ from: 0, to: 24 }),
times: changeTimes(lives),
labels: [{ at: 0, text: "00:00" }, { at: 12, text: "12:00" }],
format: (at) => `${String(Math.floor(at)).padStart(2, "0")}:00`,
onChange: ({ at }) => {
globe.show((part) => isLive(part.value, at));
stage.refresh();
},
});
- A scrubber sets the time of a picture, and it replays the changes. It has a tick at each change.
- The slider is an
inputof the typerange. A pointer, a touch screen, a keyboard and a screen reader use it. - The arrow keys go from one change to the next change. The key Space starts and stops the replay.
- The replay is a model with no browser. A test and a server use the same functions.
Name the places
import { globePoint, inSight, pointRadius } from "@mark1russell7/visuals/globe";
import { createLabels } from "@mark1russell7/visuals/labels";
import { createStage, stackContents } from "@mark1russell7/visuals/three";
import "@mark1russell7/visuals/labels.css";
const box = document.querySelector("#globe");
const labels = createLabels(box, {
labels: [
{
record: "city",
at: globePoint({ lat: 32.8, lon: -96.8 }),
text: "Dallas",
clear: pointRadius(8),
},
],
// A place on the far side of the Earth has no name.
visible: (point, eye) => inSight(point, eye, 1),
});
const stage = createStage(box, {
content: stackContents([globe, labels]),
theme,
label: "The Earth with the name of one city",
});
- A label is a short text next to a point of a stage. It moves with the camera.
- No text is on a different text or on a mark. When two texts have one place, the label with the higher rank stays.
- Each label is an HTML element. So the text is sharp, and it has the font of the page.
- The label of a highlighted record is first, and it gets the look of the highlight.
Put marks on a scene
import { fitView } from "@mark1russell7/visuals";
import { createMarkers } from "@mark1russell7/visuals/markers";
import { createStage, stackContents } from "@mark1russell7/visuals/three";
const markers = createMarkers([
{
type: "point",
record: "outlet-2",
kind: "outlet",
level: "near",
label: "Outlet 2: 1210 W of 1440 W",
// The point on the wall, and the direction out of the wall.
frame: { at: { x: 2.3, y: 0.3, z: 0 }, out: { x: 0, y: 0, z: 1 } },
},
]);
const stage = createStage(document.querySelector("#room"), {
// The content `room` has the solids. The marks are on top of them.
content: stackContents([room, markers]),
theme,
label: "A room with one outlet",
views: { corner: fitView({ polar: 1, azimuth: 0.7 }) },
home: "corner",
onHover: (mark) => console.log(mark?.label),
});
- A mark is plain data: a point, a run, a link or a field. It goes through JSON with no change.
- A mark has a level and no color. The level gives the shape of its sign, and the theme gives the color.
- A mark behind a solid stays in the picture with less color, and the pointer finds it.
- A link is a dashed line between two records. The picture shows it while one of them has a highlight.
The README tells each option. Releases shows each version, and Status shows the open work.