Three Vue3Three Vue3
Guide
Demo
AI Agents
  • English
  • 简体中文
GitHub
Guide
Demo
AI Agents
  • English
  • 简体中文
GitHub
    • Getting Started
    • Scene
    • Parameter Bus
    • SkyBox
    • Model Loader

      • Component Loader
      • Function Loader
    • Popup
    • Callout
    • Movable Element
    • Animation
    • Model Rotator
    • Picker
    • Fit Camera
    • Mesh

      • Wave Circle Mesh
      • Flow Line Mesh
    • Effect

      • Nature

        • Rain
        • Snow
        • Water
        • Water Pool
        • Sandy Beach
      • Sky & Atmosphere

        • Sky Dome
        • HeightFog
        • Nebula Galaxy
      • Light

        • Bloom
        • Sweep Light
        • Light Gradient
        • Light Pillar
        • Radar Sweep
        • Signal Wave
        • Force Shield
      • Particles & Sprites

        • Fireworks
        • Text Fireworks
        • Glow Sprite
    • GIS

      • Geographic Reference
      • GeoObject
      • GeoJsonLayer
        • Default Usage
        • GCJ02 / BD09 Data
        • Props
        • GeoJsonStyle
        • Events
      • Tile Layer

type

Component

Default Usage

GeoJsonLayer renders GeoJSON data (FeatureCollection, Feature or a bare geometry) inside the Scene's GeoReference. Supported geometry types are Point, MultiPoint, LineString, MultiLineString, Polygon and MultiPolygon, including polygon holes.

  • Points render as diamond markers using one merged LineSegments draw call.
  • Lines render as LineSegments rings.
  • Polygons render as flat ground fills (ShapeGeometry) or extruded blocks (ExtrudeGeometry) when extrudeHeight > 0.
  • Returning null from featureStyle skips a feature entirely.
Click me to view the codes
<template>
  <tv-scene
    class="scene"
    bg-color="rgb(40, 42, 54)"
    :origin="ORIGIN"
    :grid-helper="GRID"
    @created="created"
  >
    <GeoJsonLayer
      :data="data"
      :style="{ strokeColor: 0x9fd0ff, pointColor: 0xffd166, pointSize: 40 }"
      :feature-style="featureStyle"
    />
  </tv-scene>
</template>

<script lang="ts" setup>
import { GeoJsonLayer } from 'three-vue3'
import type { GeoJsonData, GeoJsonFeature, GeoJsonStyle } from 'three-vue3'

const ORIGIN = { lng: 116.397, lat: 39.909 }
const GRID = { size: 1200, divisions: 24, colorCenterLine: 0x4a6fa5, colorGrid: 0x2f3e5c }

const data: GeoJsonData = {
  type: 'FeatureCollection',
  features: [
    {
      type: 'Feature',
      properties: { kind: 'park' },
      geometry: {
        type: 'Polygon',
        coordinates: [
          [
            [116.395, 39.9095],
            [116.399, 39.9095],
            [116.399, 39.9115],
            [116.395, 39.9115],
            [116.395, 39.9095]
          ]
        ]
      }
    },
    {
      type: 'Feature',
      properties: {},
      geometry: {
        type: 'Point',
        coordinates: [116.397, 39.909]
      }
    }
  ]
}

const COLORS: Record<string, GeoJsonStyle> = {
  park: { fillColor: 0x4caf50, strokeColor: 0xb9f6ca, opacity: 0.7 }
}

const featureStyle = (feature: GeoJsonFeature): GeoJsonStyle | undefined => {
  const kind = feature.properties?.kind
  return typeof kind === 'string' ? COLORS[kind] : undefined
}

const created = (scene, { camera }) => {
  // A fixed south-side viewpoint looks north over the dataset.
  scene.setPosition(camera, { x: 0, y: 500, z: 700 })
  camera.lookAt(0, 0, 0)
}
</script>

GCJ02 / BD09 Data

When the data itself is encrypted (the typical case for tiles or data exported from Chinese map services), pass datum to the layer or set it once on the Scene. Coordinates are normalized before projection.

<GeoJsonLayer :data="amapData" datum="GCJ02" />

Props

NameTypeDefaultDescription
dataGeoJsonData—A FeatureCollection, Feature or bare geometry object
datum'WGS84' | 'GCJ02' | 'BD09'Scene datumDatum of the feature coordinates
styleGeoJsonStylesee belowBase style for all features
featureStyle(feature: GeoJsonFeature) => GeoJsonStyle | null | undefined—Per-feature override; null skips the feature
onReady(group: THREE.Group) => void—Fired when the layer has been built and added
sceneTHREE.Scenecontext sceneExplicit scene for non-Scene usage

GeoJsonStyle

PropertyTypeDefaultDescription
fillColorColorRepresentation0x4a90d9Polygon fill color
strokeColorColorRepresentation0x9fd0ffPolygon outline and line string color
pointColorColorRepresentation0xffd166Point marker color
pointSizenumber20Point marker size in world metres
extrudeHeightnumber0Polygon extrusion height in metres; 0 renders flat
opacitynumber0.85Fill opacity

Events

NameParametersDescription
onReady(group: THREE.Group) => voidFired once after the layer group is added to the scene
Edit this page on GitHub
Last Updated:
Contributors: Shing Rui
Prev
GeoObject
Next
Tile Layer