@dxos/solid-ui-geo 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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
|
@@ -1,1217 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
loadTopology
|
|
3
|
-
} from "./chunk-RMZP4JBX.mjs";
|
|
4
|
-
|
|
5
|
-
// src/components/Globe/Globe.tsx
|
|
6
|
-
import { template as _$template2 } from "solid-js/web";
|
|
7
|
-
import { className as _$className2 } from "solid-js/web";
|
|
8
|
-
import { setAttribute as _$setAttribute } from "solid-js/web";
|
|
9
|
-
import { effect as _$effect2 } from "solid-js/web";
|
|
10
|
-
import { memo as _$memo } from "solid-js/web";
|
|
11
|
-
import { createComponent as _$createComponent2 } from "solid-js/web";
|
|
12
|
-
import { insert as _$insert } from "solid-js/web";
|
|
13
|
-
import { use as _$use } from "solid-js/web";
|
|
14
|
-
import { spread as _$spread } from "solid-js/web";
|
|
15
|
-
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
16
|
-
import { createResizeObserver } from "@solid-primitives/resize-observer";
|
|
17
|
-
import { easeLinear, easeSinOut, geoMercator, geoOrthographic, geoPath as geoPath2, geoTransverseMercator, interpolateNumber, transition } from "d3";
|
|
18
|
-
import { Show, createEffect as createEffect5, createMemo, createSignal as createSignal4 } from "solid-js";
|
|
19
|
-
import { mx } from "@dxos/ui-theme";
|
|
20
|
-
|
|
21
|
-
// src/hooks/context.tsx
|
|
22
|
-
import { createComponent as _$createComponent } from "solid-js/web";
|
|
23
|
-
import { createContext, createEffect, createSignal, useContext } from "solid-js";
|
|
24
|
-
import { raise } from "@dxos/debug";
|
|
25
|
-
var defaults = {
|
|
26
|
-
center: {
|
|
27
|
-
lat: 51,
|
|
28
|
-
lng: 0
|
|
29
|
-
},
|
|
30
|
-
zoom: 4
|
|
31
|
-
};
|
|
32
|
-
var GlobeContext = createContext();
|
|
33
|
-
var GlobeContextProvider = (props) => {
|
|
34
|
-
const [size, setSize] = createSignal(props.size ?? {
|
|
35
|
-
width: 0,
|
|
36
|
-
height: 0
|
|
37
|
-
});
|
|
38
|
-
const [center, setCenter] = createSignal(props.center ?? defaults.center);
|
|
39
|
-
const [zoom, setZoom] = createSignal(props.zoom ?? defaults.zoom);
|
|
40
|
-
const [translation, setTranslation] = createSignal(props.translation);
|
|
41
|
-
const [rotation, setRotation] = createSignal(props.rotation);
|
|
42
|
-
createEffect(() => {
|
|
43
|
-
if (props.size) {
|
|
44
|
-
setSize(props.size);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
return _$createComponent(GlobeContext.Provider, {
|
|
48
|
-
value: {
|
|
49
|
-
size,
|
|
50
|
-
center,
|
|
51
|
-
zoom,
|
|
52
|
-
translation,
|
|
53
|
-
rotation,
|
|
54
|
-
setCenter,
|
|
55
|
-
setZoom,
|
|
56
|
-
setTranslation,
|
|
57
|
-
setRotation
|
|
58
|
-
},
|
|
59
|
-
get children() {
|
|
60
|
-
return props.children;
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
};
|
|
64
|
-
var useGlobeContext = () => {
|
|
65
|
-
return useContext(GlobeContext) ?? raise(new Error("Missing GlobeContext"));
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
// src/hooks/useDrag.ts
|
|
69
|
-
import { select as select2 } from "d3";
|
|
70
|
-
import { createEffect as createEffect2, onCleanup } from "solid-js";
|
|
71
|
-
|
|
72
|
-
// src/util/debug.ts
|
|
73
|
-
var debug = false;
|
|
74
|
-
var timer = (cb) => {
|
|
75
|
-
const start = Date.now();
|
|
76
|
-
const data = cb();
|
|
77
|
-
const t = Date.now() - start / 1e3;
|
|
78
|
-
if (debug) {
|
|
79
|
-
console.log({
|
|
80
|
-
t,
|
|
81
|
-
data
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
return data;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
// src/util/inertia.ts
|
|
88
|
-
import { drag, select, timer as timer2 } from "d3";
|
|
89
|
-
import versor from "versor";
|
|
90
|
-
var restrictAxis = (axis) => (original, current) => current.map((d, i) => axis[i] ? d : original[i]);
|
|
91
|
-
var geoInertiaDrag = (target, render, projection, options) => {
|
|
92
|
-
if (!options) {
|
|
93
|
-
options = {};
|
|
94
|
-
}
|
|
95
|
-
if (target.node) {
|
|
96
|
-
target = target.node();
|
|
97
|
-
}
|
|
98
|
-
target = select(target);
|
|
99
|
-
const inertia = geoInertiaDragHelper({
|
|
100
|
-
projection,
|
|
101
|
-
render: (rotation) => {
|
|
102
|
-
projection.rotate(rotation);
|
|
103
|
-
render && render();
|
|
104
|
-
},
|
|
105
|
-
axis: restrictAxis(options.xAxis ? [
|
|
106
|
-
true,
|
|
107
|
-
false,
|
|
108
|
-
false
|
|
109
|
-
] : [
|
|
110
|
-
true,
|
|
111
|
-
true,
|
|
112
|
-
true
|
|
113
|
-
]),
|
|
114
|
-
start: options.start,
|
|
115
|
-
move: options.move,
|
|
116
|
-
end: options.end,
|
|
117
|
-
stop: options.stop,
|
|
118
|
-
finish: options.finish,
|
|
119
|
-
time: options.time,
|
|
120
|
-
hold: options.hold
|
|
121
|
-
});
|
|
122
|
-
target.call(drag().on("start", inertia.start).on("drag", inertia.move).on("end", inertia.end));
|
|
123
|
-
return inertia;
|
|
124
|
-
};
|
|
125
|
-
var geoInertiaDragHelper = (opt) => {
|
|
126
|
-
const projection = opt.projection;
|
|
127
|
-
let v0;
|
|
128
|
-
let r0;
|
|
129
|
-
let q0;
|
|
130
|
-
let v10;
|
|
131
|
-
let v11;
|
|
132
|
-
let q10;
|
|
133
|
-
const inertia = inertiaHelper({
|
|
134
|
-
axis: opt.axis,
|
|
135
|
-
start: () => {
|
|
136
|
-
v0 = versor.cartesian(projection.invert(inertia.position));
|
|
137
|
-
r0 = projection.rotate();
|
|
138
|
-
q0 = versor(r0);
|
|
139
|
-
opt.start && opt.start();
|
|
140
|
-
},
|
|
141
|
-
move: () => {
|
|
142
|
-
const inv = projection.rotate(r0).invert(inertia.position);
|
|
143
|
-
if (isNaN(inv[0])) {
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
const v1 = versor.cartesian(inv);
|
|
147
|
-
const q1 = versor.multiply(q0, versor.delta(v0, v1));
|
|
148
|
-
const r1 = versor.rotation(q1);
|
|
149
|
-
const r2 = opt.axis(r0, r1);
|
|
150
|
-
opt.render(r2);
|
|
151
|
-
opt.move && opt.move();
|
|
152
|
-
},
|
|
153
|
-
end: () => {
|
|
154
|
-
v10 = versor.cartesian(projection.invert(inertia.position.map((d, i) => d - inertia.velocity[i] / 1e3)));
|
|
155
|
-
q10 = versor(projection.rotate());
|
|
156
|
-
v11 = versor.cartesian(projection.invert(inertia.position));
|
|
157
|
-
opt.end && opt.end();
|
|
158
|
-
},
|
|
159
|
-
stop: opt.stop,
|
|
160
|
-
finish: opt.finish,
|
|
161
|
-
render: (t) => {
|
|
162
|
-
const r1 = versor.rotation(versor.multiply(q10, versor.delta(v10, v11, t * 1e3)));
|
|
163
|
-
const r2 = opt.axis(r0, r1);
|
|
164
|
-
opt.render && opt.render(r2);
|
|
165
|
-
},
|
|
166
|
-
time: opt.time
|
|
167
|
-
});
|
|
168
|
-
return inertia;
|
|
169
|
-
};
|
|
170
|
-
function inertiaHelper(opt) {
|
|
171
|
-
const A = opt.time || 5e3;
|
|
172
|
-
const limit = 1.0001;
|
|
173
|
-
const B = -Math.log(1 - 1 / limit);
|
|
174
|
-
const inertia = {
|
|
175
|
-
position: [
|
|
176
|
-
0,
|
|
177
|
-
0
|
|
178
|
-
],
|
|
179
|
-
velocity: [
|
|
180
|
-
0,
|
|
181
|
-
0
|
|
182
|
-
],
|
|
183
|
-
timer: timer2(() => {
|
|
184
|
-
}),
|
|
185
|
-
time: 0,
|
|
186
|
-
t: 0,
|
|
187
|
-
start: function(ev) {
|
|
188
|
-
const position = [
|
|
189
|
-
ev.x,
|
|
190
|
-
ev.y
|
|
191
|
-
];
|
|
192
|
-
inertia.position = position;
|
|
193
|
-
inertia.velocity = [
|
|
194
|
-
0,
|
|
195
|
-
0
|
|
196
|
-
];
|
|
197
|
-
inertia.timer.stop();
|
|
198
|
-
this.classList.remove("inertia");
|
|
199
|
-
this.classList.add("dragging");
|
|
200
|
-
opt.start && opt.start.call(this, position);
|
|
201
|
-
},
|
|
202
|
-
move: function(ev) {
|
|
203
|
-
const position = [
|
|
204
|
-
ev.x,
|
|
205
|
-
ev.y
|
|
206
|
-
];
|
|
207
|
-
const time = performance.now();
|
|
208
|
-
const deltaTime = time - inertia.time;
|
|
209
|
-
const decay = 1 - Math.exp(-deltaTime / 1e3);
|
|
210
|
-
inertia.velocity = inertia.velocity.map((d, i) => {
|
|
211
|
-
const deltaPos = position[i] - inertia.position[i];
|
|
212
|
-
const deltaTime2 = time - inertia.time;
|
|
213
|
-
return 1e3 * (1 - decay) * deltaPos / deltaTime2 + d * decay;
|
|
214
|
-
});
|
|
215
|
-
inertia.velocity = opt.axis([
|
|
216
|
-
0,
|
|
217
|
-
0
|
|
218
|
-
], inertia.velocity);
|
|
219
|
-
inertia.time = time;
|
|
220
|
-
inertia.position = position;
|
|
221
|
-
opt.move && opt.move.call(this, position);
|
|
222
|
-
},
|
|
223
|
-
end: function(ev) {
|
|
224
|
-
this.classList.remove("dragging", "inertia");
|
|
225
|
-
const v = inertia.velocity;
|
|
226
|
-
if (v[0] * v[0] + v[1] * v[1] < 100) {
|
|
227
|
-
inertia.timer.stop();
|
|
228
|
-
return opt.stop && opt.stop();
|
|
229
|
-
}
|
|
230
|
-
const time = performance.now();
|
|
231
|
-
const deltaTime = time - inertia.time;
|
|
232
|
-
if (opt.hold === void 0) {
|
|
233
|
-
opt.hold = 100;
|
|
234
|
-
}
|
|
235
|
-
if (deltaTime >= opt.hold) {
|
|
236
|
-
inertia.timer.stop();
|
|
237
|
-
return opt.stop && opt.stop();
|
|
238
|
-
}
|
|
239
|
-
this.classList.add("inertia");
|
|
240
|
-
opt.end && opt.end();
|
|
241
|
-
const self = this;
|
|
242
|
-
inertia.timer.restart((e) => {
|
|
243
|
-
inertia.t = limit * (1 - Math.exp(-B * e / A));
|
|
244
|
-
opt.render && opt.render(inertia.t);
|
|
245
|
-
if (inertia.t > 1) {
|
|
246
|
-
inertia.timer.stop();
|
|
247
|
-
self.classList.remove("inertia");
|
|
248
|
-
inertia.velocity = [
|
|
249
|
-
0,
|
|
250
|
-
0
|
|
251
|
-
];
|
|
252
|
-
inertia.t = 1;
|
|
253
|
-
opt.finish && opt.finish();
|
|
254
|
-
}
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
inertia.timer.stop();
|
|
259
|
-
return inertia;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
// src/util/path.ts
|
|
263
|
-
import { geoCircle as d3GeoCircle } from "d3";
|
|
264
|
-
var positionToRotation = ([lng, lat], tilt = 0) => [
|
|
265
|
-
-lng,
|
|
266
|
-
tilt - lat,
|
|
267
|
-
0
|
|
268
|
-
];
|
|
269
|
-
var geoToPosition = ({ lat, lng }) => [
|
|
270
|
-
lng,
|
|
271
|
-
lat
|
|
272
|
-
];
|
|
273
|
-
var geoPoint = (point) => ({
|
|
274
|
-
type: "Point",
|
|
275
|
-
coordinates: geoToPosition(point)
|
|
276
|
-
});
|
|
277
|
-
var geoCircle = ({ lat, lng }, radius) => d3GeoCircle().radius(radius).center([
|
|
278
|
-
lng,
|
|
279
|
-
lat
|
|
280
|
-
])();
|
|
281
|
-
var geoLine = (p1, p2) => ({
|
|
282
|
-
type: "LineString",
|
|
283
|
-
coordinates: [
|
|
284
|
-
[
|
|
285
|
-
p1.lng,
|
|
286
|
-
p1.lat
|
|
287
|
-
],
|
|
288
|
-
[
|
|
289
|
-
p2.lng,
|
|
290
|
-
p2.lat
|
|
291
|
-
]
|
|
292
|
-
]
|
|
293
|
-
});
|
|
294
|
-
var closestPoint = (points, target) => {
|
|
295
|
-
if (points.length === 0) {
|
|
296
|
-
return target;
|
|
297
|
-
}
|
|
298
|
-
let closestPoint2 = points[0];
|
|
299
|
-
let minDistance = getDistance(points[0], target);
|
|
300
|
-
for (const point of points) {
|
|
301
|
-
const distance = getDistance(point, target);
|
|
302
|
-
if (distance < minDistance) {
|
|
303
|
-
minDistance = distance;
|
|
304
|
-
closestPoint2 = point;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
return closestPoint2;
|
|
308
|
-
};
|
|
309
|
-
var getDistance = (point1, point2) => {
|
|
310
|
-
const dx = point1[0] - point2[0];
|
|
311
|
-
const dy = point1[1] - point2[1];
|
|
312
|
-
return Math.sqrt(dx * dx + dy * dy);
|
|
313
|
-
};
|
|
314
|
-
|
|
315
|
-
// src/util/render.ts
|
|
316
|
-
import { geoGraticule } from "d3";
|
|
317
|
-
import { feature, mesh } from "topojson-client";
|
|
318
|
-
var createLayers = (topology, features, styles) => {
|
|
319
|
-
const layers = [];
|
|
320
|
-
if (styles.water) {
|
|
321
|
-
layers.push({
|
|
322
|
-
styles: styles.water,
|
|
323
|
-
path: {
|
|
324
|
-
type: "Sphere"
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
if (styles.graticule) {
|
|
329
|
-
layers.push({
|
|
330
|
-
styles: styles.graticule,
|
|
331
|
-
path: geoGraticule().step([
|
|
332
|
-
6,
|
|
333
|
-
6
|
|
334
|
-
])()
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
if (topology) {
|
|
338
|
-
if (topology.objects.land && styles.land) {
|
|
339
|
-
layers.push({
|
|
340
|
-
styles: styles.land,
|
|
341
|
-
path: feature(topology, topology.objects.land)
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
if (topology.objects.countries && styles.border) {
|
|
345
|
-
layers.push({
|
|
346
|
-
styles: styles.border,
|
|
347
|
-
path: mesh(topology, topology.objects.countries, (a, b) => a !== b)
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
if (topology.objects.dots && styles.dots) {
|
|
351
|
-
layers.push({
|
|
352
|
-
styles: styles.dots,
|
|
353
|
-
path: topology.objects.dots
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
if (features) {
|
|
358
|
-
const { points, lines } = features;
|
|
359
|
-
if (points && styles.point) {
|
|
360
|
-
layers.push({
|
|
361
|
-
styles: styles.point,
|
|
362
|
-
path: {
|
|
363
|
-
type: "GeometryCollection",
|
|
364
|
-
geometries: points.map((point) => geoPoint(point))
|
|
365
|
-
}
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
if (lines && styles.line) {
|
|
369
|
-
layers.push({
|
|
370
|
-
styles: styles.line,
|
|
371
|
-
path: {
|
|
372
|
-
type: "GeometryCollection",
|
|
373
|
-
geometries: lines.map(({ source, target }) => geoLine(source, target))
|
|
374
|
-
}
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
return layers;
|
|
379
|
-
};
|
|
380
|
-
var renderLayers = (generator, layers = [], scale, styles) => {
|
|
381
|
-
const context = generator.context();
|
|
382
|
-
const { canvas: { width, height } } = context;
|
|
383
|
-
context.reset();
|
|
384
|
-
if (styles.background) {
|
|
385
|
-
context.fillStyle = styles.background.fillStyle;
|
|
386
|
-
context.fillRect(0, 0, width, height);
|
|
387
|
-
} else {
|
|
388
|
-
context.clearRect(0, 0, width, height);
|
|
389
|
-
}
|
|
390
|
-
layers.forEach(({ path, styles: styles2 }) => {
|
|
391
|
-
context.save();
|
|
392
|
-
let fill = false;
|
|
393
|
-
let stroke = false;
|
|
394
|
-
if (styles2) {
|
|
395
|
-
Object.entries(styles2).forEach(([key, value]) => {
|
|
396
|
-
if (key === "pointRadius") {
|
|
397
|
-
generator.pointRadius(value * scale);
|
|
398
|
-
} else {
|
|
399
|
-
context[key] = value;
|
|
400
|
-
fill ||= key === "fillStyle";
|
|
401
|
-
stroke ||= key === "strokeStyle";
|
|
402
|
-
}
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
|
-
context.beginPath();
|
|
406
|
-
generator(path);
|
|
407
|
-
fill && context.fill();
|
|
408
|
-
stroke && context.stroke();
|
|
409
|
-
context.restore();
|
|
410
|
-
});
|
|
411
|
-
return context;
|
|
412
|
-
};
|
|
413
|
-
|
|
414
|
-
// src/hooks/useDrag.ts
|
|
415
|
-
var useDrag = (controller, options = {}) => {
|
|
416
|
-
createEffect2(() => {
|
|
417
|
-
const canvas = controller?.canvas;
|
|
418
|
-
if (!canvas || options.disabled) {
|
|
419
|
-
return;
|
|
420
|
-
}
|
|
421
|
-
geoInertiaDrag(select2(canvas), () => {
|
|
422
|
-
controller.setRotation(controller.projection.rotate());
|
|
423
|
-
options.onUpdate?.({
|
|
424
|
-
type: "move",
|
|
425
|
-
controller
|
|
426
|
-
});
|
|
427
|
-
}, controller.projection, {
|
|
428
|
-
xAxis: options.xAxis,
|
|
429
|
-
time: 3e3,
|
|
430
|
-
start: () => options.onUpdate?.({
|
|
431
|
-
type: "start",
|
|
432
|
-
controller
|
|
433
|
-
}),
|
|
434
|
-
finish: () => options.onUpdate?.({
|
|
435
|
-
type: "end",
|
|
436
|
-
controller
|
|
437
|
-
})
|
|
438
|
-
});
|
|
439
|
-
onCleanup(() => {
|
|
440
|
-
cancelDrag(select2(canvas));
|
|
441
|
-
});
|
|
442
|
-
});
|
|
443
|
-
};
|
|
444
|
-
var cancelDrag = (node) => node.on(".drag", null);
|
|
445
|
-
|
|
446
|
-
// src/hooks/useGlobeZoomHandler.ts
|
|
447
|
-
var ZOOM_FACTOR = 0.1;
|
|
448
|
-
var useGlobeZoomHandler = (controller) => {
|
|
449
|
-
return (event) => {
|
|
450
|
-
if (!controller) {
|
|
451
|
-
return;
|
|
452
|
-
}
|
|
453
|
-
switch (event) {
|
|
454
|
-
case "zoom-in": {
|
|
455
|
-
controller.setZoom((zoom) => {
|
|
456
|
-
return zoom * (1 + ZOOM_FACTOR);
|
|
457
|
-
});
|
|
458
|
-
break;
|
|
459
|
-
}
|
|
460
|
-
case "zoom-out": {
|
|
461
|
-
controller.setZoom((zoom) => {
|
|
462
|
-
return zoom * (1 - ZOOM_FACTOR);
|
|
463
|
-
});
|
|
464
|
-
break;
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
};
|
|
468
|
-
};
|
|
469
|
-
|
|
470
|
-
// src/hooks/useMapZoomHandler.ts
|
|
471
|
-
var useMapZoomHandler = (controller) => {
|
|
472
|
-
return (event) => {
|
|
473
|
-
if (!controller) {
|
|
474
|
-
return;
|
|
475
|
-
}
|
|
476
|
-
switch (event) {
|
|
477
|
-
case "zoom-in": {
|
|
478
|
-
controller.setZoom((scale) => scale + 1);
|
|
479
|
-
break;
|
|
480
|
-
}
|
|
481
|
-
case "zoom-out": {
|
|
482
|
-
controller.setZoom((scale) => scale - 1);
|
|
483
|
-
break;
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
};
|
|
487
|
-
};
|
|
488
|
-
|
|
489
|
-
// src/hooks/useSpinner.ts
|
|
490
|
-
import { timer as d3Timer } from "d3";
|
|
491
|
-
import { createEffect as createEffect3, createSignal as createSignal2, onCleanup as onCleanup2 } from "solid-js";
|
|
492
|
-
var useSpinner = (controller, options = {}) => {
|
|
493
|
-
const [running, setRunning] = createSignal2(false);
|
|
494
|
-
createEffect3(() => {
|
|
495
|
-
let timer3;
|
|
496
|
-
const start = () => {
|
|
497
|
-
const delta = options.delta ?? [
|
|
498
|
-
1e-3,
|
|
499
|
-
0,
|
|
500
|
-
0
|
|
501
|
-
];
|
|
502
|
-
let t = 0;
|
|
503
|
-
let lastRotation = controller.projection.rotate();
|
|
504
|
-
timer3 = d3Timer((elapsed) => {
|
|
505
|
-
const dt = elapsed - t;
|
|
506
|
-
t = elapsed;
|
|
507
|
-
const rotation = [
|
|
508
|
-
lastRotation[0] + delta[0] * dt,
|
|
509
|
-
lastRotation[1] + delta[1] * dt,
|
|
510
|
-
lastRotation[2] + delta[2] * dt
|
|
511
|
-
];
|
|
512
|
-
lastRotation = rotation;
|
|
513
|
-
controller.setRotation(rotation);
|
|
514
|
-
});
|
|
515
|
-
};
|
|
516
|
-
const stop = () => {
|
|
517
|
-
if (timer3) {
|
|
518
|
-
timer3.stop();
|
|
519
|
-
timer3 = void 0;
|
|
520
|
-
}
|
|
521
|
-
};
|
|
522
|
-
if (controller && running()) {
|
|
523
|
-
start();
|
|
524
|
-
} else {
|
|
525
|
-
stop();
|
|
526
|
-
}
|
|
527
|
-
onCleanup2(() => stop());
|
|
528
|
-
});
|
|
529
|
-
return {
|
|
530
|
-
start: () => {
|
|
531
|
-
if (!options.disabled) {
|
|
532
|
-
setRunning(true);
|
|
533
|
-
}
|
|
534
|
-
},
|
|
535
|
-
stop: () => setRunning(false)
|
|
536
|
-
};
|
|
537
|
-
};
|
|
538
|
-
|
|
539
|
-
// src/hooks/useTour.ts
|
|
540
|
-
import { selection as d3Selection, geoDistance, geoInterpolate, geoPath } from "d3";
|
|
541
|
-
import { createEffect as createEffect4, createSignal as createSignal3, onCleanup as onCleanup3 } from "solid-js";
|
|
542
|
-
import versor2 from "versor";
|
|
543
|
-
var TRANSITION_NAME = "globe-tour";
|
|
544
|
-
var defaultDuration = 1500;
|
|
545
|
-
var useTour = (controller, points, options = {}) => {
|
|
546
|
-
const selection = d3Selection();
|
|
547
|
-
const [running, setRunning] = createSignal3(options.running ?? false);
|
|
548
|
-
createEffect4(() => {
|
|
549
|
-
if (!running()) {
|
|
550
|
-
selection.interrupt(TRANSITION_NAME);
|
|
551
|
-
return;
|
|
552
|
-
}
|
|
553
|
-
let t;
|
|
554
|
-
if (controller && running()) {
|
|
555
|
-
t = setTimeout(async () => {
|
|
556
|
-
const { canvas, projection, setRotation } = controller;
|
|
557
|
-
const context = canvas.getContext("2d", {
|
|
558
|
-
alpha: false
|
|
559
|
-
});
|
|
560
|
-
const path = geoPath(projection, context).pointRadius(2);
|
|
561
|
-
const tilt = options.tilt ?? 0;
|
|
562
|
-
let last;
|
|
563
|
-
try {
|
|
564
|
-
const p = [
|
|
565
|
-
...points ?? []
|
|
566
|
-
];
|
|
567
|
-
if (options.loop) {
|
|
568
|
-
p.push(p[0]);
|
|
569
|
-
}
|
|
570
|
-
for (const next of p) {
|
|
571
|
-
if (!running()) {
|
|
572
|
-
break;
|
|
573
|
-
}
|
|
574
|
-
const p1 = last ? geoToPosition(last) : void 0;
|
|
575
|
-
const p2 = geoToPosition(next);
|
|
576
|
-
const ip = geoInterpolate(p1 || p2, p2);
|
|
577
|
-
const distance = geoDistance(p1 || p2, p2);
|
|
578
|
-
const r1 = p1 ? positionToRotation(p1, tilt) : controller.projection.rotate();
|
|
579
|
-
const r2 = positionToRotation(p2, tilt);
|
|
580
|
-
const iv = versor2.interpolate(r1, r2);
|
|
581
|
-
const transition2 = selection.transition(TRANSITION_NAME).duration(Math.max(options.duration ?? defaultDuration, distance * 2e3)).tween("render", () => (t2) => {
|
|
582
|
-
const t1 = Math.max(0, Math.min(1, t2 * 2 - 1));
|
|
583
|
-
const t22 = Math.min(1, t2 * 2);
|
|
584
|
-
context.save();
|
|
585
|
-
{
|
|
586
|
-
context.beginPath();
|
|
587
|
-
context.strokeStyle = options?.styles?.arc?.strokeStyle ?? "yellow";
|
|
588
|
-
context.lineWidth = (options?.styles?.arc?.lineWidth ?? 1.5) * (controller?.zoom ?? 1);
|
|
589
|
-
context.setLineDash(options?.styles?.arc?.lineDash ?? []);
|
|
590
|
-
path({
|
|
591
|
-
type: "LineString",
|
|
592
|
-
coordinates: [
|
|
593
|
-
ip(t1),
|
|
594
|
-
ip(t22)
|
|
595
|
-
]
|
|
596
|
-
});
|
|
597
|
-
context.stroke();
|
|
598
|
-
context.beginPath();
|
|
599
|
-
context.fillStyle = options?.styles?.cursor?.fillStyle ?? "orange";
|
|
600
|
-
path.pointRadius((options?.styles?.cursor?.pointRadius ?? 2) * (controller?.zoom ?? 1));
|
|
601
|
-
path({
|
|
602
|
-
type: "Point",
|
|
603
|
-
coordinates: ip(t22)
|
|
604
|
-
});
|
|
605
|
-
context.fill();
|
|
606
|
-
}
|
|
607
|
-
context.restore();
|
|
608
|
-
projection.rotate(iv(t2));
|
|
609
|
-
setRotation(projection.rotate());
|
|
610
|
-
});
|
|
611
|
-
await transition2.end();
|
|
612
|
-
last = next;
|
|
613
|
-
}
|
|
614
|
-
} catch {
|
|
615
|
-
} finally {
|
|
616
|
-
setRunning(false);
|
|
617
|
-
}
|
|
618
|
-
});
|
|
619
|
-
onCleanup3(() => {
|
|
620
|
-
clearTimeout(t);
|
|
621
|
-
selection.interrupt(TRANSITION_NAME);
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
});
|
|
625
|
-
return {
|
|
626
|
-
running,
|
|
627
|
-
setRunning
|
|
628
|
-
};
|
|
629
|
-
};
|
|
630
|
-
|
|
631
|
-
// src/components/Toolbar/Controls.tsx
|
|
632
|
-
import { template as _$template } from "solid-js/web";
|
|
633
|
-
import { delegateEvents as _$delegateEvents } from "solid-js/web";
|
|
634
|
-
import { className as _$className } from "solid-js/web";
|
|
635
|
-
import { effect as _$effect } from "solid-js/web";
|
|
636
|
-
var _tmpl$ = /* @__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>\u2212`);
|
|
637
|
-
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=Start><span class=text-xl>\u25B6</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>\u{1F30D}`);
|
|
638
|
-
var controlPositions = {
|
|
639
|
-
topleft: "top-2 left-2",
|
|
640
|
-
topright: "top-2 right-2",
|
|
641
|
-
bottomleft: "bottom-2 left-2",
|
|
642
|
-
bottomright: "bottom-2 right-2"
|
|
643
|
-
};
|
|
644
|
-
var ZoomControls = (props) => {
|
|
645
|
-
return (() => {
|
|
646
|
-
var _el$ = _tmpl$(), _el$2 = _el$.firstChild, _el$3 = _el$2.nextSibling;
|
|
647
|
-
_el$2.$$click = () => props.onAction?.("zoom-in");
|
|
648
|
-
_el$3.$$click = () => props.onAction?.("zoom-out");
|
|
649
|
-
_$effect(() => _$className(_el$, `flex flex-row gap-2 ${props.class ?? ""}`));
|
|
650
|
-
return _el$;
|
|
651
|
-
})();
|
|
652
|
-
};
|
|
653
|
-
var ActionControls = (props) => {
|
|
654
|
-
return (() => {
|
|
655
|
-
var _el$4 = _tmpl$2(), _el$5 = _el$4.firstChild, _el$6 = _el$5.nextSibling;
|
|
656
|
-
_el$5.$$click = () => props.onAction?.("start");
|
|
657
|
-
_el$6.$$click = () => props.onAction?.("toggle");
|
|
658
|
-
_$effect(() => _$className(_el$4, `flex flex-row gap-2 ${props.class ?? ""}`));
|
|
659
|
-
return _el$4;
|
|
660
|
-
})();
|
|
661
|
-
};
|
|
662
|
-
_$delegateEvents(["click"]);
|
|
663
|
-
|
|
664
|
-
// src/components/Globe/Globe.tsx
|
|
665
|
-
var _tmpl$3 = /* @__PURE__ */ _$template2(`<div>`);
|
|
666
|
-
var _tmpl$22 = /* @__PURE__ */ _$template2(`<canvas>`);
|
|
667
|
-
var _tmpl$32 = /* @__PURE__ */ _$template2(`<div><pre class="font-mono text-xs text-green-700">`);
|
|
668
|
-
var defaultStyles = {
|
|
669
|
-
light: {
|
|
670
|
-
background: {
|
|
671
|
-
fillStyle: "#EEE"
|
|
672
|
-
},
|
|
673
|
-
water: {
|
|
674
|
-
fillStyle: "#555"
|
|
675
|
-
},
|
|
676
|
-
land: {
|
|
677
|
-
fillStyle: "#999"
|
|
678
|
-
},
|
|
679
|
-
line: {
|
|
680
|
-
strokeStyle: "darkred"
|
|
681
|
-
},
|
|
682
|
-
point: {
|
|
683
|
-
fillStyle: "#111111",
|
|
684
|
-
strokeStyle: "#111111",
|
|
685
|
-
strokeWidth: 1,
|
|
686
|
-
pointRadius: 0.5
|
|
687
|
-
}
|
|
688
|
-
},
|
|
689
|
-
dark: {
|
|
690
|
-
background: {
|
|
691
|
-
fillStyle: "#111111"
|
|
692
|
-
},
|
|
693
|
-
water: {
|
|
694
|
-
fillStyle: "#123E6A"
|
|
695
|
-
},
|
|
696
|
-
land: {
|
|
697
|
-
fillStyle: "#032153"
|
|
698
|
-
},
|
|
699
|
-
line: {
|
|
700
|
-
strokeStyle: "#111111"
|
|
701
|
-
},
|
|
702
|
-
point: {
|
|
703
|
-
fillStyle: "#111111",
|
|
704
|
-
strokeStyle: "#111111",
|
|
705
|
-
strokeWidth: 1,
|
|
706
|
-
pointRadius: 0.5
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
};
|
|
710
|
-
var projectionMap = {
|
|
711
|
-
"orthographic": geoOrthographic,
|
|
712
|
-
"mercator": geoMercator,
|
|
713
|
-
"transverse-mercator": geoTransverseMercator
|
|
714
|
-
};
|
|
715
|
-
var getProjection = (type = "orthographic") => {
|
|
716
|
-
if (typeof type === "string") {
|
|
717
|
-
const constructor = projectionMap[type] ?? geoOrthographic;
|
|
718
|
-
return constructor();
|
|
719
|
-
}
|
|
720
|
-
return type ?? geoOrthographic();
|
|
721
|
-
};
|
|
722
|
-
var GlobeRoot = (props) => {
|
|
723
|
-
let containerRef;
|
|
724
|
-
const [size, setSize] = createSignal4({
|
|
725
|
-
width: 0,
|
|
726
|
-
height: 0
|
|
727
|
-
});
|
|
728
|
-
createResizeObserver(() => containerRef, ({
|
|
729
|
-
width,
|
|
730
|
-
height
|
|
731
|
-
}) => {
|
|
732
|
-
setSize({
|
|
733
|
-
width,
|
|
734
|
-
height
|
|
735
|
-
});
|
|
736
|
-
});
|
|
737
|
-
return _$createComponent2(GlobeContextProvider, _$mergeProps({
|
|
738
|
-
get size() {
|
|
739
|
-
return size();
|
|
740
|
-
}
|
|
741
|
-
}, props, {
|
|
742
|
-
get children() {
|
|
743
|
-
var _el$ = _tmpl$3();
|
|
744
|
-
var _ref$ = containerRef;
|
|
745
|
-
typeof _ref$ === "function" ? _$use(_ref$, _el$) : containerRef = _el$;
|
|
746
|
-
_$spread(_el$, _$mergeProps({
|
|
747
|
-
get ["class"]() {
|
|
748
|
-
return mx("relative dx-container");
|
|
749
|
-
}
|
|
750
|
-
}, props), false, true);
|
|
751
|
-
_$insert(_el$, () => props.children);
|
|
752
|
-
return _el$;
|
|
753
|
-
}
|
|
754
|
-
}));
|
|
755
|
-
};
|
|
756
|
-
var GlobeCanvas = (props) => {
|
|
757
|
-
const themeMode = "dark";
|
|
758
|
-
const styles = createMemo(() => props.styles ?? defaultStyles[themeMode]);
|
|
759
|
-
const [canvas, setCanvas] = createSignal4(null);
|
|
760
|
-
const projection = createMemo(() => getProjection(props.projection));
|
|
761
|
-
const layers = createMemo(() => {
|
|
762
|
-
return timer(() => createLayers(props.topology, props.features, styles()));
|
|
763
|
-
});
|
|
764
|
-
const {
|
|
765
|
-
size,
|
|
766
|
-
center,
|
|
767
|
-
zoom,
|
|
768
|
-
translation,
|
|
769
|
-
rotation,
|
|
770
|
-
setCenter,
|
|
771
|
-
setZoom,
|
|
772
|
-
setTranslation,
|
|
773
|
-
setRotation
|
|
774
|
-
} = useGlobeContext();
|
|
775
|
-
let zoomValue = zoom();
|
|
776
|
-
let zooming = false;
|
|
777
|
-
createEffect5(() => {
|
|
778
|
-
});
|
|
779
|
-
createEffect5(() => {
|
|
780
|
-
const c = center();
|
|
781
|
-
if (c) {
|
|
782
|
-
setZoom(1);
|
|
783
|
-
setRotation(positionToRotation(geoToPosition(c)));
|
|
784
|
-
}
|
|
785
|
-
});
|
|
786
|
-
createEffect5(() => {
|
|
787
|
-
const canvasEl = canvas();
|
|
788
|
-
if (canvasEl && props.ref) {
|
|
789
|
-
const controller = {
|
|
790
|
-
canvas: canvasEl,
|
|
791
|
-
projection: projection(),
|
|
792
|
-
get zoom() {
|
|
793
|
-
return zoomValue;
|
|
794
|
-
},
|
|
795
|
-
translation,
|
|
796
|
-
rotation,
|
|
797
|
-
setZoom: (state) => {
|
|
798
|
-
if (typeof state === "function") {
|
|
799
|
-
const is = interpolateNumber(zoomValue, state(zoomValue));
|
|
800
|
-
transition().ease(zooming ? easeLinear : easeSinOut).duration(200).tween("scale", () => (t) => {
|
|
801
|
-
const newZoom = is(t);
|
|
802
|
-
zoomValue = newZoom;
|
|
803
|
-
setZoom(newZoom);
|
|
804
|
-
}).on("end", () => {
|
|
805
|
-
zooming = false;
|
|
806
|
-
});
|
|
807
|
-
} else {
|
|
808
|
-
zoomValue = state;
|
|
809
|
-
setZoom(state);
|
|
810
|
-
}
|
|
811
|
-
},
|
|
812
|
-
setTranslation,
|
|
813
|
-
setRotation
|
|
814
|
-
};
|
|
815
|
-
props.ref(controller);
|
|
816
|
-
}
|
|
817
|
-
});
|
|
818
|
-
const generator = createMemo(() => {
|
|
819
|
-
const canvasEl = canvas();
|
|
820
|
-
const proj = projection();
|
|
821
|
-
return canvasEl && proj && geoPath2(proj, canvasEl.getContext("2d", {
|
|
822
|
-
alpha: false
|
|
823
|
-
}));
|
|
824
|
-
});
|
|
825
|
-
createEffect5(() => {
|
|
826
|
-
const canvasEl = canvas();
|
|
827
|
-
const proj = projection();
|
|
828
|
-
const gen = generator();
|
|
829
|
-
const z = zoom();
|
|
830
|
-
const t = translation();
|
|
831
|
-
const r = rotation();
|
|
832
|
-
const s = size();
|
|
833
|
-
if (canvasEl && proj && gen) {
|
|
834
|
-
timer(() => {
|
|
835
|
-
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 ?? [0, 0, 0]);
|
|
836
|
-
renderLayers(gen, layers(), z, styles());
|
|
837
|
-
});
|
|
838
|
-
}
|
|
839
|
-
});
|
|
840
|
-
return _$createComponent2(Show, {
|
|
841
|
-
get when() {
|
|
842
|
-
return _$memo(() => size().width > 0)() && size().height > 0;
|
|
843
|
-
},
|
|
844
|
-
get children() {
|
|
845
|
-
var _el$2 = _tmpl$22();
|
|
846
|
-
_$use(setCanvas, _el$2);
|
|
847
|
-
_$effect2((_p$) => {
|
|
848
|
-
var _v$ = size().width, _v$2 = size().height;
|
|
849
|
-
_v$ !== _p$.e && _$setAttribute(_el$2, "width", _p$.e = _v$);
|
|
850
|
-
_v$2 !== _p$.t && _$setAttribute(_el$2, "height", _p$.t = _v$2);
|
|
851
|
-
return _p$;
|
|
852
|
-
}, {
|
|
853
|
-
e: void 0,
|
|
854
|
-
t: void 0
|
|
855
|
-
});
|
|
856
|
-
return _el$2;
|
|
857
|
-
}
|
|
858
|
-
});
|
|
859
|
-
};
|
|
860
|
-
var GlobeDebug = (props) => {
|
|
861
|
-
const {
|
|
862
|
-
size,
|
|
863
|
-
zoom,
|
|
864
|
-
translation,
|
|
865
|
-
rotation
|
|
866
|
-
} = useGlobeContext();
|
|
867
|
-
return (() => {
|
|
868
|
-
var _el$3 = _tmpl$32(), _el$4 = _el$3.firstChild;
|
|
869
|
-
_$insert(_el$4, () => JSON.stringify({
|
|
870
|
-
size,
|
|
871
|
-
zoom: zoom(),
|
|
872
|
-
translation: translation(),
|
|
873
|
-
rotation: rotation()
|
|
874
|
-
}, null, 2));
|
|
875
|
-
_$effect2(() => _$className2(_el$3, `z-10 absolute w-96 p-2 overflow-hidden border border-green-700 rounded-sm ${controlPositions[props.position ?? "topleft"]}`));
|
|
876
|
-
return _el$3;
|
|
877
|
-
})();
|
|
878
|
-
};
|
|
879
|
-
var GlobePanel = (props) => {
|
|
880
|
-
return (() => {
|
|
881
|
-
var _el$5 = _tmpl$3();
|
|
882
|
-
_$insert(_el$5, () => props.children);
|
|
883
|
-
_$effect2(() => _$className2(_el$5, `z-10 absolute overflow-hidden ${controlPositions[props.position ?? "topleft"]} ${props.class ?? ""}`));
|
|
884
|
-
return _el$5;
|
|
885
|
-
})();
|
|
886
|
-
};
|
|
887
|
-
var CustomControl = (props) => {
|
|
888
|
-
return (() => {
|
|
889
|
-
var _el$6 = _tmpl$3();
|
|
890
|
-
_$insert(_el$6, () => props.children);
|
|
891
|
-
_$effect2(() => _$className2(_el$6, `z-10 absolute overflow-hidden ${controlPositions[props.position]}`));
|
|
892
|
-
return _el$6;
|
|
893
|
-
})();
|
|
894
|
-
};
|
|
895
|
-
var GlobeZoom = (props) => _$createComponent2(CustomControl, {
|
|
896
|
-
get position() {
|
|
897
|
-
return props.position ?? "bottomleft";
|
|
898
|
-
},
|
|
899
|
-
get children() {
|
|
900
|
-
return _$createComponent2(ZoomControls, {
|
|
901
|
-
get onAction() {
|
|
902
|
-
return props.onAction;
|
|
903
|
-
}
|
|
904
|
-
});
|
|
905
|
-
}
|
|
906
|
-
});
|
|
907
|
-
var GlobeAction = (props) => _$createComponent2(CustomControl, {
|
|
908
|
-
get position() {
|
|
909
|
-
return props.position ?? "bottomright";
|
|
910
|
-
},
|
|
911
|
-
get children() {
|
|
912
|
-
return _$createComponent2(ActionControls, {
|
|
913
|
-
get onAction() {
|
|
914
|
-
return props.onAction;
|
|
915
|
-
}
|
|
916
|
-
});
|
|
917
|
-
}
|
|
918
|
-
});
|
|
919
|
-
var Globe = {
|
|
920
|
-
Root: GlobeRoot,
|
|
921
|
-
Canvas: GlobeCanvas,
|
|
922
|
-
Zoom: GlobeZoom,
|
|
923
|
-
Action: GlobeAction,
|
|
924
|
-
Debug: GlobeDebug,
|
|
925
|
-
Panel: GlobePanel
|
|
926
|
-
};
|
|
927
|
-
|
|
928
|
-
// src/components/Map/Map.tsx
|
|
929
|
-
import { template as _$template3 } from "solid-js/web";
|
|
930
|
-
import { memo as _$memo2 } from "solid-js/web";
|
|
931
|
-
import { insert as _$insert2 } from "solid-js/web";
|
|
932
|
-
import { createComponent as _$createComponent3 } from "solid-js/web";
|
|
933
|
-
import { className as _$className3 } from "solid-js/web";
|
|
934
|
-
import { effect as _$effect3 } from "solid-js/web";
|
|
935
|
-
import { use as _$use2 } from "solid-js/web";
|
|
936
|
-
import "leaflet/dist/leaflet.css";
|
|
937
|
-
import L, { latLngBounds } from "leaflet";
|
|
938
|
-
import { Show as Show2, createContext as createContext2, createEffect as createEffect6, createSignal as createSignal5, onCleanup as onCleanup4, onMount, useContext as useContext2 } from "solid-js";
|
|
939
|
-
var _tmpl$4 = /* @__PURE__ */ _$template3(`<div style=z-index:0>`);
|
|
940
|
-
var _tmpl$23 = /* @__PURE__ */ _$template3(`<div style=display:contents>`);
|
|
941
|
-
var defaults2 = {
|
|
942
|
-
center: {
|
|
943
|
-
lat: 51,
|
|
944
|
-
lng: 0
|
|
945
|
-
},
|
|
946
|
-
zoom: 4
|
|
947
|
-
};
|
|
948
|
-
var MapContext = createContext2();
|
|
949
|
-
var useMapContext = (displayName) => {
|
|
950
|
-
const context = useContext2(MapContext);
|
|
951
|
-
if (!context) {
|
|
952
|
-
throw new Error(`${displayName} must be used within Map.Root`);
|
|
953
|
-
}
|
|
954
|
-
return context;
|
|
955
|
-
};
|
|
956
|
-
var MapRoot = (props) => {
|
|
957
|
-
let mapContainer;
|
|
958
|
-
const [map, setMap] = createSignal5(null);
|
|
959
|
-
const [attention, setAttention] = createSignal5(false);
|
|
960
|
-
onMount(() => {
|
|
961
|
-
if (!mapContainer) {
|
|
962
|
-
return;
|
|
963
|
-
}
|
|
964
|
-
const leafletMap = L.map(mapContainer, {
|
|
965
|
-
center: props.center ?? defaults2.center,
|
|
966
|
-
zoom: props.zoom ?? defaults2.zoom,
|
|
967
|
-
attributionControl: false,
|
|
968
|
-
zoomControl: false,
|
|
969
|
-
scrollWheelZoom: props.scrollWheelZoom ?? true,
|
|
970
|
-
doubleClickZoom: props.doubleClickZoom ?? true,
|
|
971
|
-
touchZoom: props.touchZoom ?? true
|
|
972
|
-
});
|
|
973
|
-
setMap(leafletMap);
|
|
974
|
-
if (props.ref) {
|
|
975
|
-
props.ref({
|
|
976
|
-
setCenter: (center, zoom) => {
|
|
977
|
-
leafletMap.setView(center, zoom);
|
|
978
|
-
},
|
|
979
|
-
setZoom: (cb) => {
|
|
980
|
-
leafletMap.setZoom(cb(leafletMap.getZoom()));
|
|
981
|
-
}
|
|
982
|
-
});
|
|
983
|
-
}
|
|
984
|
-
onCleanup4(() => {
|
|
985
|
-
leafletMap.remove();
|
|
986
|
-
});
|
|
987
|
-
});
|
|
988
|
-
createEffect6(() => {
|
|
989
|
-
const leafletMap = map();
|
|
990
|
-
if (!leafletMap) {
|
|
991
|
-
return;
|
|
992
|
-
}
|
|
993
|
-
if (attention()) {
|
|
994
|
-
leafletMap.scrollWheelZoom.enable();
|
|
995
|
-
} else {
|
|
996
|
-
leafletMap.scrollWheelZoom.disable();
|
|
997
|
-
}
|
|
998
|
-
});
|
|
999
|
-
return _$createComponent3(MapContext.Provider, {
|
|
1000
|
-
get value() {
|
|
1001
|
-
return {
|
|
1002
|
-
map,
|
|
1003
|
-
attention,
|
|
1004
|
-
setAttention,
|
|
1005
|
-
onChange: props.onChange
|
|
1006
|
-
};
|
|
1007
|
-
},
|
|
1008
|
-
get children() {
|
|
1009
|
-
return [(() => {
|
|
1010
|
-
var _el$ = _tmpl$4();
|
|
1011
|
-
var _ref$ = mapContainer;
|
|
1012
|
-
typeof _ref$ === "function" ? _$use2(_ref$, _el$) : mapContainer = _el$;
|
|
1013
|
-
_$effect3(() => _$className3(_el$, `group relative grid h-full w-full bg-gray-100 dark:bg-gray-900 ${props.class ?? ""}`));
|
|
1014
|
-
return _el$;
|
|
1015
|
-
})(), _$createComponent3(Show2, {
|
|
1016
|
-
get when() {
|
|
1017
|
-
return map();
|
|
1018
|
-
},
|
|
1019
|
-
get children() {
|
|
1020
|
-
return props.children;
|
|
1021
|
-
}
|
|
1022
|
-
})];
|
|
1023
|
-
}
|
|
1024
|
-
});
|
|
1025
|
-
};
|
|
1026
|
-
var MapTiles = () => {
|
|
1027
|
-
const {
|
|
1028
|
-
map,
|
|
1029
|
-
onChange,
|
|
1030
|
-
attention
|
|
1031
|
-
} = useMapContext(MapTiles.name);
|
|
1032
|
-
let tileLayer = null;
|
|
1033
|
-
createEffect6(() => {
|
|
1034
|
-
const leafletMap = map();
|
|
1035
|
-
if (!leafletMap) {
|
|
1036
|
-
return;
|
|
1037
|
-
}
|
|
1038
|
-
const att = attention();
|
|
1039
|
-
tileLayer = L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
|
|
1040
|
-
detectRetina: true,
|
|
1041
|
-
keepBuffer: 4,
|
|
1042
|
-
className: `dark:grayscale dark:invert ${att ? "" : "opacity-80"}`
|
|
1043
|
-
});
|
|
1044
|
-
tileLayer.addTo(leafletMap);
|
|
1045
|
-
leafletMap.on("zoomstart", (ev) => {
|
|
1046
|
-
onChange?.({
|
|
1047
|
-
center: ev.target.getCenter(),
|
|
1048
|
-
zoom: ev.target.getZoom()
|
|
1049
|
-
});
|
|
1050
|
-
});
|
|
1051
|
-
onCleanup4(() => {
|
|
1052
|
-
if (tileLayer) {
|
|
1053
|
-
tileLayer.remove();
|
|
1054
|
-
tileLayer = null;
|
|
1055
|
-
}
|
|
1056
|
-
});
|
|
1057
|
-
});
|
|
1058
|
-
createEffect6(() => {
|
|
1059
|
-
const att = attention();
|
|
1060
|
-
if (tileLayer) {
|
|
1061
|
-
const container = tileLayer.getContainer();
|
|
1062
|
-
if (container) {
|
|
1063
|
-
container.className = `dark:grayscale dark:invert ${att ? "" : "opacity-80"}`;
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
});
|
|
1067
|
-
return null;
|
|
1068
|
-
};
|
|
1069
|
-
var MapMarkers = (props) => {
|
|
1070
|
-
const {
|
|
1071
|
-
map
|
|
1072
|
-
} = useMapContext(MapMarkers.name);
|
|
1073
|
-
const leafletMarkers = [];
|
|
1074
|
-
let lastMarkerIds = /* @__PURE__ */ new Set();
|
|
1075
|
-
onCleanup4(() => {
|
|
1076
|
-
leafletMarkers.forEach((marker) => marker.remove());
|
|
1077
|
-
leafletMarkers.length = 0;
|
|
1078
|
-
});
|
|
1079
|
-
createEffect6(() => {
|
|
1080
|
-
const leafletMap = map();
|
|
1081
|
-
if (!leafletMap) {
|
|
1082
|
-
return;
|
|
1083
|
-
}
|
|
1084
|
-
const markerList = props.markers?.() ?? [];
|
|
1085
|
-
const currentIds = new Set(markerList.map((m) => m.id));
|
|
1086
|
-
if (currentIds.size === lastMarkerIds.size && [...currentIds].every((id) => lastMarkerIds.has(id)) && leafletMarkers.length > 0) {
|
|
1087
|
-
return;
|
|
1088
|
-
}
|
|
1089
|
-
leafletMarkers.forEach((marker) => marker.remove());
|
|
1090
|
-
leafletMarkers.length = 0;
|
|
1091
|
-
lastMarkerIds = currentIds;
|
|
1092
|
-
if (markerList.length > 0) {
|
|
1093
|
-
const bounds = latLngBounds(markerList.map((marker) => marker.location));
|
|
1094
|
-
leafletMap.fitBounds(bounds);
|
|
1095
|
-
markerList.forEach(({
|
|
1096
|
-
title,
|
|
1097
|
-
location
|
|
1098
|
-
}) => {
|
|
1099
|
-
const marker = L.marker(location, {
|
|
1100
|
-
icon: new L.Icon({
|
|
1101
|
-
iconUrl: "https://dxos.network/marker-icon.png",
|
|
1102
|
-
iconRetinaUrl: "https://dxos.network/marker-icon-2x.png",
|
|
1103
|
-
shadowUrl: "https://dxos.network/marker-shadow.png",
|
|
1104
|
-
iconSize: [25, 41],
|
|
1105
|
-
iconAnchor: [12, 41],
|
|
1106
|
-
popupAnchor: [1, -34],
|
|
1107
|
-
shadowSize: [41, 41]
|
|
1108
|
-
})
|
|
1109
|
-
});
|
|
1110
|
-
if (title) {
|
|
1111
|
-
marker.bindPopup(title);
|
|
1112
|
-
}
|
|
1113
|
-
marker.addTo(leafletMap);
|
|
1114
|
-
leafletMarkers.push(marker);
|
|
1115
|
-
});
|
|
1116
|
-
} else {
|
|
1117
|
-
leafletMap.setView(defaults2.center, defaults2.zoom);
|
|
1118
|
-
}
|
|
1119
|
-
});
|
|
1120
|
-
return null;
|
|
1121
|
-
};
|
|
1122
|
-
var CustomControl2 = (props) => {
|
|
1123
|
-
const {
|
|
1124
|
-
map: mapAccessor
|
|
1125
|
-
} = useMapContext(CustomControl2.name);
|
|
1126
|
-
let controlContainer;
|
|
1127
|
-
createEffect6(() => {
|
|
1128
|
-
const map = mapAccessor();
|
|
1129
|
-
if (!map || !controlContainer) {
|
|
1130
|
-
return;
|
|
1131
|
-
}
|
|
1132
|
-
const Control = L.Control.extend({
|
|
1133
|
-
onAdd: () => {
|
|
1134
|
-
const container = L.DomUtil.create("div", `${controlPositions[props.position]} m-0!`);
|
|
1135
|
-
L.DomEvent.disableClickPropagation(container);
|
|
1136
|
-
L.DomEvent.disableScrollPropagation(container);
|
|
1137
|
-
if (controlContainer) {
|
|
1138
|
-
container.appendChild(controlContainer);
|
|
1139
|
-
}
|
|
1140
|
-
return container;
|
|
1141
|
-
}
|
|
1142
|
-
});
|
|
1143
|
-
const control = new Control({
|
|
1144
|
-
position: props.position
|
|
1145
|
-
});
|
|
1146
|
-
control.addTo(map);
|
|
1147
|
-
onCleanup4(() => {
|
|
1148
|
-
control.remove();
|
|
1149
|
-
});
|
|
1150
|
-
});
|
|
1151
|
-
return (() => {
|
|
1152
|
-
var _el$2 = _tmpl$23();
|
|
1153
|
-
var _ref$2 = controlContainer;
|
|
1154
|
-
typeof _ref$2 === "function" ? _$use2(_ref$2, _el$2) : controlContainer = _el$2;
|
|
1155
|
-
_$insert2(_el$2, () => props.children);
|
|
1156
|
-
return _el$2;
|
|
1157
|
-
})();
|
|
1158
|
-
};
|
|
1159
|
-
var MapZoom = (props) => _$createComponent3(CustomControl2, {
|
|
1160
|
-
get position() {
|
|
1161
|
-
return props.position ?? "bottomleft";
|
|
1162
|
-
},
|
|
1163
|
-
get children() {
|
|
1164
|
-
return _$createComponent3(ZoomControls, {
|
|
1165
|
-
get onAction() {
|
|
1166
|
-
return props.onAction;
|
|
1167
|
-
}
|
|
1168
|
-
});
|
|
1169
|
-
}
|
|
1170
|
-
});
|
|
1171
|
-
var MapAction = (props) => _$createComponent3(CustomControl2, {
|
|
1172
|
-
get position() {
|
|
1173
|
-
return props.position ?? "bottomright";
|
|
1174
|
-
},
|
|
1175
|
-
get children() {
|
|
1176
|
-
return _$createComponent3(ActionControls, {
|
|
1177
|
-
get onAction() {
|
|
1178
|
-
return props.onAction;
|
|
1179
|
-
}
|
|
1180
|
-
});
|
|
1181
|
-
}
|
|
1182
|
-
});
|
|
1183
|
-
var Map = {
|
|
1184
|
-
Root: MapRoot,
|
|
1185
|
-
Tiles: MapTiles,
|
|
1186
|
-
Markers: MapMarkers,
|
|
1187
|
-
Zoom: MapZoom,
|
|
1188
|
-
Action: MapAction
|
|
1189
|
-
};
|
|
1190
|
-
export {
|
|
1191
|
-
ActionControls,
|
|
1192
|
-
Globe,
|
|
1193
|
-
GlobeContextProvider,
|
|
1194
|
-
Map,
|
|
1195
|
-
ZoomControls,
|
|
1196
|
-
closestPoint,
|
|
1197
|
-
controlPositions,
|
|
1198
|
-
createLayers,
|
|
1199
|
-
geoCircle,
|
|
1200
|
-
geoInertiaDrag,
|
|
1201
|
-
geoLine,
|
|
1202
|
-
geoPoint,
|
|
1203
|
-
geoToPosition,
|
|
1204
|
-
getDistance,
|
|
1205
|
-
loadTopology,
|
|
1206
|
-
positionToRotation,
|
|
1207
|
-
renderLayers,
|
|
1208
|
-
restrictAxis,
|
|
1209
|
-
timer,
|
|
1210
|
-
useDrag,
|
|
1211
|
-
useGlobeContext,
|
|
1212
|
-
useGlobeZoomHandler,
|
|
1213
|
-
useMapZoomHandler,
|
|
1214
|
-
useSpinner,
|
|
1215
|
-
useTour
|
|
1216
|
-
};
|
|
1217
|
-
//# sourceMappingURL=index.mjs.map
|