@vectoriahq/quac 0.7.0-next.1 → 0.8.0-next.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.
@@ -5,8 +5,12 @@ import type { StacAsset, StacCatalog, StacCollection } from '../model/Stac.ts';
5
5
  * Generates a STAC Catalog from an ArcGIS Online Web Map or Feature Service,
6
6
  * already read down to its layers:
7
7
  * the Web Map or item → top-level Catalog
8
+ * each group layer → nested Catalog
8
9
  * each layer → Collection
9
10
  *
11
+ * A layer's groups come from `groups`, outermost first. Layers next to each
12
+ * other that share a group are written into one Catalog for it.
13
+ *
10
14
  * A layer that can be shown carries its FeatureServer layer's address and the
11
15
  * Web Map's filter on it, and declares its ArcGIS style as its default style
12
16
  * where it has one. A layer that can't carries `quac:arcgis_not_shown` and no
@@ -32,17 +32,62 @@ export function readArcgisNotShownReason(collection) {
32
32
  function arcgisLayersToNormalized(layerSet, options) {
33
33
  const selected = selectLayers(layerSet.layers, options.layerIds);
34
34
  const hasAuthor = layerSet.itemType === 'Web Map';
35
- const nodes = selected.map((layer) => arcgisLayerToNormalized(layer, options.layerWgs84Extents?.get(layer.id) ?? null, hasAuthor));
35
+ const layers = selected.map((layer) => ({
36
+ groups: layer.groups ?? [],
37
+ node: arcgisLayerToNormalized(layer, options.layerWgs84Extents?.get(layer.id) ?? null, hasAuthor)
38
+ }));
36
39
  return {
37
40
  id: slugify(layerSet.title) || 'arcgis',
38
41
  title: layerSet.title,
39
42
  description: layerSet.summary ?? `STAC catalogue generated from the ArcGIS Online ${layerSet.itemType} "${layerSet.title}".`,
40
- bbox: unionBboxes(nodes.map((node) => node.bbox)),
43
+ bbox: unionBboxes(layers.map(({ node }) => node.bbox)),
41
44
  initialView: options.initialView ?? null,
42
45
  vendorFields: layerSet.itemId ? { 'quac:arcgis_item_id': layerSet.itemId } : {},
43
- nodes
46
+ nodes: groupLayers(layers)
44
47
  };
45
48
  }
49
+ /**
50
+ * The layers as a tree: each run of layers next to each other that share a
51
+ * group becomes one group node, nested group by group. A group whose layers
52
+ * are not next to each other, which a caller's `layerIds` order can give, is
53
+ * written once per run, each Catalog with an id of its own.
54
+ */
55
+ function groupLayers(layers) {
56
+ const usedIds = new Set();
57
+ const walk = (run, depth) => {
58
+ const nodes = [];
59
+ let index = 0;
60
+ while (index < run.length) {
61
+ const group = run[index].groups[depth];
62
+ if (!group) {
63
+ nodes.push(run[index].node);
64
+ index += 1;
65
+ continue;
66
+ }
67
+ let end = index + 1;
68
+ while (end < run.length && run[end].groups[depth]?.id === group.id)
69
+ end += 1;
70
+ nodes.push({
71
+ kind: 'group',
72
+ id: uniqueGroupId(slugify(group.id) || 'group', usedIds),
73
+ title: group.title,
74
+ description: `Group "${group.title}" of an ArcGIS Online map.`,
75
+ children: walk(run.slice(index, end), depth + 1)
76
+ });
77
+ index = end;
78
+ }
79
+ return nodes;
80
+ };
81
+ return walk(layers, 0);
82
+ }
83
+ /** `id`, or `id-2`, `id-3` and so on where an earlier group took it. */
84
+ function uniqueGroupId(id, usedIds) {
85
+ let candidate = id;
86
+ for (let suffix = 2; usedIds.has(candidate); suffix += 1)
87
+ candidate = `${id}-${suffix}`;
88
+ usedIds.add(candidate);
89
+ return candidate;
90
+ }
46
91
  /** Resolves the requested ids against the layer set, preserving the caller's order. */
47
92
  function selectLayers(layers, layerIds) {
48
93
  if (!layerIds)
package/dist/index.d.ts CHANGED
@@ -50,7 +50,7 @@ export type { WmsStacCatalogueOptions } from './generate/wmsStacCatalogue.ts';
50
50
  export { collectCatalogueCollections, listCatalogueChildren } from './model/stacTreeWalk.ts';
51
51
  export type { CatalogueChild } from './model/stacTreeWalk.ts';
52
52
  export { setDevLogging } from './util/devLog.ts';
53
- export type { ArcgisCodedValue, ArcgisExtent, ArcgisField, ArcgisFieldMetadata, ArcgisLayerSet, ArcgisLayerSource, ArcgisNotShownReason, ArcgisPassthrough, ArcgisRange, ArcgisResolution, ArcgisResolvedLayer } from './model/arcgis.ts';
53
+ export type { ArcgisCodedValue, ArcgisExtent, ArcgisField, ArcgisFieldMetadata, ArcgisLayerGroup, ArcgisLayerSet, ArcgisLayerSource, ArcgisNotShownReason, ArcgisPassthrough, ArcgisRange, ArcgisResolution, ArcgisResolvedLayer } from './model/arcgis.ts';
54
54
  export type { OgcCollection, OgcCollectionsDocument, OgcItemType, OgcLink } from './model/ogcFeatures.ts';
55
55
  export { WEB_MAP_LINKS_EXTENSION, buildWmsLink, readCollectionWms, wmsEndpoint } from './model/stacWms.ts';
56
56
  export type { StacWmsSource } from './model/stacWms.ts';
@@ -26,6 +26,13 @@ interface ArcgisLayerBase {
26
26
  /** The layer's FeatureServer URL, or null for a layer that has none. */
27
27
  layerUrl: string | null;
28
28
  itemId: string | null;
29
+ /** The Web Map group layers that hold the layer, outermost first. Absent or empty for a layer in no group. */
30
+ groups?: ArcgisLayerGroup[];
31
+ }
32
+ /** A Web Map group layer, by its own id and title. */
33
+ export interface ArcgisLayerGroup {
34
+ id: string;
35
+ title: string;
29
36
  }
30
37
  export interface ArcgisFieldMetadata {
31
38
  displayField: string | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vectoriahq/quac",
3
- "version": "0.7.0-next.1",
3
+ "version": "0.8.0-next.1",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "description": "Writes and reads QUAC, which adds map layer settings to STAC catalogues.",