Skip to content

Commit c6df241

Browse files
committed
feat!(layer-selector): add support for using with the new arcgis-map component
Closes #571
1 parent cbcb2cf commit c6df241

File tree

9 files changed

+617
-456
lines changed

9 files changed

+617
-456
lines changed

.vscode/settings.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"multipoint",
3434
"oidc",
3535
"onarcgis",
36+
"oncalcite",
3637
"packagejson",
3738
"prebuild",
3839
"safelisted",
@@ -61,5 +62,14 @@
6162
],
6263
"editor.formatOnSave": true,
6364
"editor.defaultFormatter": "esbenp.prettier-vscode",
64-
"json.validate.enable": false
65+
"json.validate.enable": false,
66+
"html.customData": [
67+
"./node_modules/@arcgis/map-components/dist/docs/vscode.html-custom-data.json",
68+
"./node_modules/@arcgis/charts-components/dist/docs/vscode.html-custom-data.json",
69+
"./node_modules/@esri/calcite-components/dist/docs/vscode.html-custom-data.json"
70+
],
71+
"css.customData": [
72+
"./node_modules/@arcgis/map-components/dist/docs/vscode.css-custom-data.json",
73+
"./node_modules/@esri/calcite-components/dist/docs/vscode.css-custom-data.json"
74+
]
6575
}

package-lock.json

Lines changed: 4 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
},
5353
"devDependencies": {
5454
"@chromatic-com/storybook": "^4.1.1",
55+
"@esri/calcite-components": "^3.3.3",
5556
"@mdx-js/react": "^3.1.1",
5657
"@storybook/addon-docs": "^9.1.13",
5758
"@storybook/addon-links": "^9.1.13",

packages/utah-design-system/README.md

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ This is UGRC's [React Aria](https://react-spectrum.adobe.com/react-aria/) plus [
66

77
This design system expects Tailwind CSS primary, secondary, and accent colors ranging from 50-950. The UGRC default presets can be used for this from [@ugrc/tailwind-preset](https://www.npmjs.com/package/@ugrc/tailwind-preset).
88

9+
## TypeScript Configuration
10+
11+
When using spatial components that integrate with ArcGIS and Calcite web components (such as `LayerSelector`), you need to include type references in your project's TypeScript configuration. Add the following to your `vite-env.d.ts` or a similar type declaration file:
12+
13+
```typescript
14+
/// <reference types="@arcgis/map-components/types/react" />
15+
/// <reference types="@esri/calcite-components/types/react" />
16+
```
17+
18+
This ensures TypeScript recognizes the global types for ArcGIS and Calcite elements (e.g., `HTMLArcgisMapElement`, `HTMLCalciteCheckboxElement`) used by these components.
19+
920
## Header
1021

1122
The Header component requires a custom font for the SVG text.
@@ -43,6 +54,56 @@ The Header component requires a custom font for the SVG text.
4354

4455
## Layer Selector
4556

46-
This is a component that allows the user to quickly toggle visibility of layers or base maps in a web map. It has `baseLayers`, `operationalLayers`, and `referenceLayers` options that allow you to add layers to the corresponding properties of your map's [Basemap](https://developers.arcgis.com/javascript/latest/api-reference/esri-Basemap.html). It also supports adding entire base maps via the `basemaps` property. When this property is used, the individual parts of the base map (`baseLayers` and `referenceLayers`) are mixed into the base map that Layer Selector manages.
57+
A component for managing map basemaps and overlay layers.
58+
59+
This is a component that allows the user to quickly toggle visibility of layers or base maps in a web map. It has `baseLayers`, `operationalLayers`, and `referenceLayers` properties that allow you to add layers to the corresponding properties of your map's [Basemap](https://developers.arcgis.com/javascript/latest/api-reference/esri-Basemap.html). It also supports adding entire base maps via the `basemaps` property. When this property is used, the individual parts of the base map (`baseLayers` and `referenceLayers`) are mixed into the base map that Layer Selector manages.
60+
61+
Layers defined in `baseLayers` or `basemaps` are represented as radio buttons in a single group. You are required to pass at least one value to at least one of these properties. The first value in `basemaps` is selected by default. If no value is passed to `basemaps`, then the first value in `baseLayers` is selected by default. The `operationalLayers` and `referenceLayers` properties are represented as checkboxes.
62+
63+
**Important:** When using `LayerSelector`, you must set a `basemap` prop on the related `arcgis-map` element (e.g., `basemap="streets"`). This is required because the map component needs an initial basemap to properly initialize the view before `LayerSelector` can take over basemap management. Without it, the initial extent related properties (center, zoom, scale, etc.) will not be honored.
64+
65+
This component will not work with base `@arcgis/core/views/MapView` API since it is built on top of the `arcgis-expand` component.
66+
67+
### Example
68+
69+
```tsx
70+
<arcgis-map basemap="streets">
71+
<LayerSelector basemaps={['Lite', 'Imagery']} />
72+
</arcgis-map>
73+
```
74+
75+
#### Migration from previous API (breaking change)
76+
77+
In earlier versions, `LayerSelector` accepted a single `options` prop (e.g., `<LayerSelector options={{ basemaps: ['Lite', 'Imagery'] }} />`). This has been replaced with flat props in order to be more idiomatic in React and easier to type and document.
78+
79+
**Before (deprecated API):**
80+
81+
```tsx
82+
useEffect(() => {
83+
// ...
84+
setSelectorOptions({
85+
options: {
86+
basemaps: ['Lite', 'Imagery'],
87+
operationalLayers: ['Parcels', 'Roads'],
88+
},
89+
});
90+
}, []);
91+
92+
<arcgis-map basemap="streets">
93+
{selectorOptions && <LayerSelector {...selectorOptions} />}
94+
</arcgis-map>;
95+
```
96+
97+
**After (current API):**
98+
99+
```tsx
100+
<arcgis-map basemap="streets">
101+
<LayerSelector
102+
// no need to pass a reference to the map since it's handled internally
103+
basemaps={['Lite', 'Imagery']}
104+
operationalLayers={['Parcels', 'Roads']}
105+
/>
106+
</arcgis-map>
107+
```
47108

48-
Layers defined in `baseLayers` or `basemaps` are represented as a radio buttons in a single group. You are required to pass at least one value to at least one of these properties. The first value in `basemaps` is selected by default. If no value is passed to `basemaps`, then the first value in `baseLayers` is selected by default. The `operationalLayers` and `referenceLayers` properties are represented as checkboxes.
109+
When upgrading, move properties that were previously nested under `options` (such as `basemaps`, `operationalLayers`, `referenceLayers`, and `baseLayers`) to top-level props on `LayerSelector`.

packages/utah-design-system/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
"ts-md5": "^2.0.1"
6363
},
6464
"peerDependencies": {
65-
"react": ">=16.8"
65+
"@arcgis/map-components": ">=4.28.0",
66+
"@esri/calcite-components": ">=2.0.0",
67+
"react": ">=19.0.0"
6668
}
6769
}

0 commit comments

Comments
 (0)