# Tools 工具类

## Tools · Draw

* **归属**：融合 — `class Draw extends ol/layer/Vector`
* **说明**：构造时 `main.map.addLayer(this)`，并 `Object.assign(this, options)`。

### new Draw(main, options?)

* **参数**：
  * `{Map} main` — 业务地图
  * `{Object} [options]` — 传给 VectorLayer 的 OL 选项 + 自定义字段（如 `style`、`removeFun`）
* **用法**：

```js
import { Draw } from '@its-cool/simple-map';
const draw = new Draw(map, {
  style: [{ 'stroke-color': '#f00', 'stroke-width': 2 }]
});
```

### cancel() / clear() / remove(item) / destroy()

* **类型**：`Function`
* **说明**：取消交互 / 清空图形 / 移除单项 / 销毁图层与交互。

> 内部 `_draw(callback, options)` 不建议业务直接调用；由 Measure、DrawSearch、analysis 使用。`options.type`：`Point` / `Line` / `Polygon` 等。

---

## Tools · Measure

* **归属**：融合 — `extends Draw`

### new Measure(main)

* **参数**：`{Map} main`
* **说明**：`initLayers` 后也可通过 `map.measureTool` 访问。

### measure(type)

* **参数**：
  * `{string} type` — `'area'` → 多边形测面；其它 → 线测距
* **用法**：

```js
map.measureTool.measure('area');
// 等价
map.measure('area');
```

---

## Tools · DrawSearch

* **归属**：融合 — `extends Draw`

### draw(searchCallback, param?)

* **参数**：
  * `{Function} searchCallback`
  * `{Object} [param]`
* **实例属性**：`results`、`resultsNum`

```js
map.drawSearchTool.draw((res, num) => console.log(res, num));
```

### cancel() / clearFun()

取消 / 清理绘制查询。

---

## Tools · Tip

* **归属**：自定义

### new Tip(main, text)

* **参数**：
  * `{Map} main`
  * `{string} text`
* **方法**：
  * `changeText(text)` — 改文案
  * `destroy()` — 移除 DOM

```js
import { Tip } from '@its-cool/simple-map';
const tip = new Tip(map, '请点击地图');
tip.changeText('请双击结束');
tip.destroy();
```

---

## Tools · WriteServer

* **归属**：融合 — `extends ol/layer/Vector`
* **推荐创建**：`map.writeServer(options)`

### 常用方法

#### insertFeature(type, attributes)

* **参数**：
  * `{string} type` — 几何类型（点/线等，内部归一化）
  * `{Object} attributes` — 业务属性
* **用法**：

```js
editor.insertFeature('Point', { objCode: 'N1', name: '新点' });
```

#### editFeature(type)

* **参数**：`{string} type` — 进入对应编辑模式

#### updateFeature(properties, type, editType)

* **参数**：
  * `{Object} properties`
  * `{string} type`
  * `{string} editType`

#### deleteFeature(properties, type) / deleteFeatures(objCodes) / deleteEditFeature()

删除单个 / 批量 / 当前编辑要素。

#### save(properties?)

* **参数**：`{Object} [properties]` — 附加提交属性
* **说明**：提交 WFS 事务。

#### clearFeature() / clear() / deactivate()

清理要素或交互。

#### importData(data) / updateProperties(objCodes, properties)

导入与批量改属性。

#### selectFromLayer(layerCode, objCodes)

从业务层选中要素进入编辑。

#### getEditFeatures() / setEditFeatures(features)

读写当前编辑要素集合。

#### unionFeaturs()

合并要素（方法名保持源码拼写）。

```js
const editor = map.writeServer({ addType: 'geoserver', layerCodes: ['valve'] });
editor.insertFeature('Point', { objCode: 'V9' });
// 用户改完几何后
editor.save();
```

---

## Tools · Track

* **归属**：自定义（内部创建两条 **OL** VectorLayer）

### 实例方法摘要

| 方法 | 参数 | 说明 |
|------|------|------|
| `drawTrackLine(list)` | `Array<{gpsX,gpsY,uploadTime}>` | 绘制轨迹 |
| `drawSegmentedTrackLine(list)` | `Array<Array<point>>` | 分段轨迹 |
| `setMarkers(startCoord, endCoord)` | `number[]`, `number[]` | 起终点标记 |
| `play(index)` | `number` | 播放到进度索引 |
| `setMovePoint(bool)` | `boolean` | 移动点显隐 |
| `getSource()` | — | 线图层 `VectorSource` |
| `destroy()` | — | 移除图层 |

```js
const track = map.addTrack(() => {});
track.drawTrackLine([
  { gpsX: 13528400, gpsY: 3676400, uploadTime: '2024-01-01 10:00:00' },
  { gpsX: 13528600, gpsY: 3676600, uploadTime: '2024-01-01 10:10:00' }
]);
track.setMarkers([13528400, 3676400], [13528600, 3676600]);
track.play(0);
```

---

## Tools · Inspection

* **归属**：融合 — `extends VectorLayer`
* **创建**：`map.pipeInspection(callback, options)`

| 方法 | 说明 |
|------|------|
| `play(index)` | 巡检播放 |
| `addTrack(list)` / `addTrackLine(list)` | 添加轨迹 |
| `trackSearch(list, data, noLine?)` | 轨迹缓冲查管网；`data`：1 管网巡检点 / 2 关键巡检点 |
| `circleSearch(coord)` | 圆形搜索 |
| `moveCenter(coord)` | 移动中心 |
| `addScope(options)` | 添加范围 |
| `updatePipeDate(list)` | 更新管线数据 |
| `destroy()` | 销毁 |

```js
const insp = map.pipeInspection(console.log, { cloudLayerCodes: ['hydrant'] });
insp.addTrackLine([{ x: 13528400, y: 3676400 }, { x: 13528500, y: 3676500 }]);
```

---

## Tools · Profile

* **归属**：融合 — `extends VectorLayer`

| 方法 | 说明 |
|------|------|
| `addStartPoint()` | 起点 |
| `addMidPoints(data)` | 中间点 |
| `addEndPoint()` | 终点 |
| `addLines(data)` | 剖面线 |

```js
const profile = map.pipeProfile(console.log, {
  pipeLayerCode: 'pipe',
  flowLayerCode: 'flow'
});
profile.addStartPoint();
```

---
