@taichina/map-sdk 1.0.0 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -17
- package/package.json +2 -4
- package/teee-sdk/teee-map-sdk.es.js +47 -34
- package/teee-sdk/teee-map-sdk.umd.js +2 -2
- package/teee-sdk/index.d.ts +0 -181
package/README.md
CHANGED
|
@@ -5,14 +5,24 @@
|
|
|
5
5
|
## 安装
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
+
npm install @taichina/map-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 开发
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
git clone ssh://git@css.teeechina.com:8882/rswp/teeemap-sdk.git
|
|
15
|
+
cd teeemap-sdk
|
|
8
16
|
npm install
|
|
9
17
|
git submodule update --init --recursive
|
|
18
|
+
npm run build
|
|
10
19
|
```
|
|
11
20
|
|
|
12
21
|
## 快速开始
|
|
13
22
|
|
|
14
23
|
```typescript
|
|
15
|
-
import { TeeeMap } from "
|
|
24
|
+
import { TeeeMap } from "@taichina/map-sdk";
|
|
25
|
+
import maplibregl from "maplibre-gl";
|
|
16
26
|
|
|
17
27
|
const teeeMap = new TeeeMap("map-container");
|
|
18
28
|
|
|
@@ -39,7 +49,7 @@ const map = teeeMap.getMap();
|
|
|
39
49
|
|
|
40
50
|
```typescript
|
|
41
51
|
// ES Module
|
|
42
|
-
import { TeeeMap } from "
|
|
52
|
+
import { TeeeMap } from "@taichina/map-sdk";
|
|
43
53
|
```
|
|
44
54
|
|
|
45
55
|
## API
|
|
@@ -47,13 +57,12 @@ import { TeeeMap } from "teee-map-sdk";
|
|
|
47
57
|
### 构造函数
|
|
48
58
|
|
|
49
59
|
```typescript
|
|
50
|
-
new TeeeMap(container: string | HTMLElement
|
|
60
|
+
new TeeeMap(container: string | HTMLElement)
|
|
51
61
|
```
|
|
52
62
|
|
|
53
63
|
| 参数 | 说明 |
|
|
54
64
|
|------|------|
|
|
55
65
|
| `container` | DOM 元素 ID 或 HTMLElement |
|
|
56
|
-
| `mbtileDbClient` | 可选。SQLite 客户端(需具备 `prepare` / `get` / `free` 方法),传入后启用 `mbtiles://` 协议 |
|
|
57
66
|
|
|
58
67
|
### 地图创建方法
|
|
59
68
|
|
|
@@ -131,15 +140,6 @@ draw.clear(); // 清空画布
|
|
|
131
140
|
| `getMapConfigs()` | 获取当前 `MapForgeConfig` |
|
|
132
141
|
| `destroy()` | 销毁地图实例 |
|
|
133
142
|
|
|
134
|
-
### LayerType
|
|
135
|
-
|
|
136
|
-
```typescript
|
|
137
|
-
type LayerType =
|
|
138
|
-
| "background" | "track" | "track_circuit"
|
|
139
|
-
| "signal" | "switch" | "switch_loc"
|
|
140
|
-
| "bumper" | "insulation" | "label" | "prevention";
|
|
141
|
-
```
|
|
142
|
-
|
|
143
143
|
## 构建
|
|
144
144
|
|
|
145
145
|
```bash
|
|
@@ -163,7 +163,9 @@ npm run build # 输出到 teee-sdk/
|
|
|
163
163
|
|
|
164
164
|
## 依赖
|
|
165
165
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
166
|
+
| 包 | 版本 | 说明 |
|
|
167
|
+
|------|------|------|
|
|
168
|
+
| `maplibre-gl` | ^5.24.0 | peer,需自行安装 |
|
|
169
|
+
| `@turf/bbox` | ^7.0.0 | GeoJSON 包围盒计算 |
|
|
170
|
+
| `@watergis/maplibre-gl-terradraw` | ^1.13.1 | 绘制工具 |
|
|
171
|
+
| `pako` | ^2.1.0 | MBTiles Gzip 解压 |
|
package/package.json
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taichina/map-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "基于 GIS 的铁路业务地图 SDK。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./teee-sdk/teee-map-sdk.umd.js",
|
|
7
7
|
"module": "./teee-sdk/teee-map-sdk.es.js",
|
|
8
|
-
"types": "./teee-sdk/index.d.ts",
|
|
9
8
|
"exports": {
|
|
10
9
|
".": {
|
|
11
|
-
"types": "./teee-sdk/index.d.ts",
|
|
12
10
|
"import": "./teee-sdk/teee-map-sdk.es.js",
|
|
13
11
|
"require": "./teee-sdk/teee-map-sdk.umd.js",
|
|
14
12
|
"default": "./teee-sdk/teee-map-sdk.es.js"
|
|
@@ -19,7 +17,7 @@
|
|
|
19
17
|
"teee-sdk"
|
|
20
18
|
],
|
|
21
19
|
"scripts": {
|
|
22
|
-
"build": "vite build
|
|
20
|
+
"build": "vite build",
|
|
23
21
|
"update-submodule": "git submodule update --remote --merge",
|
|
24
22
|
"prepublishOnly": "npm run build",
|
|
25
23
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -88,17 +88,17 @@ var n = async () => {
|
|
|
88
88
|
let r = document.createElement("canvas");
|
|
89
89
|
r.width = 66, r.height = 64;
|
|
90
90
|
let i = r.getContext("2d");
|
|
91
|
-
return i.clearRect(0, 0, r.width, r.height), n === 2 && (i.translate(66, 0), i.scale(-1, 1)), e === 1 ? (i.beginPath(), i.arc(46, 20, 20 - 4 / 2, 0, Math.PI * 2), i.fillStyle = t || "rgb(255,255,255,0)", i.strokeStyle = t || l.BASE_COLOR, i.lineWidth = 4, i.fill(), i.stroke(), i.beginPath(), i.moveTo(6, 40 / 2), i.lineTo(26, 40 / 2), i.lineWidth = 4, i.strokeStyle = l.BASE_COLOR, i.stroke(), i.beginPath(), i.lineCap = "round", i.moveTo(8 / 2, 0), i.lineTo(8 / 2, 40), i.lineWidth = 4, i.strokeStyle = l.BASE_COLOR, i.stroke(), i.beginPath(), i.moveTo(8 / 2, 40), i.lineTo(8 / 2, 64), i.lineWidth = 8, i.strokeStyle = l.BASE_COLOR, i.stroke(), r) : (i.beginPath(), i.arc(26, 20, 20 - 4 / 2, 0, Math.PI * 2), i.fillStyle = t || "rgb(255,255,255,0)", i.strokeStyle = t || l.BASE_COLOR, i.lineWidth = 4, i.fill(), i.stroke(), i.beginPath(), i.lineCap = "round", i.moveTo(8 / 2, 0), i.lineTo(8 / 2, 40), i.lineWidth = 4, i.strokeStyle = l.BASE_COLOR, i.stroke(), i.beginPath(), i.moveTo(8 / 2, 40), i.lineTo(8 / 2, 64), i.lineWidth = 8, i.strokeStyle = l.BASE_COLOR, i.stroke(), r);
|
|
91
|
+
return i ? (i.clearRect(0, 0, r.width, r.height), n === 2 && (i.translate(66, 0), i.scale(-1, 1)), e === 1 ? (i.beginPath(), i.arc(46, 20, 20 - 4 / 2, 0, Math.PI * 2), i.fillStyle = t || "rgb(255,255,255,0)", i.strokeStyle = t || l.BASE_COLOR, i.lineWidth = 4, i.fill(), i.stroke(), i.beginPath(), i.moveTo(6, 40 / 2), i.lineTo(26, 40 / 2), i.lineWidth = 4, i.strokeStyle = l.BASE_COLOR, i.stroke(), i.beginPath(), i.lineCap = "round", i.moveTo(8 / 2, 0), i.lineTo(8 / 2, 40), i.lineWidth = 4, i.strokeStyle = l.BASE_COLOR, i.stroke(), i.beginPath(), i.moveTo(8 / 2, 40), i.lineTo(8 / 2, 64), i.lineWidth = 8, i.strokeStyle = l.BASE_COLOR, i.stroke(), r) : (i.beginPath(), i.arc(26, 20, 20 - 4 / 2, 0, Math.PI * 2), i.fillStyle = t || "rgb(255,255,255,0)", i.strokeStyle = t || l.BASE_COLOR, i.lineWidth = 4, i.fill(), i.stroke(), i.beginPath(), i.lineCap = "round", i.moveTo(8 / 2, 0), i.lineTo(8 / 2, 40), i.lineWidth = 4, i.strokeStyle = l.BASE_COLOR, i.stroke(), i.beginPath(), i.moveTo(8 / 2, 40), i.lineTo(8 / 2, 64), i.lineWidth = 8, i.strokeStyle = l.BASE_COLOR, i.stroke(), r)) : r;
|
|
92
92
|
}, d = () => {
|
|
93
93
|
let e = document.createElement("canvas");
|
|
94
94
|
e.width = 24, e.height = 64;
|
|
95
95
|
let t = e.getContext("2d");
|
|
96
|
-
return t.fillStyle = l.BG_COLOR, t.fillRect(0, 0, 24, 64), t.strokeStyle = l.BASE_COLOR, t.lineWidth = 8, t.strokeRect(0, 0, 24, 64), e;
|
|
96
|
+
return t ? (t.fillStyle = l.BG_COLOR, t.fillRect(0, 0, 24, 64), t.strokeStyle = l.BASE_COLOR, t.lineWidth = 8, t.strokeRect(0, 0, 24, 64), e) : e;
|
|
97
97
|
}, f = () => {
|
|
98
98
|
let e = document.createElement("canvas");
|
|
99
99
|
e.width = 15, e.height = 40;
|
|
100
100
|
let t = e.getContext("2d");
|
|
101
|
-
return t.clearRect(0, 0, e.width, e.height), t.beginPath(), t.moveTo(0, 4 / 2), t.lineTo(15 - 4 / 2, 4 / 2), t.moveTo(4 / 2, 4 / 2), t.lineTo(4 / 2, 36), t.moveTo(0, 36), t.lineTo(15 - 4 / 2, 36), t.lineWidth = 4, t.strokeStyle = l.BASE_COLOR, t.stroke(), e;
|
|
101
|
+
return t ? (t.clearRect(0, 0, e.width, e.height), t.beginPath(), t.moveTo(0, 4 / 2), t.lineTo(15 - 4 / 2, 4 / 2), t.moveTo(4 / 2, 4 / 2), t.lineTo(4 / 2, 36), t.moveTo(0, 36), t.lineTo(15 - 4 / 2, 36), t.lineWidth = 4, t.strokeStyle = l.BASE_COLOR, t.stroke(), e) : e;
|
|
102
102
|
}, p = async (e = "h", t = "r", n = "") => {
|
|
103
103
|
let r = u(e == "h" ? 1 : 2, n, t == "l" ? 1 : 2), i = new Image();
|
|
104
104
|
return i.src = r.toDataURL(), new Promise((e, t) => {
|
|
@@ -1219,7 +1219,7 @@ var n = async () => {
|
|
|
1219
1219
|
"2",
|
|
1220
1220
|
"lightgreen",
|
|
1221
1221
|
"3",
|
|
1222
|
-
"
|
|
1222
|
+
"yellow",
|
|
1223
1223
|
"4",
|
|
1224
1224
|
"red",
|
|
1225
1225
|
"white"
|
|
@@ -1246,7 +1246,7 @@ var n = async () => {
|
|
|
1246
1246
|
"2",
|
|
1247
1247
|
"green",
|
|
1248
1248
|
"3",
|
|
1249
|
-
"
|
|
1249
|
+
"yellow",
|
|
1250
1250
|
"4",
|
|
1251
1251
|
"red",
|
|
1252
1252
|
"white"
|
|
@@ -1361,7 +1361,7 @@ var n = async () => {
|
|
|
1361
1361
|
],
|
|
1362
1362
|
paint: {
|
|
1363
1363
|
"line-width": 4,
|
|
1364
|
-
"line-color": "
|
|
1364
|
+
"line-color": "yellow",
|
|
1365
1365
|
"line-opacity": [
|
|
1366
1366
|
"case",
|
|
1367
1367
|
[
|
|
@@ -4330,7 +4330,9 @@ function ge(e) {
|
|
|
4330
4330
|
}
|
|
4331
4331
|
function _e(e) {
|
|
4332
4332
|
e.initCTCFeatureState = ge, e.initState = me, e.map.once("idle", () => {
|
|
4333
|
-
e && e.map.moveLayer(`${e.mapConfigs.id}_${e.mapConfigs.sourceLayers[e.mapConfigs.layers.indexOf("track")]}_lock`)
|
|
4333
|
+
e && (e.map.moveLayer(`${e.mapConfigs.id}_${e.mapConfigs.sourceLayers[e.mapConfigs.layers.indexOf("track")]}_lock`), setTimeout(() => {
|
|
4334
|
+
e.initState(), e.map.dragPan.enable(), e.map.scrollZoom.enable(), e.map.touchZoomRotate.enable(), e.map.doubleClickZoom.enable(), e.map.boxZoom.enable(), e.map.keyboard.enable();
|
|
4335
|
+
}, 1e3));
|
|
4334
4336
|
});
|
|
4335
4337
|
}
|
|
4336
4338
|
//#endregion
|
|
@@ -4358,7 +4360,7 @@ function be(e, t) {
|
|
|
4358
4360
|
try {
|
|
4359
4361
|
if (n.getSource(e)) console.warn(`源已存在,跳过添加: ${e}`);
|
|
4360
4362
|
else {
|
|
4361
|
-
let r = t ? y.geojson(t
|
|
4363
|
+
let r = t ? y.geojson(t) : y.geojson(void 0);
|
|
4362
4364
|
n.addSource(e, r), console.log(`成功添加 GeoJSON 源: ${e}`);
|
|
4363
4365
|
}
|
|
4364
4366
|
} catch (t) {
|
|
@@ -4654,7 +4656,7 @@ var ke = class {
|
|
|
4654
4656
|
for (let t of e.signalInterlock) {
|
|
4655
4657
|
let e = t.name.split(":")[0], n = t.name.split(":")[1], r = this.getSignalFeature(e, n);
|
|
4656
4658
|
r && this.setFeatureState("signal", r.properties.code, {
|
|
4657
|
-
state: Me[t.state],
|
|
4659
|
+
state: Me[Number(t.state)],
|
|
4658
4660
|
visiable: !0
|
|
4659
4661
|
});
|
|
4660
4662
|
}
|
|
@@ -4678,7 +4680,7 @@ var ke = class {
|
|
|
4678
4680
|
for (let t of e.signalInterlock) {
|
|
4679
4681
|
let e = t.name.split(":")[0], n = t.name.split(":")[1], r = this.getSignalFeature(e, n);
|
|
4680
4682
|
r && this.setFeatureState("signal", r.properties.code, {
|
|
4681
|
-
state: Me[t.state],
|
|
4683
|
+
state: Me[Number(t.state)],
|
|
4682
4684
|
visiable: !0
|
|
4683
4685
|
});
|
|
4684
4686
|
}
|
|
@@ -4761,7 +4763,7 @@ var ke = class {
|
|
|
4761
4763
|
if (a) {
|
|
4762
4764
|
r.push(o);
|
|
4763
4765
|
let s = String(a.properties?.name ?? ""), c = this.findSwitchInfo(s, t, n);
|
|
4764
|
-
this.validSwitchInfo(c) && !i.includes(s) && this.doseTrackConnectSwitch(o, c) && (i.push(e), this.findHandSwitchPath(s, t, n, r, i));
|
|
4766
|
+
c && this.validSwitchInfo(c) && !i.includes(s) && this.doseTrackConnectSwitch(o, c) && (i.push(e), this.findHandSwitchPath(s, t, n, r, i));
|
|
4765
4767
|
}
|
|
4766
4768
|
} else r.push(o);
|
|
4767
4769
|
}
|
|
@@ -12700,7 +12702,6 @@ var Jr = class {
|
|
|
12700
12702
|
onSelectCallback;
|
|
12701
12703
|
changeTimer = null;
|
|
12702
12704
|
lastFeatureCount = 0;
|
|
12703
|
-
forcedCoordinate = null;
|
|
12704
12705
|
constructor(e) {
|
|
12705
12706
|
this.mapInstance = e.map;
|
|
12706
12707
|
}
|
|
@@ -12712,12 +12713,12 @@ var Jr = class {
|
|
|
12712
12713
|
bindEvents() {
|
|
12713
12714
|
if (!this.drawControl) return;
|
|
12714
12715
|
let e = this.drawControl.getTerraDrawInstance();
|
|
12715
|
-
e.on("change", () => {
|
|
12716
|
+
e && (e.on("change", () => {
|
|
12716
12717
|
let t = e.getSnapshot(), n = this.toGeoJSON(t);
|
|
12717
12718
|
t.length < this.lastFeatureCount ? this.onDeleteCallback?.(n) : t.length > this.lastFeatureCount && this.onFinishCallback?.(n), this.lastFeatureCount = t.length, this.changeTimer && clearTimeout(this.changeTimer), this.changeTimer = setTimeout(() => {
|
|
12718
12719
|
this.onChangeCallback?.(n);
|
|
12719
12720
|
}, 50);
|
|
12720
|
-
}), e.on("select", (e) => this.onSelectCallback?.(e)), e.on("deselect", () => this.onSelectCallback?.(null));
|
|
12721
|
+
}), e.on("select", (e) => this.onSelectCallback?.(String(e))), e.on("deselect", () => this.onSelectCallback?.(null)));
|
|
12721
12722
|
}
|
|
12722
12723
|
toGeoJSON(e) {
|
|
12723
12724
|
return {
|
|
@@ -12735,39 +12736,49 @@ var Jr = class {
|
|
|
12735
12736
|
changeMode(e) {
|
|
12736
12737
|
if (!this.drawControl) return;
|
|
12737
12738
|
let t = this.drawControl.getTerraDrawInstance();
|
|
12738
|
-
if (
|
|
12739
|
-
|
|
12740
|
-
|
|
12741
|
-
|
|
12742
|
-
|
|
12743
|
-
|
|
12744
|
-
|
|
12745
|
-
|
|
12746
|
-
|
|
12747
|
-
|
|
12748
|
-
|
|
12739
|
+
if (t) {
|
|
12740
|
+
if (e === "undo") {
|
|
12741
|
+
t.undo();
|
|
12742
|
+
return;
|
|
12743
|
+
}
|
|
12744
|
+
if (e === "redo") {
|
|
12745
|
+
t.redo();
|
|
12746
|
+
return;
|
|
12747
|
+
}
|
|
12748
|
+
if (e === "download") {
|
|
12749
|
+
this.downloadGeoJSON();
|
|
12750
|
+
return;
|
|
12751
|
+
}
|
|
12752
|
+
t.setMode(e);
|
|
12749
12753
|
}
|
|
12750
|
-
t.setMode(e);
|
|
12751
12754
|
}
|
|
12752
12755
|
setEnabled(e) {
|
|
12753
12756
|
if (!this.drawControl) return;
|
|
12754
12757
|
let t = this.drawControl.getTerraDrawInstance();
|
|
12755
|
-
e ? t.setMode("select") : t.setMode("render");
|
|
12758
|
+
t && (e ? t.setMode("select") : t.setMode("render"));
|
|
12756
12759
|
}
|
|
12757
12760
|
getFeatureById(e) {
|
|
12758
|
-
if (this.drawControl) return
|
|
12761
|
+
if (!this.drawControl) return;
|
|
12762
|
+
let t = this.drawControl.getTerraDrawInstance();
|
|
12763
|
+
if (t) return t.getSnapshot().find((t) => t.id === e);
|
|
12759
12764
|
}
|
|
12760
12765
|
deleteFeatureById(e) {
|
|
12761
12766
|
if (!this.drawControl) return;
|
|
12762
|
-
let t = this.drawControl.getTerraDrawInstance()
|
|
12767
|
+
let t = this.drawControl.getTerraDrawInstance();
|
|
12768
|
+
if (!t) return;
|
|
12769
|
+
let n = Array.isArray(e) ? e : [e];
|
|
12763
12770
|
t.removeFeatures(n);
|
|
12764
12771
|
}
|
|
12765
12772
|
updateModeStyles(e, t) {
|
|
12766
|
-
|
|
12773
|
+
if (!this.drawControl) return;
|
|
12774
|
+
let n = this.drawControl.getTerraDrawInstance();
|
|
12775
|
+
n && n.updateModeOptions(e, { styles: t });
|
|
12767
12776
|
}
|
|
12768
12777
|
drawWithForcedCoordinates(e, t) {
|
|
12769
12778
|
if (!this.drawControl) return;
|
|
12770
|
-
let n = this.drawControl.getTerraDrawInstance()
|
|
12779
|
+
let n = this.drawControl.getTerraDrawInstance();
|
|
12780
|
+
if (!n) return;
|
|
12781
|
+
let r;
|
|
12771
12782
|
e === "point" ? r = {
|
|
12772
12783
|
type: "Point",
|
|
12773
12784
|
coordinates: t[0]
|
|
@@ -12789,11 +12800,13 @@ var Jr = class {
|
|
|
12789
12800
|
t && (t.addFeatures(e.features), this.lastFeatureCount = t.getSnapshot().length);
|
|
12790
12801
|
}
|
|
12791
12802
|
clear() {
|
|
12792
|
-
|
|
12803
|
+
if (!this.drawControl) return;
|
|
12804
|
+
let e = this.drawControl.getTerraDrawInstance();
|
|
12805
|
+
e && (e.clear(), this.lastFeatureCount = 0);
|
|
12793
12806
|
}
|
|
12794
12807
|
downloadGeoJSON() {
|
|
12795
|
-
let e = this.
|
|
12796
|
-
|
|
12808
|
+
let e = this.drawControl?.getTerraDrawInstance(), t = this.toGeoJSON(e?.getSnapshot() || []), n = new Blob([JSON.stringify(t, null, 2)], { type: "application/json" }), r = URL.createObjectURL(n), i = document.createElement("a");
|
|
12809
|
+
i.href = r, i.download = `draw_data_${Date.now()}.geojson`, i.click(), URL.revokeObjectURL(r);
|
|
12797
12810
|
}
|
|
12798
12811
|
destroy() {
|
|
12799
12812
|
this.drawControl && (this.changeTimer && clearTimeout(this.changeTimer), this.mapInstance.removeControl(this.drawControl), this.drawControl = null, this.onFinishCallback = void 0, this.onChangeCallback = void 0, this.onDeleteCallback = void 0, this.onSelectCallback = void 0);
|