ArcGIS JS 基础教程(56):Symbol 专题 - PointSymbol3D 三维点符号

ArcGIS JS 基础教程(56):Symbol 专题 - PointSymbol3D 三维点符号

零、写在前面

📌 本系列教程完整目录 :ArcGIS JS 系列基础教程(100个项目常用热门功能)

💡 在线示例 :完整可运行的 HTML 示例,无需任何环境配置,可直接在浏览器中打开体验

🗂️ 专栏导航 :收藏 + 关注,专栏文章第一时间送达

❤️ 一键三连:点赞 + 评论 + 收藏


一、功能介绍

从本课起进入三维原生符号体系 。PointSymbol3D 是三维点的标准符号类型,其核心是 symbolLayers 数组,把一个或多个「符号图层」叠加到同一个点上。

本课的主角是 ObjectSymbol3DLayer :用内置几何体模型作为三维点的显示符号。

javascript 复制代码
const symbol = {
    type: "point-3d",
    symbolLayers: [{
        type: "object",
        resource: { primitive: "sphere" },
        width: 120,
        height: 120,
        depth: 120,
        material: { color: "#12b76a" }
    }]
};

7 种内置几何体(resource.primitive)

几何体 说明 默认锚点位置
sphere 球体(默认值) 中心
cube 立方体 中心
diamond 菱形体 中心
cylinder 圆柱体 底部
cone 圆锥体 底部
inverted-cone 倒圆锥 底部
tetrahedron 四面体 底部

resource 也可以用 href 指定外部 glTF 模型 ;若 primitive 与 href 同时存在,primitive 优先。

与二维符号的本质区别

对比项 SimpleMarkerSymbol(第51课) ObjectSymbol3DLayer(本课)
尺寸单位 屏幕像素(points) 真实世界米
视觉形态 billboard 平面贴片 有体积的真实几何体
光照 / 阴影 无 受场景光照,可投射阴影
旋转 相对屏幕 heading / tilt / roll 相对地理坐标
缩放表现 远近大小不变 随距离透视缩放
自发光 无 支持 emissive

💡 三维要点 :width(东西向直径)、height(高度)、depth(南北向直径)单位都是米,这是三维符号「所见即所得」的关键。任一尺寸不设置(undefined)时,SDK 会自动按资源原始比例推算。

参考:PointSymbol3D API | ObjectSymbol3DLayer API


二、功能实现

2.1 基本结构

javascript 复制代码
{
    type: "point-3d",
    symbolLayers: [{
        type: "object",
        resource: { primitive: "sphere" },
        width: 120, height: 120, depth: 120,      // 米
        material: { color: "#12b76a" },
        heading: 0,
        castShadows: true
    }]
}

2.2 材质:颜色与自发光

javascript 复制代码
// 普通颜色
layer.material = { color: "#00e9ff" };

// 自发光:夜间场景中发亮(不依赖光照)
layer.material = {
    color: "#00e9ff",
    emissive: { strength: 1, source: "color" }
};

emissive(自发光)是三维符号独有的能力,智慧城市夜景、告警高亮都靠它。

2.3 旋转:heading / tilt / roll

javascript 复制代码
layer.heading = 180;   // 绕 z 轴(水平面),y 轴指向北,顺时针
layer.tilt = 45;       // 绕 x 轴,正值抬起前部
layer.roll = 90;       // 绕 y 轴,正值抬起左侧

三者语义的前提是资源按「前朝 y 轴、上朝 z 轴、右朝 x 轴」对齐(内置几何体均满足)。

2.4 锚点:anchor / anchorPosition

javascript 复制代码
// 默认:origin(球/立方体/菱形在中心,柱/锥在底部)
layer.anchor = "origin";

// 自定义:比例值指定,{0,0,0} 为中心,{-0.5,-0.5,-0.5} 为西南下角
layer.anchor = "relative";
layer.anchorPosition = { x: 0, y: 0, z: -0.5 };   // 等效「底部对齐」
layer.anchorPosition = { x: 0, y: 0, z: 0.5 };    // 「顶部对齐」

