Skip to content

feat: optionally show a search bar when drawing on an OS basemap to position the map view#618

Merged
jessicamcinchak merged 6 commits into
mainfrom
jess/map-with-search
May 12, 2026
Merged

feat: optionally show a search bar when drawing on an OS basemap to position the map view#618
jessicamcinchak merged 6 commits into
mainfrom
jess/map-with-search

Conversation

@jessicamcinchak
Copy link
Copy Markdown
Member

@jessicamcinchak jessicamcinchak commented Apr 27, 2026

Changes / how this works

  • Add a prop showOSSearch which will render the geocode autocomplete search component above the map
  • The searched address is used to position the map only, it does not inherently place the draw point (because may be using drawMany, draw polygon etc)
  • The geocode autocomplete will inherently return all OS addresses throughout the UK, but an error will be thrown if the map uses a small clip extent (eg Lambeth's boundary) and you search an address outside of it (eg in Buckinghamshire)

Next steps

Prior art
Originally started here theopensystemslab/planx-new#6455, but ultimately couldn't hack two-way data flow and Lit's update life cycle so opted for this "composite component" approach directly within render and controlled via map props instead ➕

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 27, 2026

Deploy Preview for oslmap ready!

Name Link
🔨 Latest commit a591b2e
🔍 Latest deploy log https://app.netlify.com/projects/oslmap/deploys/6a024004f455df00087e7954
😎 Deploy Preview https://deploy-preview-618--oslmap.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

coordinates: [],
},
};
clipGeojsonData: GeoJSONFeature | undefined = undefined;
Copy link
Copy Markdown
Member Author

@jessicamcinchak jessicamcinchak May 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lit Object types have always been a bit weird with default value handling, but this feels a lot more semantically meaningful now and should be functioning exactly the same (eg snap feature which has good unit test coverage also relies on clip extent).

this.showOSSearch &&
this.drawMode &&
["OSVectorTile", "OSRaster"].includes(this.basemap) &&
(Boolean(this.osApiKey) || Boolean(this.osProxyEndpoint));
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Showing search" isn't as simple as setting only the showOSSearch prop, we also want to confirm that these other conditions are met for the best UI/UX.

This should avoid a few weird edge cases which could otherwise be created, for example:

  • Showing search on a static map, not in draw mode
  • Showing OS-based search on a draw mode map using Mapbox Satellite basemap

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me...!

We have a few similar guards here where props need to be grouped. If this was a pure React component it would be a good case for a discriminated union of props to enforce this, but I'm not too sure how we'd...

  • Set that up in Lit
  • Enforce this in a consumer application (exporting prop types somewhere?)

One to have a look at (timeboxed) in future maybe.

@@ -1,3 +1,5 @@
@import "govuk-frontend/dist/govuk/index";
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now required for styling govuk error classes.

// display "none" ensures always present in DOM, which means role="status" will work for screenreaders
if (errorEl) errorEl.style.display = "none";
if (errorEl && this._searchError) errorEl.style.display = "";
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This follows the pattern established by postcode-search and address-autocomplete, so should hopefully be a11y compliant come our next audit 🤞

@jessicamcinchak jessicamcinchak marked this pull request as ready for review May 11, 2026 21:02
@jessicamcinchak jessicamcinchak requested a review from a team May 11, 2026 21:02
this.showOSSearch &&
this.drawMode &&
["OSVectorTile", "OSRaster"].includes(this.basemap) &&
(Boolean(this.osApiKey) || Boolean(this.osProxyEndpoint));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me...!

We have a few similar guards here where props need to be grouped. If this was a pure React component it would be a good case for a discriminated union of props to enforce this, but I'm not too sure how we'd...

  • Set that up in Lit
  • Enforce this in a consumer application (exporting prop types somewhere?)

One to have a look at (timeboxed) in future maybe.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to see this included 👍

drawPointer="dot"
showOSSearch
basemap="OSVectorTile"
osVectorTilesApiKey="${osApiKey}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually can't get this to render on the Netlify env, or locally, when I pass in either a key or proxy endpoint.

This might be a problem with how I originally set this up though, the same applied to other stories 🤔

Were you able to get this to work locally?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was also not able to get Storybook working locally, even with API key as plain string passed in, but not uniuqe to this new story for me! Happy to come back to this as a follow-up, meant to similarly point out here!

Local dev & index.html examples were completely fine/working as usual, so not anticipating issues with FindProperty integration. But will be an alpha release regardless, justt in case!

@jessicamcinchak jessicamcinchak merged commit 8115a19 into main May 12, 2026
5 checks passed
@jessicamcinchak jessicamcinchak deleted the jess/map-with-search branch May 12, 2026 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants