# Map 图层

## Map 方法 · 图层管理

### initLayers(businessLayers, tagLayers?, alarmList?)

* **类型**：`Function`
* **归属**：自定义（内部大量 **OL** 建层）
* **参数**：
  * `{Object|Array} businessLayers` — 业务图层配置表（常来自 GIS_LAYER_CONFIG）。每一项关键字段：
    * `{string} code` — 图层唯一编码
    * `{string} type` — 见下方 type 表（`'1'`…`'17'` 或字面量如 `'CloudLayer'`）
    * `{string} [serviceAddress]` — 服务名 / URL
    * `{number} [serviceSublayerIndex]` — 子层顺序
    * `{string|Object} [parameter]` — JSON 字符串或对象，会 merge 进配置
    * `{string|Object} [label]` — 标注配置
    * `{string} [style]` — WMS 样式名等
    * `{boolean} [visible]`
  * `{Array<Object>} [tagLayers]` — 标注层配置
  * `{Array<{value, color}>} [alarmList]` — 告警等级配色
* **返回值**：无
* **副作用**：写入 `businessLayers`、`layers`；创建 `drawSearchTool`、`measureTool`；调用 `callback.layersReadyCallback()`
* **用法**：

```js
map.initLayers({
  pipe: {
    code: 'pipe',
    type: '5',
    serviceAddress: 'water',
    serviceSublayerIndex: 0,
    parameter: JSON.stringify({ queryable: true })
  },
  hydrant: {
    code: 'hydrant',
    type: '1',
    minZoom: 12,
    label: { minZoom: 14, field: 'name' }
  }
});
```

#### businessLayers.type 一览

| type | 含义 | 底层 |
|------|------|------|
| `1` / `CloudLayer` | 点 + 飘窗 | CloudLayer → `ol/layer/Vector` |
| `2`/`3` | ArcGIS 动态 | `ImageArcGISRest` + `ImageLayer` |
| `4` | ArcGIS 切片 | 自定义 Source + `TileLayer` |
| `5` | GeoServer WMS 聚合 | `ImageWMS`（字典键常为 `geoserver`） |
| `6` | 矢量瓦片 | VectorTileLayer |
| `7` | SuperMap WMS | WMS |
| `9` / `WMTSLayer` | WMTS | `ol/source/WMTS` |
| `11` / `GLayer` | 通用矢量 | GLayer |
| `12` / `ClusterLayer` | 聚合 | ClusterLayer |
| `13` / `ContourLayer` | 等值 | ContourLayer |
| `14` / `EchartsLayer` | ECharts | ol-echarts |
| `15` / `HeatmapLayer` | 热力 | `ol/layer/Heatmap` |
| `16` / `GeoTIFFLayer` / `TifLayer` | 服务器 GeoTIFF 栅格 | `WebGLTile` + `GeoTIFF` |
| `17` / `GraphicLayer` | Canvas 分类线/点 | GraphicLayer → 自定义 `ol/layer/Layer` |

### addLayer(options)

* **类型**：`Function`
* **参数**：
  * `{Object} options` — 至少含 `code`、`type`；其它同 `initLayers` 单项；支持 `parameter` / `label` JSON 字符串
* **返回值**：`Object|null` — 图层实例；缺 `code` 时返回 `null`
* **用法**：

```js
map.addLayer({
  code: 'tempPoint',
  type: 'CloudLayer',
  minZoom: 10
});
map.drawPoint({
  tempPoint: [{ objCode: 'T1', gpsX: 13528430, gpsY: 3676466 }]
});
```

### removeLayer(layerCode)

* **类型**：`Function`
* **参数**：
  * `{string} layerCode`
* **返回值**：无
* **相关 OL**：`map.removeLayer`
* **用法**：

```js
map.removeLayer('tempPoint');
```

### displayLayer(layerCode, bool)

* **类型**：`Function`
* **归属**：融合
* **参数**：
  * `{string} layerCode`
  * `{boolean} bool` — 是否显示
* **返回值**：无
* **说明**：按图层 type 分支：WMS/ArcGIS 会改 source `params`；矢量层调用 `setVisible`。
* **用法**：

```js
map.displayLayer('pipe', true);
map.displayLayer('hydrant', false);
```

### showLayers(layerCodes)

* **类型**：`Function`
* **参数**：
  * `{string[]} layerCodes` — 要显示的 code 列表；未列出的业务层隐藏
* **返回值**：无
* **用法**：

