@fusion.dev/helix-map 0.110.5 → 0.111.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.
|
@@ -249,7 +249,12 @@ export interface MapLayerSpec {
|
|
|
249
249
|
points: MapPlace[];
|
|
250
250
|
}
|
|
251
251
|
/**
|
|
252
|
-
* The stretch of the world some places cover, and their middle
|
|
252
|
+
* The stretch of the world some places cover, and their middle, with at least
|
|
253
|
+
* `least` degrees either side where they cover less than that.
|
|
254
|
+
*
|
|
255
|
+
* **No least reach for a cluster that was pressed**, which is framed to come
|
|
256
|
+
* apart: widened to half a kilometer, a cluster of places a street apart was
|
|
257
|
+
* framed as far out as it already was, and pressing it never opened it.
|
|
253
258
|
*
|
|
254
259
|
* **One pass rather than `Math.max(...lats)`**, which spreads every place into
|
|
255
260
|
* an argument list and throws past about 65,000 of them in Safari: a points
|
|
@@ -261,7 +266,7 @@ export interface MapLayerSpec {
|
|
|
261
266
|
* to the globe, and their middle landed at 0. The bounds may run past 180 as
|
|
262
267
|
* a result, which both renderers draw.
|
|
263
268
|
*/
|
|
264
|
-
export declare const reachOf: (places: readonly MapPlace[]) => {
|
|
269
|
+
export declare const reachOf: (places: readonly MapPlace[], least?: number) => {
|
|
265
270
|
bounds: MapBounds;
|
|
266
271
|
middle: MapPlace;
|
|
267
272
|
};
|
|
@@ -27,9 +27,30 @@ const fanOut = (count, spacing) => {
|
|
|
27
27
|
const sameNames = (had, names) => (had?.length ?? 0) === names.length && names.every((name, at) => had?.[at] === name);
|
|
28
28
|
const isMarker = (node) => node?.isMapMarker === true;
|
|
29
29
|
const isPosition = (node) => node?.isMapPosition === true;
|
|
30
|
+
const placeOn = (element, properties) => {
|
|
31
|
+
if (element.place) {
|
|
32
|
+
element.place(properties);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
for (const [name, value] of Object.entries(properties)) {
|
|
36
|
+
if (value === undefined) {
|
|
37
|
+
element.style.removeProperty(name);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
element.style.setProperty(name, value);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const UNPLACED_POSITION = {
|
|
45
|
+
'--_map-position-heading': undefined,
|
|
46
|
+
'--_map-position-pitch': undefined,
|
|
47
|
+
'--_map-position-radius': undefined,
|
|
48
|
+
'--_map-position-x': undefined,
|
|
49
|
+
'--_map-position-y': undefined,
|
|
50
|
+
};
|
|
30
51
|
const METERS_PER_DEGREE = 111_320;
|
|
31
52
|
const LEAST_REACH = 0.005;
|
|
32
|
-
export const reachOf = (places) => {
|
|
53
|
+
export const reachOf = (places, least = 0) => {
|
|
33
54
|
const first = places[0]?.lng ?? 0;
|
|
34
55
|
let north = -90;
|
|
35
56
|
let south = 90;
|
|
@@ -48,11 +69,11 @@ export const reachOf = (places) => {
|
|
|
48
69
|
}
|
|
49
70
|
const count = Math.max(places.length, 1);
|
|
50
71
|
const across = ((lngs / count + 540) % 360) - 180;
|
|
51
|
-
if (north - south <
|
|
52
|
-
north +=
|
|
53
|
-
south -=
|
|
54
|
-
east +=
|
|
55
|
-
west -=
|
|
72
|
+
if (north - south < least && east - west < least) {
|
|
73
|
+
north += least;
|
|
74
|
+
south -= least;
|
|
75
|
+
east += least;
|
|
76
|
+
west -= least;
|
|
56
77
|
}
|
|
57
78
|
return {
|
|
58
79
|
bounds: { northEast: { lat: north, lng: east }, southWest: { lat: south, lng: west } },
|
|
@@ -579,8 +600,10 @@ export const connectMap = (frame, driver, options = {}) => {
|
|
|
579
600
|
if (member.fanned !== true) {
|
|
580
601
|
member.fanned = true;
|
|
581
602
|
}
|
|
582
|
-
member
|
|
583
|
-
|
|
603
|
+
placeOn(member, {
|
|
604
|
+
'--_map-marker-leg': `${Math.hypot(offset.x, offset.y)}px`,
|
|
605
|
+
'--_map-marker-leg-angle': `${Math.atan2(-offset.y, -offset.x)}rad`,
|
|
606
|
+
});
|
|
584
607
|
placing.push({
|
|
585
608
|
at: { x: center.x + offset.x, y: center.y + offset.y },
|
|
586
609
|
marker: member,
|
|
@@ -591,8 +614,7 @@ export const connectMap = (frame, driver, options = {}) => {
|
|
|
591
614
|
for (const marker of markers()) {
|
|
592
615
|
if (!fan.has(marker) && marker.fanned === true) {
|
|
593
616
|
marker.fanned = false;
|
|
594
|
-
marker
|
|
595
|
-
marker.style.removeProperty('--_map-marker-leg-angle');
|
|
617
|
+
placeOn(marker, { '--_map-marker-leg': undefined, '--_map-marker-leg-angle': undefined });
|
|
596
618
|
}
|
|
597
619
|
}
|
|
598
620
|
for (const one of standing) {
|
|
@@ -636,8 +658,7 @@ export const connectMap = (frame, driver, options = {}) => {
|
|
|
636
658
|
}
|
|
637
659
|
placing.push(...hidden.map(({ at, marker, reach }) => ({ at, marker, reach })));
|
|
638
660
|
for (const { at, marker, reach } of placing) {
|
|
639
|
-
marker
|
|
640
|
-
marker.style.setProperty('--_map-marker-y', `${at.y}px`);
|
|
661
|
+
placeOn(marker, { '--_map-marker-x': `${at.x}px`, '--_map-marker-y': `${at.y}px` });
|
|
641
662
|
if (reach !== undefined) {
|
|
642
663
|
const ahead = rtl ? at.x : width - at.x;
|
|
643
664
|
const behind = rtl ? width - at.x : at.x;
|
|
@@ -666,9 +687,7 @@ export const connectMap = (frame, driver, options = {}) => {
|
|
|
666
687
|
continue;
|
|
667
688
|
}
|
|
668
689
|
if (driver.behind?.({ lat: position.lat, lng: position.lng })) {
|
|
669
|
-
|
|
670
|
-
position.style.removeProperty(`--_map-position-${name}`);
|
|
671
|
-
}
|
|
690
|
+
placeOn(position, UNPLACED_POSITION);
|
|
672
691
|
continue;
|
|
673
692
|
}
|
|
674
693
|
const at = project({ lat: position.lat, lng: position.lng });
|
|
@@ -681,11 +700,13 @@ export const connectMap = (frame, driver, options = {}) => {
|
|
|
681
700
|
(METERS_PER_DEGREE * Math.cos((position.lat * Math.PI) / 180)),
|
|
682
701
|
})
|
|
683
702
|
: at;
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
703
|
+
placeOn(position, {
|
|
704
|
+
'--_map-position-heading': `${headingOf({ heading: position.heading, lat: position.lat, lng: position.lng }, at)}deg`,
|
|
705
|
+
'--_map-position-pitch': `${pitch}deg`,
|
|
706
|
+
'--_map-position-radius': `${Math.hypot(edge.x - at.x, edge.y - at.y)}px`,
|
|
707
|
+
'--_map-position-x': `${at.x}px`,
|
|
708
|
+
'--_map-position-y': `${at.y}px`,
|
|
709
|
+
});
|
|
689
710
|
}
|
|
690
711
|
for (const [layer, found] of seen) {
|
|
691
712
|
const walk = found.map(({ place, ...one }) => ({ ...one, ...project(place) }));
|
|
@@ -865,8 +886,12 @@ export const connectMap = (frame, driver, options = {}) => {
|
|
|
865
886
|
frame.removeEventListener('pointerdown', handleFanDown);
|
|
866
887
|
frame.removeEventListener('click', handleFanPress);
|
|
867
888
|
for (const marker of markers()) {
|
|
868
|
-
|
|
869
|
-
|
|
889
|
+
placeOn(marker, {
|
|
890
|
+
'--_map-marker-leg': undefined,
|
|
891
|
+
'--_map-marker-leg-angle': undefined,
|
|
892
|
+
'--_map-marker-x': undefined,
|
|
893
|
+
'--_map-marker-y': undefined,
|
|
894
|
+
});
|
|
870
895
|
if (marker.gatheredBy !== undefined) {
|
|
871
896
|
marker.gatheredBy = undefined;
|
|
872
897
|
}
|
|
@@ -882,16 +907,12 @@ export const connectMap = (frame, driver, options = {}) => {
|
|
|
882
907
|
if (marker.side === 'start') {
|
|
883
908
|
marker.side = 'end';
|
|
884
909
|
}
|
|
885
|
-
marker.style.removeProperty('--_map-marker-leg');
|
|
886
|
-
marker.style.removeProperty('--_map-marker-leg-angle');
|
|
887
910
|
}
|
|
888
911
|
for (const layer of seen.keys()) {
|
|
889
912
|
layer.walk = [];
|
|
890
913
|
}
|
|
891
914
|
for (const position of positions()) {
|
|
892
|
-
|
|
893
|
-
position.style.removeProperty(`--_map-position-${name}`);
|
|
894
|
-
}
|
|
915
|
+
placeOn(position, UNPLACED_POSITION);
|
|
895
916
|
}
|
|
896
917
|
frame.removeEventListener(HelixMapPanEvent.eventName, handlePan);
|
|
897
918
|
frame.removeEventListener(HelixMapZoomEvent.eventName, handleZoom);
|
|
@@ -931,7 +952,7 @@ export const connectMap = (frame, driver, options = {}) => {
|
|
|
931
952
|
if (places.length === 0) {
|
|
932
953
|
return;
|
|
933
954
|
}
|
|
934
|
-
driver.fit(reachOf(places).bounds, options.padding ?? 48, options.animate === false ? null : motionOf(frame, 'travel'));
|
|
955
|
+
driver.fit(reachOf(places, LEAST_REACH).bounds, options.padding ?? 48, options.animate === false ? null : motionOf(frame, 'travel'));
|
|
935
956
|
},
|
|
936
957
|
};
|
|
937
958
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fusion.dev/helix-map",
|
|
3
3
|
"description": "Connects the Helix Map frame to a map renderer: MapLibre, Leaflet, or a driver of your own.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.111.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Ross Sheppard <ross.sheppard@fusion.dev>",
|
|
7
7
|
"repository": {
|
|
@@ -43,14 +43,14 @@
|
|
|
43
43
|
},
|
|
44
44
|
"bugs": "https://github.com/project-fusion/fusion/issues",
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@fusion.dev/helix-core": "0.
|
|
47
|
-
"@fusion.dev/helix-icons": "0.
|
|
46
|
+
"@fusion.dev/helix-core": "0.111.0",
|
|
47
|
+
"@fusion.dev/helix-icons": "0.111.0",
|
|
48
48
|
"@mapbox/vector-tile": "^3.0.0",
|
|
49
49
|
"pbf": "^5.1.2"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@fusion.dev/helix-headless": "0.
|
|
53
|
-
"@fusion.dev/helix-testing": "0.
|
|
52
|
+
"@fusion.dev/helix-headless": "0.111.0",
|
|
53
|
+
"@fusion.dev/helix-testing": "0.111.0",
|
|
54
54
|
"@maplibre/maplibre-gl-style-spec": "^26.4.4",
|
|
55
55
|
"@types/bun": "^1.3.0",
|
|
56
56
|
"@types/leaflet": "^1.9.20",
|