@caoguo/maplibre-pipeline 0.0.2 → 0.0.4
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/dist/burst/index.cjs +708 -0
- package/dist/burst/index.cjs.map +1 -0
- package/dist/burst/index.js +4 -0
- package/dist/burst/index.js.map +1 -0
- package/dist/burstClass-CGMjcAYy.d.cts +161 -0
- package/dist/burstClass-Cf2p71LE.d.ts +161 -0
- package/dist/chunk-BWQKY35F.js +259 -0
- package/dist/chunk-BWQKY35F.js.map +1 -0
- package/dist/chunk-CDEYJ67B.js +80 -0
- package/dist/chunk-CDEYJ67B.js.map +1 -0
- package/dist/chunk-GCDA7KJM.js +289 -0
- package/dist/chunk-GCDA7KJM.js.map +1 -0
- package/dist/chunk-HCT6NSNS.js +532 -0
- package/dist/chunk-HCT6NSNS.js.map +1 -0
- package/dist/chunk-HIRNJVCV.js +13 -0
- package/dist/chunk-HIRNJVCV.js.map +1 -0
- package/dist/chunk-PJMHTPSA.js +352 -0
- package/dist/chunk-PJMHTPSA.js.map +1 -0
- package/dist/chunk-QVY4WJLM.js +256 -0
- package/dist/chunk-QVY4WJLM.js.map +1 -0
- package/dist/chunk-VA2TQWL3.js +340 -0
- package/dist/chunk-VA2TQWL3.js.map +1 -0
- package/dist/chunk-YBLESEN4.js +133 -0
- package/dist/chunk-YBLESEN4.js.map +1 -0
- package/dist/chunk-YS2ICFVK.js +101 -0
- package/dist/chunk-YS2ICFVK.js.map +1 -0
- package/dist/graph/index.cjs +382 -0
- package/dist/graph/index.cjs.map +1 -0
- package/dist/graph/index.js +4 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/health/index.cjs +348 -0
- package/dist/health/index.cjs.map +1 -0
- package/dist/health/index.js +3 -0
- package/dist/health/index.js.map +1 -0
- package/dist/index.cjs +2389 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/leakage/index.cjs +7 -6
- package/dist/leakage/index.cjs.map +1 -1
- package/dist/leakage/index.js +1 -1
- package/dist/topology/index.cjs +113 -14
- package/dist/topology/index.cjs.map +1 -1
- package/dist/topology/index.d.cts +65 -15
- package/dist/topology/index.d.ts +65 -15
- package/dist/topology/index.js +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
// src/style/pipelineTheme.ts
|
|
2
|
+
var PIPELINE_TYPE_COLORS = {
|
|
3
|
+
gas: "#f59e0b",
|
|
4
|
+
// 琥珀(燃气)
|
|
5
|
+
water: "#3b82f6",
|
|
6
|
+
// 蓝(供水)
|
|
7
|
+
drainage: "#6b7280",
|
|
8
|
+
// 灰(排水)
|
|
9
|
+
heating: "#ef4444",
|
|
10
|
+
// 红(供热)
|
|
11
|
+
power: "#8b5cf6",
|
|
12
|
+
// 紫(电力管沟)
|
|
13
|
+
telecom: "#10b981"
|
|
14
|
+
// 绿(通信管沟)
|
|
15
|
+
};
|
|
16
|
+
var PIPELINE_TYPE_LABELS = {
|
|
17
|
+
gas: "\u71C3\u6C14\u7BA1",
|
|
18
|
+
water: "\u4F9B\u6C34\u7BA1",
|
|
19
|
+
drainage: "\u6392\u6C34\u7BA1",
|
|
20
|
+
heating: "\u4F9B\u70ED\u7BA1",
|
|
21
|
+
power: "\u7535\u529B\u7BA1\u6C9F",
|
|
22
|
+
telecom: "\u901A\u4FE1\u7BA1\u6C9F"
|
|
23
|
+
};
|
|
24
|
+
var PIPELINE_TYPE_ICONS = {
|
|
25
|
+
gas: "\u{1F525}",
|
|
26
|
+
water: "\u{1F4A7}",
|
|
27
|
+
drainage: "\u{1F6B0}",
|
|
28
|
+
heating: "\u{1F534}",
|
|
29
|
+
power: "\u26A1",
|
|
30
|
+
telecom: "\u{1F4E1}"
|
|
31
|
+
};
|
|
32
|
+
var PIPE_STATUS_COLORS = {
|
|
33
|
+
normal: "#4ade80",
|
|
34
|
+
// 绿
|
|
35
|
+
aging: "#fbbf24",
|
|
36
|
+
// 黄
|
|
37
|
+
damaged: "#ef4444",
|
|
38
|
+
// 红
|
|
39
|
+
under_repair: "#8b5cf6",
|
|
40
|
+
// 紫
|
|
41
|
+
abandoned: "#4b5563",
|
|
42
|
+
// 深灰
|
|
43
|
+
unknown: "#6b7280"
|
|
44
|
+
// 灰
|
|
45
|
+
};
|
|
46
|
+
var PIPE_STATUS_META = {
|
|
47
|
+
normal: { label: "\u6B63\u5E38", animation: "none" },
|
|
48
|
+
aging: { label: "\u8001\u5316", animation: "none" },
|
|
49
|
+
damaged: { label: "\u635F\u574F", animation: "pulse" },
|
|
50
|
+
under_repair: { label: "\u7EF4\u4FEE\u4E2D", animation: "dashed" },
|
|
51
|
+
abandoned: { label: "\u5E9F\u5F03", animation: "none" },
|
|
52
|
+
unknown: { label: "\u672A\u77E5", animation: "none" }
|
|
53
|
+
};
|
|
54
|
+
var PIPE_MATERIAL_COLORS = {
|
|
55
|
+
cast_iron: "#94a3b8",
|
|
56
|
+
// 蓝灰(旧铸铁)
|
|
57
|
+
ductile_iron: "#0ea5e9",
|
|
58
|
+
// 天蓝(球墨铸铁)
|
|
59
|
+
steel: "#64748b",
|
|
60
|
+
// 钢蓝
|
|
61
|
+
pe: "#22c55e",
|
|
62
|
+
// 绿(PE 现代管材)
|
|
63
|
+
pvc: "#a78bfa",
|
|
64
|
+
// 紫(PVC)
|
|
65
|
+
concrete: "#a8a29e",
|
|
66
|
+
// 米灰(混凝土)
|
|
67
|
+
hdpe: "#16a34a",
|
|
68
|
+
// 深绿(HDPE)
|
|
69
|
+
copper: "#d97706",
|
|
70
|
+
// 橙(铜)
|
|
71
|
+
unknown: "#6b7280"
|
|
72
|
+
};
|
|
73
|
+
var NODE_KIND_ICONS = {
|
|
74
|
+
junction: "M -6 0 L 6 0 M 0 -6 L 0 6",
|
|
75
|
+
// 十字
|
|
76
|
+
valve: "M -8 -4 L 8 4 M 0 -4 L 0 4",
|
|
77
|
+
// X
|
|
78
|
+
pump: "M -6 0 A 6 6 0 1 0 6 0 A 6 6 0 1 0 -6 0",
|
|
79
|
+
// 圆
|
|
80
|
+
meter: "M -6 -6 L 6 -6 L 6 6 L -6 6 Z",
|
|
81
|
+
// 方
|
|
82
|
+
source: "M 0 -10 L 6 6 L -6 6 Z",
|
|
83
|
+
// 三角
|
|
84
|
+
tank: "M -8 -6 Q 0 -10 8 -6 L 8 6 L -8 6 Z",
|
|
85
|
+
// 圆角
|
|
86
|
+
junction_box: "M -7 -4 L 7 -4 L 7 4 L -7 4 Z"
|
|
87
|
+
// 小方
|
|
88
|
+
};
|
|
89
|
+
var NODE_KIND_COLORS = {
|
|
90
|
+
junction: "#94a3b8",
|
|
91
|
+
valve: "#ef4444",
|
|
92
|
+
// 阀门=红(控制关键)
|
|
93
|
+
pump: "#f59e0b",
|
|
94
|
+
meter: "#3b82f6",
|
|
95
|
+
source: "#22c55e",
|
|
96
|
+
tank: "#06b6d4",
|
|
97
|
+
junction_box: "#8b5cf6"
|
|
98
|
+
};
|
|
99
|
+
var HEALTH_LEVEL_COLORS = {
|
|
100
|
+
excellent: "#22c55e",
|
|
101
|
+
// 绿 80-100
|
|
102
|
+
good: "#3b82f6",
|
|
103
|
+
// 蓝 60-80
|
|
104
|
+
fair: "#eab308",
|
|
105
|
+
// 黄 40-60
|
|
106
|
+
poor: "#f97316",
|
|
107
|
+
// 橙 20-40
|
|
108
|
+
critical: "#ef4444"
|
|
109
|
+
// 红 0-20
|
|
110
|
+
};
|
|
111
|
+
var HEALTH_LEVEL_LABELS = {
|
|
112
|
+
excellent: "\u4F18",
|
|
113
|
+
good: "\u826F",
|
|
114
|
+
fair: "\u4E2D",
|
|
115
|
+
poor: "\u5DEE",
|
|
116
|
+
critical: "\u5371"
|
|
117
|
+
};
|
|
118
|
+
function healthLevel(score) {
|
|
119
|
+
if (score >= 80) return "excellent";
|
|
120
|
+
if (score >= 60) return "good";
|
|
121
|
+
if (score >= 40) return "fair";
|
|
122
|
+
if (score >= 20) return "poor";
|
|
123
|
+
return "critical";
|
|
124
|
+
}
|
|
125
|
+
function pipelineTypeColor(type) {
|
|
126
|
+
if (!type) return "#94a3b8";
|
|
127
|
+
return PIPELINE_TYPE_COLORS[type];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/style/paintRules.ts
|
|
131
|
+
function paintPipeByType(types) {
|
|
132
|
+
if (!types || types.length === 0) {
|
|
133
|
+
return [
|
|
134
|
+
"match",
|
|
135
|
+
["get", "pipelineType"],
|
|
136
|
+
...Object.entries(PIPELINE_TYPE_COLORS).flatMap(([k, v]) => [k, v]),
|
|
137
|
+
"#94a3b8"
|
|
138
|
+
];
|
|
139
|
+
}
|
|
140
|
+
return [
|
|
141
|
+
"match",
|
|
142
|
+
["get", "pipelineType"],
|
|
143
|
+
...types.flatMap((t) => [t, PIPELINE_TYPE_COLORS[t]]),
|
|
144
|
+
"#94a3b8"
|
|
145
|
+
];
|
|
146
|
+
}
|
|
147
|
+
function paintPipeByDiameter() {
|
|
148
|
+
return [
|
|
149
|
+
"interpolate",
|
|
150
|
+
["linear"],
|
|
151
|
+
["coalesce", ["get", "diameter"], 0],
|
|
152
|
+
0,
|
|
153
|
+
"#4ade80",
|
|
154
|
+
// 极细管 绿
|
|
155
|
+
50,
|
|
156
|
+
"#4ade80",
|
|
157
|
+
// DN50 以下 绿(支管)
|
|
158
|
+
150,
|
|
159
|
+
"#60a5fa",
|
|
160
|
+
// DN150 蓝(配水管)
|
|
161
|
+
300,
|
|
162
|
+
"#f59e0b",
|
|
163
|
+
// DN300 黄(干管)
|
|
164
|
+
600,
|
|
165
|
+
"#ef4444",
|
|
166
|
+
// DN600+ 红(主管)
|
|
167
|
+
1500,
|
|
168
|
+
"#7f1d1d"
|
|
169
|
+
// 极大管 深红
|
|
170
|
+
];
|
|
171
|
+
}
|
|
172
|
+
function paintPipeByStatus() {
|
|
173
|
+
return [
|
|
174
|
+
"match",
|
|
175
|
+
["coalesce", ["get", "status"], "unknown"],
|
|
176
|
+
...Object.entries(PIPE_STATUS_COLORS).flatMap(([k, v]) => [k, v]),
|
|
177
|
+
"#6b7280"
|
|
178
|
+
];
|
|
179
|
+
}
|
|
180
|
+
function paintPipeByMaterial() {
|
|
181
|
+
return [
|
|
182
|
+
"match",
|
|
183
|
+
["coalesce", ["get", "material"], "unknown"],
|
|
184
|
+
...Object.entries(PIPE_MATERIAL_COLORS).flatMap(([k, v]) => [k, v]),
|
|
185
|
+
"#6b7280"
|
|
186
|
+
];
|
|
187
|
+
}
|
|
188
|
+
function paintPipeByHealth() {
|
|
189
|
+
return [
|
|
190
|
+
"step",
|
|
191
|
+
["coalesce", ["get", "healthScore"], 100],
|
|
192
|
+
HEALTH_LEVEL_COLORS.critical,
|
|
193
|
+
// <20
|
|
194
|
+
20,
|
|
195
|
+
HEALTH_LEVEL_COLORS.poor,
|
|
196
|
+
40,
|
|
197
|
+
HEALTH_LEVEL_COLORS.fair,
|
|
198
|
+
60,
|
|
199
|
+
HEALTH_LEVEL_COLORS.good,
|
|
200
|
+
80,
|
|
201
|
+
HEALTH_LEVEL_COLORS.excellent
|
|
202
|
+
];
|
|
203
|
+
}
|
|
204
|
+
function paintPipeBy(mode, opts) {
|
|
205
|
+
switch (mode) {
|
|
206
|
+
case "type":
|
|
207
|
+
return paintPipeByType(opts?.types);
|
|
208
|
+
case "diameter":
|
|
209
|
+
return paintPipeByDiameter();
|
|
210
|
+
case "status":
|
|
211
|
+
return paintPipeByStatus();
|
|
212
|
+
case "material":
|
|
213
|
+
return paintPipeByMaterial();
|
|
214
|
+
case "health":
|
|
215
|
+
return paintPipeByHealth();
|
|
216
|
+
case "uniform":
|
|
217
|
+
default:
|
|
218
|
+
return "#60a5fa";
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
function paintNodeByKind() {
|
|
222
|
+
return [
|
|
223
|
+
"match",
|
|
224
|
+
["get", "kind"],
|
|
225
|
+
"junction",
|
|
226
|
+
"#94a3b8",
|
|
227
|
+
"valve",
|
|
228
|
+
"#ef4444",
|
|
229
|
+
"pump",
|
|
230
|
+
"#f59e0b",
|
|
231
|
+
"meter",
|
|
232
|
+
"#3b82f6",
|
|
233
|
+
"source",
|
|
234
|
+
"#22c55e",
|
|
235
|
+
"tank",
|
|
236
|
+
"#06b6d4",
|
|
237
|
+
"junction_box",
|
|
238
|
+
"#8b5cf6",
|
|
239
|
+
"#cbd5e1"
|
|
240
|
+
];
|
|
241
|
+
}
|
|
242
|
+
function paintPipeWidthByDiameter(minWidth = 1.5, maxWidth = 6) {
|
|
243
|
+
return [
|
|
244
|
+
"interpolate",
|
|
245
|
+
["linear"],
|
|
246
|
+
["coalesce", ["get", "diameter"], 100],
|
|
247
|
+
0,
|
|
248
|
+
minWidth,
|
|
249
|
+
1500,
|
|
250
|
+
maxWidth
|
|
251
|
+
];
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export { HEALTH_LEVEL_COLORS, HEALTH_LEVEL_LABELS, NODE_KIND_COLORS, NODE_KIND_ICONS, PIPELINE_TYPE_COLORS, PIPELINE_TYPE_ICONS, PIPELINE_TYPE_LABELS, PIPE_MATERIAL_COLORS, PIPE_STATUS_COLORS, PIPE_STATUS_META, healthLevel, paintNodeByKind, paintPipeBy, paintPipeByDiameter, paintPipeByHealth, paintPipeByMaterial, paintPipeByStatus, paintPipeByType, paintPipeWidthByDiameter, pipelineTypeColor };
|
|
255
|
+
//# sourceMappingURL=chunk-QVY4WJLM.js.map
|
|
256
|
+
//# sourceMappingURL=chunk-QVY4WJLM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/style/pipelineTheme.ts","../src/style/paintRules.ts"],"names":[],"mappings":";AAcO,IAAM,oBAAA,GAAqD;AAAA,EAChE,GAAA,EAAK,SAAA;AAAA;AAAA,EACL,KAAA,EAAO,SAAA;AAAA;AAAA,EACP,QAAA,EAAU,SAAA;AAAA;AAAA,EACV,OAAA,EAAS,SAAA;AAAA;AAAA,EACT,KAA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AAK,UAAA;AACH,MAAA,OAAO,mBAAA,EAAoB;AAAA,IAC7B,KAAK,QAAA;AACH,MAAA,OAAO,iBAAA,EAAkB;AAAA,IAC3B,KAAK,UAAA;AACH,MAAA,OAAO,mBAAA,EAAoB;AAAA,IAC7B,KAAK,QAAA;AACH,MAAA,OAAO,iBAAA,EAAkB;AAAA,IAC3B,KAAK,SAAA;AAAA,IACL;AACE,MAAA,OAAO,SAAA;AAAA;AAEb;AAGO,SAAS,eAAA,GAA6B;AAC3C,EAAA,OAAO;AAAA,IACL,OAAA;AAAA,IACA,CAAC,OAAO,MAAM,CAAA;AAAA,IACd,UAAA;AAAA,IAAY,SAAA;AAAA,IACZ,OAAA;AAAA,IAAS,SAAA;AAAA,IACT,MAAA;AAAA,IAAQ,SAAA;AAAA,IACR,OAAA;AAAA,IAAS,SAAA;AAAA,IACT,QAAA;AAAA,IAAU,SAAA;AAAA,IACV,MAAA;AAAA,IAAQ,SAAA;AAAA,IACR,cAAA;AAAA,IAAgB,SAAA;AAAA,IAChB;AAAA,GACF;AACF;AAGO,SAAS,wBAAA,CAAyB,QAAA,GAAW,GAAA,EAAK,QAAA,GAAW,CAAA,EAAc;AAChF,EAAA,OAAO;AAAA,IACL,aAAA;AAAA,IACA,CAAC,QAAQ,CAAA;AAAA,IACT,CAAC,UAAA,EAAY,CAAC,KAAA,EAAO,UAAU,GAAG,GAAG,CAAA;AAAA,IACrC,CAAA;AAAA,IAAG,QAAA;AAAA,IACH,IAAA;AAAA,IAAM;AAAA,GACR;AACF","file":"chunk-QVY4WJLM.js","sourcesContent":["/**\n * 草果地图管网专用样式 - `caoguo-pipeline`\n *\n * 设计目标:\n * - 行业辨识度高:燃气=琥珀、供水=蓝、供热=红、电力=紫、通信=绿、排水=灰\n * - 状态语义强:正常/老化/损坏/维修中 各有专属色 + 动画\n * - 与 caoguo-dark/light 主题协调:在亮/暗模式下都可读\n *\n * 颜色规范依据 PRD §4.5。\n */\n\nimport type { PipelineType, PipeMaterial, PipeStatus, NodeKind } from '../types';\n\n/** 管线大类配色(caoguo-pipeline) */\nexport const PIPELINE_TYPE_COLORS: Record<PipelineType, string> = {\n gas: '#f59e0b', // 琥珀(燃气)\n water: '#3b82f6', // 蓝(供水)\n drainage: '#6b7280', // 灰(排水)\n heating: '#ef4444', // 红(供热)\n power: '#8b5cf6', // 紫(电力管沟)\n telecom: '#10b981', // 绿(通信管沟)\n};\n\n/** 管线大类的中文标签(地图图例/卡片显示) */\nexport const PIPELINE_TYPE_LABELS: Record<PipelineType, string> = {\n gas: '燃气管',\n water: '供水管',\n drainage: '排水管',\n heating: '供热管',\n power: '电力管沟',\n telecom: '通信管沟',\n};\n\n/** 管线大类的 Emoji 图标(轻量可视化标识,用于卡片/Tag) */\nexport const PIPELINE_TYPE_ICONS: Record<PipelineType, string> = {\n gas: '🔥',\n water: '💧',\n drainage: '🚰',\n heating: '🔴',\n power: '⚡',\n telecom: '📡',\n};\n\n/** 管段状态配色 */\nexport const PIPE_STATUS_COLORS: Record<PipeStatus, string> = {\n normal: '#4ade80', // 绿\n aging: '#fbbf24', // 黄\n damaged: '#ef4444', // 红\n under_repair: '#8b5cf6', // 紫\n abandoned: '#4b5563', // 深灰\n unknown: '#6b7280', // 灰\n};\n\n/** 状态的语义 + 动画 */\nexport const PIPE_STATUS_META: Record<\n PipeStatus,\n { label: string; animation?: 'pulse' | 'dashed' | 'none' }\n> = {\n normal: { label: '正常', animation: 'none' },\n aging: { label: '老化', animation: 'none' },\n damaged: { label: '损坏', animation: 'pulse' },\n under_repair: { label: '维修中', animation: 'dashed' },\n abandoned: { label: '废弃', animation: 'none' },\n unknown: { label: '未知', animation: 'none' },\n};\n\n/** 管材配色(maplibre style 用) */\nexport const PIPE_MATERIAL_COLORS: Record<PipeMaterial, string> = {\n cast_iron: '#94a3b8', // 蓝灰(旧铸铁)\n ductile_iron: '#0ea5e9', // 天蓝(球墨铸铁)\n steel: '#64748b', // 钢蓝\n pe: '#22c55e', // 绿(PE 现代管材)\n pvc: '#a78bfa', // 紫(PVC)\n concrete: '#a8a29e', // 米灰(混凝土)\n hdpe: '#16a34a', // 深绿(HDPE)\n copper: '#d97706', // 橙(铜)\n unknown: '#6b7280',\n};\n\n/** 节点图标(用 SVG path 描点,地图渲染层用) */\nexport const NODE_KIND_ICONS: Record<NodeKind, string> = {\n junction: 'M -6 0 L 6 0 M 0 -6 L 0 6', // 十字\n valve: 'M -8 -4 L 8 4 M 0 -4 L 0 4', // X\n pump: 'M -6 0 A 6 6 0 1 0 6 0 A 6 6 0 1 0 -6 0', // 圆\n meter: 'M -6 -6 L 6 -6 L 6 6 L -6 6 Z', // 方\n source: 'M 0 -10 L 6 6 L -6 6 Z', // 三角\n tank: 'M -8 -6 Q 0 -10 8 -6 L 8 6 L -8 6 Z', // 圆角\n junction_box: 'M -7 -4 L 7 -4 L 7 4 L -7 4 Z',// 小方\n};\n\n/** 节点配色(默认按 type 衍生) */\nexport const NODE_KIND_COLORS: Record<NodeKind, string> = {\n junction: '#94a3b8',\n valve: '#ef4444', // 阀门=红(控制关键)\n pump: '#f59e0b',\n meter: '#3b82f6',\n source: '#22c55e',\n tank: '#06b6d4',\n junction_box: '#8b5cf6',\n};\n\n/** 健康度等级配色(PipelineHealth 用) */\nexport const HEALTH_LEVEL_COLORS: Record<string, string> = {\n excellent: '#22c55e', // 绿 80-100\n good: '#3b82f6', // 蓝 60-80\n fair: '#eab308', // 黄 40-60\n poor: '#f97316', // 橙 20-40\n critical: '#ef4444', // 红 0-20\n};\n\n/** 健康等级 label */\nexport const HEALTH_LEVEL_LABELS: Record<string, string> = {\n excellent: '优',\n good: '良',\n fair: '中',\n poor: '差',\n critical: '危',\n};\n\n/**\n * 健康度 → 等级(保留闭区间,遵守 PRD §4.4.2)\n * @param score 0-100 健康分\n */\nexport function healthLevel(score: number): 'excellent' | 'good' | 'fair' | 'poor' | 'critical' {\n if (score >= 80) return 'excellent';\n if (score >= 60) return 'good';\n if (score >= 40) return 'fair';\n if (score >= 20) return 'poor';\n return 'critical';\n}\n\n/** 按管线类型取默认色(兜底用) */\nexport function pipelineTypeColor(type: PipelineType | undefined): string {\n if (!type) return '#94a3b8';\n return PIPELINE_TYPE_COLORS[type];\n}\n","/**\n * 管网 MapLibre paint 规则(caoguo-pipeline)\n *\n * 把\"管线/节点如何着色\"的业务规则翻译成 MapLibre style spec,\n * 业务方可直接 addLayer / setPaintProperty 使用。\n *\n * 规则集:\n * - 管线按管线大类着色(type)\n * - 管线按管径着色(diameter,PRD §4.1.4)\n * - 管线按状态着色(status)\n * - 管线按材质着色(material)\n * - 管线按健康度着色(health,PipelineHealth 集成)\n *\n * 节点按节点类型着色 + 图标。\n */\n\nimport type {\n PipelineType,\n PipeMaterial,\n PipeStatus,\n ColorByMode,\n} from '../types';\nimport { PIPELINE_TYPE_COLORS, PIPE_STATUS_COLORS, HEALTH_LEVEL_COLORS, PIPE_MATERIAL_COLORS } from './pipelineTheme';\n\n/**\n * MapLibre style spec 的 color function DSL(typed),\n * 业务方可直接 `map.addLayer({type:'line', paint: {'line-color': rule} })`\n *\n * MapLibre 表达式其实接受 string | number | 嵌套数组,所以我们用 unknown 让 TS 放行\n */\nexport type PaintRule = unknown;\n\n/** 管线按\"管线大类\"着色 */\nexport function paintPipeByType(types?: PipelineType[]): PaintRule {\n if (!types || types.length === 0) {\n // 全部类型都涂色\n return [\n 'match',\n ['get', 'pipelineType'],\n ...Object.entries(PIPELINE_TYPE_COLORS).flatMap(([k, v]) => [k, v]),\n '#94a3b8',\n ];\n }\n return [\n 'match',\n ['get', 'pipelineType'],\n ...types.flatMap((t) => [t, PIPELINE_TYPE_COLORS[t]]),\n '#94a3b8',\n ];\n}\n\n/** 管线按\"管径\"渐变着色(PRD §4.1.4) */\nexport function paintPipeByDiameter(): PaintRule {\n return [\n 'interpolate',\n ['linear'],\n ['coalesce', ['get', 'diameter'], 0],\n 0, '#4ade80', // 极细管 绿\n 50, '#4ade80', // DN50 以下 绿(支管)\n 150, '#60a5fa', // DN150 蓝(配水管)\n 300, '#f59e0b', // DN300 黄(干管)\n 600, '#ef4444', // DN600+ 红(主管)\n 1500, '#7f1d1d', // 极大管 深红\n ];\n}\n\n/** 管线按\"状态\"着色 */\nexport function paintPipeByStatus(): PaintRule {\n return [\n 'match',\n ['coalesce', ['get', 'status'], 'unknown'],\n ...Object.entries(PIPE_STATUS_COLORS).flatMap(([k, v]) => [k, v]),\n '#6b7280',\n ];\n}\n\n/** 管线按\"材质\"着色 */\nexport function paintPipeByMaterial(): PaintRule {\n return [\n 'match',\n ['coalesce', ['get', 'material'], 'unknown'],\n ...Object.entries(PIPE_MATERIAL_COLORS).flatMap(([k, v]) => [k, v]),\n '#6b7280',\n ];\n}\n\n/** 管线按\"健康度\"着色(健康分 0-100,规则按 healthLevel 离散) */\nexport function paintPipeByHealth(): PaintRule {\n return [\n 'step',\n ['coalesce', ['get', 'healthScore'], 100],\n HEALTH_LEVEL_COLORS.critical, // <20\n 20, HEALTH_LEVEL_COLORS.poor,\n 40, HEALTH_LEVEL_COLORS.fair,\n 60, HEALTH_LEVEL_COLORS.good,\n 80, HEALTH_LEVEL_COLORS.excellent,\n ];\n}\n\n/** 根据模式返回 paint rule 工厂 */\nexport function paintPipeBy(mode: ColorByMode, opts?: { types?: PipelineType[] }): PaintRule {\n switch (mode) {\n case 'type':\n return paintPipeByType(opts?.types);\n case 'diameter':\n return paintPipeByDiameter();\n case 'status':\n return paintPipeByStatus();\n case 'material':\n return paintPipeByMaterial();\n case 'health':\n return paintPipeByHealth();\n case 'uniform':\n default:\n return '#60a5fa';\n }\n}\n\n/** 节点按 kind 着色(maplibre style circle-color 用) */\nexport function paintNodeByKind(): PaintRule {\n return [\n 'match',\n ['get', 'kind'],\n 'junction', '#94a3b8',\n 'valve', '#ef4444',\n 'pump', '#f59e0b',\n 'meter', '#3b82f6',\n 'source', '#22c55e',\n 'tank', '#06b6d4',\n 'junction_box', '#8b5cf6',\n '#cbd5e1',\n ];\n}\n\n/** 默认管段宽度(按管径递推) */\nexport function paintPipeWidthByDiameter(minWidth = 1.5, maxWidth = 6): PaintRule {\n return [\n 'interpolate',\n ['linear'],\n ['coalesce', ['get', 'diameter'], 100],\n 0, minWidth,\n 1500, maxWidth,\n ];\n}\n"]}
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
// src/health/healthScorer.ts
|
|
2
|
+
var DEFAULT_WEIGHTS = {
|
|
3
|
+
age: 0.25,
|
|
4
|
+
material: 0.2,
|
|
5
|
+
soil: 0.15,
|
|
6
|
+
history: 0.2,
|
|
7
|
+
pressure: 0.1,
|
|
8
|
+
protection: 0.1
|
|
9
|
+
};
|
|
10
|
+
var MATERIAL_RISK = {
|
|
11
|
+
cast_iron: 0.85,
|
|
12
|
+
// 铸铁 = 高风险(旧管网)
|
|
13
|
+
ductile_iron: 0.2,
|
|
14
|
+
// 球墨铸铁
|
|
15
|
+
steel: 0.4,
|
|
16
|
+
pe: 0.1,
|
|
17
|
+
pvc: 0.15,
|
|
18
|
+
concrete: 0.3,
|
|
19
|
+
hdpe: 0.05,
|
|
20
|
+
copper: 0.1,
|
|
21
|
+
unknown: 0.5
|
|
22
|
+
};
|
|
23
|
+
function scorePipeHealth(input, weights = DEFAULT_WEIGHTS) {
|
|
24
|
+
const dims = {
|
|
25
|
+
age: scoreAge(input, weights.age),
|
|
26
|
+
material: scoreMaterial(input, weights.material),
|
|
27
|
+
soil: scoreSoil(input, weights.soil),
|
|
28
|
+
history: scoreHistory(input, weights.history),
|
|
29
|
+
pressure: scorePressure(input, weights.pressure),
|
|
30
|
+
protection: scoreProtection(input, weights.protection)
|
|
31
|
+
};
|
|
32
|
+
const total = dims.age.score * dims.age.weight + dims.material.score * dims.material.weight + dims.soil.score * dims.soil.weight + dims.history.score * dims.history.weight + dims.pressure.score * dims.pressure.weight + dims.protection.score * dims.protection.weight;
|
|
33
|
+
let final = total;
|
|
34
|
+
if (input.status === "damaged") final *= 0.5;
|
|
35
|
+
else if (input.status === "under_repair") final *= 0.7;
|
|
36
|
+
else if (input.status === "abandoned") final = 0;
|
|
37
|
+
return {
|
|
38
|
+
score: Math.round(final),
|
|
39
|
+
level: toLevel(final),
|
|
40
|
+
dimensions: dims
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function toLevel(score) {
|
|
44
|
+
if (score >= 80) return "excellent";
|
|
45
|
+
if (score >= 60) return "good";
|
|
46
|
+
if (score >= 40) return "fair";
|
|
47
|
+
if (score >= 20) return "poor";
|
|
48
|
+
return "critical";
|
|
49
|
+
}
|
|
50
|
+
function scoreAge(input, weight) {
|
|
51
|
+
if (!input.installDate) {
|
|
52
|
+
return { score: 50, weight, reason: "\u672A\u77E5\u5B89\u88C5\u65E5\u671F\uFF0C\u6309\u4E2D\u7B49\u8BA1" };
|
|
53
|
+
}
|
|
54
|
+
const ageYears = (Date.now() - new Date(input.installDate).getTime()) / (365.25 * 24 * 3600 * 1e3);
|
|
55
|
+
if (ageYears < 0) return { score: 100, weight, reason: "\u672A\u6765\u65E5\u671F\uFF0C\u89C6\u4E3A\u4F18\u79C0" };
|
|
56
|
+
if (ageYears < 5) return { score: 100, weight, reason: "\u65B0\u5EFA\u7BA1\u7EBF (<5\u5E74)" };
|
|
57
|
+
if (ageYears < 15) return { score: 85, weight, reason: "\u8F83\u65B0 (5-15\u5E74)" };
|
|
58
|
+
if (ageYears < 25) return { score: 65, weight, reason: "\u4E2D\u9F84 (15-25\u5E74)" };
|
|
59
|
+
if (ageYears < 40) return { score: 40, weight, reason: "\u8001\u9F84 (25-40\u5E74)" };
|
|
60
|
+
if (ageYears < 60) return { score: 20, weight, reason: "\u8D85\u671F (>40\u5E74)" };
|
|
61
|
+
return { score: 5, weight, reason: "\u8D85\u671F (>60\u5E74)" };
|
|
62
|
+
}
|
|
63
|
+
function scoreMaterial(input, weight) {
|
|
64
|
+
if (!input.material) {
|
|
65
|
+
return { score: 50, weight, reason: "\u672A\u77E5\u6750\u8D28\uFF0C\u6309\u4E2D\u7B49\u8BA1" };
|
|
66
|
+
}
|
|
67
|
+
const risk = MATERIAL_RISK[input.material] ?? 0.5;
|
|
68
|
+
const score = Math.round((1 - risk) * 100);
|
|
69
|
+
const labels = {
|
|
70
|
+
cast_iron: "\u94F8\u94C1\uFF08\u9AD8\u98CE\u9669\uFF09",
|
|
71
|
+
ductile_iron: "\u7403\u58A8\u94F8\u94C1",
|
|
72
|
+
steel: "\u94A2",
|
|
73
|
+
pe: "PE\uFF08\u4F4E\u98CE\u9669\uFF09",
|
|
74
|
+
pvc: "PVC",
|
|
75
|
+
concrete: "\u6DF7\u51DD\u571F",
|
|
76
|
+
hdpe: "HDPE\uFF08\u6700\u4F73\uFF09",
|
|
77
|
+
copper: "\u94DC",
|
|
78
|
+
unknown: "\u672A\u77E5"
|
|
79
|
+
};
|
|
80
|
+
return {
|
|
81
|
+
score,
|
|
82
|
+
weight,
|
|
83
|
+
reason: labels[input.material] ?? input.material
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function scoreSoil(input, weight) {
|
|
87
|
+
const c = input.soilCorrosion ?? 0.5;
|
|
88
|
+
const score = Math.round((1 - c) * 100);
|
|
89
|
+
return {
|
|
90
|
+
score,
|
|
91
|
+
weight,
|
|
92
|
+
reason: c === 0.5 && !input.soilCorrosion ? "\u65E0\u571F\u58E4\u6570\u636E\uFF0C\u6309\u5E73\u5747\u8BA1" : `\u571F\u58E4\u8150\u8680\u6307\u6570 ${c.toFixed(2)}`
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function scoreHistory(input, weight) {
|
|
96
|
+
const fail = input.failureCount ?? 0;
|
|
97
|
+
if (fail === 0) return { score: 100, weight, reason: "\u5386\u53F2\u65E0\u6545\u969C" };
|
|
98
|
+
if (fail === 1) return { score: 75, weight, reason: "\u5386\u53F2 1 \u6B21\u6545\u969C" };
|
|
99
|
+
if (fail === 2) return { score: 50, weight, reason: "\u5386\u53F2 2 \u6B21\u6545\u969C" };
|
|
100
|
+
if (fail === 3) return { score: 25, weight, reason: "\u5386\u53F2 3 \u6B21\u6545\u969C" };
|
|
101
|
+
return { score: 0, weight, reason: `\u5386\u53F2 \u2265${fail} \u6B21\u6545\u969C` };
|
|
102
|
+
}
|
|
103
|
+
function scorePressure(input, weight) {
|
|
104
|
+
if (!input.pressure) {
|
|
105
|
+
return { score: 75, weight, reason: "\u65E0\u538B\u529B\u6570\u636E\uFF0C\u6309\u4E2D\u7B49\u504F\u597D\u8BA1" };
|
|
106
|
+
}
|
|
107
|
+
if (!input.ratedPressure) {
|
|
108
|
+
return { score: 75, weight, reason: "\u4EC5\u77E5\u5F53\u524D\u538B\u529B" };
|
|
109
|
+
}
|
|
110
|
+
const ratio = input.pressure / input.ratedPressure;
|
|
111
|
+
if (ratio < 0.5) return { score: 60, weight, reason: "\u538B\u529B\u504F\u4F4E (\u4F7F\u7528\u7387 <50%)" };
|
|
112
|
+
if (ratio < 0.8) return { score: 90, weight, reason: "\u538B\u529B\u6B63\u5E38 (\u4F7F\u7528\u7387 50-80%)" };
|
|
113
|
+
if (ratio < 1) return { score: 75, weight, reason: "\u538B\u529B\u504F\u9AD8 (\u4F7F\u7528\u7387 80-100%)" };
|
|
114
|
+
if (ratio < 1.2) return { score: 30, weight, reason: "\u538B\u529B\u8D85\u9650 (100-120%)" };
|
|
115
|
+
return { score: 0, weight, reason: "\u538B\u529B\u4E25\u91CD\u8D85\u9650 (>120%)" };
|
|
116
|
+
}
|
|
117
|
+
function scoreProtection(input, weight) {
|
|
118
|
+
if (input.hasCathodicProtection === true) {
|
|
119
|
+
return { score: 90, weight, reason: "\u6709\u9634\u6781\u4FDD\u62A4" };
|
|
120
|
+
}
|
|
121
|
+
if (input.hasCathodicProtection === false) {
|
|
122
|
+
return { score: 30, weight, reason: "\u65E0\u9634\u6781\u4FDD\u62A4" };
|
|
123
|
+
}
|
|
124
|
+
return { score: 50, weight, reason: "\u9634\u4FDD\u72B6\u6001\u672A\u77E5" };
|
|
125
|
+
}
|
|
126
|
+
function scorePipes(inputs, weights = DEFAULT_WEIGHTS) {
|
|
127
|
+
return inputs.map((i) => scorePipeHealth(i, weights));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/health/riskHeatmap.ts
|
|
131
|
+
function aggregateHeatmap(points, options = {}) {
|
|
132
|
+
const cell = options.cellSize ?? 500;
|
|
133
|
+
const agg = options.aggregation ?? "average";
|
|
134
|
+
if (points.length === 0) return [];
|
|
135
|
+
const refLat = points[0].lat;
|
|
136
|
+
const refLng = points[0].lng;
|
|
137
|
+
const mPerDegLat = 110540;
|
|
138
|
+
const mPerDegLng = 111320 * Math.cos(refLat * Math.PI / 180);
|
|
139
|
+
const grid = /* @__PURE__ */ new Map();
|
|
140
|
+
for (const p of points) {
|
|
141
|
+
const x = (p.lng - refLng) * mPerDegLng;
|
|
142
|
+
const y = (p.lat - refLat) * mPerDegLat;
|
|
143
|
+
const cx = Math.floor(x / cell);
|
|
144
|
+
const cy = Math.floor(y / cell);
|
|
145
|
+
const key = `${cx}:${cy}`;
|
|
146
|
+
const cur = grid.get(key);
|
|
147
|
+
if (!cur) {
|
|
148
|
+
grid.set(key, {
|
|
149
|
+
acc: p.healthScore,
|
|
150
|
+
count: 1,
|
|
151
|
+
minS: p.healthScore,
|
|
152
|
+
maxS: p.healthScore,
|
|
153
|
+
lng: p.lng,
|
|
154
|
+
lat: p.lat
|
|
155
|
+
});
|
|
156
|
+
} else {
|
|
157
|
+
cur.acc += p.healthScore;
|
|
158
|
+
cur.count += 1;
|
|
159
|
+
if (p.healthScore < cur.minS) cur.minS = p.healthScore;
|
|
160
|
+
if (p.healthScore > cur.maxS) cur.maxS = p.healthScore;
|
|
161
|
+
cur.lng = (cur.lng * (cur.count - 1) + p.lng) / cur.count;
|
|
162
|
+
cur.lat = (cur.lat * (cur.count - 1) + p.lat) / cur.count;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
const cells = [];
|
|
166
|
+
for (const v of grid.values()) {
|
|
167
|
+
let score;
|
|
168
|
+
if (agg === "min") score = v.minS;
|
|
169
|
+
else if (agg === "max") score = v.maxS;
|
|
170
|
+
else score = v.acc / v.count;
|
|
171
|
+
cells.push({
|
|
172
|
+
lng: v.lng,
|
|
173
|
+
lat: v.lat,
|
|
174
|
+
healthScore: Math.round(score),
|
|
175
|
+
pipeCount: v.count
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
return cells;
|
|
179
|
+
}
|
|
180
|
+
function heatmapToGeoJSON(cells) {
|
|
181
|
+
return {
|
|
182
|
+
type: "FeatureCollection",
|
|
183
|
+
features: cells.map((c) => ({
|
|
184
|
+
type: "Feature",
|
|
185
|
+
geometry: { type: "Point", coordinates: [c.lng, c.lat] },
|
|
186
|
+
properties: {
|
|
187
|
+
healthScore: c.healthScore,
|
|
188
|
+
pipeCount: c.pipeCount
|
|
189
|
+
}
|
|
190
|
+
}))
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function prioritizeMaintenance(pipes, topN = 10) {
|
|
194
|
+
return [...pipes].sort((a, b) => a.healthScore - b.healthScore).slice(0, topN);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// src/health/PipelineHealth.ts
|
|
198
|
+
var PipelineHealth = class {
|
|
199
|
+
map;
|
|
200
|
+
dataset;
|
|
201
|
+
cellSize;
|
|
202
|
+
layerPrefix;
|
|
203
|
+
listeners = /* @__PURE__ */ new Set();
|
|
204
|
+
lastResult = null;
|
|
205
|
+
layerIds = [];
|
|
206
|
+
constructor(options) {
|
|
207
|
+
this.map = options.map;
|
|
208
|
+
this.dataset = options.dataset;
|
|
209
|
+
this.cellSize = options.cellSize ?? 500;
|
|
210
|
+
this.layerPrefix = options.layerPrefix ?? "cg-health";
|
|
211
|
+
}
|
|
212
|
+
/** 评估全网管线健康度 */
|
|
213
|
+
evaluate(weights = DEFAULT_WEIGHTS) {
|
|
214
|
+
const t0 = typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
215
|
+
const nodeById = new Map(this.dataset.nodes.map((n) => [n.id, n]));
|
|
216
|
+
const scores = this.dataset.pipes.map((p) => {
|
|
217
|
+
const input = {
|
|
218
|
+
installDate: p.properties?.installDate,
|
|
219
|
+
material: p.properties?.material,
|
|
220
|
+
failureCount: void 0,
|
|
221
|
+
pressure: p.properties?.pressure,
|
|
222
|
+
ratedPressure: p.properties?.ratedPressure,
|
|
223
|
+
hasCathodicProtection: void 0,
|
|
224
|
+
status: p.properties?.status
|
|
225
|
+
};
|
|
226
|
+
return { pipeId: p.id, score: scorePipeHealth(input, weights) };
|
|
227
|
+
});
|
|
228
|
+
const points = scores.flatMap((s, i) => {
|
|
229
|
+
const pipe = this.dataset.pipes[i];
|
|
230
|
+
const from = nodeById.get(pipe.fromNode);
|
|
231
|
+
const to = nodeById.get(pipe.toNode);
|
|
232
|
+
if (!from || !to) return [];
|
|
233
|
+
return [
|
|
234
|
+
{
|
|
235
|
+
lng: (from.lng + to.lng) / 2,
|
|
236
|
+
lat: (from.lat + to.lat) / 2,
|
|
237
|
+
healthScore: s.score.score
|
|
238
|
+
}
|
|
239
|
+
];
|
|
240
|
+
});
|
|
241
|
+
const heatmap = aggregateHeatmap(points, { cellSize: this.cellSize });
|
|
242
|
+
const maintenance = prioritizeMaintenance(
|
|
243
|
+
scores.flatMap((s, i) => {
|
|
244
|
+
const pipe = this.dataset.pipes[i];
|
|
245
|
+
const from = nodeById.get(pipe.fromNode);
|
|
246
|
+
const to = nodeById.get(pipe.toNode);
|
|
247
|
+
if (!from || !to) return [];
|
|
248
|
+
return [
|
|
249
|
+
{
|
|
250
|
+
id: pipe.id,
|
|
251
|
+
healthScore: s.score.score,
|
|
252
|
+
lng: (from.lng + to.lng) / 2,
|
|
253
|
+
lat: (from.lat + to.lat) / 2,
|
|
254
|
+
label: pipe.id
|
|
255
|
+
}
|
|
256
|
+
];
|
|
257
|
+
})
|
|
258
|
+
);
|
|
259
|
+
const durationMs = (typeof performance !== "undefined" ? performance.now() : Date.now()) - t0;
|
|
260
|
+
const result = { scores, heatmap, maintenance, durationMs };
|
|
261
|
+
this.lastResult = result;
|
|
262
|
+
this.renderHeatmap(result);
|
|
263
|
+
for (const l of this.listeners) l(result);
|
|
264
|
+
return result;
|
|
265
|
+
}
|
|
266
|
+
/** 清空图层 */
|
|
267
|
+
clear() {
|
|
268
|
+
for (const id of this.layerIds) {
|
|
269
|
+
this.map.removeLayer(id);
|
|
270
|
+
}
|
|
271
|
+
this.layerIds = [];
|
|
272
|
+
}
|
|
273
|
+
/** 销毁 */
|
|
274
|
+
destroy() {
|
|
275
|
+
this.clear();
|
|
276
|
+
this.listeners.clear();
|
|
277
|
+
this.lastResult = null;
|
|
278
|
+
}
|
|
279
|
+
/** 订阅结果 */
|
|
280
|
+
onResult(fn) {
|
|
281
|
+
this.listeners.add(fn);
|
|
282
|
+
return () => this.listeners.delete(fn);
|
|
283
|
+
}
|
|
284
|
+
/** 取最后一次结果 */
|
|
285
|
+
getLastResult() {
|
|
286
|
+
return this.lastResult;
|
|
287
|
+
}
|
|
288
|
+
renderHeatmap(result) {
|
|
289
|
+
this.clear();
|
|
290
|
+
const mlMap = this.map.instance;
|
|
291
|
+
const data = heatmapToGeoJSON(result.heatmap);
|
|
292
|
+
const sourceId = `${this.layerPrefix}-heat-src`;
|
|
293
|
+
const layerId = `${this.layerPrefix}-heat-point`;
|
|
294
|
+
if (!mlMap.getSource(sourceId)) mlMap.addSource(sourceId, data);
|
|
295
|
+
try {
|
|
296
|
+
mlMap.addLayer({
|
|
297
|
+
id: layerId,
|
|
298
|
+
type: "heatmap",
|
|
299
|
+
source: sourceId,
|
|
300
|
+
paint: {
|
|
301
|
+
"heatmap-weight": [
|
|
302
|
+
"interpolate",
|
|
303
|
+
["linear"],
|
|
304
|
+
["get", "healthScore"],
|
|
305
|
+
0,
|
|
306
|
+
1,
|
|
307
|
+
50,
|
|
308
|
+
0.5,
|
|
309
|
+
100,
|
|
310
|
+
0
|
|
311
|
+
],
|
|
312
|
+
"heatmap-intensity": 1,
|
|
313
|
+
"heatmap-color": [
|
|
314
|
+
"interpolate",
|
|
315
|
+
["linear"],
|
|
316
|
+
["heatmap-density"],
|
|
317
|
+
0,
|
|
318
|
+
"rgba(34,197,94,0)",
|
|
319
|
+
0.2,
|
|
320
|
+
"rgba(34,197,94,0.5)",
|
|
321
|
+
0.5,
|
|
322
|
+
"rgba(245,158,11,0.7)",
|
|
323
|
+
0.8,
|
|
324
|
+
"rgba(239,68,68,0.8)",
|
|
325
|
+
1,
|
|
326
|
+
"rgba(127,29,29,0.9)"
|
|
327
|
+
],
|
|
328
|
+
"heatmap-radius": 25,
|
|
329
|
+
"heatmap-opacity": 0.7
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
this.layerIds.push(layerId);
|
|
333
|
+
} catch {
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
export { DEFAULT_WEIGHTS, PipelineHealth, aggregateHeatmap, heatmapToGeoJSON, prioritizeMaintenance, scorePipeHealth, scorePipes };
|
|
339
|
+
//# sourceMappingURL=chunk-VA2TQWL3.js.map
|
|
340
|
+
//# sourceMappingURL=chunk-VA2TQWL3.js.map
|