Skip to content

Commit

Permalink
Deprecate mapId (#397, #404)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Antonia van Eek <a.vaneek@conterra.de>
  • Loading branch information
mbeckem and antoniave authored Feb 24, 2025
1 parent ad4ee5a commit 193068a
Show file tree
Hide file tree
Showing 67 changed files with 1,409 additions and 1,209 deletions.
35 changes: 35 additions & 0 deletions .changeset/ninety-houses-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
"@open-pioneer/map": minor
"@open-pioneer/basemap-switcher": minor
"@open-pioneer/coordinate-search": minor
"@open-pioneer/coordinate-viewer": minor
"@open-pioneer/geolocation": minor
"@open-pioneer/legend": minor
"@open-pioneer/map-navigation": minor
"@open-pioneer/measurement": minor
"@open-pioneer/overview-map": minor
"@open-pioneer/printing": minor
"@open-pioneer/result-list": minor
"@open-pioneer/scale-bar": minor
"@open-pioneer/scale-setter": minor
"@open-pioneer/scale-viewer": minor
"@open-pioneer/search": minor
"@open-pioneer/selection": minor
"@open-pioneer/spatial-bookmarks": minor
"@open-pioneer/toc": minor
---

Deprecate the `mapId` property on React components.
Use the `MapModel` directly instead to pass a reference to the map.

Example:

```tsx
// Default map for entire component tree
<DefaultMapProvider map={mapModel}>
<Toc />
</DefaultMapProvider>

// Map for specific component
<Toc map={mapModel} />
```
6 changes: 6 additions & 0 deletions .changeset/thick-mayflies-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@open-pioneer/editing": minor
---

Deprecate the method signatures taking `mapId` on the `EditingService`.
Use an instance of `MapModel` as a parameter instead.
4 changes: 2 additions & 2 deletions docs/concepts/UI.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Those css classes will be appended to the default class name when the component
Add class name `my-class` to the component:

```tsx
<ScaleViewer mapId={MAP_ID} className="my-class" />
<ScaleViewer map={map} className="my-class" />
```

Renders as (for example):
Expand All @@ -55,7 +55,7 @@ zoomButton.current!.focus()

return (
{/* ... */}
<ZoomIn mapId={MAP_ID} ref={zoomButton} />
<ZoomIn map={map} ref={zoomButton} />
{/* ... */}
);
```
Expand Down
4 changes: 3 additions & 1 deletion docs/templates/package-README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ To add the component/button/... in your app, `[...]`.
> To add the button to your app, insert the following snippet with a reference to a map ID:
>
> ```jsx
> <InitialExtent mapId="map_id" />
> <InitialExtent
> map={map}
> /> /* instead of passing the map, the `DefaultMapProvider` can alternatively be used */
> ```
To `[...]`, add the optional property `[...]`:
Expand Down
54 changes: 22 additions & 32 deletions src/packages/basemap-switcher/BasemapSwitcher.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ const defaultBasemapConfig = [
];

it("should successfully create a basemap switcher component", async () => {
const { mapId, registry } = await setupMap();
await registry.expectMapModel(mapId); // wait for model load
const { registry, map } = await setupMap();

const injectedServices = createServiceOptions({ registry });
render(
<PackageContextProvider services={injectedServices}>
<BasemapSwitcher mapId={mapId} allowSelectingEmptyBasemap data-testid="switcher" />
<BasemapSwitcher map={map} allowSelectingEmptyBasemap data-testid="switcher" />
</PackageContextProvider>
);

Expand All @@ -52,15 +51,14 @@ it("should successfully create a basemap switcher component", async () => {
});

it("should successfully create a basemap switcher component with additional css classes and box properties", async () => {
const { mapId, registry } = await setupMap({
const { registry, map } = await setupMap({
layers: defaultBasemapConfig
});
await registry.expectMapModel(mapId); // wait for model load

const injectedServices = createServiceOptions({ registry });
render(
<PackageContextProvider services={injectedServices}>
<BasemapSwitcher mapId={mapId} className="test" data-testid="switcher" />
<BasemapSwitcher map={map} className="test" data-testid="switcher" />
</PackageContextProvider>
);

Expand All @@ -71,15 +69,14 @@ it("should successfully create a basemap switcher component with additional css

it("should successfully select a basemap from basemap switcher", async () => {
const user = userEvent.setup();
const { mapId, registry } = await setupMap({
const { registry, map } = await setupMap({
layers: defaultBasemapConfig
});
const map = await registry.expectMapModel(mapId);

const injectedServices = createServiceOptions({ registry });
render(
<PackageContextProvider services={injectedServices}>
<BasemapSwitcher mapId={mapId} data-testid="switcher" />
<BasemapSwitcher map={map} data-testid="switcher" />
</PackageContextProvider>
);

Expand Down Expand Up @@ -111,15 +108,14 @@ it("should successfully select a basemap from basemap switcher", async () => {

it("should allow selecting 'no basemap' when enabled", async () => {
const user = userEvent.setup();
const { mapId, registry } = await setupMap({
const { registry, map } = await setupMap({
layers: defaultBasemapConfig
});

const map = await registry.expectMapModel(mapId);
const injectedServices = createServiceOptions({ registry });
render(
<PackageContextProvider services={injectedServices}>
<BasemapSwitcher mapId={mapId} allowSelectingEmptyBasemap data-testid="switcher" />
<BasemapSwitcher map={map} allowSelectingEmptyBasemap data-testid="switcher" />
</PackageContextProvider>
);

Expand All @@ -142,15 +138,14 @@ it("should allow selecting 'no basemap' when enabled", async () => {
});

it("should not allow selecting 'no basemap' by default", async () => {
const { mapId, registry } = await setupMap({
const { registry, map } = await setupMap({
layers: defaultBasemapConfig
});

const map = await registry.expectMapModel(mapId);
const injectedServices = createServiceOptions({ registry });
render(
<PackageContextProvider services={injectedServices}>
<BasemapSwitcher mapId={mapId} data-testid="switcher" />
<BasemapSwitcher map={map} data-testid="switcher" />
</PackageContextProvider>
);

Expand All @@ -169,15 +164,14 @@ it("should not allow selecting 'no basemap' by default", async () => {
});

it("should update when a new basemap is registered", async () => {
const { mapId, registry } = await setupMap({
const { registry, map } = await setupMap({
layers: defaultBasemapConfig
});

const map = await registry.expectMapModel(mapId);
const injectedServices = createServiceOptions({ registry });
render(
<PackageContextProvider services={injectedServices}>
<BasemapSwitcher mapId={mapId} data-testid="switcher" />
<BasemapSwitcher map={map} data-testid="switcher" />
</PackageContextProvider>
);

Expand Down Expand Up @@ -212,15 +206,14 @@ it("should update when a new basemap is registered", async () => {
});

it("should update when a different basemap is activated from somewhere else", async () => {
const { mapId, registry } = await setupMap({
const { registry, map } = await setupMap({
layers: defaultBasemapConfig
});

const map = await registry.expectMapModel(mapId);
const injectedServices = createServiceOptions({ registry });
render(
<PackageContextProvider services={injectedServices}>
<BasemapSwitcher mapId={mapId} data-testid="switcher" />
<BasemapSwitcher map={map} data-testid="switcher" />
</PackageContextProvider>
);

Expand All @@ -238,15 +231,14 @@ it("should update when a different basemap is activated from somewhere else", as

describe("should successfully select the correct basemap from basemap switcher", () => {
it("basemap with id `osm` (first in layers array) is visible", async () => {
const { mapId, registry } = await setupMap({
const { registry, map } = await setupMap({
layers: defaultBasemapConfig
});

const map = await registry.expectMapModel(mapId);
const injectedServices = createServiceOptions({ registry });
render(
<PackageContextProvider services={injectedServices}>
<BasemapSwitcher mapId={mapId} data-testid="switcher" />
<BasemapSwitcher map={map} data-testid="switcher" />
</PackageContextProvider>
);

Expand All @@ -260,7 +252,7 @@ describe("should successfully select the correct basemap from basemap switcher",
});

it("basemap with id `topplus-open` (second in layers array) is visible", async () => {
const { mapId, registry } = await setupMap({
const { registry, map } = await setupMap({
layers: [
{
id: "osm",
Expand All @@ -281,11 +273,10 @@ describe("should successfully select the correct basemap from basemap switcher",
]
});

const map = await registry.expectMapModel(mapId);
const injectedServices = createServiceOptions({ registry });
render(
<PackageContextProvider services={injectedServices}>
<BasemapSwitcher mapId={mapId} data-testid="switcher" />
<BasemapSwitcher map={map} data-testid="switcher" />
</PackageContextProvider>
);

Expand All @@ -306,7 +297,7 @@ it("should disable selection of unavailable layers and show a warning", async ()
osmSource.setState("error");
});

const { mapId, registry } = await setupMap({
const { registry, map } = await setupMap({
layers: [
{
id: "osm",
Expand All @@ -330,7 +321,7 @@ it("should disable selection of unavailable layers and show a warning", async ()
const injectedServices = createServiceOptions({ registry });
render(
<PackageContextProvider services={injectedServices}>
<BasemapSwitcher mapId={mapId} data-testid="switcher" />
<BasemapSwitcher map={map} data-testid="switcher" />
</PackageContextProvider>
);

Expand All @@ -342,15 +333,14 @@ it("should disable selection of unavailable layers and show a warning", async ()
});

it("should update the ui when a layer title changes", async () => {
const { mapId, registry } = await setupMap({
const { registry, map } = await setupMap({
layers: defaultBasemapConfig
});
const map = await registry.expectMapModel(mapId);

const injectedServices = createServiceOptions({ registry });
render(
<PackageContextProvider services={injectedServices}>
<BasemapSwitcher mapId={mapId} data-testid="switcher" />
<BasemapSwitcher map={map} data-testid="switcher" />
</PackageContextProvider>
);

Expand Down
10 changes: 6 additions & 4 deletions src/packages/basemap-switcher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ Unavailable basemaps are marked with an icon and will be deactivated for selecti

## Usage

To add the component to your app, insert the following snippet with a reference to a map ID:
To add the component to your app, insert the following snippet:

```jsx
<BasemapSwitcher mapId="map_id" />
<BasemapSwitcher
map={map}
/> /* instead of passing the map, the `DefaultMapProvider` can alternatively be used */
```

To provide an option to deactivate all basemap layers, add the optional property `allowSelectingEmptyBasemap` (default: `false`).

```jsx
<BasemapSwitcher mapId="map_id" allowSelectingEmptyBasemap />
<BasemapSwitcher map={map} allowSelectingEmptyBasemap />
```

## Accessibility
Expand All @@ -35,7 +37,7 @@ Example:
<FormLabel ps={1}>
<Text as="b">{intl.formatMessage({ id: "basemapLabel" })}</Text>
</FormLabel>
<BasemapSwitcher mapId="map_id" allowSelectingEmptyBasemap></BasemapSwitcher>
<BasemapSwitcher map={map} allowSelectingEmptyBasemap></BasemapSwitcher>
</FormControl>
```

Expand Down
Loading

0 comments on commit 193068a

Please sign in to comment.