@optimum-intelligence/opti-ui 0.7.3 → 0.7.4

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.
@@ -79,11 +79,13 @@ export type MapView = {
79
79
  };
80
80
  /**
81
81
  * Builds a MapLibre style from a raster tile URL template (`{z}`, `{x}`, `{y}`), for `MapBaseLayer.style`.
82
+ * The style gets a `glyphs` URL (OpenFreeMap's font server by default) so `Map.Points` labels can render;
83
+ * pass your own `glyphs` URL to use another font server.
82
84
  *
83
85
  * @example
84
86
  * const satellite = rasterStyle('https://tiles.example.com/{z}/{x}/{y}.jpg', '© Example');
85
87
  */
86
- export declare function rasterStyle(tiles: string | string[], attribution?: string, tileSize?: number): StyleSpecification;
88
+ export declare function rasterStyle(tiles: string | string[], attribution?: string, tileSize?: number, glyphs?: string): StyleSpecification;
87
89
  export interface MapRootProps extends Omit<MapProps, 'mapStyle' | 'initialViewState' | 'interactiveLayerIds' | 'cursor' | 'locale' | 'style' | 'children' | 'id' | 'attributionControl' | 'workerUrl' | 'mapLib'> {
88
90
  /** Ref to the map instance (`flyTo`, `getMap()`, …), set once the map has loaded MapLibre. */
89
91
  ref?: React.Ref<MapRef>;
@@ -222,6 +224,12 @@ export interface MapPointItem {
222
224
  * when you filter `items`; otherwise colours shift and stop matching the legend.
223
225
  */
224
226
  colorIndex?: number;
227
+ /**
228
+ * Short text drawn in the point, such as a stop number in visiting order. Labelled points are drawn
229
+ * larger so 1–3 digits fit; points without a label render as plain dots. Needs a style with a `glyphs`
230
+ * URL (OpenFreeMap styles and `rasterStyle()` have one).
231
+ */
232
+ label?: string | number;
225
233
  }
226
234
  export interface MapPointsProps {
227
235
  /** Points to draw, all in one GeoJSON source and one circle layer. */
@@ -234,11 +242,20 @@ export interface MapPointsProps {
234
242
  onItemHover?: (item: MapPointItem | null, event: MapLayerMouseEvent) => void;
235
243
  }
236
244
  /**
237
- * Many simple points (sensors, stops, events) as one circle layer. For a few dozen styled pins with HTML
238
- * content, use `Map.Marker` instead.
245
+ * Many simple points (sensors, stops, events) as one circle layer. Items with a `label` get it drawn in
246
+ * the circle by a symbol layer on the same source, so thousands of numbered stops stay fast. For a few
247
+ * dozen styled pins with HTML content, use `Map.Marker` instead.
239
248
  *
240
249
  * @example
241
250
  * <Map.Points items={sensors.map((s) => ({ id: s.id, coordinates: s.position, tone: s.ok ? 'success' : 'danger' }))} />
251
+ *
252
+ * @example
253
+ * // Stops numbered in visiting order, one colour per truck.
254
+ * <Map.Points
255
+ * items={trucks.flatMap((truck, t) =>
256
+ * truck.stops.map((stop, i) => ({ id: stop.id, coordinates: stop.position, colorIndex: t, label: i + 1 })),
257
+ * )}
258
+ * />
242
259
  */
243
260
  declare function MapPoints({ items, selectedIds, onItemClick, onItemHover }: MapPointsProps): React.JSX.Element;
244
261
  export interface MapMarkerProps {
@@ -44,15 +44,22 @@ function useMapContext(part) {
44
44
  if (!ctx) throw new Error(`${part} must be used inside Map.Root`);
45
45
  return ctx;
46
46
  }
47
+ /** Glyph server for text labels (`Map.Points` `label`); OpenFreeMap's serves `Noto Sans Bold`. */
48
+ var DEFAULT_GLYPHS = "https://tiles.openfreemap.org/fonts/{fontstack}/{range}.pbf";
49
+ /** Font stack of `Map.Points` labels. Glyph servers without it make MapLibre draw the digits with a local font. */
50
+ var LABEL_FONT = ["Noto Sans Bold"];
47
51
  /**
48
52
  * Builds a MapLibre style from a raster tile URL template (`{z}`, `{x}`, `{y}`), for `MapBaseLayer.style`.
53
+ * The style gets a `glyphs` URL (OpenFreeMap's font server by default) so `Map.Points` labels can render;
54
+ * pass your own `glyphs` URL to use another font server.
49
55
  *
50
56
  * @example
51
57
  * const satellite = rasterStyle('https://tiles.example.com/{z}/{x}/{y}.jpg', '© Example');
52
58
  */
53
- function rasterStyle(tiles, attribution, tileSize = 256) {
59
+ function rasterStyle(tiles, attribution, tileSize = 256, glyphs = DEFAULT_GLYPHS) {
54
60
  return {
55
61
  version: 8,
62
+ glyphs,
56
63
  sources: { raster: {
57
64
  type: "raster",
58
65
  tiles: Array.isArray(tiles) ? tiles : [tiles],
@@ -1375,25 +1382,36 @@ function _temp11(item) {
1375
1382
  return item.geometry.coordinates;
1376
1383
  }
1377
1384
  /**
1378
- * Many simple points (sensors, stops, events) as one circle layer. For a few dozen styled pins with HTML
1379
- * content, use `Map.Marker` instead.
1385
+ * Many simple points (sensors, stops, events) as one circle layer. Items with a `label` get it drawn in
1386
+ * the circle by a symbol layer on the same source, so thousands of numbered stops stay fast. For a few
1387
+ * dozen styled pins with HTML content, use `Map.Marker` instead.
1380
1388
  *
1381
1389
  * @example
1382
1390
  * <Map.Points items={sensors.map((s) => ({ id: s.id, coordinates: s.position, tone: s.ok ? 'success' : 'danger' }))} />
1391
+ *
1392
+ * @example
1393
+ * // Stops numbered in visiting order, one colour per truck.
1394
+ * <Map.Points
1395
+ * items={trucks.flatMap((truck, t) =>
1396
+ * truck.stops.map((stop, i) => ({ id: stop.id, coordinates: stop.position, colorIndex: t, label: i + 1 })),
1397
+ * )}
1398
+ * />
1383
1399
  */
1384
1400
  function MapPoints(t0) {
1385
- const $ = c(34);
1401
+ const $ = c(43);
1386
1402
  const { items, selectedIds, onItemClick, onItemHover } = t0;
1387
1403
  const sourceId = usePartId("points");
1388
1404
  const circleId = `${sourceId}-circle`;
1405
+ const labelId = `${sourceId}-label`;
1389
1406
  let t1;
1390
- if ($[0] !== circleId) {
1391
- t1 = [circleId];
1407
+ if ($[0] !== circleId || $[1] !== labelId) {
1408
+ t1 = [circleId, labelId];
1392
1409
  $[0] = circleId;
1393
- $[1] = t1;
1394
- } else t1 = $[1];
1410
+ $[1] = labelId;
1411
+ $[2] = t1;
1412
+ } else t1 = $[2];
1395
1413
  let t2;
1396
- if ($[2] !== items || $[3] !== onItemClick || $[4] !== onItemHover || $[5] !== selectedIds || $[6] !== t1) {
1414
+ if ($[3] !== items || $[4] !== onItemClick || $[5] !== onItemHover || $[6] !== selectedIds || $[7] !== t1) {
1397
1415
  t2 = {
1398
1416
  items,
1399
1417
  selectedIds,
@@ -1402,119 +1420,178 @@ function MapPoints(t0) {
1402
1420
  onItemClick,
1403
1421
  onItemHover
1404
1422
  };
1405
- $[2] = items;
1406
- $[3] = onItemClick;
1407
- $[4] = onItemHover;
1408
- $[5] = selectedIds;
1409
- $[6] = t1;
1410
- $[7] = t2;
1411
- } else t2 = $[7];
1423
+ $[3] = items;
1424
+ $[4] = onItemClick;
1425
+ $[5] = onItemHover;
1426
+ $[6] = selectedIds;
1427
+ $[7] = t1;
1428
+ $[8] = t2;
1429
+ } else t2 = $[8];
1412
1430
  const { colors, hasSelection, valid } = useDataPart("Map.Points", sourceId, t2);
1431
+ let data;
1432
+ let opacity;
1413
1433
  let t3;
1414
- if ($[8] !== colors || $[9] !== items || $[10] !== valid) {
1434
+ if ($[9] !== colors || $[10] !== hasSelection || $[11] !== items || $[12] !== valid) {
1415
1435
  let t4;
1416
- if ($[12] !== colors || $[13] !== valid) {
1436
+ if ($[16] !== colors || $[17] !== valid) {
1417
1437
  t4 = (item_0, index) => valid.has(item_0) ? [{
1418
1438
  type: "Feature",
1419
1439
  properties: {
1420
1440
  id: item_0.id,
1421
- color: colors.color(item_0.color ?? (item_0.tone ? toneColors[item_0.tone].solid : seriesColor(item_0.colorIndex ?? index)))
1441
+ color: colors.color(item_0.color ?? (item_0.tone ? toneColors[item_0.tone].solid : seriesColor(item_0.colorIndex ?? index))),
1442
+ ...item_0.label != null && item_0.label !== "" && { label: String(item_0.label) }
1422
1443
  },
1423
1444
  geometry: {
1424
1445
  type: "Point",
1425
1446
  coordinates: item_0.coordinates
1426
1447
  }
1427
1448
  }] : [];
1428
- $[12] = colors;
1429
- $[13] = valid;
1430
- $[14] = t4;
1431
- } else t4 = $[14];
1432
- t3 = items.flatMap(t4);
1433
- $[8] = colors;
1434
- $[9] = items;
1435
- $[10] = valid;
1436
- $[11] = t3;
1437
- } else t3 = $[11];
1438
- let t4;
1439
- if ($[15] !== t3) {
1440
- t4 = {
1449
+ $[16] = colors;
1450
+ $[17] = valid;
1451
+ $[18] = t4;
1452
+ } else t4 = $[18];
1453
+ data = {
1441
1454
  type: "FeatureCollection",
1442
- features: t3
1455
+ features: items.flatMap(t4)
1443
1456
  };
1457
+ let t5;
1458
+ if ($[19] !== colors || $[20] !== hasSelection) {
1459
+ t5 = dimmed(hasSelection, colors.number("--oui-map-dim-opacity", .35));
1460
+ $[19] = colors;
1461
+ $[20] = hasSelection;
1462
+ $[21] = t5;
1463
+ } else t5 = $[21];
1464
+ opacity = t5;
1465
+ t3 = data.features.some(_temp13);
1466
+ $[9] = colors;
1467
+ $[10] = hasSelection;
1468
+ $[11] = items;
1469
+ $[12] = valid;
1470
+ $[13] = data;
1471
+ $[14] = opacity;
1444
1472
  $[15] = t3;
1445
- $[16] = t4;
1446
- } else t4 = $[16];
1447
- const data = t4;
1448
- let t5;
1449
- if ($[17] !== colors || $[18] !== hasSelection) {
1450
- t5 = dimmed(hasSelection, colors.number("--oui-map-dim-opacity", .35));
1451
- $[17] = colors;
1452
- $[18] = hasSelection;
1453
- $[19] = t5;
1454
- } else t5 = $[19];
1455
- const opacity = t5;
1456
- let t6;
1457
- let t7;
1458
- if ($[20] === Symbol.for("react.memo_cache_sentinel")) {
1459
- t6 = ["get", "color"];
1460
- t7 = [
1473
+ } else {
1474
+ data = $[13];
1475
+ opacity = $[14];
1476
+ t3 = $[15];
1477
+ }
1478
+ const hasLabels = t3;
1479
+ let t4;
1480
+ if ($[22] === Symbol.for("react.memo_cache_sentinel")) {
1481
+ t4 = [
1461
1482
  "case",
1462
1483
  ACTIVE,
1463
- 7,
1464
- 5
1484
+ 2,
1485
+ 0
1465
1486
  ];
1466
- $[20] = t6;
1467
- $[21] = t7;
1468
- } else {
1469
- t6 = $[20];
1470
- t7 = $[21];
1471
- }
1487
+ $[22] = t4;
1488
+ } else t4 = $[22];
1489
+ let t5;
1490
+ if ($[23] === Symbol.for("react.memo_cache_sentinel")) {
1491
+ t5 = ["has", "label"];
1492
+ $[23] = t5;
1493
+ } else t5 = $[23];
1494
+ let t6;
1495
+ if ($[24] === Symbol.for("react.memo_cache_sentinel")) {
1496
+ t6 = [
1497
+ "+",
1498
+ t4,
1499
+ [
1500
+ "case",
1501
+ t5,
1502
+ [
1503
+ "step",
1504
+ ["length", ["get", "label"]],
1505
+ 9,
1506
+ 3,
1507
+ 11
1508
+ ],
1509
+ 5
1510
+ ]
1511
+ ];
1512
+ $[24] = t6;
1513
+ } else t6 = $[24];
1514
+ const radius = t6;
1515
+ let t7;
1516
+ if ($[25] === Symbol.for("react.memo_cache_sentinel")) {
1517
+ t7 = ["get", "color"];
1518
+ $[25] = t7;
1519
+ } else t7 = $[25];
1472
1520
  let t8;
1473
- if ($[22] !== colors) {
1521
+ if ($[26] !== colors) {
1474
1522
  t8 = colors.color("var(--oui-map-casing-color)");
1475
- $[22] = colors;
1476
- $[23] = t8;
1477
- } else t8 = $[23];
1523
+ $[26] = colors;
1524
+ $[27] = t8;
1525
+ } else t8 = $[27];
1478
1526
  let t9;
1479
- if ($[24] !== opacity || $[25] !== t8) {
1527
+ if ($[28] !== opacity || $[29] !== t8) {
1480
1528
  t9 = {
1481
- "circle-color": t6,
1482
- "circle-radius": t7,
1529
+ "circle-color": t7,
1530
+ "circle-radius": radius,
1483
1531
  "circle-stroke-color": t8,
1484
1532
  "circle-stroke-width": 1.5,
1485
1533
  "circle-opacity": opacity,
1486
1534
  "circle-stroke-opacity": opacity
1487
1535
  };
1488
- $[24] = opacity;
1489
- $[25] = t8;
1490
- $[26] = t9;
1491
- } else t9 = $[26];
1536
+ $[28] = opacity;
1537
+ $[29] = t8;
1538
+ $[30] = t9;
1539
+ } else t9 = $[30];
1492
1540
  let t10;
1493
- if ($[27] !== circleId || $[28] !== t9) {
1541
+ if ($[31] !== circleId || $[32] !== t9) {
1494
1542
  t10 = /* @__PURE__ */ jsx(Layer, {
1495
1543
  id: circleId,
1496
1544
  type: "circle",
1497
1545
  paint: t9
1498
1546
  });
1499
- $[27] = circleId;
1500
- $[28] = t9;
1501
- $[29] = t10;
1502
- } else t10 = $[29];
1547
+ $[31] = circleId;
1548
+ $[32] = t9;
1549
+ $[33] = t10;
1550
+ } else t10 = $[33];
1503
1551
  let t11;
1504
- if ($[30] !== data || $[31] !== sourceId || $[32] !== t10) {
1505
- t11 = /* @__PURE__ */ jsx(Source, {
1552
+ if ($[34] !== hasLabels || $[35] !== labelId || $[36] !== opacity) {
1553
+ t11 = hasLabels && /* @__PURE__ */ jsx(Layer, {
1554
+ id: labelId,
1555
+ type: "symbol",
1556
+ filter: ["has", "label"],
1557
+ layout: {
1558
+ "text-field": ["get", "label"],
1559
+ "text-font": LABEL_FONT,
1560
+ "text-size": 10,
1561
+ "text-allow-overlap": true,
1562
+ "text-ignore-placement": true
1563
+ },
1564
+ paint: {
1565
+ "text-color": "#ffffff",
1566
+ "text-halo-color": "rgba(0, 0, 0, 0.55)",
1567
+ "text-halo-width": 1,
1568
+ "text-opacity": opacity
1569
+ }
1570
+ });
1571
+ $[34] = hasLabels;
1572
+ $[35] = labelId;
1573
+ $[36] = opacity;
1574
+ $[37] = t11;
1575
+ } else t11 = $[37];
1576
+ let t12;
1577
+ if ($[38] !== data || $[39] !== sourceId || $[40] !== t10 || $[41] !== t11) {
1578
+ t12 = /* @__PURE__ */ jsxs(Source, {
1506
1579
  id: sourceId,
1507
1580
  type: "geojson",
1508
1581
  data,
1509
1582
  promoteId: "id",
1510
- children: t10
1583
+ children: [t10, t11]
1511
1584
  });
1512
- $[30] = data;
1513
- $[31] = sourceId;
1514
- $[32] = t10;
1515
- $[33] = t11;
1516
- } else t11 = $[33];
1517
- return t11;
1585
+ $[38] = data;
1586
+ $[39] = sourceId;
1587
+ $[40] = t10;
1588
+ $[41] = t11;
1589
+ $[42] = t12;
1590
+ } else t12 = $[42];
1591
+ return t12;
1592
+ }
1593
+ function _temp13(feature) {
1594
+ return "label" in feature.properties;
1518
1595
  }
1519
1596
  function _temp12(item) {
1520
1597
  return item.coordinates;
@@ -1859,7 +1936,7 @@ function MapLegend(t0) {
1859
1936
  const labels = React.use(MapContext)?.labels ?? defaultLabels;
1860
1937
  let t6;
1861
1938
  if ($[13] !== items) {
1862
- t6 = items.every(_temp13);
1939
+ t6 = items.every(_temp14);
1863
1940
  $[13] = items;
1864
1941
  $[14] = t6;
1865
1942
  } else t6 = $[14];
@@ -1888,7 +1965,7 @@ function MapLegend(t0) {
1888
1965
  t9 = onVisibilityChange && showAllToggle && /* @__PURE__ */ jsx("button", {
1889
1966
  type: "button",
1890
1967
  className: "oui-map-legend__toggle-all",
1891
- onClick: () => onVisibilityChange(items.map(_temp14), !allVisible),
1968
+ onClick: () => onVisibilityChange(items.map(_temp15), !allVisible),
1892
1969
  children: allVisible ? labels.hideAll : labels.showAll
1893
1970
  });
1894
1971
  $[21] = allVisible;
@@ -1987,10 +2064,10 @@ function MapLegend(t0) {
1987
2064
  } else t12 = $[49];
1988
2065
  return t12;
1989
2066
  }
1990
- function _temp14(item_0) {
2067
+ function _temp15(item_0) {
1991
2068
  return item_0.id;
1992
2069
  }
1993
- function _temp13(item) {
2070
+ function _temp14(item) {
1994
2071
  return item.visible !== false;
1995
2072
  }
1996
2073
  /**
@@ -2080,7 +2157,7 @@ function MapBaseLayerSwitch(t0) {
2080
2157
  }
2081
2158
  let t3;
2082
2159
  if ($[23] !== baseLayers) {
2083
- t3 = baseLayers.map(_temp15);
2160
+ t3 = baseLayers.map(_temp16);
2084
2161
  $[23] = baseLayers;
2085
2162
  $[24] = t3;
2086
2163
  } else t3 = $[24];
@@ -2124,7 +2201,7 @@ function MapBaseLayerSwitch(t0) {
2124
2201
  * </Map.Overlay>
2125
2202
  * </Map.Root>
2126
2203
  */
2127
- function _temp15(layer_0) {
2204
+ function _temp16(layer_0) {
2128
2205
  return {
2129
2206
  value: layer_0.id,
2130
2207
  label: layer_0.label