锚点决定符号「钉」在坐标点的哪个部位。做「从地里长出来的柱子」用底部锚点;做「悬吊的灯」用顶部锚点。

2.5 阴影与图层叠加

javascript 复制代码
layer.castShadows = false;   // 关闭单个符号的投影(默认 true)

// 一个点上叠多个 symbolLayer:如「圆柱底座 + 球体顶部」
symbolLayers: [
    { type: "object", resource: { primitive: "cylinder" }, width: 60, height: 200, ... },
    { type: "object", resource: { primitive: "sphere" }, width: 120, height: 120, ...,
      anchor: "relative", anchorPosition: { x: 0, y: 0, z: 1 } }
]

三、功能应用

场景 说明
监测站点状态标记 球体 + 绿/黄/红颜色表示运行状态
市政设施符号化 路灯(cylinder + 底部锚点)、摄像头(cube + heading 朝向)
地下管井立体标识 inverted-cone 向下示意地下设施
夜间可视化 emissive 自发光,无需外部光源
风向 / 设备朝向 heading 按属性字段旋转(配合视觉变量)
glTF 精细模型 resource.href 指向模型文件(第 61 课 Mesh 前的过渡方案)

四、核心代码

📦 完整代码 已保存至 sample/lesson56_point_symbol_3d.html,可直接在浏览器打开。

