@protomaze/geometry 0.0.0-stage → 0.1.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.
Files changed (118) hide show
  1. package/GeometryDemo.d.ts +1 -0
  2. package/GeometryDemo.js +1 -0
  3. package/README.md +294 -2
  4. package/common/Colors.d.ts +47 -0
  5. package/common/Colors.js +1 -0
  6. package/common/Disposables.d.ts +7 -0
  7. package/common/Disposables.js +1 -0
  8. package/data/Geometry.d.ts +62 -0
  9. package/data/Geometry.js +1 -0
  10. package/demo/DemoControls.d.ts +68 -0
  11. package/demo/DemoControls.js +1 -0
  12. package/demo/Town.d.ts +115 -0
  13. package/demo/Town.js +1 -0
  14. package/edit/CreateController.d.ts +101 -0
  15. package/edit/CreateController.js +1 -0
  16. package/edit/EditController.d.ts +121 -0
  17. package/edit/EditController.js +1 -0
  18. package/edit/EditHistory.d.ts +46 -0
  19. package/edit/EditHistory.js +1 -0
  20. package/edit/EditShape.d.ts +45 -0
  21. package/edit/EditShape.js +1 -0
  22. package/edit/GeometryController.d.ts +83 -0
  23. package/edit/GeometryController.js +1 -0
  24. package/edit/MeasureController.d.ts +102 -0
  25. package/edit/MeasureController.js +1 -0
  26. package/edit/Sketch.d.ts +73 -0
  27. package/edit/Sketch.js +1 -0
  28. package/edit/Snapper.d.ts +67 -0
  29. package/edit/Snapper.js +1 -0
  30. package/engine/GeometryEngine.d.ts +257 -0
  31. package/engine/GeometryEngine.js +1 -0
  32. package/engine/GeometryFrame.d.ts +91 -0
  33. package/engine/GeometryFrame.js +1 -0
  34. package/engine/GeometryOptions.d.ts +79 -0
  35. package/engine/GeometryOptions.js +1 -0
  36. package/engine/GeometryView.d.ts +192 -0
  37. package/engine/GeometryView.js +1 -0
  38. package/engine/Labels.d.ts +42 -0
  39. package/engine/Labels.js +1 -0
  40. package/engine/MapCamera.d.ts +78 -0
  41. package/engine/MapCamera.js +1 -0
  42. package/event/TypedEventEmitter.d.ts +13 -0
  43. package/event/TypedEventEmitter.js +1 -0
  44. package/index.d.ts +53 -0
  45. package/index.js +1 -0
  46. package/layers/AreaLayer.d.ts +36 -0
  47. package/layers/AreaLayer.js +1 -0
  48. package/layers/GeometryLayer.d.ts +312 -0
  49. package/layers/GeometryLayer.js +1 -0
  50. package/layers/LineLayer.d.ts +48 -0
  51. package/layers/LineLayer.js +1 -0
  52. package/layers/PointLayer.d.ts +42 -0
  53. package/layers/PointLayer.js +1 -0
  54. package/layers/SphereLayer.d.ts +25 -0
  55. package/layers/SphereLayer.js +1 -0
  56. package/layers/TubeLayer.d.ts +52 -0
  57. package/layers/TubeLayer.js +1 -0
  58. package/math/Boolean.d.ts +21 -0
  59. package/math/Boolean.js +1 -0
  60. package/math/FeatureIndex.d.ts +70 -0
  61. package/math/FeatureIndex.js +1 -0
  62. package/math/Geodesy.d.ts +29 -0
  63. package/math/Geodesy.js +1 -0
  64. package/math/Lines.d.ts +115 -0
  65. package/math/Lines.js +1 -0
  66. package/math/Measure.d.ts +71 -0
  67. package/math/Measure.js +1 -0
  68. package/math/Polygons.d.ts +59 -0
  69. package/math/Polygons.js +1 -0
  70. package/math/Projection.d.ts +25 -0
  71. package/math/Projection.js +1 -0
  72. package/math/Relations.d.ts +27 -0
  73. package/math/Relations.js +1 -0
  74. package/math/SpatialIndex.d.ts +36 -0
  75. package/math/SpatialIndex.js +1 -0
  76. package/math/Transform.d.ts +36 -0
  77. package/math/Transform.js +1 -0
  78. package/math/Triangulate.d.ts +19 -0
  79. package/math/Triangulate.js +1 -0
  80. package/math/Vector.d.ts +24 -0
  81. package/math/Vector.js +1 -0
  82. package/package.json +76 -4
  83. package/react/ReactGeometry.d.ts +35 -0
  84. package/react/ReactGeometry.js +1 -0
  85. package/three/CanvasGeometryEngine.d.ts +79 -0
  86. package/three/CanvasGeometryEngine.js +1 -0
  87. package/three/DensityMap.d.ts +31 -0
  88. package/three/DensityMap.js +1 -0
  89. package/three/FeatureLook.d.ts +191 -0
  90. package/three/FeatureLook.js +1 -0
  91. package/three/Ground.d.ts +54 -0
  92. package/three/Ground.js +1 -0
  93. package/three/Halo.d.ts +26 -0
  94. package/three/Halo.js +1 -0
  95. package/three/HostedGeometryEngine.d.ts +57 -0
  96. package/three/HostedGeometryEngine.js +1 -0
  97. package/three/RiaGeometryEngine.d.ts +48 -0
  98. package/three/RiaGeometryEngine.js +1 -0
  99. package/three/Shading.d.ts +42 -0
  100. package/three/Shading.js +1 -0
  101. package/three/Sky.d.ts +27 -0
  102. package/three/Sky.js +1 -0
  103. package/three/Tsl.d.ts +47 -0
  104. package/three/Tsl.js +1 -0
  105. package/three/primitives/Body.d.ts +82 -0
  106. package/three/primitives/Body.js +1 -0
  107. package/three/primitives/GpuAreas.d.ts +72 -0
  108. package/three/primitives/GpuAreas.js +1 -0
  109. package/three/primitives/GpuIcons.d.ts +112 -0
  110. package/three/primitives/GpuIcons.js +1 -0
  111. package/three/primitives/GpuLines.d.ts +198 -0
  112. package/three/primitives/GpuLines.js +1 -0
  113. package/three/primitives/GpuSpheres.d.ts +55 -0
  114. package/three/primitives/GpuSpheres.js +1 -0
  115. package/three/primitives/GpuTubes.d.ts +125 -0
  116. package/three/primitives/GpuTubes.js +1 -0
  117. package/three/primitives/IconAtlas.d.ts +12 -0
  118. package/three/primitives/IconAtlas.js +1 -0
