-
Notifications
You must be signed in to change notification settings - Fork 84
feat(google-maps): add ScriptGoogleMapsGeoJson component #656
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
+449
β2
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d4a0cfc
feat: add `ScriptGoogleMapsGeoJson` component (closes #655)
harlan-zw 1715e78
test: add tests for ScriptGoogleMapsGeoJson component
harlan-zw 2585f77
fix: resolve type error in GeoJson feature event emit
harlan-zw 3f80d2e
Merge branch 'main' into worktree-geojson-655
harlan-zw b90d10a
docs: add ScriptGoogleMapsGeoJson to Google Maps documentation
harlan-zw f6c2243
fix: address PR review comments and fix lockfile
harlan-zw da3d5f1
fix: update bundle hash snapshot after adding GeoJson component
harlan-zw 8b5d6dc
Update docs/content/scripts/google-maps.md
harlan-zw 825bc84
fix: address reviewer feedback on GeoJson docs and component
harlan-zw 042cb6c
Merge branch 'main' into worktree-geojson-655
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
86 changes: 86 additions & 0 deletions
86
src/runtime/components/GoogleMaps/ScriptGoogleMapsGeoJson.vue
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,86 @@ | ||
| <script setup lang="ts"> | ||
| import { watch } from 'vue' | ||
| import { useGoogleMapsResource } from './useGoogleMapsResource' | ||
| const props = defineProps<{ | ||
| src: string | object | ||
| style?: google.maps.Data.StylingFunction | google.maps.Data.StyleOptions | ||
| }>() | ||
| const emit = defineEmits<{ | ||
| (event: typeof dataEvents[number], payload: google.maps.Data.MouseEvent): void | ||
| (event: 'addfeature', payload: google.maps.Data.AddFeatureEvent): void | ||
| (event: 'removefeature', payload: google.maps.Data.RemoveFeatureEvent): void | ||
| (event: 'setgeometry', payload: google.maps.Data.SetGeometryEvent): void | ||
| (event: 'setproperty', payload: google.maps.Data.SetPropertyEvent): void | ||
| (event: 'removeproperty', payload: google.maps.Data.RemovePropertyEvent): void | ||
| }>() | ||
| const dataEvents = [ | ||
| 'click', | ||
| 'contextmenu', | ||
| 'dblclick', | ||
| 'mousedown', | ||
| 'mousemove', | ||
| 'mouseout', | ||
| 'mouseover', | ||
| 'mouseup', | ||
| ] as const | ||
| const featureEvents = [ | ||
| 'addfeature', | ||
| 'removefeature', | ||
| 'setgeometry', | ||
| 'setproperty', | ||
| 'removeproperty', | ||
| ] as const | ||
| function loadGeoJson(src: string | object, layer: google.maps.Data) { | ||
| if (typeof src === 'string') | ||
| layer.loadGeoJson(src) | ||
| else | ||
| layer.addGeoJson(src) | ||
| } | ||
| const dataLayer = useGoogleMapsResource<google.maps.Data>({ | ||
| create({ mapsApi, map }) { | ||
| const layer = new mapsApi.Data({ map }) | ||
| if (props.style) | ||
| layer.setStyle(props.style) | ||
| loadGeoJson(props.src, layer) | ||
| setupEventListeners(layer) | ||
| return layer | ||
| }, | ||
| cleanup(layer, { mapsApi }) { | ||
| mapsApi.event.clearInstanceListeners(layer) | ||
| layer.setMap(null) | ||
| }, | ||
| }) | ||
| watch(() => props.src, (src) => { | ||
| if (!dataLayer.value) | ||
| return | ||
| dataLayer.value.forEach(feature => dataLayer.value!.remove(feature)) | ||
| loadGeoJson(src, dataLayer.value) | ||
| }) | ||
| watch(() => props.style, (style) => { | ||
| if (dataLayer.value) | ||
| dataLayer.value.setStyle(style ?? {}) | ||
| }, { deep: true }) | ||
| function setupEventListeners(layer: google.maps.Data) { | ||
| dataEvents.forEach((event) => { | ||
| layer.addListener(event, (payload: google.maps.Data.MouseEvent) => emit(event, payload)) | ||
| }) | ||
| featureEvents.forEach((event) => { | ||
| layer.addListener(event, (payload: any) => (emit as any)(event, payload)) | ||
| }) | ||
| } | ||
| </script> | ||
|
|
||
| <template> | ||
| </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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could (but we don't need to) repeat
:styleand@clickattrs for explicitness.