```js
map.showLayers(['pipe', 'valve', 'hydrant']);
```

### showTagLayers(layerCodes, tagTypes)

* **类型**：`Function`
* **参数**：
  * `{string[]} layerCodes`
  * `{string[]} tagTypes` — 标注类型
* **返回值**：无
* **用法**：

```js
map.showTagLayers(['pipe'], ['diameter', 'material']);
```

### displayPartInLayer(data)

* **类型**：`Function`
* **参数**：
  * `{Object<string, string|string[]|null>} data` — 每层要显示的 `objCode` 列表；`null` 可恢复
* **返回值**：无
* **用法**：

```js
map.displayPartInLayer({
  hydrant: ['H1', 'H3'],
  pipe: ['P100']
});
```

### displayPartByCondition(data)

* **类型**：`Function`
* **参数**：
  * `{Object} data` — 每层条件：数组走 `displayPart`；对象则写 CQL / 样式条件（依 type）
* **返回值**：无
* **用法**：

```js
map.displayPartByCondition({
  pipe: { caliber: 'DN200' },
  hydrant: [{ field: 'alarm', value: 1 }]
});
```

### changeLayerStatus(layerCode, status)

* **类型**：`Function`
* **参数**：
  * `{string} layerCode`
  * `{*} status` — 状态值（点图层样式切换）
* **返回值**：无

```js
map.changeLayerStatus('hydrant', 1);
```

### changeLayerScope(data)

* **类型**：`Function`
* **参数**：
  * `{Object} data` — 范围过滤数据
* **返回值**：无

---

## Map 方法 · 云图层（飘窗）

飘窗基于 **OL** `Overlay`；本库扩展了 `Overlay.prototype.setVisible`（融合）。

### addCloud(layerCode, cloudData)

* **类型**：`Function`
* **参数**：
  * `{string} layerCode`
  * `{Object|Array} cloudData` — 飘窗数据（含定位与 DOM/HTML）
* **返回值**：无

```js
map.addCloud('hydrant', {
  objCode: 'H1',
  content: '<div class="cloud">栓体信息</div>'
});
```

### addCloudLayer(options)

* **类型**：`Function`
* **参数**：`{Object} options` — 云图层配置
* **返回值**：无

### hideCloud(layerCode, objCode) / showCloud(layerCode, objCode)

* **类型**：`Function`
* **参数**：
  * `{string} layerCode`
  * `{string|number} objCode`
* **返回值**：无

```js
map.hideCloud('hydrant', 'H1');
map.showCloud('hydrant', 'H1');
```

### hideAllClouds(layerCode) / showAllClouds(layerCode, hideClouds?)

* **类型**：`Function`
* **参数**：
  * `{string} layerCode`
  * `{Array} [hideClouds]` — `showAllClouds` 时仍保持隐藏的 code 列表
* **返回值**：无

### clearCloudLayer(layerCode)

* **类型**：`Function`
* **参数**：`{string} layerCode`
* **返回值**：无

### addHighlightCloud(data) / destroyHighlightCloud(objCode)

* **类型**：`Function`
* **说明**：高亮专用飘窗的添加与销毁。

---

## Map 方法 · 高亮

### clearHighlight()

* **类型**：`Function`
* **参数**：无
* **返回值**：无

```js
map.clearHighlight();
```

### highlightList(data, param?)

* **类型**：`Function`
* **参数**：
  * `{Array|Object} data` — 待高亮列表。线用 `objXStart/objYStart/objXEnd/objYEnd`；点用 `objX/objY`。有 `index` 时显示序号钉标
  * `{Object} [param]`
    * `{boolean} [param.noMarker=false]` — `true` 时不画序号/结果钉，只保留 Canvas/Vector 闪烁
    * `{boolean} [param.noline=false]` — `true` 时不画线，只留钉标/点闪烁
    * `{boolean} [param.canvas=true]` — 线、点默认走 Canvas 闪烁层（约 10w 级流畅）；`false` 回退 Vector（兼容按 `index` 的 `triggerHighlight` 显隐）
    * `{boolean} [param.locateTo=false]` — 定位到第一条
    * `{string} [param.lineColor]` — 闪烁颜色，默认 `#00ff00`（线描边 / 点填充）
    * `{number} [param.lineWidth]` — 闪烁线宽，默认 `3`
    * `{number} [param.circleRadius]` — 点闪烁半径，默认 `6`
    * `{boolean} [param.halo]` — 是否带白色描边/光晕，默认 `true`
