Repository navigation
feat(web-forms#517): add support to map layers with Google Maps - #1993
Conversation
🦋 Changeset detectedLatest commit: dffe11c The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| openFullScreen: 'mdiArrowExpand', | ||
| closeFullScreen: 'mdiArrowCollapse', | ||
| openInfo: 'mdiInformationSlabCircleOutline', | ||
| baseLayers: 'mdiLayersOutline', |
There was a problem hiding this comment.
We replaced the info button with the layers button instead of adding one more. The controls bar is already at its limit, with the advanced panel open, or on a phone in landscape, there is no room for another button. In landscape the layers button is hidden for the same reason (just like info button was)
| attachmentMaxSize: props.attachmentMaxSize, | ||
| }); | ||
| provide(FORM_OPTIONS, formOptions); | ||
| provide(CLIENT_OPTIONS, readonly<ClientOptions>({ googleMapsKey: props.googleMapsKey })); |
There was a problem hiding this comment.
FORM_OPTIONS belongs to the engine, it is defined and used there. CLIENT_OPTIONS is a separate bag because it is only read by the Vue client. So the engine does need to know about client-only settings like the Google Maps key.
|
@garethbowen There's a follow-up PR that Matthew is reviewing, where I add the Google Maps key variable getodk/central#2326 I'm planning to add a visual test for this in another PR, where I’ll try to mock the Google tiles for all three layers. |
garethbowen
left a comment
There was a problem hiding this comment.
Initial thoughts inline. I'd like to run this locally - how are you getting a maps key? It looks like I need a personal gmail account to generate a dev one. Is that what you did?
| "@getodk/forms": minor | ||
| --- | ||
|
|
||
| Add support to map layers with Google Maps [web-forms#517](https://github.com/getodk/web-forms/issues/517) |
There was a problem hiding this comment.
| Add support to map layers with Google Maps [web-forms#517](https://github.com/getodk/web-forms/issues/517) | |
| Added support for map layers with Google Maps [web-forms#517](https://github.com/getodk/web-forms/issues/517) |
|
|
||
| <Dialog v-model:visible="isDialogOpen" modal class="map-block-dialog" :draggable="false"> | ||
| <template #header> | ||
| <strong>{{ t('map_privacy_dialog.header.title') }}</strong> |
There was a problem hiding this comment.
Consider using h3 or similar?
|
|
||
| readonly lastSavedXml?: string; | ||
|
|
||
| readonly googleMapsKey?: string; |
There was a problem hiding this comment.
I'm not sure about this as the API because it feels too specific, and not nicely extensible. What about using mapProvider instead, which takes a MapProvider type object, and defaults to osm?
|
|
||
| readonly lastSavedXml?: string; | ||
|
|
||
| readonly googleMapsKey?: string; |
There was a problem hiding this comment.
Don't forget to document this in the README.
| </script> | ||
|
|
||
| <template> | ||
| <div class="base-layer-options" role="group"> |
There was a problem hiding this comment.
Can we use a primevue/select instead of a custom menu? This way the styling will be consistent with the language picker in the header, as well as select1 questions in the form.
There was a problem hiding this comment.
I started with PrimeVue's popover and moved to a plain panel, like the canvas color picker, because PrimeVue renders its overlays at the end of body with their own z-index, outside our z-index scale. PrimeVue's select does the same. It's also a text trigger with a chevron, so making it an icon button means hiding its parts with :deep overrides, which feels like a hack and easy to regress.
I agree on consistency. I'll match the option styles!
Happy to create a dev key for use to share if that's helpful. Do we need one for CI? |
|
For CI it'd be better to mock google maps out for stability and performance, so any string could be made to work! |
Yes, I created a API key using my GCP |
|
@garethbowen I've applied your feedback. When you have a chance, could you please take another look? |
garethbowen
left a comment
There was a problem hiding this comment.
Very nice. Works smoothly, and can swap between providers easily.
| "string": "Map data privacy", | ||
| "developer_comment": "Header of the dialog explaining what data Google receives when the map is displayed." | ||
| }, | ||
| "map_privacy_dialog.body.text": { |
There was a problem hiding this comment.
This key doesn't match what's in the .i18n.json file. Remember to npm run build:translation before merging.
| const response = await super | ||
| .fetchSessionToken(url, config) | ||
| .catch(() => failedSessionResponse()); | ||
| return this.disposed ? failedSessionResponse() : response; |
There was a problem hiding this comment.
I think the non-catch case could go in a then to avoid double handling...
| const response = await super | |
| .fetchSessionToken(url, config) | |
| .catch(() => failedSessionResponse()); | |
| return this.disposed ? failedSessionResponse() : response; | |
| return super | |
| .fetchSessionToken(url, config) | |
| .then(response => this.disposed ? failedSessionResponse() : response) | |
| .catch(() => failedSessionResponse()); |
| [BASE_LAYER_IDS.TERRAIN]: { mapType: 'terrain', layerTypes: ['layerRoadmap'] }, | ||
| }; | ||
|
|
||
| const FAILED_SESSION_STATUS = 410; |
There was a problem hiding this comment.
Why a 410? That doesn't seem right. Is it used internally in OL?
There was a problem hiding this comment.
Ah, I was checking that status in another place, then removed that code and forgot about this. Removed!
| /** | ||
| * Base map provider for map questions. The host builds it from its own config. | ||
| */ | ||
| export type MapProvider = { kind: 'google'; apiKey: string } | { kind: 'osm' }; |
There was a problem hiding this comment.
I don't think kind is right. How about name?
| border-radius: var(--odk-radius); | ||
| } | ||
|
|
||
| .base-layer-option { |
There was a problem hiding this comment.
Can we remove this class and just have button {...} nested inside the base-layer-options block above?
|
|
||
| <template> | ||
| <div class="base-layer-options" role="group"> | ||
| <button |
There was a problem hiding this comment.
I don't think this should be a button. Can we use ul and li instead? I don't think we're getting anything for free by having a button, and a list is more semantic (we're not submitting the form!) and probably easier to make consistent with the select menus we use in other places.
There was a problem hiding this comment.
I think the button is still fine here because it triggers an action (switching the layer), it's focusable, the Enter key works out of the box, and screen readers pick it up. But it seems I used the incorrect aria (aria-pressed).
I'll replace it with ul/li to match other dropdowns, since it still fits because it's a list of options. The only difference is that it requires more setup: role="listbox"/role="option", aria-selected, and tabindex plus Enter handling for the keyboard.
| .base-layer-panel { | ||
| position: absolute; | ||
| top: 0; | ||
| right: calc(100% + var(--odk-spacing-m)); |
There was a problem hiding this comment.
I think the --odk-spacing-m is too much... the panel looks disconnected from the button. You could almost just do 100% but 100% + 1px looks best too me.
|
|
||
| <template> | ||
| <div class="map-privacy-badge"> | ||
| <button |
There was a problem hiding this comment.
I think a link (a) would be more semantic.
There was a problem hiding this comment.
I think the button is right here, it's not a hyperlink and it doesn't navigate anywhere, it just opens the dialog. The actual link to Google's policy is inside the dialog.
|
@garethbowen could you please have a look again? |
…nto map-layers-wf # Conflicts: # .image-hashes # apps/forms/src/components/web-form-renderer.vue # packages/web-forms/e2e/test-cases/visual/all-question-types.test.ts-snapshots/select-map-point-selected-chromium.png


Closes getodk/web-forms#517
What has been done to verify that this works as intended?
Unit tests and manual tests
Screen.Recording.2026-11-12.at.10.26.39.PM.mov
Why is this the best possible solution? Were any other approaches considered?
Central already serves a client-config.json to the frontend, so the key is included. The map component reads it and selects the provider, keeping the rest of Web Forms independent of maps. For the tiles, I used OpenLayers' built-in Google source, which handles session tokens and attribution without adding a dependency. I also didn’t reuse Enketo's layer list, since we decided that Web Forms should always offer the same three layers.
How does this change impact users? Describe intentional behavior changes from code updates. What are the regression risks?
If there is no key, nothing changes for users except that the "how to use this map" help dialog is gone. If there is a key, map questions show Google Maps with a layer picker, the Google logo with attribution, and a small privacy notice. If the key is invalid or over its quota, users see an error banner and the map stays usable. There is no fallback to OpenStreetMap on purpose since the system admin wants the user to use Google Maps.
Does this change require updates to user documentation? If so, please file an issue here and include the link below.
Yes, it's a work in progress here getodk/docs#2128