diff --git a/docs/content/scripts/google-maps.md b/docs/content/scripts/google-maps.md index 223e9272..ca825a0f 100644 --- a/docs/content/scripts/google-maps.md +++ b/docs/content/scripts/google-maps.md @@ -434,6 +434,7 @@ All Google Maps SFC components must work within a ``{lang="htm - ``{lang="html"} - Line paths - ``{lang="html"} - Rectangular overlays - ``{lang="html"} - Heatmap visualization +- ``{lang="html"} - GeoJSON data layers ### Basic Usage @@ -521,6 +522,48 @@ onMounted(() => { ``` +**GeoJSON Data Layer** + +Load GeoJSON from a URL or inline object and apply custom styling: + +```vue + + + +``` + ### Component Hierarchy ```text @@ -531,10 +574,11 @@ ScriptGoogleMaps (root) ├── ScriptGoogleMapsAdvancedMarkerElement │ ├── ScriptGoogleMapsPinElement (optional) │ └── ScriptGoogleMapsInfoWindow (optional) +├── ScriptGoogleMapsGeoJson (GeoJSON data layer) └── ScriptGoogleMapsCircle / Polygon / Polyline / Rectangle / HeatmapLayer ``` -All SFC components accept an `options` prop matching their Google Maps API options type (excluding `map`, which the parent component injects automatically). Options are reactive - changes update the basic Google Maps object. Components clean up automatically on unmount. +Most SFC components accept an `options` prop matching their Google Maps API options type (excluding `map`, which the parent component injects automatically). `ScriptGoogleMapsGeoJson` uses `src` and `style` props instead. Options are reactive - changes update the basic Google Maps object. Components clean up automatically on unmount. ### Component Reference @@ -550,6 +594,34 @@ All SFC components accept an `options` prop matching their Google Maps API optio | `ScriptGoogleMapsPolyline` | `google.maps.PolylineOptions` | | | `ScriptGoogleMapsRectangle` | `google.maps.RectangleOptions` | | | `ScriptGoogleMapsHeatmapLayer` | `google.maps.visualization.HeatmapLayerOptions` | | +| `ScriptGoogleMapsGeoJson` | `src`: `string \| object`, `style`: `google.maps.Data.StylingFunction \| google.maps.Data.StyleOptions` | Emits mouse & feature events | + +### `ScriptGoogleMapsGeoJson`{lang="html"} + +Loads GeoJSON data onto the map using `google.maps.Data` and either `loadGeoJson` (when `src` is a URL) or `addGeoJson` (when `src` is an inline object). + +#### Props + +| Prop | Type | Description | +|---|---|---| +| `src` | `string \| object` | URL to load via `loadGeoJson()`{lang="ts"} or a GeoJSON object to add via `addGeoJson()`{lang="ts"}. Reactive - changing it clears existing features and loads the new data. | +| `style` | `google.maps.Data.StylingFunction \| google.maps.Data.StyleOptions` | Styling applied to the data layer. Reactive with deep watching. | + +#### Events + +**Mouse events**: emitted with a `google.maps.Data.MouseEvent` payload: + +`click`, `contextmenu`, `dblclick`, `mousedown`, `mousemove`, `mouseout`, `mouseover`, `mouseup` + +**Feature lifecycle events:** + +| Event | Payload | +|---|---| +| `addfeature` | `google.maps.Data.AddFeatureEvent` | +| `removefeature` | `google.maps.Data.RemoveFeatureEvent` | +| `setgeometry` | `google.maps.Data.SetGeometryEvent` | +| `setproperty` | `google.maps.Data.SetPropertyEvent` | +| `removeproperty` | `google.maps.Data.RemovePropertyEvent` | ## [`useScriptGoogleMaps()`{lang="ts"}](/scripts/google-maps){lang="ts"} diff --git a/playground/pages/third-parties/google-maps/sfcs.vue b/playground/pages/third-parties/google-maps/sfcs.vue index cf58f3fb..3fd79955 100644 --- a/playground/pages/third-parties/google-maps/sfcs.vue +++ b/playground/pages/third-parties/google-maps/sfcs.vue @@ -36,6 +36,28 @@ const heatmapLayerData = ref([]) const isCircleShown = ref(false) +const isGeoJsonShown = ref(false) + +const geoJsonData = { + type: 'FeatureCollection', + features: [ + { + type: 'Feature', + geometry: { + type: 'Polygon', + coordinates: [[ + [151.20, -33.87], + [151.25, -33.87], + [151.25, -33.90], + [151.20, -33.90], + [151.20, -33.87], + ]], + }, + properties: { name: 'Sydney CBD' }, + }, + ], +} + const googleMapsRef = useTemplateRef('googleMapsRef') whenever(() => googleMapsRef.value?.googleMaps, (googleMaps) => { @@ -191,6 +213,17 @@ whenever(() => googleMapsRef.value?.googleMaps, (googleMaps) => { }" /> + + + {{ `${isGeoJsonShown ? 'Hide' : 'Show'} geojson` }} + +