主题
符号工厂
符号工厂用于定义要素的可视化样式。
G.fillSymbol(options)
创建填充符号。
ts
G.fillSymbol(options?: FillSymbolOptions): FillSymbol| 参数 | 类型 | 描述 |
|---|---|---|
| color | string | 填充颜色(CSS 颜色值) |
| outlineColor | string | 外轮廓颜色 |
| outlineWidth | number | 外轮廓宽度 |
| opacity | number | 不透明度 (0-1) |
返回对象属性:type 固定为 'fill'。
ts
const s = G.fillSymbol({
color: 'rgba(255,0,0,0.5)',
outlineColor: '#000',
outlineWidth: 1,
});G.lineSymbol(options)
创建线符号。
ts
G.lineSymbol(options?: LineSymbolOptions): LineSymbol| 参数 | 类型 | 描述 |
|---|---|---|
| color | string | 线条颜色 |
| width | number | 线条宽度(像素) |
| style | string | 线条样式('solid'、'dashed'、'dotted') |
| opacity | number | 不透明度 (0-1) |
返回对象属性:type 固定为 'line'。
ts
const s = G.lineSymbol({
color: '#3498db',
width: 5,
style: 'dashed',
});G.markerSymbol(options)
创建标记符号。
ts
G.markerSymbol(options?: MarkerSymbolOptions): MarkerSymbol| 参数 | 类型 | 描述 |
|---|---|---|
| shape | string | 图形('pin'、'circle'、'diamond'、'square'、'triangle') |
| color | string | 标记颜色 |
| size | number | 大小(像素) |
| outlineColor | string | 外轮廓颜色 |
| outlineWidth | number | 外轮廓宽度 |
返回对象属性:type 固定为 'marker'。
ts
const s = G.markerSymbol({
shape: 'pin',
color: '#e74c3c',
size: 12,
});G.textSymbol(options)
创建文本符号。
ts
G.textSymbol(options?: TextSymbolOptions): TextSymbol| 参数 | 类型 | 描述 |
|---|---|---|
| text | string | 文本内容 |
| fontSize | number | 字号 |
| fontFamily | string | 字体 |
| color | string | 文本颜色 |
| haloColor | string | 光晕颜色 |
| haloWidth | number | 光晕宽度 |
| x | number | X 偏移 |
| y | number | Y 偏移 |
返回对象属性:type 固定为 'text'。
ts
const s = G.textSymbol({
text: '北京',
fontSize: 14,
color: '#333',
haloColor: '#fff',
haloWidth: 2,
});G.pictureSymbol(options)
创建图片符号。
ts
G.pictureSymbol(options?: PictureSymbolOptions): PictureSymbol| 参数 | 类型 | 描述 |
|---|---|---|
| url | string | 图片 URL |
| width | number | 显示宽度(像素) |
| height | number | 显示高度(像素) |
ts
const s = G.pictureSymbol({
url: 'https://example.com/icon.png',
width: 24,
height: 24,
});G.iconSymbol(options)
创建图标符号(基于预定义图标集)。
ts
G.iconSymbol(options?: IconSymbolOptions): IconSymbol| 参数 | 类型 | 描述 |
|---|---|---|
| name | string | 图标名称 |
| color | string | 颜色 |
ts
const s = G.iconSymbol({ name: 'pin', color: '#e74c3c' });G.modelSymbol(options)
创建 3D 模型符号。
ts
G.modelSymbol(options?: ModelSymbolOptions): ModelSymbol| 参数 | 类型 | 描述 |
|---|---|---|
| url | string | 模型 URL(gltf/glb 格式) |
| scale | number | 缩放倍数 |
| heading | number | 朝向角度 |
ts
const s = G.modelSymbol({
url: 'https://example.com/model.gltf',
scale: 1.0,
});G.billboardSymbol(options)
创建广告牌符号(始终面向相机)。
ts
G.billboardSymbol(options?: BillboardSymbolOptions): BillboardSymbol| 参数 | 类型 | 描述 |
|---|---|---|
| fill | object | 填充配置 { color: string } |
ts
const s = G.billboardSymbol({ fill: { color: '#fff' } });G.compositeSymbol(symbols)
创建复合符号,组合多个符号。
ts
G.compositeSymbol(symbols: Symbol[]): CompositeSymbol| 参数 | 类型 | 描述 |
|---|---|---|
| symbols | Symbol[] | 符号数组(至少 2 个) |
返回对象属性:type 固定为 'composite',symbols 为子符号数组。
ts
const s = G.compositeSymbol([
G.fillSymbol({ color: 'rgba(255,0,0,0.3)' }),
G.lineSymbol({ color: '#000', width: 1 }),
]);
// s.type === 'composite'
// s.symbols.length === 2G.symbol(type, options)
通用符号工厂。
ts
G.symbol(type: string, options?: object): Symbol| 参数 | 类型 | 描述 |
|---|---|---|
| type | string | 符号类型('fill'、'line'、'marker'、'text') |
| options | object | 类型对应的选项 |
ts
const s = G.symbol('fill', { color: 'rgba(0,128,0,0.5)' });支持的类型
| type | 等效方法 |
|---|---|
'fill' | G.fillSymbol(options) |
'line' | G.lineSymbol(options) |
'marker' | G.markerSymbol(options) |
'text' | G.textSymbol(options) |