* **返回值**：无

```js
// 全量替换
map.highlightList(rows, { noMarker: true });

// 点闪烁
map.highlightList([{ objX: 13528430, objY: 3676466 }]);

// 线、点分两次写入（第二次不要再用 highlightList，否则会清空）
map.highlightList(lines, { canvas: true });
map.addHighlightList(points, { noMarker: true });

// 少量且要按序号点击显隐时，关闭 canvas
map.highlightList(rows, { canvas: false });
```

**id 规则**（`add` / `update` / `remove` 依赖）：`objCode` → `id` → `index`（加 `line:` / `point:` 前缀）→ 坐标拼串。有业务主键请带 `objCode`。Canvas 整层共用一套 `lineColor`。

### addHighlightList(data, param?)

* **类型**：`Function`
* **参数**：与 `highlightList` 相同。不清空已有高亮；同 id 则更新坐标。
* **返回值**：无

```js
map.addHighlightList(points, { noMarker: true });
```

### updateHighlightList(data, param?)

* **类型**：`Function`
* **说明**：与 `addHighlightList` 相同（upsert）。
* **返回值**：无

```js
map.updateHighlightList([{ objCode: 'P1', objX: 13528430, objY: 3676466 }]);
```

### removeHighlightList(data)

* **类型**：`Function`
* **参数**：`{Array<string|number|Object>|string|number|Object} data` — id 或行对象
* **返回值**：无

```js
map.removeHighlightList(['P1', 'L2']);
map.removeHighlightList([{ objCode: 'P1' }]);
```

### triggerHighlight(index, type, cloudData?, options?, lineData?)

* **类型**：`Function`
* **参数**：
  * `{number} index` — 列表项索引
  * `{string} type` — 高亮类型
  * `{*} [cloudData]` — 飘窗
  * `{Object} [options]`
  * `{*} [lineData]` — 线高亮数据
* **返回值**：无

```js
map.triggerHighlight(0, 'point', { html: '当前选中' });
```

### resetHighlight() / hideHighlight() / showHighlight()

* **类型**：`Function`
* **参数**：无
* **返回值**：无

### highlightGraphicInLayer(layerCode, objCode, noFeature?)

* **类型**：`Function`
* **参数**：
  * `{string} layerCode`
  * `{string|number} objCode`
  * `{boolean} [noFeature]` — 是否不依赖已有 Feature
* **返回值**：无

```js
map.highlightGraphicInLayer('hydrant', 'H1');
```

---

## Map 方法 · GLayer / 等值线

### addGLayer(options)

* **类型**：`Function`
* **参数**：`{Object} options` — 含 `code` 等，type 为 GLayer
* **返回值**：图层实例相关（内部 `_addLayer`）

```js
map.addGLayer({ code: 'sketch', type: 'GLayer' });
map.layers.sketch.addPoint([13528430, 3676466], { fill: '#f00' }, 'A');
```

### addGraphicLayer(options)

* **类型**：`Function`
* **参数**：`{Object|string} options` — 含 `code`、`series`、`style`、`highlightStyle`、`hitDetect` 等；type 固定为 GraphicLayer。字符串则视为 `code`。缺 `code` 时用 `'graphic'`。默认 `queryable: false`（不参与 WFS 点查）；默认 `hitDetect: true`（地图点击可拾取）。
* **返回值**：`GraphicLayer` 实例（内部 `addLayer`）

```js
var layer = map.addGraphicLayer({
  code: 'deviceSketch',
  series: [
    { type: 'line', style: { type: 'solid', color: '#1890ff', width: 2 },
      data: [{ objCode: 'L1', objXStart: 13528430, objYStart: 3676466, objXEnd: 13528500, objYEnd: 3676500 }] },
    { type: 'circle', style: { type: 'dash' },
      data: [{ objCode: 'P1', objX: 13528430, objY: 3676466 }] }
  ]
});
layer.highlight(['L1', 'P1']);
```

也可用 `initLayers` / `addLayer`：`type: '17'` 或 `'GraphicLayer'`。

### displayGLayer(layerCode, bool)

* **类型**：`Function`
* **参数**：`{string} layerCode`，`{boolean} bool`
* **返回值**：无

### addContour(options) / cancelContour()

* **类型**：`Function`
* **参数**：`addContour` 接收等值配置（采样点、分级色带等，见 ContourLayer）
* **返回值**：无

```js
map.addContour({ /* 点值与样式 */ });
map.cancelContour();
```

---
