-
Notifications
You must be signed in to change notification settings - Fork 84
feat!: extract ScriptGoogleMapsStaticMap as standalone component
#673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
32c6bbb
feat!: extract static map into standalone ScriptGoogleMapsStaticMap cβ¦
harlan-zw 335a953
fix: move regex to module scope for lint compliance
harlan-zw f64da30
fix: address CodeRabbit review + add docs for ScriptGoogleMapsStaticMap
harlan-zw 3ad3235
fix: resolve doc linting issues (em-dashes, passive voice)
harlan-zw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| --- | ||
| title: <ScriptGoogleMapsStaticMap> | ||
| --- | ||
|
|
||
| Renders a [Google Maps Static API](https://developers.google.com/maps/documentation/maps-static) image. Use standalone for static map previews, or drop into the `#placeholder` slot of [`<ScriptGoogleMaps>`{lang="html"}](/scripts/google-maps/api/script-google-maps) for a loading placeholder. | ||
|
|
||
| ::script-types{script-key="google-maps" filter="ScriptGoogleMapsStaticMap"} | ||
| :: | ||
|
|
||
| ## Usage | ||
|
|
||
| ### Standalone | ||
|
|
||
| Display a static map without loading the interactive Google Maps JavaScript API. | ||
|
|
||
| ```vue | ||
| <template> | ||
| <ScriptGoogleMapsStaticMap | ||
| center="51.95,19.13" | ||
| :zoom="7" | ||
| width="100%" | ||
| height="300" | ||
| /> | ||
| </template> | ||
| ``` | ||
|
|
||
| ### As Placeholder | ||
|
|
||
| Use inside [`<ScriptGoogleMaps>`{lang="html"}](/scripts/google-maps/api/script-google-maps) to show a static map while the interactive map loads. | ||
|
|
||
| ```vue | ||
| <template> | ||
| <ScriptGoogleMaps :center="center" :zoom="7"> | ||
| <template #placeholder> | ||
| <ScriptGoogleMapsStaticMap | ||
| :center="center" | ||
| :zoom="7" | ||
| loading="eager" | ||
| maptype="satellite" | ||
| /> | ||
| </template> | ||
| </ScriptGoogleMaps> | ||
| </template> | ||
| ``` | ||
|
|
||
| ## Props | ||
|
|
||
| | Prop | Type | Default | Description | | ||
| |------|------|---------|-------------| | ||
| | `center` | `string \| { lat: number, lng: number }` | | Map center as `"lat,lng"` string or `LatLngLiteral`. | | ||
| | `zoom` | `number` | `15` | Zoom level (0 to 21). | | ||
| | `size` | `` `${number}x${number}` `` | auto | Explicit pixel size for the API request. When omitted, measures the rendered container on mount. Falls back to `640x400` during SSR. | | ||
| | `scale` | `1 \| 2` | `2` | Device pixel ratio. | | ||
| | `format` | `StaticMapFormat` | | Image format: `png`, `jpg`, `gif`, `png8`, `png32`, `jpg-baseline`. | | ||
| | `maptype` | `StaticMapType` | | Map type: `roadmap`, `satellite`, `terrain`, `hybrid`. | | ||
| | `mapId` | `string` | | Cloud-based map styling ID. | | ||
| | `markers` | `string \| string[]` | | [Marker descriptors](https://developers.google.com/maps/documentation/maps-static/start#Markers). | | ||
| | `path` | `string \| string[]` | | [Polyline path descriptors](https://developers.google.com/maps/documentation/maps-static/start#Paths). | | ||
| | `visible` | `string \| string[]` | | Locations that should be visible on the map. | | ||
| | `style` | `string \| string[] \| MapTypeStyle[]` | | Map styling. Accepts raw Static Maps API style strings or Google Maps JS API `MapTypeStyle[]` objects. | | ||
| | `language` | `string` | | Language code for map labels. | | ||
| | `region` | `string` | | Region bias. | | ||
| | `signature` | `string` | | Digital signature for keyless requests. | | ||
| | `apiKey` | `string` | | API key override. Takes priority over the proxy; the component falls back to the server-side key when omitted. | | ||
| | `width` | `number \| string` | `640` | CSS width for the container. | | ||
| | `height` | `number \| string` | `400` | CSS height for the container. | | ||
| | `loading` | `'eager' \| 'lazy'` | `'lazy'` | Image loading strategy. | | ||
| | `objectFit` | `string` | `'cover'` | Object-fit for the `<img>`{lang="html"} within its container. | | ||
| | `imgAttrs` | `ImgHTMLAttributes` | | Additional attributes for the `<img>`{lang="html"} element. | | ||
|
|
||
| ## Size Handling | ||
|
|
||
| When `size` is not provided, the component: | ||
|
|
||
| 1. **Client-side**: Measures the container's pixel dimensions on mount and clamps to the [Static Maps API limit](https://developers.google.com/maps/documentation/maps-static/start) of 640x640 (preserving aspect ratio). | ||
| 2. **SSR**: Derives from `width`/`height` props if both are pixel values. | ||
| 3. **Fallback**: Uses `640x400`. | ||
|
|
||
| Set `size` explicitly to bypass auto-measurement. | ||
|
|
||
| ## Proxy Support | ||
|
|
||
| Configuring `googleMaps` in `scripts.registry` enables a server-side proxy automatically. The component routes requests through the proxy unless you provide an explicit `apiKey` prop. | ||
|
|
||
| ## Slots | ||
|
|
||
| **default** | ||
|
|
||
| Override the `<img>`{lang="html"} element with a custom template. Receives `{ src }` with the computed Static Maps URL. | ||
|
|
||
| ```vue | ||
| <template> | ||
| <ScriptGoogleMapsStaticMap center="51.95,19.13" :zoom="7"> | ||
| <template #default="{ src }"> | ||
| <img :src="src" alt="Custom static map" class="rounded-lg shadow"> | ||
| </template> | ||
| </ScriptGoogleMapsStaticMap> | ||
| </template> | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.