@fusion.dev/helix-map 0.110.4 → 0.110.6

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.
@@ -27,6 +27,27 @@ 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
53
  export const reachOf = (places) => {
@@ -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.style.setProperty('--_map-marker-leg', `${Math.hypot(offset.x, offset.y)}px`);
583
- member.style.setProperty('--_map-marker-leg-angle', `${Math.atan2(-offset.y, -offset.x)}rad`);
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.style.removeProperty('--_map-marker-leg');
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.style.setProperty('--_map-marker-x', `${at.x}px`);
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
- for (const name of ['heading', 'pitch', 'radius', 'x', 'y']) {
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
- position.style.setProperty('--_map-position-x', `${at.x}px`);
685
- position.style.setProperty('--_map-position-y', `${at.y}px`);
686
- position.style.setProperty('--_map-position-heading', `${headingOf({ heading: position.heading, lat: position.lat, lng: position.lng }, at)}deg`);
687
- position.style.setProperty('--_map-position-radius', `${Math.hypot(edge.x - at.x, edge.y - at.y)}px`);
688
- position.style.setProperty('--_map-position-pitch', `${pitch}deg`);
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
- marker.style.removeProperty('--_map-marker-x');
869
- marker.style.removeProperty('--_map-marker-y');
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
- for (const name of ['heading', 'pitch', 'radius', 'x', 'y']) {
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);
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.110.4",
4
+ "version": "0.110.6",
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.110.4",
47
- "@fusion.dev/helix-icons": "0.110.4",
46
+ "@fusion.dev/helix-core": "0.110.6",
47
+ "@fusion.dev/helix-icons": "0.110.6",
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.110.4",
53
- "@fusion.dev/helix-testing": "0.110.4",
52
+ "@fusion.dev/helix-headless": "0.110.6",
53
+ "@fusion.dev/helix-testing": "0.110.6",
54
54
  "@maplibre/maplibre-gl-style-spec": "^26.4.4",
55
55
  "@types/bun": "^1.3.0",
56
56
  "@types/leaflet": "^1.9.20",