@dxos/solid-ui-geo 0.10.0 → 0.11.1
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/dist/lib/chunk-countries-110m.mjs +11548 -0
- package/dist/lib/chunk-countries-110m.mjs.map +1 -0
- package/dist/lib/data.mjs +8 -0
- package/dist/lib/data.mjs.map +1 -0
- package/dist/lib/index.mjs +980 -0
- package/dist/lib/index.mjs.map +1 -0
- package/dist/lib/translations.mjs +12 -0
- package/dist/lib/translations.mjs.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -14
- package/dist/lib/browser/chunk-RMZP4JBX.mjs +0 -9
- package/dist/lib/browser/chunk-RMZP4JBX.mjs.map +0 -7
- package/dist/lib/browser/countries-110m-MXSNZ6PF.mjs +0 -37859
- package/dist/lib/browser/countries-110m-MXSNZ6PF.mjs.map +0 -7
- package/dist/lib/browser/data.mjs +0 -7
- package/dist/lib/browser/data.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -1217
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/translations.mjs +0 -19
- package/dist/lib/browser/translations.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-ICM52DKE.mjs +0 -11
- package/dist/lib/node-esm/chunk-ICM52DKE.mjs.map +0 -7
- package/dist/lib/node-esm/countries-110m-HEHEK3AV.mjs +0 -37861
- package/dist/lib/node-esm/countries-110m-HEHEK3AV.mjs.map +0 -7
- package/dist/lib/node-esm/data.mjs +0 -8
- package/dist/lib/node-esm/data.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -1218
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/translations.mjs +0 -21
- package/dist/lib/node-esm/translations.mjs.map +0 -7
|
@@ -0,0 +1,980 @@
|
|
|
1
|
+
import { loadTopology } from "./data.mjs";
|
|
2
|
+
import { className, createComponent, delegateEvents, effect, insert, memo, mergeProps, setAttribute, spread, template, use } from "solid-js/web";
|
|
3
|
+
import { createResizeObserver } from "@solid-primitives/resize-observer";
|
|
4
|
+
import { drag, easeLinear, easeSinOut, geoCircle as geoCircle$1, geoDistance, geoGraticule, geoInterpolate, geoMercator, geoOrthographic, geoPath, geoTransverseMercator, interpolateNumber, select, selection, timer as timer$1, transition } from "d3";
|
|
5
|
+
import { Show, createContext, createEffect, createMemo, createSignal, onCleanup, onMount, useContext } from "solid-js";
|
|
6
|
+
import { mx } from "@dxos/ui-theme";
|
|
7
|
+
import { raise } from "@dxos/debug";
|
|
8
|
+
import versor from "versor";
|
|
9
|
+
import { feature, mesh } from "topojson-client";
|
|
10
|
+
import "leaflet/dist/leaflet.css";
|
|
11
|
+
import L, { latLngBounds } from "leaflet";
|
|
12
|
+
//#region src/hooks/context.tsx
|
|
13
|
+
var defaults$1 = {
|
|
14
|
+
center: {
|
|
15
|
+
lat: 51,
|
|
16
|
+
lng: 0
|
|
17
|
+
},
|
|
18
|
+
zoom: 4
|
|
19
|
+
};
|
|
20
|
+
var GlobeContext = createContext();
|
|
21
|
+
var GlobeContextProvider = (props) => {
|
|
22
|
+
const [size, setSize] = createSignal(props.size ?? {
|
|
23
|
+
width: 0,
|
|
24
|
+
height: 0
|
|
25
|
+
});
|
|
26
|
+
const [center, setCenter] = createSignal(props.center ?? defaults$1.center);
|
|
27
|
+
const [zoom, setZoom] = createSignal(props.zoom ?? defaults$1.zoom);
|
|
28
|
+
const [translation, setTranslation] = createSignal(props.translation);
|
|
29
|
+
const [rotation, setRotation] = createSignal(props.rotation);
|
|
30
|
+
createEffect(() => {
|
|
31
|
+
if (props.size) setSize(props.size);
|
|
32
|
+
});
|
|
33
|
+
return createComponent(GlobeContext.Provider, {
|
|
34
|
+
value: {
|
|
35
|
+
size,
|
|
36
|
+
center,
|
|
37
|
+
zoom,
|
|
38
|
+
translation,
|
|
39
|
+
rotation,
|
|
40
|
+
setCenter,
|
|
41
|
+
setZoom,
|
|
42
|
+
setTranslation,
|
|
43
|
+
setRotation
|
|
44
|
+
},
|
|
45
|
+
get children() {
|
|
46
|
+
return props.children;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
var useGlobeContext = () => {
|
|
51
|
+
return useContext(GlobeContext) ?? raise(/* @__PURE__ */ new Error("Missing GlobeContext"));
|
|
52
|
+
};
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/util/debug.ts
|
|
55
|
+
var timer = (cb) => {
|
|
56
|
+
const start = Date.now();
|
|
57
|
+
const data = cb();
|
|
58
|
+
Date.now() - start / 1e3;
|
|
59
|
+
return data;
|
|
60
|
+
};
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/util/inertia.ts
|
|
63
|
+
var restrictAxis = (axis) => (original, current) => current.map((d, i) => axis[i] ? d : original[i]);
|
|
64
|
+
/**
|
|
65
|
+
* Applies a drag handler to the specified target element.
|
|
66
|
+
*/
|
|
67
|
+
var geoInertiaDrag = (target, render, projection, options) => {
|
|
68
|
+
if (!options) options = {};
|
|
69
|
+
if (target.node) target = target.node();
|
|
70
|
+
target = select(target);
|
|
71
|
+
const inertia = geoInertiaDragHelper({
|
|
72
|
+
projection,
|
|
73
|
+
render: (rotation) => {
|
|
74
|
+
projection.rotate(rotation);
|
|
75
|
+
render && render();
|
|
76
|
+
},
|
|
77
|
+
axis: restrictAxis(options.xAxis ? [
|
|
78
|
+
true,
|
|
79
|
+
false,
|
|
80
|
+
false
|
|
81
|
+
] : [
|
|
82
|
+
true,
|
|
83
|
+
true,
|
|
84
|
+
true
|
|
85
|
+
]),
|
|
86
|
+
start: options.start,
|
|
87
|
+
move: options.move,
|
|
88
|
+
end: options.end,
|
|
89
|
+
stop: options.stop,
|
|
90
|
+
finish: options.finish,
|
|
91
|
+
time: options.time,
|
|
92
|
+
hold: options.hold
|
|
93
|
+
});
|
|
94
|
+
target.call(drag().on("start", inertia.start).on("drag", inertia.move).on("end", inertia.end));
|
|
95
|
+
return inertia;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* A versor is a compact way to describe a rotation in 3D space.
|
|
99
|
+
* It consists of four components [𝑤,x,y,z], where:
|
|
100
|
+
* 𝑤 is a scalar representing the angle of rotation.
|
|
101
|
+
* x, y, z are the vector components, representing the axis of rotation.
|
|
102
|
+
*/
|
|
103
|
+
var geoInertiaDragHelper = (opt) => {
|
|
104
|
+
const projection = opt.projection;
|
|
105
|
+
let v0;
|
|
106
|
+
let r0;
|
|
107
|
+
let q0;
|
|
108
|
+
let v10;
|
|
109
|
+
let v11;
|
|
110
|
+
let q10;
|
|
111
|
+
const inertia = inertiaHelper({
|
|
112
|
+
axis: opt.axis,
|
|
113
|
+
start: () => {
|
|
114
|
+
v0 = versor.cartesian(projection.invert(inertia.position));
|
|
115
|
+
r0 = projection.rotate();
|
|
116
|
+
q0 = versor(r0);
|
|
117
|
+
opt.start && opt.start();
|
|
118
|
+
},
|
|
119
|
+
move: () => {
|
|
120
|
+
const inv = projection.rotate(r0).invert(inertia.position);
|
|
121
|
+
if (isNaN(inv[0])) return;
|
|
122
|
+
const v1 = versor.cartesian(inv);
|
|
123
|
+
const q1 = versor.multiply(q0, versor.delta(v0, v1));
|
|
124
|
+
const r1 = versor.rotation(q1);
|
|
125
|
+
const r2 = opt.axis(r0, r1);
|
|
126
|
+
opt.render(r2);
|
|
127
|
+
opt.move && opt.move();
|
|
128
|
+
},
|
|
129
|
+
end: () => {
|
|
130
|
+
v10 = versor.cartesian(projection.invert(inertia.position.map((d, i) => d - inertia.velocity[i] / 1e3)));
|
|
131
|
+
q10 = versor(projection.rotate());
|
|
132
|
+
v11 = versor.cartesian(projection.invert(inertia.position));
|
|
133
|
+
opt.end && opt.end();
|
|
134
|
+
},
|
|
135
|
+
stop: opt.stop,
|
|
136
|
+
finish: opt.finish,
|
|
137
|
+
render: (t) => {
|
|
138
|
+
const r1 = versor.rotation(versor.multiply(q10, versor.delta(v10, v11, t * 1e3)));
|
|
139
|
+
const r2 = opt.axis(r0, r1);
|
|
140
|
+
opt.render && opt.render(r2);
|
|
141
|
+
},
|
|
142
|
+
time: opt.time
|
|
143
|
+
});
|
|
144
|
+
return inertia;
|
|
145
|
+
};
|
|
146
|
+
function inertiaHelper(opt) {
|
|
147
|
+
const A = opt.time || 5e3;
|
|
148
|
+
const limit = 1.0001;
|
|
149
|
+
const B = -Math.log(1 - 1 / limit);
|
|
150
|
+
const inertia = {
|
|
151
|
+
position: [0, 0],
|
|
152
|
+
velocity: [0, 0],
|
|
153
|
+
timer: timer$1(() => {}),
|
|
154
|
+
time: 0,
|
|
155
|
+
t: 0,
|
|
156
|
+
start: function(ev) {
|
|
157
|
+
const position = [ev.x, ev.y];
|
|
158
|
+
inertia.position = position;
|
|
159
|
+
inertia.velocity = [0, 0];
|
|
160
|
+
inertia.timer.stop();
|
|
161
|
+
this.classList.remove("inertia");
|
|
162
|
+
this.classList.add("dragging");
|
|
163
|
+
opt.start && opt.start.call(this, position);
|
|
164
|
+
},
|
|
165
|
+
move: function(ev) {
|
|
166
|
+
const position = [ev.x, ev.y];
|
|
167
|
+
const time = performance.now();
|
|
168
|
+
const deltaTime = time - inertia.time;
|
|
169
|
+
const decay = 1 - Math.exp(-deltaTime / 1e3);
|
|
170
|
+
inertia.velocity = inertia.velocity.map((d, i) => {
|
|
171
|
+
const deltaPos = position[i] - inertia.position[i];
|
|
172
|
+
const deltaTime = time - inertia.time;
|
|
173
|
+
return 1e3 * (1 - decay) * deltaPos / deltaTime + d * decay;
|
|
174
|
+
});
|
|
175
|
+
inertia.velocity = opt.axis([0, 0], inertia.velocity);
|
|
176
|
+
inertia.time = time;
|
|
177
|
+
inertia.position = position;
|
|
178
|
+
opt.move && opt.move.call(this, position);
|
|
179
|
+
},
|
|
180
|
+
end: function(ev) {
|
|
181
|
+
this.classList.remove("dragging", "inertia");
|
|
182
|
+
const v = inertia.velocity;
|
|
183
|
+
if (v[0] * v[0] + v[1] * v[1] < 100) {
|
|
184
|
+
inertia.timer.stop();
|
|
185
|
+
return opt.stop && opt.stop();
|
|
186
|
+
}
|
|
187
|
+
const deltaTime = performance.now() - inertia.time;
|
|
188
|
+
if (opt.hold === void 0) opt.hold = 100;
|
|
189
|
+
if (deltaTime >= opt.hold) {
|
|
190
|
+
inertia.timer.stop();
|
|
191
|
+
return opt.stop && opt.stop();
|
|
192
|
+
}
|
|
193
|
+
this.classList.add("inertia");
|
|
194
|
+
opt.end && opt.end();
|
|
195
|
+
const self = this;
|
|
196
|
+
inertia.timer.restart((e) => {
|
|
197
|
+
inertia.t = limit * (1 - Math.exp(-B * e / A));
|
|
198
|
+
opt.render && opt.render(inertia.t);
|
|
199
|
+
if (inertia.t > 1) {
|
|
200
|
+
inertia.timer.stop();
|
|
201
|
+
self.classList.remove("inertia");
|
|
202
|
+
inertia.velocity = [0, 0];
|
|
203
|
+
inertia.t = 1;
|
|
204
|
+
opt.finish && opt.finish();
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
inertia.timer.stop();
|
|
210
|
+
return inertia;
|
|
211
|
+
}
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region src/util/path.ts
|
|
214
|
+
var positionToRotation = ([lng, lat], tilt = 0) => [
|
|
215
|
+
-lng,
|
|
216
|
+
tilt - lat,
|
|
217
|
+
0
|
|
218
|
+
];
|
|
219
|
+
var geoToPosition = ({ lat, lng }) => [lng, lat];
|
|
220
|
+
var geoPoint = (point) => ({
|
|
221
|
+
type: "Point",
|
|
222
|
+
coordinates: geoToPosition(point)
|
|
223
|
+
});
|
|
224
|
+
var geoCircle = ({ lat, lng }, radius) => geoCircle$1().radius(radius).center([lng, lat])();
|
|
225
|
+
var geoLine = (p1, p2) => ({
|
|
226
|
+
type: "LineString",
|
|
227
|
+
coordinates: [[p1.lng, p1.lat], [p2.lng, p2.lat]]
|
|
228
|
+
});
|
|
229
|
+
var closestPoint = (points, target) => {
|
|
230
|
+
if (points.length === 0) return target;
|
|
231
|
+
let closestPoint = points[0];
|
|
232
|
+
let minDistance = getDistance(points[0], target);
|
|
233
|
+
for (const point of points) {
|
|
234
|
+
const distance = getDistance(point, target);
|
|
235
|
+
if (distance < minDistance) {
|
|
236
|
+
minDistance = distance;
|
|
237
|
+
closestPoint = point;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return closestPoint;
|
|
241
|
+
};
|
|
242
|
+
var getDistance = (point1, point2) => {
|
|
243
|
+
const dx = point1[0] - point2[0];
|
|
244
|
+
const dy = point1[1] - point2[1];
|
|
245
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
246
|
+
};
|
|
247
|
+
//#endregion
|
|
248
|
+
//#region src/util/render.ts
|
|
249
|
+
/**
|
|
250
|
+
* Create rendering layers.
|
|
251
|
+
*/
|
|
252
|
+
var createLayers = (topology, features, styles) => {
|
|
253
|
+
const layers = [];
|
|
254
|
+
if (styles.water) layers.push({
|
|
255
|
+
styles: styles.water,
|
|
256
|
+
path: { type: "Sphere" }
|
|
257
|
+
});
|
|
258
|
+
if (styles.graticule) layers.push({
|
|
259
|
+
styles: styles.graticule,
|
|
260
|
+
path: geoGraticule().step([6, 6])()
|
|
261
|
+
});
|
|
262
|
+
if (topology) {
|
|
263
|
+
if (topology.objects.land && styles.land) layers.push({
|
|
264
|
+
styles: styles.land,
|
|
265
|
+
path: feature(topology, topology.objects.land)
|
|
266
|
+
});
|
|
267
|
+
if (topology.objects.countries && styles.border) layers.push({
|
|
268
|
+
styles: styles.border,
|
|
269
|
+
path: mesh(topology, topology.objects.countries, (a, b) => a !== b)
|
|
270
|
+
});
|
|
271
|
+
if (topology.objects.dots && styles.dots) layers.push({
|
|
272
|
+
styles: styles.dots,
|
|
273
|
+
path: topology.objects.dots
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
if (features) {
|
|
277
|
+
const { points, lines } = features;
|
|
278
|
+
if (points && styles.point) layers.push({
|
|
279
|
+
styles: styles.point,
|
|
280
|
+
path: {
|
|
281
|
+
type: "GeometryCollection",
|
|
282
|
+
geometries: points.map((point) => geoPoint(point))
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
if (lines && styles.line) layers.push({
|
|
286
|
+
styles: styles.line,
|
|
287
|
+
path: {
|
|
288
|
+
type: "GeometryCollection",
|
|
289
|
+
geometries: lines.map(({ source, target }) => geoLine(source, target))
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
return layers;
|
|
294
|
+
};
|
|
295
|
+
/**
|
|
296
|
+
* Render layers created above.
|
|
297
|
+
*/
|
|
298
|
+
var renderLayers = (generator, layers = [], scale, styles) => {
|
|
299
|
+
const context = generator.context();
|
|
300
|
+
const { canvas: { width, height } } = context;
|
|
301
|
+
context.reset();
|
|
302
|
+
if (styles.background) {
|
|
303
|
+
context.fillStyle = styles.background.fillStyle;
|
|
304
|
+
context.fillRect(0, 0, width, height);
|
|
305
|
+
} else context.clearRect(0, 0, width, height);
|
|
306
|
+
layers.forEach(({ path, styles }) => {
|
|
307
|
+
context.save();
|
|
308
|
+
let fill = false;
|
|
309
|
+
let stroke = false;
|
|
310
|
+
if (styles) Object.entries(styles).forEach(([key, value]) => {
|
|
311
|
+
if (key === "pointRadius") generator.pointRadius(value * scale);
|
|
312
|
+
else {
|
|
313
|
+
context[key] = value;
|
|
314
|
+
fill ||= key === "fillStyle";
|
|
315
|
+
stroke ||= key === "strokeStyle";
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
context.beginPath();
|
|
319
|
+
generator(path);
|
|
320
|
+
fill && context.fill();
|
|
321
|
+
stroke && context.stroke();
|
|
322
|
+
context.restore();
|
|
323
|
+
});
|
|
324
|
+
return context;
|
|
325
|
+
};
|
|
326
|
+
//#endregion
|
|
327
|
+
//#region src/hooks/useDrag.ts
|
|
328
|
+
/**
|
|
329
|
+
* Allows user to drag globe.
|
|
330
|
+
*/
|
|
331
|
+
var useDrag = (controller, options = {}) => {
|
|
332
|
+
createEffect(() => {
|
|
333
|
+
const canvas = controller?.canvas;
|
|
334
|
+
if (!canvas || options.disabled) return;
|
|
335
|
+
geoInertiaDrag(select(canvas), () => {
|
|
336
|
+
controller.setRotation(controller.projection.rotate());
|
|
337
|
+
options.onUpdate?.({
|
|
338
|
+
type: "move",
|
|
339
|
+
controller
|
|
340
|
+
});
|
|
341
|
+
}, controller.projection, {
|
|
342
|
+
xAxis: options.xAxis,
|
|
343
|
+
time: 3e3,
|
|
344
|
+
start: () => options.onUpdate?.({
|
|
345
|
+
type: "start",
|
|
346
|
+
controller
|
|
347
|
+
}),
|
|
348
|
+
finish: () => options.onUpdate?.({
|
|
349
|
+
type: "end",
|
|
350
|
+
controller
|
|
351
|
+
})
|
|
352
|
+
});
|
|
353
|
+
onCleanup(() => {
|
|
354
|
+
cancelDrag(select(canvas));
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
};
|
|
358
|
+
var cancelDrag = (node) => node.on(".drag", null);
|
|
359
|
+
//#endregion
|
|
360
|
+
//#region src/hooks/useGlobeZoomHandler.ts
|
|
361
|
+
var ZOOM_FACTOR = .1;
|
|
362
|
+
var useGlobeZoomHandler = (controller) => {
|
|
363
|
+
return (event) => {
|
|
364
|
+
if (!controller) return;
|
|
365
|
+
switch (event) {
|
|
366
|
+
case "zoom-in":
|
|
367
|
+
controller.setZoom((zoom) => {
|
|
368
|
+
return zoom * 1.1;
|
|
369
|
+
});
|
|
370
|
+
break;
|
|
371
|
+
case "zoom-out":
|
|
372
|
+
controller.setZoom((zoom) => {
|
|
373
|
+
return zoom * (1 - ZOOM_FACTOR);
|
|
374
|
+
});
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
};
|
|
379
|
+
//#endregion
|
|
380
|
+
//#region src/hooks/useMapZoomHandler.ts
|
|
381
|
+
var useMapZoomHandler = (controller) => {
|
|
382
|
+
return (event) => {
|
|
383
|
+
if (!controller) return;
|
|
384
|
+
switch (event) {
|
|
385
|
+
case "zoom-in":
|
|
386
|
+
controller.setZoom((scale) => scale + 1);
|
|
387
|
+
break;
|
|
388
|
+
case "zoom-out":
|
|
389
|
+
controller.setZoom((scale) => scale - 1);
|
|
390
|
+
break;
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
};
|
|
394
|
+
//#endregion
|
|
395
|
+
//#region src/hooks/useSpinner.ts
|
|
396
|
+
/**
|
|
397
|
+
* Rotates globe.
|
|
398
|
+
*/
|
|
399
|
+
var useSpinner = (controller, options = {}) => {
|
|
400
|
+
const [running, setRunning] = createSignal(false);
|
|
401
|
+
createEffect(() => {
|
|
402
|
+
let timer;
|
|
403
|
+
const start = () => {
|
|
404
|
+
const delta = options.delta ?? [
|
|
405
|
+
.001,
|
|
406
|
+
0,
|
|
407
|
+
0
|
|
408
|
+
];
|
|
409
|
+
let t = 0;
|
|
410
|
+
let lastRotation = controller.projection.rotate();
|
|
411
|
+
timer = timer$1((elapsed) => {
|
|
412
|
+
const dt = elapsed - t;
|
|
413
|
+
t = elapsed;
|
|
414
|
+
const rotation = [
|
|
415
|
+
lastRotation[0] + delta[0] * dt,
|
|
416
|
+
lastRotation[1] + delta[1] * dt,
|
|
417
|
+
lastRotation[2] + delta[2] * dt
|
|
418
|
+
];
|
|
419
|
+
lastRotation = rotation;
|
|
420
|
+
controller.setRotation(rotation);
|
|
421
|
+
});
|
|
422
|
+
};
|
|
423
|
+
const stop = () => {
|
|
424
|
+
if (timer) {
|
|
425
|
+
timer.stop();
|
|
426
|
+
timer = void 0;
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
if (controller && running()) start();
|
|
430
|
+
else stop();
|
|
431
|
+
onCleanup(() => stop());
|
|
432
|
+
});
|
|
433
|
+
return {
|
|
434
|
+
start: () => {
|
|
435
|
+
if (!options.disabled) setRunning(true);
|
|
436
|
+
},
|
|
437
|
+
stop: () => setRunning(false)
|
|
438
|
+
};
|
|
439
|
+
};
|
|
440
|
+
//#endregion
|
|
441
|
+
//#region src/hooks/useTour.ts
|
|
442
|
+
var TRANSITION_NAME = "globe-tour";
|
|
443
|
+
var defaultDuration = 1500;
|
|
444
|
+
/**
|
|
445
|
+
* Iterates between points.
|
|
446
|
+
* Inspired by: https://observablehq.com/@mbostock/top-100-cities
|
|
447
|
+
*/
|
|
448
|
+
var useTour = (controller, points, options = {}) => {
|
|
449
|
+
const selection$1 = selection();
|
|
450
|
+
const [running, setRunning] = createSignal(options.running ?? false);
|
|
451
|
+
createEffect(() => {
|
|
452
|
+
if (!running()) {
|
|
453
|
+
selection$1.interrupt(TRANSITION_NAME);
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
let t;
|
|
457
|
+
if (controller && running()) {
|
|
458
|
+
t = setTimeout(async () => {
|
|
459
|
+
const { canvas, projection, setRotation } = controller;
|
|
460
|
+
const context = canvas.getContext("2d", { alpha: false });
|
|
461
|
+
const path = geoPath(projection, context).pointRadius(2);
|
|
462
|
+
const tilt = options.tilt ?? 0;
|
|
463
|
+
let last;
|
|
464
|
+
try {
|
|
465
|
+
const p = [...points ?? []];
|
|
466
|
+
if (options.loop) p.push(p[0]);
|
|
467
|
+
for (const next of p) {
|
|
468
|
+
if (!running()) break;
|
|
469
|
+
const p1 = last ? geoToPosition(last) : void 0;
|
|
470
|
+
const p2 = geoToPosition(next);
|
|
471
|
+
const ip = geoInterpolate(p1 || p2, p2);
|
|
472
|
+
const distance = geoDistance(p1 || p2, p2);
|
|
473
|
+
const r1 = p1 ? positionToRotation(p1, tilt) : controller.projection.rotate();
|
|
474
|
+
const r2 = positionToRotation(p2, tilt);
|
|
475
|
+
const iv = versor.interpolate(r1, r2);
|
|
476
|
+
await selection$1.transition(TRANSITION_NAME).duration(Math.max(options.duration ?? defaultDuration, distance * 2e3)).tween("render", () => (t) => {
|
|
477
|
+
const t1 = Math.max(0, Math.min(1, t * 2 - 1));
|
|
478
|
+
const t2 = Math.min(1, t * 2);
|
|
479
|
+
context.save();
|
|
480
|
+
context.beginPath();
|
|
481
|
+
context.strokeStyle = options?.styles?.arc?.strokeStyle ?? "yellow";
|
|
482
|
+
context.lineWidth = (options?.styles?.arc?.lineWidth ?? 1.5) * (controller?.zoom ?? 1);
|
|
483
|
+
context.setLineDash(options?.styles?.arc?.lineDash ?? []);
|
|
484
|
+
path({
|
|
485
|
+
type: "LineString",
|
|
486
|
+
coordinates: [ip(t1), ip(t2)]
|
|
487
|
+
});
|
|
488
|
+
context.stroke();
|
|
489
|
+
context.beginPath();
|
|
490
|
+
context.fillStyle = options?.styles?.cursor?.fillStyle ?? "orange";
|
|
491
|
+
path.pointRadius((options?.styles?.cursor?.pointRadius ?? 2) * (controller?.zoom ?? 1));
|
|
492
|
+
path({
|
|
493
|
+
type: "Point",
|
|
494
|
+
coordinates: ip(t2)
|
|
495
|
+
});
|
|
496
|
+
context.fill();
|
|
497
|
+
context.restore();
|
|
498
|
+
projection.rotate(iv(t));
|
|
499
|
+
setRotation(projection.rotate());
|
|
500
|
+
}).end();
|
|
501
|
+
last = next;
|
|
502
|
+
}
|
|
503
|
+
} catch {} finally {
|
|
504
|
+
setRunning(false);
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
onCleanup(() => {
|
|
508
|
+
clearTimeout(t);
|
|
509
|
+
selection$1.interrupt(TRANSITION_NAME);
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
return {
|
|
514
|
+
running,
|
|
515
|
+
setRunning
|
|
516
|
+
};
|
|
517
|
+
};
|
|
518
|
+
//#endregion
|
|
519
|
+
//#region src/components/Toolbar/Controls.tsx
|
|
520
|
+
var _tmpl$$2 = /*#__PURE__*/ template(`<div><button type=button class="dx-button dx-focus-ring w-10 h-10 min-h-[2.5rem] px-3 rounded-xs flex items-center justify-center"title="Zoom in"><span class=text-xl>+</span></button><button type=button class="dx-button dx-focus-ring w-10 h-10 min-h-[2.5rem] px-3 rounded-xs flex items-center justify-center"title="Zoom out"><span class=text-xl>−`);
|
|
521
|
+
var _tmpl$2$2 = /*#__PURE__*/ template(`<div><button type=button class="dx-button dx-focus-ring w-10 h-10 min-h-[2.5rem] px-3 rounded-xs flex items-center justify-center"title=Start><span class=text-xl>▶</span></button><button type=button class="dx-button dx-focus-ring w-10 h-10 min-h-[2.5rem] px-3 rounded-xs flex items-center justify-center"title=Toggle><span class=text-xl>🌍`);
|
|
522
|
+
var controlPositions = {
|
|
523
|
+
topleft: "top-2 left-2",
|
|
524
|
+
topright: "top-2 right-2",
|
|
525
|
+
bottomleft: "bottom-2 left-2",
|
|
526
|
+
bottomright: "bottom-2 right-2"
|
|
527
|
+
};
|
|
528
|
+
var ZoomControls = (props) => {
|
|
529
|
+
return (() => {
|
|
530
|
+
var _el$ = _tmpl$$2(), _el$2 = _el$.firstChild, _el$3 = _el$2.nextSibling;
|
|
531
|
+
_el$2.$$click = () => props.onAction?.("zoom-in");
|
|
532
|
+
_el$3.$$click = () => props.onAction?.("zoom-out");
|
|
533
|
+
effect(() => className(_el$, `flex flex-row gap-2 ${props.class ?? ""}`));
|
|
534
|
+
return _el$;
|
|
535
|
+
})();
|
|
536
|
+
};
|
|
537
|
+
var ActionControls = (props) => {
|
|
538
|
+
return (() => {
|
|
539
|
+
var _el$4 = _tmpl$2$2(), _el$5 = _el$4.firstChild, _el$6 = _el$5.nextSibling;
|
|
540
|
+
_el$5.$$click = () => props.onAction?.("start");
|
|
541
|
+
_el$6.$$click = () => props.onAction?.("toggle");
|
|
542
|
+
effect(() => className(_el$4, `flex flex-row gap-2 ${props.class ?? ""}`));
|
|
543
|
+
return _el$4;
|
|
544
|
+
})();
|
|
545
|
+
};
|
|
546
|
+
delegateEvents(["click"]);
|
|
547
|
+
//#endregion
|
|
548
|
+
//#region src/components/Globe/Globe.tsx
|
|
549
|
+
var _tmpl$$1 = /*#__PURE__*/ template(`<div>`);
|
|
550
|
+
var _tmpl$2$1 = /*#__PURE__*/ template(`<canvas>`);
|
|
551
|
+
var _tmpl$3 = /*#__PURE__*/ template(`<div><pre class="font-mono text-xs text-green-700">`);
|
|
552
|
+
/**
|
|
553
|
+
* https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute
|
|
554
|
+
*/
|
|
555
|
+
var defaultStyles = {
|
|
556
|
+
light: {
|
|
557
|
+
background: { fillStyle: "#EEE" },
|
|
558
|
+
water: { fillStyle: "#555" },
|
|
559
|
+
land: { fillStyle: "#999" },
|
|
560
|
+
line: { strokeStyle: "darkred" },
|
|
561
|
+
point: {
|
|
562
|
+
fillStyle: "#111111",
|
|
563
|
+
strokeStyle: "#111111",
|
|
564
|
+
strokeWidth: 1,
|
|
565
|
+
pointRadius: .5
|
|
566
|
+
}
|
|
567
|
+
},
|
|
568
|
+
dark: {
|
|
569
|
+
background: { fillStyle: "#111111" },
|
|
570
|
+
water: { fillStyle: "#123E6A" },
|
|
571
|
+
land: { fillStyle: "#032153" },
|
|
572
|
+
line: { strokeStyle: "#111111" },
|
|
573
|
+
point: {
|
|
574
|
+
fillStyle: "#111111",
|
|
575
|
+
strokeStyle: "#111111",
|
|
576
|
+
strokeWidth: 1,
|
|
577
|
+
pointRadius: .5
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
};
|
|
581
|
+
var projectionMap = {
|
|
582
|
+
"orthographic": geoOrthographic,
|
|
583
|
+
"mercator": geoMercator,
|
|
584
|
+
"transverse-mercator": geoTransverseMercator
|
|
585
|
+
};
|
|
586
|
+
var getProjection = (type = "orthographic") => {
|
|
587
|
+
if (typeof type === "string") return (projectionMap[type] ?? geoOrthographic)();
|
|
588
|
+
return type ?? geoOrthographic();
|
|
589
|
+
};
|
|
590
|
+
var GlobeRoot = (props) => {
|
|
591
|
+
let containerRef;
|
|
592
|
+
const [size, setSize] = createSignal({
|
|
593
|
+
width: 0,
|
|
594
|
+
height: 0
|
|
595
|
+
});
|
|
596
|
+
createResizeObserver(() => containerRef, ({ width, height }) => {
|
|
597
|
+
setSize({
|
|
598
|
+
width,
|
|
599
|
+
height
|
|
600
|
+
});
|
|
601
|
+
});
|
|
602
|
+
return createComponent(GlobeContextProvider, mergeProps({ get size() {
|
|
603
|
+
return size();
|
|
604
|
+
} }, props, { get children() {
|
|
605
|
+
var _el$ = _tmpl$$1();
|
|
606
|
+
var _ref$ = containerRef;
|
|
607
|
+
typeof _ref$ === "function" ? use(_ref$, _el$) : containerRef = _el$;
|
|
608
|
+
spread(_el$, mergeProps({ get ["class"]() {
|
|
609
|
+
return mx("relative dx-container");
|
|
610
|
+
} }, props), false, true);
|
|
611
|
+
insert(_el$, () => props.children);
|
|
612
|
+
return _el$;
|
|
613
|
+
} }));
|
|
614
|
+
};
|
|
615
|
+
/**
|
|
616
|
+
* Basic globe renderer.
|
|
617
|
+
* https://github.com/topojson/world-atlas
|
|
618
|
+
*/
|
|
619
|
+
var GlobeCanvas = (props) => {
|
|
620
|
+
const themeMode = "dark";
|
|
621
|
+
const styles = createMemo(() => props.styles ?? defaultStyles[themeMode]);
|
|
622
|
+
const [canvas, setCanvas] = createSignal(null);
|
|
623
|
+
const projection = createMemo(() => getProjection(props.projection));
|
|
624
|
+
const layers = createMemo(() => {
|
|
625
|
+
return timer(() => createLayers(props.topology, props.features, styles()));
|
|
626
|
+
});
|
|
627
|
+
const { size, center, zoom, translation, rotation, setCenter, setZoom, setTranslation, setRotation } = useGlobeContext();
|
|
628
|
+
let zoomValue = zoom();
|
|
629
|
+
let zooming = false;
|
|
630
|
+
createEffect(() => {});
|
|
631
|
+
createEffect(() => {
|
|
632
|
+
const c = center();
|
|
633
|
+
if (c) {
|
|
634
|
+
setZoom(1);
|
|
635
|
+
setRotation(positionToRotation(geoToPosition(c)));
|
|
636
|
+
}
|
|
637
|
+
});
|
|
638
|
+
createEffect(() => {
|
|
639
|
+
const canvasEl = canvas();
|
|
640
|
+
if (canvasEl && props.ref) {
|
|
641
|
+
const controller = {
|
|
642
|
+
canvas: canvasEl,
|
|
643
|
+
projection: projection(),
|
|
644
|
+
get zoom() {
|
|
645
|
+
return zoomValue;
|
|
646
|
+
},
|
|
647
|
+
translation,
|
|
648
|
+
rotation,
|
|
649
|
+
setZoom: (state) => {
|
|
650
|
+
if (typeof state === "function") {
|
|
651
|
+
const is = interpolateNumber(zoomValue, state(zoomValue));
|
|
652
|
+
transition().ease(zooming ? easeLinear : easeSinOut).duration(200).tween("scale", () => (t) => {
|
|
653
|
+
const newZoom = is(t);
|
|
654
|
+
zoomValue = newZoom;
|
|
655
|
+
setZoom(newZoom);
|
|
656
|
+
}).on("end", () => {
|
|
657
|
+
zooming = false;
|
|
658
|
+
});
|
|
659
|
+
} else {
|
|
660
|
+
zoomValue = state;
|
|
661
|
+
setZoom(state);
|
|
662
|
+
}
|
|
663
|
+
},
|
|
664
|
+
setTranslation,
|
|
665
|
+
setRotation
|
|
666
|
+
};
|
|
667
|
+
props.ref(controller);
|
|
668
|
+
}
|
|
669
|
+
});
|
|
670
|
+
const generator = createMemo(() => {
|
|
671
|
+
const canvasEl = canvas();
|
|
672
|
+
const proj = projection();
|
|
673
|
+
return canvasEl && proj && geoPath(proj, canvasEl.getContext("2d", { alpha: false }));
|
|
674
|
+
});
|
|
675
|
+
createEffect(() => {
|
|
676
|
+
const canvasEl = canvas();
|
|
677
|
+
const proj = projection();
|
|
678
|
+
const gen = generator();
|
|
679
|
+
const z = zoom();
|
|
680
|
+
const t = translation();
|
|
681
|
+
const r = rotation();
|
|
682
|
+
const s = size();
|
|
683
|
+
if (canvasEl && proj && gen) timer(() => {
|
|
684
|
+
proj.scale(Math.min(s.width, s.height) / 2 * z).translate([s.width / 2 + (t?.x ?? 0), s.height / 2 + (t?.y ?? 0)]).rotate(r ?? [
|
|
685
|
+
0,
|
|
686
|
+
0,
|
|
687
|
+
0
|
|
688
|
+
]);
|
|
689
|
+
renderLayers(gen, layers(), z, styles());
|
|
690
|
+
});
|
|
691
|
+
});
|
|
692
|
+
return createComponent(Show, {
|
|
693
|
+
get when() {
|
|
694
|
+
return memo(() => size().width > 0)() && size().height > 0;
|
|
695
|
+
},
|
|
696
|
+
get children() {
|
|
697
|
+
var _el$2 = _tmpl$2$1();
|
|
698
|
+
use(setCanvas, _el$2);
|
|
699
|
+
effect((_p$) => {
|
|
700
|
+
var _v$ = size().width, _v$2 = size().height;
|
|
701
|
+
_v$ !== _p$.e && setAttribute(_el$2, "width", _p$.e = _v$);
|
|
702
|
+
_v$2 !== _p$.t && setAttribute(_el$2, "height", _p$.t = _v$2);
|
|
703
|
+
return _p$;
|
|
704
|
+
}, {
|
|
705
|
+
e: void 0,
|
|
706
|
+
t: void 0
|
|
707
|
+
});
|
|
708
|
+
return _el$2;
|
|
709
|
+
}
|
|
710
|
+
});
|
|
711
|
+
};
|
|
712
|
+
var GlobeDebug = (props) => {
|
|
713
|
+
const { size, zoom, translation, rotation } = useGlobeContext();
|
|
714
|
+
return (() => {
|
|
715
|
+
var _el$3 = _tmpl$3(), _el$4 = _el$3.firstChild;
|
|
716
|
+
insert(_el$4, () => JSON.stringify({
|
|
717
|
+
size,
|
|
718
|
+
zoom: zoom(),
|
|
719
|
+
translation: translation(),
|
|
720
|
+
rotation: rotation()
|
|
721
|
+
}, null, 2));
|
|
722
|
+
effect(() => className(_el$3, `z-10 absolute w-96 p-2 overflow-hidden border border-green-700 rounded-sm ${controlPositions[props.position ?? "topleft"]}`));
|
|
723
|
+
return _el$3;
|
|
724
|
+
})();
|
|
725
|
+
};
|
|
726
|
+
var GlobePanel = (props) => {
|
|
727
|
+
return (() => {
|
|
728
|
+
var _el$5 = _tmpl$$1();
|
|
729
|
+
insert(_el$5, () => props.children);
|
|
730
|
+
effect(() => className(_el$5, `z-10 absolute overflow-hidden ${controlPositions[props.position ?? "topleft"]} ${props.class ?? ""}`));
|
|
731
|
+
return _el$5;
|
|
732
|
+
})();
|
|
733
|
+
};
|
|
734
|
+
var CustomControl$1 = (props) => {
|
|
735
|
+
return (() => {
|
|
736
|
+
var _el$6 = _tmpl$$1();
|
|
737
|
+
insert(_el$6, () => props.children);
|
|
738
|
+
effect(() => className(_el$6, `z-10 absolute overflow-hidden ${controlPositions[props.position]}`));
|
|
739
|
+
return _el$6;
|
|
740
|
+
})();
|
|
741
|
+
};
|
|
742
|
+
var GlobeZoom = (props) => createComponent(CustomControl$1, {
|
|
743
|
+
get position() {
|
|
744
|
+
return props.position ?? "bottomleft";
|
|
745
|
+
},
|
|
746
|
+
get children() {
|
|
747
|
+
return createComponent(ZoomControls, { get onAction() {
|
|
748
|
+
return props.onAction;
|
|
749
|
+
} });
|
|
750
|
+
}
|
|
751
|
+
});
|
|
752
|
+
var GlobeAction = (props) => createComponent(CustomControl$1, {
|
|
753
|
+
get position() {
|
|
754
|
+
return props.position ?? "bottomright";
|
|
755
|
+
},
|
|
756
|
+
get children() {
|
|
757
|
+
return createComponent(ActionControls, { get onAction() {
|
|
758
|
+
return props.onAction;
|
|
759
|
+
} });
|
|
760
|
+
}
|
|
761
|
+
});
|
|
762
|
+
var Globe = {
|
|
763
|
+
Root: GlobeRoot,
|
|
764
|
+
Canvas: GlobeCanvas,
|
|
765
|
+
Zoom: GlobeZoom,
|
|
766
|
+
Action: GlobeAction,
|
|
767
|
+
Debug: GlobeDebug,
|
|
768
|
+
Panel: GlobePanel
|
|
769
|
+
};
|
|
770
|
+
//#endregion
|
|
771
|
+
//#region src/components/Map/Map.tsx
|
|
772
|
+
var _tmpl$ = /*#__PURE__*/ template(`<div style=z-index:0>`);
|
|
773
|
+
var _tmpl$2 = /*#__PURE__*/ template(`<div style=display:contents>`);
|
|
774
|
+
var defaults = {
|
|
775
|
+
center: {
|
|
776
|
+
lat: 51,
|
|
777
|
+
lng: 0
|
|
778
|
+
},
|
|
779
|
+
zoom: 4
|
|
780
|
+
};
|
|
781
|
+
var MapContext = createContext();
|
|
782
|
+
var useMapContext = (displayName) => {
|
|
783
|
+
const context = useContext(MapContext);
|
|
784
|
+
if (!context) throw new Error(`${displayName} must be used within Map.Root`);
|
|
785
|
+
return context;
|
|
786
|
+
};
|
|
787
|
+
/**
|
|
788
|
+
* https://leafletjs.com/reference.html#map
|
|
789
|
+
*/
|
|
790
|
+
var MapRoot = (props) => {
|
|
791
|
+
let mapContainer;
|
|
792
|
+
const [map, setMap] = createSignal(null);
|
|
793
|
+
const [attention, setAttention] = createSignal(false);
|
|
794
|
+
onMount(() => {
|
|
795
|
+
if (!mapContainer) return;
|
|
796
|
+
const leafletMap = L.map(mapContainer, {
|
|
797
|
+
center: props.center ?? defaults.center,
|
|
798
|
+
zoom: props.zoom ?? defaults.zoom,
|
|
799
|
+
attributionControl: false,
|
|
800
|
+
zoomControl: false,
|
|
801
|
+
scrollWheelZoom: props.scrollWheelZoom ?? true,
|
|
802
|
+
doubleClickZoom: props.doubleClickZoom ?? true,
|
|
803
|
+
touchZoom: props.touchZoom ?? true
|
|
804
|
+
});
|
|
805
|
+
setMap(leafletMap);
|
|
806
|
+
if (props.ref) props.ref({
|
|
807
|
+
setCenter: (center, zoom) => {
|
|
808
|
+
leafletMap.setView(center, zoom);
|
|
809
|
+
},
|
|
810
|
+
setZoom: (cb) => {
|
|
811
|
+
leafletMap.setZoom(cb(leafletMap.getZoom()));
|
|
812
|
+
}
|
|
813
|
+
});
|
|
814
|
+
onCleanup(() => {
|
|
815
|
+
leafletMap.remove();
|
|
816
|
+
});
|
|
817
|
+
});
|
|
818
|
+
createEffect(() => {
|
|
819
|
+
const leafletMap = map();
|
|
820
|
+
if (!leafletMap) return;
|
|
821
|
+
if (attention()) leafletMap.scrollWheelZoom.enable();
|
|
822
|
+
else leafletMap.scrollWheelZoom.disable();
|
|
823
|
+
});
|
|
824
|
+
return createComponent(MapContext.Provider, {
|
|
825
|
+
get value() {
|
|
826
|
+
return {
|
|
827
|
+
map,
|
|
828
|
+
attention,
|
|
829
|
+
setAttention,
|
|
830
|
+
onChange: props.onChange
|
|
831
|
+
};
|
|
832
|
+
},
|
|
833
|
+
get children() {
|
|
834
|
+
return [(() => {
|
|
835
|
+
var _el$ = _tmpl$();
|
|
836
|
+
var _ref$ = mapContainer;
|
|
837
|
+
typeof _ref$ === "function" ? use(_ref$, _el$) : mapContainer = _el$;
|
|
838
|
+
effect(() => className(_el$, `group relative grid h-full w-full bg-gray-100 dark:bg-gray-900 ${props.class ?? ""}`));
|
|
839
|
+
return _el$;
|
|
840
|
+
})(), createComponent(Show, {
|
|
841
|
+
get when() {
|
|
842
|
+
return map();
|
|
843
|
+
},
|
|
844
|
+
get children() {
|
|
845
|
+
return props.children;
|
|
846
|
+
}
|
|
847
|
+
})];
|
|
848
|
+
}
|
|
849
|
+
});
|
|
850
|
+
};
|
|
851
|
+
var MapTiles = () => {
|
|
852
|
+
const { map, onChange, attention } = useMapContext(MapTiles.name);
|
|
853
|
+
let tileLayer = null;
|
|
854
|
+
createEffect(() => {
|
|
855
|
+
const leafletMap = map();
|
|
856
|
+
if (!leafletMap) return;
|
|
857
|
+
const att = attention();
|
|
858
|
+
tileLayer = L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
|
|
859
|
+
detectRetina: true,
|
|
860
|
+
keepBuffer: 4,
|
|
861
|
+
className: `dark:grayscale dark:invert ${att ? "" : "opacity-80"}`
|
|
862
|
+
});
|
|
863
|
+
tileLayer.addTo(leafletMap);
|
|
864
|
+
leafletMap.on("zoomstart", (ev) => {
|
|
865
|
+
onChange?.({
|
|
866
|
+
center: ev.target.getCenter(),
|
|
867
|
+
zoom: ev.target.getZoom()
|
|
868
|
+
});
|
|
869
|
+
});
|
|
870
|
+
onCleanup(() => {
|
|
871
|
+
if (tileLayer) {
|
|
872
|
+
tileLayer.remove();
|
|
873
|
+
tileLayer = null;
|
|
874
|
+
}
|
|
875
|
+
});
|
|
876
|
+
});
|
|
877
|
+
createEffect(() => {
|
|
878
|
+
const att = attention();
|
|
879
|
+
if (tileLayer) {
|
|
880
|
+
const container = tileLayer.getContainer();
|
|
881
|
+
if (container) container.className = `dark:grayscale dark:invert ${att ? "" : "opacity-80"}`;
|
|
882
|
+
}
|
|
883
|
+
});
|
|
884
|
+
return null;
|
|
885
|
+
};
|
|
886
|
+
var MapMarkers = (props) => {
|
|
887
|
+
const { map } = useMapContext(MapMarkers.name);
|
|
888
|
+
const leafletMarkers = [];
|
|
889
|
+
let lastMarkerIds = /* @__PURE__ */ new Set();
|
|
890
|
+
onCleanup(() => {
|
|
891
|
+
leafletMarkers.forEach((marker) => marker.remove());
|
|
892
|
+
leafletMarkers.length = 0;
|
|
893
|
+
});
|
|
894
|
+
createEffect(() => {
|
|
895
|
+
const leafletMap = map();
|
|
896
|
+
if (!leafletMap) return;
|
|
897
|
+
const markerList = props.markers?.() ?? [];
|
|
898
|
+
const currentIds = new Set(markerList.map((m) => m.id));
|
|
899
|
+
if (currentIds.size === lastMarkerIds.size && [...currentIds].every((id) => lastMarkerIds.has(id)) && leafletMarkers.length > 0) return;
|
|
900
|
+
leafletMarkers.forEach((marker) => marker.remove());
|
|
901
|
+
leafletMarkers.length = 0;
|
|
902
|
+
lastMarkerIds = currentIds;
|
|
903
|
+
if (markerList.length > 0) {
|
|
904
|
+
const bounds = latLngBounds(markerList.map((marker) => marker.location));
|
|
905
|
+
leafletMap.fitBounds(bounds);
|
|
906
|
+
markerList.forEach(({ title, location }) => {
|
|
907
|
+
const marker = L.marker(location, { icon: new L.Icon({
|
|
908
|
+
iconUrl: "https://dxos.network/marker-icon.png",
|
|
909
|
+
iconRetinaUrl: "https://dxos.network/marker-icon-2x.png",
|
|
910
|
+
shadowUrl: "https://dxos.network/marker-shadow.png",
|
|
911
|
+
iconSize: [25, 41],
|
|
912
|
+
iconAnchor: [12, 41],
|
|
913
|
+
popupAnchor: [1, -34],
|
|
914
|
+
shadowSize: [41, 41]
|
|
915
|
+
}) });
|
|
916
|
+
if (title) marker.bindPopup(title);
|
|
917
|
+
marker.addTo(leafletMap);
|
|
918
|
+
leafletMarkers.push(marker);
|
|
919
|
+
});
|
|
920
|
+
} else leafletMap.setView(defaults.center, defaults.zoom);
|
|
921
|
+
});
|
|
922
|
+
return null;
|
|
923
|
+
};
|
|
924
|
+
var CustomControl = (props) => {
|
|
925
|
+
const { map: mapAccessor } = useMapContext(CustomControl.name);
|
|
926
|
+
let controlContainer;
|
|
927
|
+
createEffect(() => {
|
|
928
|
+
const map = mapAccessor();
|
|
929
|
+
if (!map || !controlContainer) return;
|
|
930
|
+
const control = new (L.Control.extend({ onAdd: () => {
|
|
931
|
+
const container = L.DomUtil.create("div", `${controlPositions[props.position]} m-0!`);
|
|
932
|
+
L.DomEvent.disableClickPropagation(container);
|
|
933
|
+
L.DomEvent.disableScrollPropagation(container);
|
|
934
|
+
if (controlContainer) container.appendChild(controlContainer);
|
|
935
|
+
return container;
|
|
936
|
+
} }))({ position: props.position });
|
|
937
|
+
control.addTo(map);
|
|
938
|
+
onCleanup(() => {
|
|
939
|
+
control.remove();
|
|
940
|
+
});
|
|
941
|
+
});
|
|
942
|
+
return (() => {
|
|
943
|
+
var _el$2 = _tmpl$2();
|
|
944
|
+
var _ref$2 = controlContainer;
|
|
945
|
+
typeof _ref$2 === "function" ? use(_ref$2, _el$2) : controlContainer = _el$2;
|
|
946
|
+
insert(_el$2, () => props.children);
|
|
947
|
+
return _el$2;
|
|
948
|
+
})();
|
|
949
|
+
};
|
|
950
|
+
var MapZoom = (props) => createComponent(CustomControl, {
|
|
951
|
+
get position() {
|
|
952
|
+
return props.position ?? "bottomleft";
|
|
953
|
+
},
|
|
954
|
+
get children() {
|
|
955
|
+
return createComponent(ZoomControls, { get onAction() {
|
|
956
|
+
return props.onAction;
|
|
957
|
+
} });
|
|
958
|
+
}
|
|
959
|
+
});
|
|
960
|
+
var MapAction = (props) => createComponent(CustomControl, {
|
|
961
|
+
get position() {
|
|
962
|
+
return props.position ?? "bottomright";
|
|
963
|
+
},
|
|
964
|
+
get children() {
|
|
965
|
+
return createComponent(ActionControls, { get onAction() {
|
|
966
|
+
return props.onAction;
|
|
967
|
+
} });
|
|
968
|
+
}
|
|
969
|
+
});
|
|
970
|
+
var Map = {
|
|
971
|
+
Root: MapRoot,
|
|
972
|
+
Tiles: MapTiles,
|
|
973
|
+
Markers: MapMarkers,
|
|
974
|
+
Zoom: MapZoom,
|
|
975
|
+
Action: MapAction
|
|
976
|
+
};
|
|
977
|
+
//#endregion
|
|
978
|
+
export { ActionControls, Globe, GlobeContextProvider, Map, ZoomControls, closestPoint, controlPositions, createLayers, geoCircle, geoInertiaDrag, geoLine, geoPoint, geoToPosition, getDistance, loadTopology, positionToRotation, renderLayers, restrictAxis, timer, useDrag, useGlobeContext, useGlobeZoomHandler, useMapZoomHandler, useSpinner, useTour };
|
|
979
|
+
|
|
980
|
+
//# sourceMappingURL=index.mjs.map
|