@@ -0,0 +1 @@
1
+ import{Matrix4 as e,Vector2 as r}from"three/webgpu";import{uniform as i}from"three/tsl";export function pickPassUniforms(){return{window:i(new e),origin:i(new r),frameSize:i(new r(1,1))}}
@@ -0,0 +1,79 @@
1
+ import type { ColorRamp } from '../common/Colors';
2
+ import type { CameraLimits, CameraState } from './MapCamera';
3
+ /** How what is lit - selected, pointed at, emphasized - is set off. */
4
+ export interface GeometryHighlightOptions {
5
+ /** A glow round it, or an outline. A glow by default. */
6
+ look?: 'glow' | 'outline';
7
+ /** The glow from the bloom pass - soft, over everything - or drawn in the line shader, cheaper. */
8
+ glow?: 'bloom' | 'shader';
9
+ /** The outline's colour, and width in view pixels. */
10
+ outlineColor?: string;
11
+ outlineWidth?: number;
12
+ /** Whether pointing at something shades the rest of what is drawn. On by default. */
13
+ hoverFades?: boolean;
14
+ /** How bright the rest is then, 0 to 1. */
15
+ othersShade?: number;
16
+ /** Whether pointing at a feature lights it as the selection is. On by default. */
17
+ hoverLights?: boolean;
18
+ }
19
+ export interface GeometryTheme {
20
+ background: string;
21
+ ground: string;
22
+ grid: string;
23
+ outline: string;
24
+ /** What the rest is shaded towards while something is lit: 0 black, 1 white. */
25
+ othersToward: number;
26
+ /** The sky in perspective: overhead, at the horizon, and the glow just above it. */
27
+ sky: {
28
+ zenith: string;
29
+ horizon: string;
30
+ glow: string;
31
+ };
32
+ /** Windows on volumes lit at night (dark), or dark glass (light). */
33
+ windowsLit: number;
34
+ }
35
+ export declare const DARK_THEME: GeometryTheme;
36
+ export declare const LIGHT_THEME: GeometryTheme;
37
+ export interface GeometryViewOptions {
38
+ /** A 2D map (orthographic, straight down) or 3D (perspective, tilting). 3D by default. */
39
+ mode?: '2d' | '3d';
40
+ theme?: 'dark' | 'light' | Partial<GeometryTheme>;
41
+ /** Where the camera starts. */
42
+ camera?: Partial<CameraState>;
43
+ limits?: Partial<CameraLimits>;
44
+ /** The perspective's vertical field of view, degrees. */
45
+ fov?: number;
46
+ highlight?: GeometryHighlightOptions;
47
+ /** Whether the pointer lights what it rests on. On by default. */
48
+ hover?: boolean;
49
+ /**
50
+ * What a click does: selects one feature (`single`), or one and more with Ctrl or Shift
51
+ * (`multi`, the default), or nothing (`none`).
52
+ */
53
+ selection?: 'single' | 'multi' | 'none';
54
+ /** Whether the camera follows the pointer and the wheel. On by default. */
55
+ interactive?: boolean;
56
+ /** The selection's bloom. */
57
+ bloom?: {
58
+ strength?: number;
59
+ radius?: number;
60
+ threshold?: number;
61
+ };
62
+ /** The halo round what is seen through the ground; false for none. */
63
+ halo?: {
64
+ strength?: number;
65
+ blur?: number;
66
+ } | false;
67
+ /** The heatmap's colours and the sum that takes the top one. */
68
+ density?: {
69
+ ramp?: ColorRamp;
70
+ top?: number;
71
+ opacity?: number;
72
+ };
73
+ /** Multisampled edges. On by default. */
74
+ antialias?: boolean;
75
+ /** Draw with WebGL 2 even where WebGPU is there. */
76
+ forceWebGL?: boolean;
77
+ /** The most frame pixels per view pixel. 2 by default. */
78
+ maxPixelRatio?: number;
79
+ }
@@ -0,0 +1 @@
1
+ export const DARK_THEME={background:"#0b0d10",ground:"#14181d",grid:"#ffffff",outline:"#EBE8E0",othersToward:0,sky:{zenith:"#05080d",horizon:"#1d2938",glow:"#2e4d6c"},windowsLit:.35};export const LIGHT_THEME={background:"#e9ecef",ground:"#f8f9fa",grid:"#000000",outline:"#1A1A1A",othersToward:1,sky:{zenith:"#9fb7cf",horizon:"#e8eef3",glow:"#ffffff"},windowsLit:0};
@@ -0,0 +1,192 @@
1
+ import { Bounds3, GeometryFeature, GeometryId, Position } from '../data/Geometry';
2
+ import type { ControllerHost, GeometryController } from '../edit/GeometryController';
3
+ import { TypedEventEmitter } from '../event/TypedEventEmitter';
4
+ import type { Vec3 } from '../math/Vector';
5
+ import { LabelOverlay } from './Labels';
6
+ import { GeometryLayer, LayerHit, LayerHost, ResolvedHighlight, SelectMode } from '../layers/GeometryLayer';
7
+ import { CanvasGeometryEngine } from '../three/CanvasGeometryEngine';
8
+ import { Ground, GroundOptions } from '../three/Ground';
9
+ import { Lighting } from '../three/Shading';
10
+ import { GeometryFrameStats } from './GeometryEngine';
11
+ import { GeometryViewOptions } from './GeometryOptions';
12
+ import { CameraState, MapCamera } from './MapCamera';
13
+ /** What the pointer is on, or a click hit: a layer's feature, and the point on it. */
14
+ export interface GeometryHit<F = GeometryFeature> extends LayerHit<F> {
15
+ point: [number, number, number];
16
+ }
17
+ export interface GeometryClick {
18
+ hit: GeometryHit | null;
19
+ shift: boolean;
20
+ ctrl: boolean;
21
+ alt: boolean;
22
+ /** View pixels from the view's top-left. */
23
+ x: number;
24
+ y: number;
25
+ native: PointerEvent | MouseEvent;
26
+ }
27
+ /** The selection, layer by layer, after a change. */
28
+ export interface GeometrySelection {
29
+ layers: {
30
+ layer: GeometryLayer<any, any>;
31
+ ids: GeometryId[];
32
+ }[];
33
+ /** Features selected in all, together. */
34
+ count: number;
35
+ }
36
+ export interface GeometryViewStats extends GeometryFrameStats {
37
+ fps: number;
38
+ drawCalls: number;
39
+ triangles: number;
40
+ backend: 'webgpu' | 'webgl';
41
+ }
42
+ export interface GeometryViewEvents {
43
+ hover: GeometryHit | null;
44
+ click: GeometryClick;
45
+ select: GeometrySelection;
46
+ camera: CameraState;
47
+ mode: '2d' | '3d';
48
+ frame: GeometryViewStats;
49
+ ready: void;
50
+ }
51
+ /**
52
+ * A view of geometry: a canvas, a camera that pans, zooms and orbits, and layers - lines, points,
53
+ * tubes, spheres, areas - lit when pointed at, selected when clicked, all drawn by one
54
+ * `CanvasGeometryEngine` on the GPU. The geometry engine's `Chart`.
55
+ *
56
+ * ```ts
57
+ * const view = new GeometryView({ mode: '3d' });
58
+ * await view.init(container);
59
+ * view.addLayer(new TubeLayer({ features: pipes, style: f => ({ color: colorOf(f) }) }));
60
+ * view.on('select', selection => ...);
61
+ * ```
62
+ */
63
+ export declare class GeometryView extends TypedEventEmitter<GeometryViewEvents> implements LayerHost, ControllerHost {
64
+ readonly engine: CanvasGeometryEngine;
65
+ readonly camera: MapCamera;
66
+ readonly lighting: Lighting;
67
+ readonly up: [number, number, number];
68
+ mode: '2d' | '3d';
69
+ highlight: ResolvedHighlight;
70
+ /** Labels on world positions over the view: what controllers measure, or the application's own. */
71
+ labels: LabelOverlay | null;
72
+ private options;
73
+ private theme;
74
+ private layers;
75
+ private overlays;
76
+ private controller;
77
+ /** The pointer whose drag the controller took. */
78
+ private controllerDrag;
79
+ private root;
80
+ private disposables;
81
+ private hovered;
82
+ private ground;
83
+ private groundOptions;
84
+ private lastCamera;
85
+ private frames;
86
+ private pendingMode;
87
+ private hoverQueued;
88
+ private pointer;
89
+ private drag;
90
+ private touches;
91
+ private pinch;
92
+ constructor(options?: GeometryViewOptions);
93
+ /** Puts the view into `container`, which it fills, and starts drawing. */
94
+ init(container: HTMLElement): Promise<void>;
95
+ dispose(): void;
96
+ /** The view's element, once in a container. */
97
+ get element(): HTMLDivElement | null;
98
+ setOptions(options: Partial<GeometryViewOptions>): void;
99
+ getOptions(): Readonly<GeometryViewOptions>;
100
+ private applyOptions;
101
+ /** What needs the engine started: the bloom's settings, the halo's, the heatmap's. */
102
+ private applyRuntimeOptions;
103
+ /** Adds a layer on top, or under `below`. */
104
+ addLayer<L extends GeometryLayer<any, any>>(layer: L, below?: GeometryLayer<any, any>): L;
105
+ removeLayer(layer: GeometryLayer<any, any>): void;
106
+ getLayers(): readonly GeometryLayer<any, any>[];
107
+ getLayer(id: string): GeometryLayer<any, any> | undefined;
108
+ /**
109
+ * Adds a layer drawn over everything else, whatever is in front of it: an editor's handles,
110
+ * a sketch, a measurement. Not picked, not among `getLayers()`, not in `bounds()`.
111
+ */
112
+ addOverlay(layer: GeometryLayer<any, any>): void;
113
+ removeOverlay(layer: GeometryLayer<any, any>): void;
114
+ /**
115
+ * Hands the pointer and keys to a controller - drawing, editing, measuring - which sees every
116
+ * event first; null gives the view its own ways back. The one before is detached.
117
+ */
118
+ setController(controller: GeometryController<any> | null): void;
119
+ getController(): GeometryController<any> | null;
120
+ /** The view's size in view (CSS) pixels. */
121
+ get viewSize(): {
122
+ width: number;
123
+ height: number;
124
+ pixelRatio: number;
125
+ };
126
+ /** Where a world position is in the view, in view pixels from its top-left; null behind the camera. */
127
+ toScreen(p: Position): [number, number] | null;
128
+ /** The ray through a view point: from the eye (perspective) or the view plane (2D), and its direction. */
129
+ rayAt(x: number, y: number): {
130
+ origin: Vec3;
131
+ direction: Vec3;
132
+ };
133
+ /** Where the ray through a view point meets the level `z` - the camera target's by default. */
134
+ toGround(x: number, y: number, z?: number): Vec3 | null;
135
+ /** World units per view pixel at a world position: how large a pixel is there. */
136
+ pixelSizeAt(p: Position): number;
137
+ /** Where everything in the view is. */
138
+ bounds(): Bounds3 | null;
139
+ /** A ground under everything: its depth is the scene's, what lies under it ghosted. Null for none. */
140
+ setGround(options: GroundOptions | null): void;
141
+ getGround(): Ground | null;
142
+ /** The heatmap of these layers - all, by default - instead of them; null to draw them again. */
143
+ setDensity(spec: {
144
+ layers?: (GeometryLayer<any, any> | string)[];
145
+ ramp?: import('../common/Colors').ColorRamp;
146
+ top?: number;
147
+ } | null): void;
148
+ getCamera(): CameraState;
149
+ setCamera(state: Partial<CameraState>): void;
150
+ flyTo(state: Partial<CameraState>, ms?: number): void;
151
+ /** Flies to show a box - every layer's by default. */
152
+ fit(bounds?: Bounds3 | null, ms?: number, padding?: number): void;
153
+ /**
154
+ * Switches between a 2D map and 3D: to 2D the camera first comes straight down, then the
155
+ * layers draw as a map; to 3D they draw in depth and the camera tilts up.
156
+ */
157
+ setMode(mode: '2d' | '3d', tilt?: number): void;
158
+ private finishModeSwitch;
159
+ /** What is drawn under a view point (view pixels from the view's top-left), or null. */
160
+ pickAt(x: number, y: number): Promise<GeometryHit | null>;
161
+ /** Lights a feature as if pointed at; null for none. */
162
+ setHover(hit: Pick<GeometryHit, 'layer' | 'id'> | null): void;
163
+ /** Selects in a layer; the other layers keep theirs. */
164
+ select(layer: GeometryLayer<any, any>, ids: Iterable<GeometryId>, mode?: SelectMode): void;
165
+ clearSelection(): void;
166
+ getSelection(): GeometrySelection;
167
+ /** A layer's place among the view's, overlays above them all. */
168
+ rankOf(layer: GeometryLayer<any, any>): number;
169
+ get anyHovered(): boolean;
170
+ get windowsLit(): number;
171
+ requestRepaint(): void;
172
+ setAnimating(key: string, animating: boolean): void;
173
+ private emitSelection;
174
+ private emitCamera;
175
+ private onFrame;
176
+ private local;
177
+ private pointerOf;
178
+ /** Keeps a pointer's events coming while it drags, wherever it goes; a pointer the browser no longer knows is let be. */
179
+ private capture;
180
+ /** The controller's cursor, or the view's own: a hand to grab, a pointer over something. */
181
+ private applyCursor;
182
+ private listen;
183
+ private onDown;
184
+ private onMove;
185
+ private onUp;
186
+ private onClick;
187
+ private onWheel;
188
+ private pinchOf;
189
+ private onPinch;
190
+ /** One pick a frame at most for the pointer's hover, against the last frame. */
191
+ private queueHover;
192
+ }
@@ -0,0 +1 @@
1
+ import{parseColor as t}from"../common/Colors.js";import{Disposables as e}from"../common/Disposables.js";import{isEmptyBounds as i,unionBounds as s}from"../data/Geometry.js";import{TypedEventEmitter as n}from"../event/TypedEventEmitter.js";import{LabelOverlay as o}from"./Labels.js";import{CanvasGeometryEngine as r}from"../three/CanvasGeometryEngine.js";import{Ground as h}from"../three/Ground.js";import{Lighting as a}from"../three/Shading.js";import{DARK_THEME as l,LIGHT_THEME as c}from"./GeometryOptions.js";import{MapCamera as d}from"./MapCamera.js";export class GeometryView extends n{constructor(t={}){super(),this.lighting=new a,this.up=[0,0,1],this.labels=null,this.layers=[],this.overlays=[],this.controller=null,this.controllerDrag=null,this.root=null,this.disposables=new e,this.hovered=null,this.ground=null,this.groundOptions=null,this.lastCamera="",this.frames=[],this.pendingMode=null,this.hoverQueued=!1,this.pointer=null,this.drag=null,this.touches=new Map,this.pinch=null,this.options=t,this.mode=t.mode??"3d",this.engine=new r({antialias:t.antialias,forceWebGL:t.forceWebGL,maxPixelRatio:t.maxPixelRatio}),this.camera=new d(t.camera),this.camera.orthographic="2d"===this.mode,t.fov&&(this.camera.fovY=t.fov),t.limits&&(this.camera.limits={...this.camera.limits,...t.limits}),this.applyOptions()}async init(t){this.disposables=new e;const i=document.createElement("div");i.style.position="relative",i.style.width="100%",i.style.height="100%",i.style.overflow="hidden",i.style.outline="none",i.tabIndex=0,t.appendChild(i),i.appendChild(this.engine.canvas),this.root=i,this.disposables.add(()=>i.remove());const s=new o(i,t=>this.toScreen(t));this.labels=s,this.disposables.add(()=>{s.dispose(),this.labels=null});const n=()=>{const t=i.getBoundingClientRect();this.engine.setSize(t.width,t.height,window.devicePixelRatio||1)};n();const r=new ResizeObserver(n);r.observe(i),this.disposables.add(()=>r.disconnect()),this.listen(),this.engine.setCamera((t,e)=>(this.camera.tick()?this.engine.setAnimating("camera",!0):(this.engine.setAnimating("camera",!1),this.finishModeSwitch()),this.emitCamera(),this.ground?.setViewDistance(this.camera.state.distance),this.camera.frame(t,e))),this.disposables.add(this.engine.onBeforeRender(()=>{let t=!1;for(const e of[...this.layers,...this.overlays]){const i=e.wantsBuild;e.beforeRender(!t),i&&(t&&this.requestRepaint(),t=!0)}})),this.disposables.add(this.engine.on("frame",t=>this.onFrame(t))),await this.engine.init(),this.applyRuntimeOptions(),this.emit("ready")}dispose(){this.setController(null),this.disposables.dispose(),this.layers.forEach(t=>t.detach()),this.overlays.forEach(t=>t.detach()),this.ground?.dispose(),this.ground=null,this.engine.dispose(),this.root=null}get element(){return this.root}setOptions(t){const e=void 0!==t.mode&&t.mode!==this.mode;this.options={...this.options,...t},t.limits&&(this.camera.limits={...this.camera.limits,...t.limits}),t.fov&&(this.camera.fovY=t.fov),this.applyOptions(),this.applyRuntimeOptions(),e&&this.setMode(t.mode),this.requestRepaint()}getOptions(){return this.options}applyOptions(){const e=this.options.theme;this.theme="light"===e?c:"dark"!==e&&e?{...l,...e}:l;const i=this.options.highlight??{};this.highlight={look:i.look??"glow",glow:i.glow??"bloom",outlineColor:t(i.outlineColor??this.theme.outline),outlineWidth:i.outlineWidth??2,hoverFades:i.hoverFades??!0,othersShade:i.othersShade??.55,othersToward:this.theme.othersToward,hoverLights:i.hoverLights??!0},this.engine.setBackground(this.theme.background),this.engine.sky.setColors({...this.theme.sky,below:this.theme.sky.horizon})}applyRuntimeOptions(){const t=this.options.bloom;this.engine.bloom&&(this.engine.bloom.strength.value=t?.strength??1.2,this.engine.bloom.radius.value=t?.radius??.5,this.engine.bloom.threshold.value=t?.threshold??0);const e=this.options.halo;this.engine.halo.strength.value=!1===e?0:e?.strength??.55,this.engine.halo.blur.value=!1===e?0:e?.blur??12;const i=this.options.density;(i?.ramp||i?.top)&&this.engine.density.setColorMap(i.ramp??this.engine.density.colorMap,i.top),void 0!==i?.opacity&&(this.engine.density.opacity.value=i.opacity)}addLayer(t,e){if(this.layers.includes(t))return t;const i=e?this.layers.indexOf(e):-1;return i>=0?this.layers.splice(i,0,t):this.layers.push(t),t.attach(this),this.requestRepaint(),t}removeLayer(t){const e=this.layers.indexOf(t);e<0||(this.hovered?.layer===t&&this.setHover(null),this.layers.splice(e,1),t.detach(),this.requestRepaint())}getLayers(){return this.layers}getLayer(t){return this.layers.find(e=>e.id===t)}addOverlay(t){this.overlays.includes(t)||(this.overlays.push(t),t.setOverlay(!0,this.overlays.length),t.setPickable(!1),t.attach(this),this.requestRepaint())}removeOverlay(t){const e=this.overlays.indexOf(t);e<0||(this.overlays.splice(e,1),t.detach(),this.requestRepaint())}setController(t){t!==this.controller&&(this.controller?.detach(),this.controller=t,this.controllerDrag=null,t?.attach(this),this.applyCursor(),this.requestRepaint())}getController(){return this.controller}get viewSize(){return this.engine.viewSize}toScreen(t){const{width:e,height:i}=this.engine.viewSize;if(e<=0||i<=0)return null;const s=this.camera.frame(e,i).viewProjection,n=t[0],o=t[1],r=t[2]??0,h=s[0]*n+s[1]*o+s[2]*r+s[3],a=s[4]*n+s[5]*o+s[6]*r+s[7],l=s[12]*n+s[13]*o+s[14]*r+s[15];return l<=1e-9?null:[(h/l+1)/2*e,(1-a/l)/2*i]}rayAt(t,e){const{width:i,height:s}=this.engine.viewSize;return this.camera.ray(t,e,i,s)}toGround(t,e,i=this.camera.state.target[2]){const{width:s,height:n}=this.engine.viewSize;return this.camera.groundAt(t,e,s,n,i)}pixelSizeAt(t){const{height:e}=this.engine.viewSize,i=Math.tan(this.camera.fovY*Math.PI/360);if(this.camera.orthographic)return 2*this.camera.state.distance*i/Math.max(1,e);const{f:s,eye:n}=this.camera.basis(),o=(t[0]-n[0])*s[0]+(t[1]-n[1])*s[1]+((t[2]??0)-n[2])*s[2];return 2*Math.max(o,this.camera.near())*i/Math.max(1,e)}bounds(){let t=null;for(const e of this.layers){const n=e.bounds();i(n)||(t=t?s(t,n):n)}return t}setGround(t){if(this.ground&&(this.engine.baseScene.remove(this.ground.mesh),this.ground.dispose(),this.ground=null),this.groundOptions=t,!t)return void this.requestRepaint();const[e,i,s,n]=t.bounds,o=this.engine.originFor([(e+s)/2,(i+n)/2,t.z??0]);this.ground=new h({color:this.theme.ground,grid:{spacing:10,major:10,color:this.theme.grid},...t},o,{eye:this.engine.sky.eye,fog:this.engine.sky.horizon}),this.engine.baseScene.add(this.ground.mesh),this.requestRepaint()}getGround(){return this.ground}setDensity(t){const e=t?.layers?.map(t=>"string"==typeof t?this.getLayer(t):t);this.layers.forEach(i=>i.setDensity(!!t&&(!e||e.includes(i)))),(t?.ramp||t?.top)&&this.engine.density.setColorMap(t.ramp??this.engine.density.colorMap,t.top),this.requestRepaint()}getCamera(){return{...this.camera.state,target:[...this.camera.state.target]}}setCamera(t){this.camera.set(t),this.requestRepaint()}flyTo(t,e=900){this.camera.flyTo(t,e),this.engine.setAnimating("camera",!0)}fit(t=this.bounds(),e=900,s=.1){if(!t||i(t))return;const{width:n,height:o}=this.engine.viewSize,r=this.camera.fit(t.min,t.max,n,o,s);e>0?this.flyTo(r,e):this.setCamera(r)}setMode(t,e=55){if(this.options.mode=t,"2d"===t){if("2d"===this.mode&&this.camera.orthographic)return;this.pendingMode="2d",this.flyTo({tilt:0},450)}else{this.pendingMode=null;const t="2d"===this.mode;this.mode="3d",this.camera.orthographic=!1,t&&this.flyTo({tilt:Math.max(this.camera.state.tilt,e)},800),this.emit("mode","3d"),this.requestRepaint()}}finishModeSwitch(){"2d"===this.pendingMode&&(this.pendingMode=null,this.mode="2d",this.camera.orthographic=!0,this.emit("mode","2d"),this.requestRepaint())}async pickAt(t,e){const i=await this.engine.pick(t,e);return i?{...i.hit,point:i.point}:null}setHover(t){const e=this.hovered;e?.layer===t?.layer&&e?.id===t?.id||(e?.layer.setHovered(null),t?.layer.setHovered(t.id),this.hovered=t?{...e??{},...t}:null,this.applyCursor(),this.requestRepaint())}select(t,e,i="replace"){t.select(e,i),this.emitSelection()}clearSelection(){this.layers.forEach(t=>t.clearSelection()),this.emitSelection()}getSelection(){const t=this.layers.map(t=>({layer:t,ids:t.selection()})).filter(t=>t.ids.length>0);return{layers:t,count:t.reduce((t,e)=>t+e.ids.length,0)}}rankOf(t){const e=this.layers.indexOf(t);if(e>=0)return e;const i=this.overlays.indexOf(t);return i>=0?this.layers.length+i:0}get anyHovered(){return null!==this.hovered}get windowsLit(){return this.theme.windowsLit}requestRepaint(){this.engine.requestRepaint()}setAnimating(t,e){this.engine.setAnimating(t,e)}emitSelection(){this.emit("select",this.getSelection())}emitCamera(){const t=this.camera.state,e=`${t.target.join(",")}|${t.distance}|${t.heading}|${t.tilt}`;e!==this.lastCamera&&(this.lastCamera=e,this.emit("camera",this.getCamera()))}onFrame(t){this.labels?.update();const e=performance.now();for(this.frames.push(e);this.frames.length>0&&e-this.frames[0]>1e3;)this.frames.shift();const i=this.engine.getRenderer()?.info?.render??{};this.emit("frame",{...t,fps:this.frames.length,drawCalls:i.drawCalls??i.calls??0,triangles:i.triangles??0,backend:this.engine.webgpu?"webgpu":"webgl"})}local(t){const e=this.root.getBoundingClientRect();return{x:t.clientX-e.left,y:t.clientY-e.top}}pointerOf(t){const{x:e,y:i}=this.local(t);return{x:e,y:i,button:t.button,shift:t.shiftKey,ctrl:t.ctrlKey||t.metaKey,alt:t.altKey,pointerType:t.pointerType??"mouse",native:t}}capture(t){try{this.engine.canvas.setPointerCapture(t)}catch{}}applyCursor(){if(!this.root)return;const t=this.hovered?"pointer":this.drag?.moved?"pan"===this.drag.kind?"grabbing":"move":"grab";this.engine.canvas.style.cursor=this.controller?.cursor??t}listen(){const t=this.engine.canvas;t.style.cursor="grab";const e=(t,e,i,s)=>{t.addEventListener(e,i,s),this.disposables.add(()=>t.removeEventListener(e,i,s))};e(t,"contextmenu",t=>t.preventDefault()),e(t,"pointerdown",t=>this.onDown(t)),e(t,"pointermove",t=>this.onMove(t)),e(t,"pointerup",t=>this.onUp(t)),e(t,"pointercancel",t=>this.onUp(t,!0)),e(t,"pointerleave",()=>{this.pointer=null,this.controller?.onPointerLeave(),this.drag||this.setHover(null),this.emit("hover",null)}),e(t,"wheel",t=>this.onWheel(t),{passive:!1}),e(t,"dblclick",t=>{if(this.controller?.onDoubleClick(this.pointerOf(t)))return void this.applyCursor();if(!1===this.options.interactive)return;const{x:e,y:i}=this.local(t),{width:s,height:n}=this.engine.viewSize,o=this.camera.groundAt(e,i,s,n);o&&this.flyTo({target:o,distance:this.camera.state.distance*(t.shiftKey?2:.45)},600)}),e(this.root,"keydown",t=>{if(this.controller?.onKeyDown(t))return t.preventDefault(),void this.applyCursor();"Escape"===t.key&&this.clearSelection()})}onDown(t){this.root?.focus({preventScroll:!0});const{x:e,y:i}=this.local(t);if("touch"===t.pointerType&&(this.touches.set(t.pointerId,{x:e,y:i}),2===this.touches.size))return this.drag=null,void(this.pinch=this.pinchOf());if(this.controller&&null===this.controllerDrag&&this.controller.onPointerDown(this.pointerOf(t)))return this.controllerDrag=t.pointerId,this.camera.stop(),this.capture(t.pointerId),void this.applyCursor();this.camera.stop();const s=2===t.button||1===t.button||t.ctrlKey&&0===t.button&&"none"===this.options.selection,{width:n,height:o}=this.engine.viewSize;this.drag={id:t.pointerId,kind:s?"rotate":"pan",x:e,y:i,startX:e,startY:i,time:performance.now(),anchor:s?null:this.camera.groundAt(e,i,n,o),moved:!1,history:[]},this.capture(t.pointerId)}onMove(t){const{x:e,y:i}=this.local(t);if(this.pointer={x:e,y:i},this.controllerDrag===t.pointerId)return this.controller?.onPointerDrag(this.pointerOf(t)),void this.applyCursor();if("touch"===t.pointerType&&this.touches.has(t.pointerId)&&(this.touches.set(t.pointerId,{x:e,y:i}),this.pinch&&2===this.touches.size))return void this.onPinch();const s=this.drag;if(!s||s.id!==t.pointerId){return(this.controller?.onPointerMove(this.pointerOf(t))??!1)||this.queueHover(),void this.applyCursor()}if(!s.moved&&Math.hypot(e-s.startX,i-s.startY)>5&&(s.moved=!0,this.applyCursor()),!s.moved||!1===this.options.interactive)return;const{width:n,height:o}=this.engine.viewSize;if("pan"===s.kind&&s.anchor){this.camera.panTo(s.anchor,e,i,n,o);const t=performance.now();for(s.history.push({t:t,target:[this.camera.state.target[0],this.camera.state.target[1]]});s.history.length>0&&t-s.history[0].t>100;)s.history.shift()}else"rotate"===s.kind&&this.camera.rotate(.3*(e-s.x),"3d"===this.mode?.25*(i-s.y):0);s.x=e,s.y=i,this.requestRepaint()}onUp(t,e=!1){if(this.touches.delete(t.pointerId),this.touches.size<2&&(this.pinch=null),this.controllerDrag===t.pointerId){this.controllerDrag=null;try{this.engine.canvas.releasePointerCapture(t.pointerId)}catch{}return this.controller?.onPointerUp(this.pointerOf(t)),void this.applyCursor()}const i=this.drag;if(i&&i.id===t.pointerId){this.drag=null;try{this.engine.canvas.releasePointerCapture(t.pointerId)}catch{}if(this.applyCursor(),!e){if(i.moved&&"pan"===i.kind&&i.history.length>1){const t=i.history[0],e=i.history[i.history.length-1],s=(e.t-t.t)/1e3;s>.01&&performance.now()-e.t<60&&(this.camera.glide([(e.target[0]-t.target[0])/s,(e.target[1]-t.target[1])/s]),this.engine.setAnimating("camera",!0))}!i.moved&&performance.now()-i.time<600&&0===t.button&&this.onClick(t)}}}async onClick(t){if(this.controller?.onClick(this.pointerOf(t)))return void this.applyCursor();const{x:e,y:i}=this.local(t),s=await this.pickAt(e,i),n={hit:s,shift:t.shiftKey,ctrl:t.ctrlKey||t.metaKey,alt:t.altKey,x:e,y:i,native:t};this.emit("click",n);const o=this.options.selection??"multi";if("none"===o)return;const r="multi"===o&&(n.ctrl||n.shift);if(s){if(r)s.layer.select([s.id],n.ctrl?"toggle":"add");else{this.layers.forEach(t=>{t!==s.layer&&t.clearSelection()});const t=s.layer.selection(),e=1===t.length&&t[0]===s.id;s.layer.select(e?[]:[s.id],"replace")}this.emitSelection()}else r||this.clearSelection()}onWheel(t){if(!1===this.options.interactive)return;t.preventDefault();const{x:e,y:i}=this.local(t),{width:s,height:n}=this.engine.viewSize,o=1===t.deltaMode?33:2===t.deltaMode?400:1,r=Math.exp(t.deltaY*o*.0016);this.camera.stop(),this.camera.zoomAt(r,e,i,s,n),this.requestRepaint(),this.queueHover()}pinchOf(){const[t,e]=[...this.touches.values()];return{distance:Math.hypot(e.x-t.x,e.y-t.y),angle:Math.atan2(e.y-t.y,e.x-t.x),midY:(t.y+e.y)/2}}onPinch(){const t=this.pinch,e=this.pinchOf(),[i,s]=[...this.touches.values()],{width:n,height:o}=this.engine.viewSize;this.camera.zoomAt(t.distance/Math.max(1,e.distance),(i.x+s.x)/2,(i.y+s.y)/2,n,o),this.camera.rotate(180*-(e.angle-t.angle)/Math.PI,"3d"===this.mode?.25*(e.midY-t.midY):0),this.pinch=e,this.requestRepaint()}queueHover(){!1===this.options.hover||this.hoverQueued||this.drag?.moved||(this.hoverQueued=!0,requestAnimationFrame(async()=>{this.hoverQueued=!1;const t=this.pointer;if(!t||this.drag?.moved)return;const e=await this.pickAt(t.x,t.y);if(!this.pointer)return;const i=e?.layer!==this.hovered?.layer||e?.id!==this.hovered?.id;this.setHover(e),e&&(this.hovered=e),i&&this.emit("hover",e)}))}}
@@ -0,0 +1,42 @@
1
+ import type { Position } from '../data/Geometry';
2
+ /** How a label looks: a measurement, a figure along an edge, a note, a warning. */
3
+ export type LabelKind = 'measure' | 'segment' | 'info' | 'warning';
4
+ /** A label on a world position, kept there as the camera moves. */
5
+ export interface LabelSpec {
6
+ /** Unique within its group: a label of the same id is moved, not made again. */
7
+ id: string;
8
+ position: Position;
9
+ text: string;
10
+ kind?: LabelKind;
11
+ /** View pixels off its position: right and down. */
12
+ offset?: [number, number];
13
+ /** What of the label is on its position (and offset): its middle, or its left end - beside what it names. */
14
+ anchor?: 'center' | 'left';
15
+ }
16
+ /**
17
+ * Labels in the page over the view, each on a world position and moved with it every frame:
18
+ * lengths along edges, an area, a radius, a warning. Grouped, so that each controller or tool
19
+ * replaces its own without touching another's. Plain DOM: crisp text at any size, a few hundred
20
+ * of them cheap to move.
21
+ */
22
+ export declare class LabelOverlay {
23
+ private readonly project;
24
+ readonly element: HTMLDivElement;
25
+ private readonly groups;
26
+ constructor(parent: HTMLElement, project: (p: Position) => [number, number] | null);
27
+ /** Sets a group's labels: new ones made, gone ones removed, the rest moved and re-texted. */
28
+ set(group: string, labels: readonly LabelSpec[]): void;
29
+ /** Removes a group's labels, or every label. */
30
+ clear(group?: string): void;
31
+ /** Puts every label where its position is on screen now; hides those behind the camera. */
32
+ update(): void;
33
+ dispose(): void;
34
+ }
35
+ /** A length for a label: centimetres under a metre, metres, kilometres from 10 km. */
36
+ export declare function formatLength(metres: number): string;
37
+ /** An area for a label: square metres, hectares from 1 ha, square kilometres from 1 km². */
38
+ export declare function formatArea(squareMetres: number): string;
39
+ /** An angle for a label, in degrees. */
40
+ export declare function formatAngle(degrees: number): string;
41
+ /** A slope for a label: per mille under 10 %, else per cent. */
42
+ export declare function formatSlope(slope: number): string;
@@ -0,0 +1 @@
1
+ const e={measure:{background:"rgba(12, 16, 22, 0.86)",color:"#ffffff",fontWeight:"600",fontSize:"12px",padding:"3px 7px"},segment:{background:"rgba(12, 16, 22, 0.72)",color:"#e8eef5",fontWeight:"500",fontSize:"11px",padding:"2px 5px"},info:{background:"rgba(12, 16, 22, 0.72)",color:"#c9d4e0",fontWeight:"400",fontSize:"11px",padding:"2px 6px"},warning:{background:"rgba(160, 24, 48, 0.9)",color:"#ffffff",fontWeight:"600",fontSize:"11px",padding:"2px 6px"}};export class LabelOverlay{constructor(e,t){this.project=t,this.groups=new Map;const o=document.createElement("div");o.style.position="absolute",o.style.inset="0",o.style.pointerEvents="none",o.style.overflow="hidden",o.style.font="12px Roboto, system-ui, sans-serif",e.appendChild(o),this.element=o}set(t,o){let n=this.groups.get(t);n||(n=new Map,this.groups.set(t,n));const s=new Set(o.map(e=>e.id));n.forEach((e,t)=>{s.has(t)||(e.node.remove(),n.delete(t))});for(const t of o){let o=n.get(t.id);if(!o){const e=document.createElement("div");e.style.position="absolute",e.style.left="0",e.style.top="0",e.style.whiteSpace="nowrap",e.style.borderRadius="4px",e.style.fontVariantNumeric="tabular-nums",e.style.letterSpacing="0.2px",e.style.boxShadow="0 2px 6px rgba(0, 0, 0, 0.35)",e.style.willChange="transform",this.element.appendChild(e),o={spec:t,node:e},n.set(t.id,o)}o.node.textContent!==t.text&&(o.node.textContent=t.text),o.spec.kind===t.kind&&o.node.dataset.kind||(Object.assign(o.node.style,e[t.kind??"measure"]),o.node.dataset.kind=t.kind??"measure"),o.spec=t}this.update()}clear(e){const t=e?[e]:[...this.groups.keys()];for(const e of t)this.groups.get(e)?.forEach(e=>e.node.remove()),this.groups.delete(e)}update(){this.groups.forEach(e=>e.forEach(({spec:e,node:t})=>{const o=this.project(e.position);if(!o)return void(t.style.display="none");t.style.display="";const[n,s]=e.offset??[0,0];t.style.transform=`translate(${Math.round(o[0]+n)}px, ${Math.round(o[1]+s)}px) translate(${"left"===e.anchor?"0":"-50%"}, -50%)`}))}dispose(){this.clear(),this.element.remove()}}export function formatLength(e){const t=Math.abs(e);return t<1?`${(100*e).toFixed(t<.1?1:0)} cm`:t<1e4?`${e.toFixed(t<100?2:1)} m`:`${(e/1e3).toFixed(2)} km`}export function formatArea(e){const t=Math.abs(e);return t<1e4?`${e.toFixed(t<100?2:1)} m²`:t<1e6?`${(e/1e4).toFixed(2)} ha`:`${(e/1e6).toFixed(3)} km²`}export function formatAngle(e){return`${e.toFixed(1)}°`}export function formatSlope(e){if(!Number.isFinite(e))return"vertical";return Math.abs(e)<.1?`${(1e3*e).toFixed(1)} ‰`:`${(100*e).toFixed(1)} %`}
@@ -0,0 +1,78 @@
1
+ import type { FrameCamera } from '../three/CanvasGeometryEngine';
2
+ /** Where the camera looks from: a point on the ground, how far back, which way, how tilted. */
3
+ export interface CameraState {
4
+ /** The point looked at, in world units. */
5
+ target: [number, number, number];
6
+ /** From the camera to the target, in world units. */
7
+ distance: number;
8
+ /** Degrees clockwise from north (+y): the way the camera faces. */
9
+ heading: number;
10
+ /** Degrees from straight down: 0 a map, 90 the horizon. */
11
+ tilt: number;
12
+ }
13
+ export interface CameraLimits {
14
+ minDistance: number;
15
+ maxDistance: number;
16
+ maxTilt: number;
17
+ }
18
+ type Vec3 = [number, number, number];
19
+ /**
20
+ * The view's camera: a target, a distance, a heading and a tilt, drawn in perspective - its far
21
+ * plane at infinity and its depth `1 - near / w`, the scene depth the geometry reads - or, for a
22
+ * 2D map, orthographic and straight down. Both take the same distance: a frame pixel at the
23
+ * target is as large in either, so switching between them keeps the scale.
24
+ *
25
+ * Moves are ground-anchored: a pan keeps the point grabbed under the pointer, a zoom the point
26
+ * under the wheel. `flyTo` eases from one state to another, the distance on a log scale.
27
+ */
28
+ export declare class MapCamera {
29
+ state: CameraState;
30
+ /** The perspective's vertical field of view, degrees. */
31
+ fovY: number;
32
+ orthographic: boolean;
33
+ limits: CameraLimits;
34
+ private animation;
35
+ private velocity;
36
+ private lastTick;
37
+ constructor(state?: Partial<CameraState>);
38
+ get animating(): boolean;
39
+ set(state: Partial<CameraState>): void;
40
+ /** Eases to a state over `ms`. */
41
+ flyTo(state: Partial<CameraState>, ms?: number): void;
42
+ stop(): void;
43
+ /** Moves an animation or a glide on to `now`; true while there is more to come. */
44
+ tick(now?: number): boolean;
45
+ /** A pan's speed at release, world units a second: it glides on and slows. */
46
+ glide(velocity: [number, number]): void;
47
+ /** The camera's frame: everything the engine needs, for a frame `width` by `height` frame pixels. */
48
+ frame(width: number, height: number): FrameCamera;
49
+ /** The near plane: close enough for what is near the camera, far enough to keep the depth fine. */
50
+ near(): number;
51
+ eye(): Vec3;
52
+ /**
53
+ * The camera's axes: right, up on screen and forward, and its position. Heading 0 looks north
54
+ * with east to the right; a 2D map is straight down.
55
+ */
56
+ basis(): {
57
+ r: Vec3;
58
+ u: Vec3;
59
+ f: Vec3;
60
+ eye: Vec3;
61
+ };
62
+ /** The ray through a view point (view pixels in a view `width` by `height`): origin and direction. */
63
+ ray(x: number, y: number, width: number, height: number): {
64
+ origin: Vec3;
65
+ direction: Vec3;
66
+ };
67
+ /** Where the ray through a view point meets the level `z` (the target's by default), or null above the horizon. */
68
+ groundAt(x: number, y: number, width: number, height: number, z?: number): Vec3 | null;
69
+ /** Moves the target so that `anchor` - a ground point - comes under the view point. */
70
+ panTo(anchor: Vec3, x: number, y: number, width: number, height: number): void;
71
+ /** Zooms by `factor` keeping the ground point under the view point where it is. */
72
+ zoomAt(factor: number, x: number, y: number, width: number, height: number): void;
73
+ rotate(dHeading: number, dTilt: number): void;
74
+ /** A state that shows a box, from the current heading and tilt, for a view `width` by `height`. */
75
+ fit(min: Vec3, max: Vec3, width: number, height: number, padding?: number): CameraState;
76
+ private clamp;
77
+ }
78
+ export {};
@@ -0,0 +1 @@
1
+ export class MapCamera{constructor(t){this.fovY=40,this.orthographic=!1,this.limits={minDistance:2,maxDistance:2e5,maxTilt:82},this.animation=null,this.velocity=[0,0],this.lastTick=0,this.state={target:[0,0,0],distance:1500,heading:0,tilt:45,...t}}get animating(){return null!==this.animation||Math.hypot(this.velocity[0],this.velocity[1])>.001}set(t){this.animation=null,this.velocity=[0,0],this.state=this.clamp({...this.state,...t})}flyTo(t,i=900){const a=this.clamp({...this.state,...t});let s=a.heading;for(;s-this.state.heading>180;)s-=360;for(;s-this.state.heading<-180;)s+=360;this.velocity=[0,0],this.animation={from:{...this.state,target:[...this.state.target]},to:{...a,heading:s},start:performance.now(),duration:Math.max(1,i)}}stop(){this.animation=null,this.velocity=[0,0]}tick(t=performance.now()){const i=this.lastTick?Math.min(.05,(t-this.lastTick)/1e3):0;if(this.lastTick=t,this.animation){const{from:i,to:a,start:s,duration:e}=this.animation,h=Math.min(1,(t-s)/e),n=(t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2)(h),o=(t,i)=>t+(i-t)*n;return this.state={target:[o(i.target[0],a.target[0]),o(i.target[1],a.target[1]),o(i.target[2],a.target[2])],distance:Math.exp(o(Math.log(i.distance),Math.log(a.distance))),heading:o(i.heading,a.heading),tilt:o(i.tilt,a.tilt)},h>=1&&(this.state.heading=(a.heading%360+360)%360,this.animation=null),!0}if(Math.hypot(this.velocity[0],this.velocity[1])>.001&&i>0){this.state.target[0]+=this.velocity[0]*i,this.state.target[1]+=this.velocity[1]*i;const t=Math.exp(6*-i);return this.velocity=[this.velocity[0]*t,this.velocity[1]*t],Math.hypot(this.velocity[0],this.velocity[1])<.002*this.state.distance&&(this.velocity=[0,0]),!0}return!1}glide(t){this.velocity=t,this.lastTick=0}frame(t,i){const{r:a,u:s,f:e,eye:h}=this.basis(),n=Math.tan(this.fovY*Math.PI/360),o=i/2/n,r=(t,i)=>t[0]*i[0]+t[1]*i[1]+t[2]*i[2];if(this.orthographic){const n=o/this.state.distance,c=2*n/t,l=2*n/i,g=1e-5;return{viewProjection:[c*a[0],c*a[1],c*a[2],-c*r(a,h),l*s[0],l*s[1],l*s[2],-l*r(s,h),g*e[0],g*e[1],g*e[2],-g*r(e,h),0,0,0,1],near:.1,focal:n,pxPerWorld:n,orthographic:!0,eye:h}}const c=1/n,l=c/(t/i),g=this.near();return{viewProjection:[l*a[0],l*a[1],l*a[2],-l*r(a,h),c*s[0],c*s[1],c*s[2],-c*r(s,h),e[0],e[1],e[2],-r(e,h)-2*g,e[0],e[1],e[2],-r(e,h)],near:g,focal:o,pxPerWorld:o/this.state.distance,orthographic:!1,eye:h}}near(){const t=this.eye()[2]-this.state.target[2];return Math.max(.05,Math.min(.002*this.state.distance,Math.max(.05,.25*Math.abs(t))))}eye(){return this.basis().eye}basis(){const t=this.state.heading*Math.PI/180,i=this.orthographic?0:this.state.tilt*Math.PI/180,a=[Math.cos(t),-Math.sin(t),0],s=[Math.sin(t)*Math.sin(i),Math.cos(t)*Math.sin(i),-Math.cos(i)],e=[a[1]*s[2]-a[2]*s[1],a[2]*s[0]-a[0]*s[2],a[0]*s[1]-a[1]*s[0]],h=this.state.distance,n=this.state.target;return{r:a,u:e,f:s,eye:[n[0]-s[0]*h,n[1]-s[1]*h,n[2]-s[2]*h]}}ray(t,i,a,s){const{r:e,u:h,f:n,eye:o}=this.basis(),r=t/a*2-1,c=1-i/s*2,l=Math.tan(this.fovY*Math.PI/360);if(this.orthographic){const t=this.state.distance*l,i=t*(a/s);return{origin:[0,1,2].map(a=>o[a]+e[a]*r*i+h[a]*c*t),direction:n}}const g=a/s,m=[0,1,2].map(t=>n[t]+e[t]*r*l*g+h[t]*c*l),d=Math.hypot(m[0],m[1],m[2]);return{origin:o,direction:[m[0]/d,m[1]/d,m[2]/d]}}groundAt(t,i,a,s,e=this.state.target[2]){const{origin:h,direction:n}=this.ray(t,i,a,s);if(Math.abs(n[2])<1e-6)return null;const o=(e-h[2])/n[2];return o<=0||o>40*this.state.distance?null:[h[0]+n[0]*o,h[1]+n[1]*o,e]}panTo(t,i,a,s,e){const h=this.groundAt(i,a,s,e,t[2]);h&&(this.state.target[0]+=t[0]-h[0],this.state.target[1]+=t[1]-h[1])}zoomAt(i,a,s,e,h){const n=this.groundAt(a,s,e,h);this.state.distance=t(this.state.distance*i,this.limits.minDistance,this.limits.maxDistance),n&&this.panTo(n,a,s,e,h)}rotate(i,a){this.state.heading=((this.state.heading+i)%360+360)%360,this.state.tilt=t(this.state.tilt+a,0,this.limits.maxTilt)}fit(t,i,a,s,e=.1){const h=[(t[0]+i[0])/2,(t[1]+i[1])/2,t[2]<=0&&i[2]>=0?0:(t[2]+i[2])/2],n=Math.max(1,Math.hypot(i[0]-t[0],i[1]-t[1])/2)*(1+e)/(Math.tan(this.fovY*Math.PI/360)*Math.min(1,a/Math.max(1,s)));return this.clamp({...this.state,target:h,distance:n})}clamp(i){return{target:[...i.target],distance:t(i.distance,this.limits.minDistance,this.limits.maxDistance),heading:i.heading,tilt:t(i.tilt,0,this.limits.maxTilt)}}}function t(t,i,a){return Math.min(a,Math.max(i,t))}
@@ -0,0 +1,13 @@
1
+ type EventHandler<T> = (data: T) => void;
2
+ type AnyEventHandler<Events> = <K extends keyof Events>(event: K, data: Events[K]) => void;
3
+ export declare class TypedEventEmitter<Events extends Record<string, any>> {
4
+ private listeners;
5
+ private anyListeners;
6
+ on(handler: AnyEventHandler<Events>): () => void;
7
+ on<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): () => void;
8
+ off<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): void;
9
+ off(handler: AnyEventHandler<Events>): void;
10
+ protected emit<K extends keyof Events>(event: K, data: Events[K]): void;
11
+ protected emit<K extends keyof Events>(event: K): void;
12
+ }
13
+ export {};
@@ -0,0 +1 @@
1
+ export class TypedEventEmitter{constructor(){this.listeners={},this.anyListeners=new Set}on(e,t){if("function"==typeof e){const t=e;return this.anyListeners.add(t),()=>this.anyListeners.delete(t)}if("function"==typeof t){const s=e;return this.listeners[s]||(this.listeners[s]=new Set),this.listeners[s].add(t),()=>this.listeners[s].delete(t)}return()=>{}}off(e,t){if("function"==typeof e){const t=e;this.anyListeners.delete(t)}else"function"==typeof t&&this.listeners[e]?.delete(t)}emit(e,t){this.listeners[e]?.forEach(e=>{e(t)}),this.anyListeners.forEach(s=>{s(e,t)})}}
package/index.d.ts ADDED
@@ -0,0 +1,53 @@
1
+ export * from './data/Geometry';
2
+ export * from './math/Triangulate';
3
+ export * from './math/Projection';
4
+ export * from './math/Vector';
5
+ export * from './math/Measure';
6
+ export * from './math/Lines';
7
+ export * from './math/Polygons';
8
+ export * from './math/Boolean';
9
+ export * from './math/Transform';
10
+ export * from './math/Relations';
11
+ export * from './math/Geodesy';
12
+ export * from './math/SpatialIndex';
13
+ export * from './math/FeatureIndex';
14
+ export * from './engine/GeometryFrame';
15
+ export * from './engine/GeometryEngine';
16
+ export * from './engine/GeometryOptions';
17
+ export * from './engine/GeometryView';
18
+ export * from './engine/MapCamera';
19
+ export * from './engine/Labels';
20
+ export * from './edit/GeometryController';
21
+ export * from './edit/Snapper';
22
+ export * from './edit/Sketch';
23
+ export * from './edit/EditShape';
24
+ export * from './edit/EditHistory';
25
+ export * from './edit/CreateController';
26
+ export * from './edit/EditController';
27
+ export * from './edit/MeasureController';
28
+ export * from './three/CanvasGeometryEngine';
29
+ export * from './three/HostedGeometryEngine';
30
+ export * from './three/RiaGeometryEngine';
31
+ export * from './three/FeatureLook';
32
+ export * from './three/Shading';
33
+ export * from './three/DensityMap';
34
+ export * from './three/Halo';
35
+ export * from './three/Ground';
36
+ export * from './three/Tsl';
37
+ export * from './three/primitives/GpuLines';
38
+ export * from './three/primitives/GpuIcons';
39
+ export * from './three/primitives/GpuTubes';
40
+ export * from './three/primitives/GpuSpheres';
41
+ export * from './three/primitives/GpuAreas';
42
+ export * from './three/primitives/IconAtlas';
43
+ export * from './three/primitives/Body';
44
+ export * from './layers/GeometryLayer';
45
+ export * from './layers/LineLayer';
46
+ export * from './layers/PointLayer';
47
+ export * from './layers/TubeLayer';
48
+ export * from './layers/SphereLayer';
49
+ export * from './layers/AreaLayer';
50
+ export * from './react/ReactGeometry';
51
+ export * from './common/Colors';
52
+ export * from './common/Disposables';
53
+ export * from './event/TypedEventEmitter';
package/index.js ADDED
@@ -0,0 +1 @@
1
+ export*from"./data/Geometry.js";export*from"./math/Triangulate.js";export*from"./math/Projection.js";export*from"./math/Vector.js";export*from"./math/Measure.js";export*from"./math/Lines.js";export*from"./math/Polygons.js";export*from"./math/Boolean.js";export*from"./math/Transform.js";export*from"./math/Relations.js";export*from"./math/Geodesy.js";export*from"./math/SpatialIndex.js";export*from"./math/FeatureIndex.js";export*from"./engine/GeometryFrame.js";export*from"./engine/GeometryEngine.js";export*from"./engine/GeometryOptions.js";export*from"./engine/GeometryView.js";export*from"./engine/MapCamera.js";export*from"./engine/Labels.js";export*from"./edit/GeometryController.js";export*from"./edit/Snapper.js";export*from"./edit/Sketch.js";export*from"./edit/EditShape.js";export*from"./edit/EditHistory.js";export*from"./edit/CreateController.js";export*from"./edit/EditController.js";export*from"./edit/MeasureController.js";export*from"./three/CanvasGeometryEngine.js";export*from"./three/HostedGeometryEngine.js";export*from"./three/RiaGeometryEngine.js";export*from"./three/FeatureLook.js";export*from"./three/Shading.js";export*from"./three/DensityMap.js";export*from"./three/Halo.js";export*from"./three/Ground.js";export*from"./three/Tsl.js";export*from"./three/primitives/GpuLines.js";export*from"./three/primitives/GpuIcons.js";export*from"./three/primitives/GpuTubes.js";export*from"./three/primitives/GpuSpheres.js";export*from"./three/primitives/GpuAreas.js";export*from"./three/primitives/IconAtlas.js";export*from"./three/primitives/Body.js";export*from"./layers/GeometryLayer.js";export*from"./layers/LineLayer.js";export*from"./layers/PointLayer.js";export*from"./layers/TubeLayer.js";export*from"./layers/SphereLayer.js";export*from"./layers/AreaLayer.js";export*from"./react/ReactGeometry.js";export*from"./common/Colors.js";export*from"./common/Disposables.js";export*from"./event/TypedEventEmitter.js";
@@ -0,0 +1,36 @@
1
+ import { ColorLike } from '../common/Colors';
2
+ import { GeometryFeature } from '../data/Geometry';
3
+ import { GeometryPrimitive } from '../engine/GeometryFrame';
4
+ import { BaseStyle, GeometryLayer, GeometryLayerOptions, LayerHost } from './GeometryLayer';
5
+ export interface AreaStyle extends BaseStyle {
6
+ /** The fill's colour; its alpha how much of what is under it shows. */
7
+ color?: ColorLike;
8
+ /** Hatched rather than filled. */
9
+ pattern?: 'solid' | 'hatch';
10
+ /** Extruded: its height, and how high its foot is above its points. */
11
+ height?: number;
12
+ base?: number;
13
+ /** The finish of an extruded area's walls and roof. */
14
+ material?: string | number;
15
+ /** The outline's colour, none for no outline; and its width in view pixels. */
16
+ outline?: ColorLike | null;
17
+ outlineWidth?: number;
18
+ outlineDashed?: boolean;
19
+ }
20
+ export interface AreaLayerOptions<F> extends GeometryLayerOptions<F, AreaStyle> {
21
+ /** Stand the areas up to their style's `height`: buildings, volumes. In 3D only; flat on a 2D map. */
22
+ extrude?: boolean;
23
+ /** Outlines along every ring. On by default for flat areas. */
24
+ outlines?: boolean;
25
+ }
26
+ /**
27
+ * Areas (`GpuAreas`): flat fills, hatched or solid, with outlines (`GpuLines`) - zones, parcels,
28
+ * risk areas - or lit volumes in 3D whose heights live on the GPU, so a height change, a filter
29
+ * or a growing-in is a texture write.
30
+ */
31
+ export declare class AreaLayer<F extends GeometryFeature = GeometryFeature> extends GeometryLayer<F, AreaStyle> {
32
+ private readonly options;
33
+ constructor(options?: AreaLayerOptions<F>);
34
+ protected createPrimitives(host: LayerHost, origin: [number, number, number]): GeometryPrimitive[];
35
+ private flat;
36
+ }
@@ -0,0 +1 @@
1
+ import{parseColor as t}from"../common/Colors.js";import{polygonsOf as e}from"../data/Geometry.js";import{FeatureState as o,LookFlag as i}from"../three/FeatureLook.js";import{GpuAreas as r}from"../three/primitives/GpuAreas.js";import{GpuLines as s}from"../three/primitives/GpuLines.js";import{materialCode as a}from"../three/Shading.js";import{GeometryLayer as n}from"./GeometryLayer.js";export class AreaLayer extends n{constructor(t={}){super(t),this.options=t}createPrimitives(n,h){const l=!!this.options.extrude&&"3d"===n.mode,m=this.addRole((t,e,o,r,s)=>{s.color=this.colorOf(o.color,o.opacity,r,l?"#8d99ae":"#4cc9f033"),s.flags="hatch"===o.pattern?i.Hatch:0,s.width=o.height??0,s.realWidth=o.base??0,s.material=a(o.material)}),p=[];this.features.forEach((t,o)=>{for(const i of e(t.geometry))p.push({index:o,rings:i.map(t=>t.map(t=>[t[0]-h[0],t[1]-h[1],(t[2]??0)-h[2]]))})});const c=[new r(p,{look:m,lighting:n.lighting,extrude:l,up:n.up,pick:this.pick??void 0,rank:n.rankOf?.(this)??0})];if(this.options.outlines??!l){const r=this.addRole((e,r,s,a,n)=>{const h=null===s.outline?[0,0,0,0]:t(s.outline??s.color??"#4cc9f0");n.color=this.colorOf([h[0],h[1],h[2],void 0===s.outline?1:h[3]],s.opacity,a,"#4cc9f0"),n.width=s.outlineWidth??1.5,n.meters=!1,n.flags=(s.outlineDashed?i.Dashed:0)|i.NoArrow,null===s.outline&&a!==o.Selected&&(n.state=o.Hidden)}),a=this.features.map(t=>e(t.geometry).flatMap(t=>t.filter(t=>t.length>2).map(t=>(t[0][0]===t[t.length-1][0]&&t[0][1]===t[t.length-1][1]?t:[...t,t[0]]).map(t=>({x:t[0]-h[0],y:t[1]-h[1],z:(t[2]??0)-h[2]}))))),l="2d"===n.mode?{}:this.flat()?{ground:{up:n.up}}:{space:!0};c.push(new s(a,{look:r,pick:this.pick??void 0,arrows:!1,...l}))}return c}flat(){const t=this.bounds();return Math.abs(t.max[2]-t.min[2])<1e-6&&Math.abs(t.max[2])<1e-6}}