---
title: "<ScriptGoogleMapsGeoJson> · Nuxt Scripts"
description: "Load inline or remote GeoJSON into a reactive Google Maps Data layer."
canonical_url: "https://scripts.nuxt.com/scripts/google-maps/api/geojson"
meta:
  "og:description": "Load inline or remote GeoJSON into a reactive Google Maps Data layer."
  "og:image": "https://scripts.nuxt.com/_og/s/o_08ebd5ea4ab70007.png"
  "og:image:height": "600"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "<ScriptGoogleMapsGeoJson> · Nuxt Scripts"
  "twitter:image": "https://scripts.nuxt.com/_og/s/o_08ebd5ea4ab70007.png"
---

> Index of every page on this site: [llms.txt](https://scripts.nuxt.com/llms.txt)

**Api**

# **\<ScriptGoogleMapsGeoJson>**

[Copy for LLMs](https://scripts.nuxt.com/scripts/google-maps/api/geojson.md)

Renders [**GeoJSON (RFC 7946)**](https://datatracker.ietf.org/doc/html/rfc7946) through the [**Google Maps Data layer**](https://developers.google.com/maps/documentation/javascript/datalayer). Pass a URL or an inline GeoJSON object, and place the component inside [`**<ScriptGoogleMaps>**`](https://scripts.nuxt.com/scripts/google-maps/api/script-google-maps).

`**src**``string | object`** required **

The GeoJSON source. Can be a URL string or a GeoJSON object.

`**style**``google.maps.Data.StylingFunction | google.maps.Data.StyleOptions`

Styling options or a function that computes styles per feature.

## Usage

### Inline GeoJSON

```vue
<script setup lang="ts">
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' },
    },
  ],
}
</script>

<template>
  <ScriptGoogleMaps
    api-key="your-api-key"
    :map-options="{
      center: { lat: -33.885, lng: 151.225 },
      zoom: 13,
    }"
  >
    <ScriptGoogleMapsGeoJson
      :src="geoJsonData"
      :style="{ fillColor: '#4285F4', fillOpacity: 0.3, strokeColor: '#4285F4', strokeWeight: 2 }"
    />
  </ScriptGoogleMaps>
</template>
```

### Remote URL

The browser fetches remote GeoJSON with XHR, so a different origin must allow the request with CORS. Google's [**GeoJSON import guide**](https://developers.google.com/maps/documentation/javascript/importing_data#loading-data-across-domains) shows the required response header.

```vue
<template>
  <ScriptGoogleMaps api-key="your-api-key">
    <ScriptGoogleMapsGeoJson
      src="https://example.com/boundaries.geojson"
      :style="{ fillColor: '#34a853', fillOpacity: 0.2, strokeWeight: 1 }"
    />
  </ScriptGoogleMaps>
</template>
```

### Dynamic Styling Function

Pass a function to `**style**` instead of a static object to style features based on their properties.

```vue
<script setup lang="ts">
function styleFeature(feature: google.maps.Data.Feature) {
  const population = feature.getProperty('population') as number
  return {
    fillColor: population > 1000000 ? '#EA4335' : '#34a853',
    fillOpacity: 0.4,
    strokeWeight: 1,
  }
}
</script>

<template>
  <ScriptGoogleMaps api-key="your-api-key">
    <ScriptGoogleMapsGeoJson
      src="https://example.com/regions.geojson"
      :style="styleFeature"
    />
  </ScriptGoogleMaps>
</template>
```

### Feature Click Events

Listen to click events to build interactive GeoJSON layers. The event payload includes the clicked feature and its properties.

```vue
<script setup lang="ts">
function onFeatureClick(event: google.maps.Data.MouseEvent) {
  const name = event.feature.getProperty('name')
  console.log('Clicked:', name)
}
</script>

<template>
  <ScriptGoogleMaps api-key="your-api-key">
    <ScriptGoogleMapsGeoJson
      src="https://example.com/boundaries.geojson"
      :style="{ fillColor: '#4285F4', fillOpacity: 0.2 }"
      @click="onFeatureClick"
    />
  </ScriptGoogleMaps>
</template>
```

The component clears existing features and loads the new data when you replace `**src**`. It does not observe nested mutations to an inline `**src**` object. It watches `**style**` deeply and updates the layer in place. The component also emits `**addfeature**`, `**removefeature**`, `**setgeometry**`, `**setproperty**`, and `**removeproperty**`.

[Edit this page](https://github.com/nuxt/scripts/edit/main/docs/content/google-maps/2.api/9.geojson.md)

[Markdown For LLMs](https://scripts.nuxt.com/scripts/google-maps/api/geojson.md)

[**\<ScriptGoogleMapsRectangle>** Draw a reactive rectangular map overlay with resize, drag, and pointer events.](https://scripts.nuxt.com/scripts/google-maps/api/rectangle) [**Google Maps** Load interactive maps, static maps, and location search on demand.](https://scripts.nuxt.com/scripts/google-maps)

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://scripts.nuxt.com/#website","@type":"WebSite","description":"Nuxt Scripts lets you load third-party scripts with better performance, privacy, security and DX. It includes many popular third-parties out of the box.","name":"Nuxt Scripts","url":"https://scripts.nuxt.com/","publisher":{"@id":"https://scripts.nuxt.com/#identity"}},{"@id":"https://scripts.nuxt.com/scripts/google-maps/api/geojson#webpage","@type":"WebPage","description":"Load inline or remote GeoJSON into a reactive Google Maps Data layer.","name":"<ScriptGoogleMapsGeoJson>","url":"https://scripts.nuxt.com/scripts/google-maps/api/geojson","breadcrumb":{"@id":"https://scripts.nuxt.com/scripts/google-maps/api/geojson#breadcrumb"},"isPartOf":{"@id":"https://scripts.nuxt.com/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://scripts.nuxt.com/scripts/google-maps/api/geojson"]}],"primaryImageOfPage":{"@id":"https://scripts.nuxt.com/#logo"}},{"@id":"https://scripts.nuxt.com/#identity","@type":"Organization","name":"Nuxt Scripts","url":"https://scripts.nuxt.com","logo":{"@id":"https://scripts.nuxt.com/#logo"}},{"@id":"https://scripts.nuxt.com/scripts/google-maps/api/geojson#breadcrumb","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","name":"Nuxt Scripts","item":"https://scripts.nuxt.com/","position":1},{"@type":"ListItem","name":"Scripts","item":"https://scripts.nuxt.com/scripts","position":2},{"@type":"ListItem","name":"Google Maps","item":"https://scripts.nuxt.com/scripts/google-maps","position":3},{"@type":"ListItem","name":"API","item":"https://scripts.nuxt.com/scripts/google-maps/api","position":4},{"@type":"ListItem","name":"<ScriptGoogleMapsGeoJson>","item":"https://scripts.nuxt.com/scripts/google-maps/api/geojson","position":5}]},{"@id":"https://scripts.nuxt.com/#logo","@type":"ImageObject","caption":"Nuxt Scripts","contentUrl":"https://scripts.nuxt.com/logo.svg","inLanguage":"en","url":"https://scripts.nuxt.com/logo.svg"}]}
```

## Sitemap

See the full [sitemap](https://scripts.nuxt.com/sitemap.md) for all pages.
