Appearance
Poi2
说明
Poi2 是一个地图兴趣点类,用于在地图上渲染带有图标和文字的标记点。
构造函数
typescript
new Poi2(context: Context, options?: Partial<PoiOptions2>);
参数
参数 | 类型 | 说明 | 默认值 |
---|---|---|---|
context | Context | 地图上下文 | - |
options | Partial<PoiOptions2> | POI配置 | {} |
返回值
Poi2 实例
属性
options
- 类型:
PoiOptions2
- 默认值:见下方默认配置
POI配置项,包含以下字段:
字段 | 类型 | 说明 | 默认值 |
---|---|---|---|
text | string | POI文本内容 | "" |
icon | string | POI图标URL | "" |
icon_size | [number, number] | 图标尺寸[宽,高] | [22, 22] |
level | number | 渲染优先级 | 1 |
collision_enable | boolean | 是否参与碰撞检测 | true |
opacity | number | 整体透明度 | 1 |
id | string | POI唯一标识 | "" |
position | { x: number; y: number; z: number } | POI位置坐标 | { x: 0, y: 0, z: 0 } |
text_font_size | number | 文本字体大小 | 14 |
icon_rotate | number | 图标旋转角度 | 0 |
depth_test | boolean | 是否进行深度测试 | false |
hide_text | boolean | 是否隐藏文本 | false |
icon_border | { width: number; color: string } | 图标边框配置 | undefined |
maxWeight | number | 最大权重 | 25 |
minWeight | number | 最小权重 | 1 |
text_opacity | number | 文本透明度 | 1 |
icon_opacity | number | 图标透明度 | 1 |
visible
- 类型:
boolean
- 默认值:
true
POI是否可见
方法
getPosition
typescript
getPosition(): Vector3;
获取POI的位置
返回值
返回POI的位置坐标
dispose
typescript
dispose(): void;
销毁POI实例
事件
change-{property}
typescript
(event: `change-${keyof PoiOptions2}`, args: { value: any }): void;
当POI的任意配置项发生变化时触发
参数
参数 | 类型 | 说明 | 默认值 |
---|---|---|---|
value | any | 变化后的值 | - |
使用示例
typescript
poi.addEventListener("change-text", ({ value }) => {
console.log("text changed to:", value);
});