html 复制代码
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>第56课:Symbol 专题 - PointSymbol3D 三维点符号</title>
    <link rel="stylesheet" href="https://js.arcgis.com/5.0/esri/themes/light/main.css">
    <script type="module" src="https://js.arcgis.com/5.0/"></script>
    <style>
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body { font-family: "Microsoft YaHei", sans-serif; }
        #mapContainer { width: 100vw; height: 100vh; }
        .page-title {
            position: absolute; top: 20px; left: 50%; transform: translateX(-50%);
            background: rgba(255,255,255,0.95); padding: 10px 24px; border-radius: 6px;
            font-size: 18px; font-weight: bold; z-index: 100;
            box-shadow: 0 2px 8px rgba(0,0,0,0.15);
        }
        .panel {
            position: absolute; top: 80px; right: 20px; width: 300px;
            background: rgba(255,255,255,0.95); padding: 16px; border-radius: 8px;
            box-shadow: 0 2px 12px rgba(0,0,0,0.15); z-index: 100;
        }
        .panel h3 { margin: 0 0 10px 0; font-size: 14px; }
        .form-group { margin-bottom: 8px; }
        .form-group label { display: block; font-size: 12px; margin-bottom: 4px; color: #555; }
        .form-group select,
        .form-group input[type="range"] { width: 100%; }
        .form-group input[type="color"] { width: 100%; height: 28px; border: 1px solid #d9d9d9; }
        .val { float: right; color: #1890ff; font-weight: bold; }
        .btn-row { display: flex; gap: 8px; margin-top: 10px; }
        .btn-row button {
            flex: 1; padding: 6px 0; font-size: 12px;
            border: 1px solid #d9d9d9; border-radius: 4px;
            background: white; cursor: pointer;
        }
        .btn-row button:hover { border-color: #1890ff; color: #1890ff; }
        .tip {
            margin-top: 10px; padding: 8px; font-size: 11px; line-height: 1.6;
            background: #e6f7ff; border-left: 3px solid #1890ff; border-radius: 3px; color: #003a8c;
        }
        .status {
            position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
            background: rgba(0,0,0,0.7); color: white; padding: 8px 20px;
            border-radius: 20px; font-size: 13px; z-index: 100; pointer-events: none;
        }
    </style>
</head>
<body>
<h1 class="page-title">第56课:Symbol 专题 - PointSymbol3D 三维点符号</h1>

<div class="panel">
    <h3>🔷 ObjectSymbol3DLayer 参数</h3>

    <div class="form-group">
        <label>几何体 primitive</label>
        <select id="selPrimitive">
            <option value="sphere">sphere 球体(默认,锚点在中心)</option>
            <option value="cube">cube 立方体(锚点在中心)</option>
            <option value="diamond">diamond 菱形体(锚点在中心)</option>
            <option value="cylinder">cylinder 圆柱体(锚点在底部)</option>
            <option value="cone">cone 圆锥体(锚点在底部)</option>
            <option value="inverted-cone">inverted-cone 倒圆锥(锚点在底部)</option>
            <option value="tetrahedron">tetrahedron 四面体(锚点在底部)</option>
        </select>
    </div>

    <div class="form-group">
        <label>宽度 width(米)<span class="val" id="vWidth">120</span></label>
        <input type="range" id="rngWidth" min="20" max="400" step="10" value="120">
    </div>

    <div class="form-group">
        <label>高度 height(米)<span class="val" id="vHeight">120</span></label>
        <input type="range" id="rngHeight" min="20" max="400" step="10" value="120">
    </div>

    <div class="form-group">
        <label>深度 depth(米)<span class="val" id="vDepth">120</span></label>
        <input type="range" id="rngDepth" min="20" max="400" step="10" value="120">
    </div>

    <div class="form-group">
        <label>颜色 material.color</label>
        <input type="color" id="clrColor" value="#12b76a">
    </div>

    <div class="form-group">
        <label>旋转 heading(度)<span class="val" id="vHeading">0</span></label>
        <input type="range" id="rngHeading" min="0" max="360" step="15" value="0">
    </div>

    <div class="form-group">
        <label>锚点 anchor</label>
        <select id="selAnchor">
            <option value="origin">origin 默认锚点</option>
            <option value="bottom">relative + 底部对齐</option>
            <option value="top">relative + 顶部对齐</option>
        </select>
    </div>

    <div class="btn-row">
        <button id="btnEmissive">切换自发光</button>
        <button id="btnShadow">切换投影</button>
    </div>

    <div class="tip">
        💡 尺寸单位是<b>真实世界米</b>,会随距离透视缩放;
        任一尺寸留空(undefined)会自动按比例计算。
        自发光 <code>emissive</code> 让符号在夜间场景中发亮。
    </div>
</div>

<div class="status" id="st">PointSymbol3D | 调整参数观察真实三维几何体的变化</div>
<div id="mapContainer"></div>

<script type="module">
    const Map = await $arcgis.import("@arcgis/core/Map.js");
    const SceneView = await $arcgis.import("@arcgis/core/views/SceneView.js");
    const GraphicsLayer = await $arcgis.import("@arcgis/core/layers/GraphicsLayer.js");
    const Graphic = await $arcgis.import("@arcgis/core/Graphic.js");
    const Point = await $arcgis.import("@arcgis/core/geometry/Point.js");
    const ElevationLayer = await $arcgis.import("@arcgis/core/layers/ElevationLayer.js");
    const getTianditu = await $arcgis.import("https://openlayers.vip/examples/resources/tianditu.js");

    const tl = getTianditu.default({ type: "vec_w" });
    const map = new Map({
        basemap: { baseLayers: [tl.base, tl.anno] },
        ground: {
            surface: {
                elevationLayers: [new ElevationLayer({
                    url: "https://www.geosceneonline.cn/image/rest/services/OpenData/ChinaTerrain3D/ImageServer/"
                })]
            }
        }
    });

    const view = new SceneView({
        container: "mapContainer",
        map: map,
        camera: { position: { longitude: 116.397, latitude: 39.900, z: 1000 }, heading: 10, tilt: 62 },
        environment: { lighting: { directShadowsEnabled: true } }
    });

    const gl = new GraphicsLayer({ title: "监测站点", elevationInfo: { mode: "relative-to-ground" } });
    map.add(gl);

    // 一排监测站(默认绿色球体)
    const stations = [
        { x: 116.3880, y: 39.9060, name: "监测站-1" },
        { x: 116.3940, y: 39.9080, name: "监测站-2" },
        { x: 116.4000, y: 39.9050, name: "监测站-3" },
        { x: 116.4060, y: 39.9080, name: "监测站-4" }
    ];

    const cfg = {
        primitive: "sphere", width: 120, height: 120, depth: 120,
        color: "#12b76a", heading: 0, anchor: "origin",
        emissive: false, castShadows: true
    };

    function buildSymbol() {
        const layer = {
            type: "object",
            resource: { primitive: cfg.primitive },
            width: cfg.width,
            height: cfg.height,
            depth: cfg.depth,
            heading: cfg.heading,
            castShadows: cfg.castShadows
        };
        // 材质:普通颜色或自发光
        layer.material = cfg.emissive
            ? { color: cfg.color, emissive: { strength: 1, source: "color" } }
            : { color: cfg.color };
        // 锚点
        if (cfg.anchor === "bottom") {
            layer.anchor = "relative";
            layer.anchorPosition = { x: 0, y: 0, z: -0.5 };
        } else if (cfg.anchor === "top") {
            layer.anchor = "relative";
            layer.anchorPosition = { x: 0, y: 0, z: 0.5 };
        } else {
            layer.anchor = "origin";
        }
        return { type: "point-3d", symbolLayers: [layer] };
    }

    function rebuild() {
        const symbol = buildSymbol();
        gl.removeAll();
        stations.forEach((s, i) => {
            gl.add(new Graphic({
                geometry: new Point({ longitude: s.x, latitude: s.y, z: 30, spatialReference: { wkid: 4326 } }),
                symbol: symbol,
                attributes: { OBJECTID: i + 1, NAME: s.name }
            }));
        });
        setStatus("已更新:" + cfg.primitive + " | " + cfg.width + "×" + cfg.height + "×" + cfg.depth + " 米");
    }

    function setStatus(msg) { document.getElementById("st").textContent = msg; }

    document.getElementById("selPrimitive").onchange = (e) => { cfg.primitive = e.target.value; rebuild(); };
    document.getElementById("rngWidth").oninput = (e) => {
        cfg.width = Number(e.target.value);
        document.getElementById("vWidth").textContent = cfg.width;
        rebuild();
    };
    document.getElementById("rngHeight").oninput = (e) => {
        cfg.height = Number(e.target.value);
        document.getElementById("vHeight").textContent = cfg.height;
        rebuild();
    };
    document.getElementById("rngDepth").oninput = (e) => {
        cfg.depth = Number(e.target.value);
        document.getElementById("vDepth").textContent = cfg.depth;
        rebuild();
    };
    document.getElementById("clrColor").oninput = (e) => { cfg.color = e.target.value; rebuild(); };
    document.getElementById("rngHeading").oninput = (e) => {
        cfg.heading = Number(e.target.value);
        document.getElementById("vHeading").textContent = cfg.heading;
        rebuild();
    };
    document.getElementById("selAnchor").onchange = (e) => { cfg.anchor = e.target.value; rebuild(); };
    document.getElementById("btnEmissive").onclick = (e) => {
        cfg.emissive = !cfg.emissive;
        e.target.textContent = cfg.emissive ? "关闭自发光" : "开启自发光";
        rebuild();
    };
    document.getElementById("btnShadow").onclick = (e) => {
        cfg.castShadows = !cfg.castShadows;
        e.target.textContent = cfg.castShadows ? "关闭投影" : "开启投影";
        rebuild();
    };

    await view.when();
    rebuild();
    view.goTo(gl.graphics.toArray(), { duration: 1500 }).catch(() => {});
    setStatus("PointSymbol3D 示例就绪 | 切换几何体观察真实体积与光照");
</script>
</body>
</html>

五、在线示例

🔗 在线体验 :https://southjor.github.io/arcgis-examples/lessons/lesson56.html

操作说明:

  1. 场景中四个监测站默认为绿色球体(120 米见方),切换「几何体 primitive」体验全部 7 种内置模型。
  2. 拖动「宽 / 高 / 深」滑块,注意单位是米且三轴独立,把 height 拉满可做出「柱状」效果。
  3. 切换「锚点」为底部对齐,几何体会「立」在坐标点上(如圆柱、锥体)。
  4. 点击「切换自发光」,符号在场景光照之外独立发亮;「切换投影」控制是否投射阴影。
  5. 旋转场景观察:三维几何体有真实的透视与遮挡,与第 51 课的 billboard 贴片形成鲜明对比。

六、关键 API 说明

API 说明
PointSymbol3D 三维点符号容器,type: "point-3d"
symbolLayers 符号图层数组,可叠加多个图层
ObjectSymbol3DLayer 几何体符号图层,type: "object"
resource.primitive 7 种内置几何体:sphere(默认)/ cube / diamond / cylinder / cone / inverted-cone / tetrahedron
resource.href 外部 glTF 模型地址(与 primitive 同时存在时 primitive 优先)
width / height / depth 三轴尺寸,单位米;留空自动按比例推算
material.color 材质颜色,支持 hex / rgb(a) / CSS 颜色名
material.emissive 自发光 `{ strength, source: "color"
heading / tilt / roll 三轴旋转(度),相对地理坐标
anchor / anchorPosition 锚点:"origin" 或 "relative" + 比例位置
castShadows 是否投射阴影(默认 true,4.11+)

参考链接:


七、系列导航

⬅️ 上一篇 :ArcGIS JS 基础教程(55):Symbol 专题 图片符号

➡️ 下一篇 :ArcGIS JS 基础教程(57):IconSymbol3D 图标符号


💡 小贴士 :三维符号最容易犯的错是拿二维的数值直觉来填 ,size: 12 在二维里是 12 像素的小点,而三维的 width: 12 只有 12 米,在俯瞰视角下小到几乎看不见。经验值:城市级场景的标记球体给 100~300 米才醒目。另一个技巧是「多 symbolLayer 叠加」:圆柱底座 + 球体顶部可以拼出路灯/信号塔造型,配合 anchorPosition 精确对位,不用外部模型也能搭出组合体。

相关推荐
行者-全栈开发16 天前
【供应链攻击】CVE-2026-45321:TanStack供应链攻击漏洞深度解析与修复指南
arcgis
思特奇时空智能17 天前
大规模点要素地图渲染性能优化实践
vue.js·arcgis·性能优化·node.js·html·gis·webgl
上海懒图科技24 天前
工厂厂区电子地图定位导航:厂区人车精准定位,安全合规双保障
前端·arcgis·vue
非科班Java出身GISer1 个月前
ArcGIS JS 基础教程(48):SceneView watch 状态监听
arcgis·arcgis js基础·arcgis js入门·arcgis js监听状态·arcgis js监听事件·arcgis js 监听飞行·arcgis js 监听功能
JudithHuang1 个月前
React 嵌套路由与布局
前端·react.js·arcgis·react·react router
Dxy12393102161 个月前
JS DES 加密详解
开发语言·javascript·arcgis
非科班Java出身GISer1 个月前
ArcGIS JS 基础教程(46):编辑要素属性 FeatureForm
arcgis·arcgis js编辑要素·arcgis js 要素·arcgis js要素属性·arcgis js 编辑属性·arcgis js编辑要素属性
梅如你1 个月前
ISPRS | 1990-2020年间中国人工林与天然林的空间分布数据
arcgis·gis·遥感
limit00751 个月前
公开 WMTS / XYZ 瓦片接入 Cesium:6 类常见问题与排查顺序
chrome·低代码·arcgis·web3·旅游