Three Vue3Three Vue3
指南
在线演示
AI 智能体
  • English
  • 简体中文
GitHub
指南
在线演示
AI 智能体
  • English
  • 简体中文
GitHub
    • 快速开始
    • 场景
    • 参数总线
    • 天空盒
    • 模型加载器

      • 组件加载器
      • 函数加载器
    • 弹出窗口
    • 标注
    • 动态元素
    • 动画
    • 模型旋转器
    • 拾取
    • 相机自适应
    • 网格模型

      • 波动圆
      • 流动线网格
    • 效果

      • 自然

        • 雨
        • 雪
        • 海洋水面
        • 互动水池
        • 沙滩漫步
      • 天空与大气

        • 天空穹顶
        • 高度雾
        • 星云星系
      • 光照

        • 泛光
        • 扫光
        • 灯光渐变
        • 光柱
        • 雷达扫描
        • 信号波
        • 力场护盾
      • 粒子与精灵

        • 烟花
        • 文字烟花
        • 光晕精灵
    • 地理

      • 地理参考系
      • GeoObject 地理对象
      • GeoJsonLayer 图层
        • 默认用法
        • GCJ02 / BD09 数据
        • Props
        • GeoJsonStyle
        • 事件
      • 瓦片图层

类型

组件

默认用法

GeoJsonLayer 在 Scene 的 GeoReference 中渲染 GeoJSON 数据(FeatureCollection、Feature 或裸几何体)。支持的几何类型包括 Point、MultiPoint、LineString、MultiLineString、Polygon 和 MultiPolygon,并支持多边形孔洞。

  • 点使用一次合并的 LineSegments 绘制调用渲染为菱形标记。
  • 线使用 LineSegments 渲染为环。
  • 多边形渲染为贴地填充(ShapeGeometry);当 extrudeHeight > 0 时渲染为拉伸块(ExtrudeGeometry)。
  • featureStyle 返回 null 时会完全跳过该要素。
点击我查看代码
<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 }) => {
  // 固定的南侧视角向北俯视数据集。
  scene.setPosition(camera, { x: 0, y: 500, z: 700 })
  camera.lookAt(0, 0, 0)
}
</script>

GCJ02 / BD09 数据

当数据本身经过加密(来自国内地图服务的瓦片或导出数据常见这种情况)时,给图层传入 datum,或在 Scene 上统一设置一次。坐标在投影前会自动归一化。

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

Props

名称类型默认值描述
dataGeoJsonData—FeatureCollection、Feature 或裸几何体对象
datum'WGS84' | 'GCJ02' | 'BD09'Scene 的 datum要素坐标所使用的基准面
styleGeoJsonStyle见下文所有要素的基础样式
featureStyle(feature: GeoJsonFeature) => GeoJsonStyle | null | undefined—逐要素样式覆盖;返回 null 跳过该要素
onReady(group: THREE.Group) => void—图层构建完成并加入场景后触发
sceneTHREE.Scene上下文中的 scene非 Scene 用法下显式指定场景

GeoJsonStyle

属性类型默认值描述
fillColorColorRepresentation0x4a90d9多边形填充色
strokeColorColorRepresentation0x9fd0ff多边形描边与线要素颜色
pointColorColorRepresentation0xffd166点标记颜色
pointSizenumber20点标记的世界尺寸(米)
extrudeHeightnumber0多边形拉伸高度(米);0 表示贴地渲染
opacitynumber0.85填充透明度

事件

名称参数描述
onReady(group: THREE.Group) => void图层组加入场景后触发一次
在 GitHub 上编辑此页
Last Updated:
Contributors: Shing Rui
Prev
GeoObject 地理对象
Next
瓦片图层