# Map 工具工厂

## Map 方法 · 工具工厂

示例页：[`/advanced`](/advanced)

### addTrack(callback, options?)

* **类型**：`Function`
* **参数**：
  * `{Function} callback` — 播放过程回调
  * `{Object} [options]`
    * `{string} [options.lineColor]` — 默认 `'green'`
    * `{number} [options.lineWidth]` — 默认 `6`
    * `{string} [options.passedLineColor]` — 默认 `'#0ff'`
    * `{boolean} [options.showLine]` — 默认 `true`
    * `{Array} [options.list]` — 初始轨迹点（含 `gpsX`/`gpsY`/`uploadTime`）
    * `{number} [options.lineZIndex]` / `{number} [options.markerZIndex]`
* **返回值**：`Track`
* **说明**：若已有 `this.track` 会先 `destroy`。
* **用法**：

```js
const track = map.addTrack((index) => console.log('play', index), {
  lineColor: '#22c55e',
  list: [
    { gpsX: 13528400, gpsY: 3676400, uploadTime: '2024-01-01 10:00:00' },
    { gpsX: 13528500, gpsY: 3676500, uploadTime: '2024-01-01 10:05:00' }
  ]
});
track.play(0);
```

### pipeInspection(callback, options)

* **类型**：`Function`
* **参数**：
  * `{Function} callback`
  * `{Object} options`
    * `{string[]} [options.cloudLayerCodes]` — 参与缓冲的云图层
    * 其它 Inspection 选项
* **返回值**：`Inspection`
* **说明**：自动注入 `layers.geoserver` 的 title 与云图层 features。

```js
const insp = map.pipeInspection((msg) => console.log(msg), {
  cloudLayerCodes: ['hydrant']
});
```

### historyDispatch(options)

* **类型**：`Function`
* **参数**：
  * `{Object} options`
    * `{string[]} options.layerCodes` — 调度点所在云图层
    * 其它 HistoryDispatch 选项
* **返回值**：`HistoryDispatch`

```js
const hd = map.historyDispatch({ layerCodes: ['vehicle'] });
hd.play(0);
```

### pipeProfile(callback, options)

* **类型**：`Function`
* **参数**：
  * `{Function} callback` — 必填
  * `{Object} options`
    * `{string} options.pipeLayerCode` — 管线层
    * `{string} options.flowLayerCode` — 流向/流量相关层
    * `{*} [options.offset]`
* **返回值**：`Profile | undefined`（callback 非法时无返回）

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

---
