-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrefactor-complete-test.html
More file actions
499 lines (427 loc) · 18.2 KB
/
refactor-complete-test.html
File metadata and controls
499 lines (427 loc) · 18.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>重构完成测试 - OpenLayers Serializer</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@10.2.1/ol.css">
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
margin: 0;
padding: 20px;
background-color: #f5f5f7;
}
.container {
max-width: 1200px;
margin: 0 auto;
background: white;
padding: 20px;
border-radius: 12px;
box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}
.header {
text-align: center;
margin-bottom: 30px;
padding: 20px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border-radius: 8px;
}
.test-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
margin-bottom: 30px;
}
.test-section {
background: #f8f9fa;
padding: 20px;
border-radius: 8px;
border-left: 4px solid #007aff;
}
.test-section h3 {
margin: 0 0 15px 0;
color: #333;
display: flex;
align-items: center;
gap: 10px;
}
.test-buttons {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin: 15px 0;
}
button {
padding: 8px 16px;
border: none;
border-radius: 6px;
background: #007aff;
color: white;
cursor: pointer;
font-size: 13px;
transition: all 0.2s ease;
}
button:hover {
background: #0056b3;
transform: translateY(-1px);
}
button.secondary {
background: #6c757d;
}
button.success {
background: #28a745;
}
button.danger {
background: #dc3545;
}
.status {
margin: 15px 0;
padding: 12px;
border-radius: 6px;
font-weight: 500;
}
.status.success {
background: #d1f2eb;
color: #00875a;
border: 1px solid #79f2c0;
}
.status.error {
background: #ffe6e6;
color: #d04e4e;
border: 1px solid #ff9999;
}
.status.info {
background: #e6f3ff;
color: #0066cc;
border: 1px solid #99ccff;
}
.output {
background: #1e1e1e;
color: #d4d4d4;
padding: 15px;
font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', monospace;
font-size: 12px;
max-height: 300px;
overflow-y: auto;
border-radius: 6px;
margin-top: 15px;
white-space: pre-wrap;
}
.summary {
background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
color: white;
padding: 20px;
border-radius: 8px;
text-align: center;
margin-top: 20px;
}
.summary h2 {
margin: 0 0 10px 0;
}
.stats {
display: flex;
justify-content: center;
gap: 30px;
font-size: 18px;
font-weight: 600;
}
.map-container {
height: 300px;
border-radius: 8px;
overflow: hidden;
margin: 20px 0;
border: 2px solid #e1e5e9;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🎉 重构完成测试</h1>
<p>验证新的模块化序列化器架构</p>
</div>
<div class="test-grid">
<div class="test-section">
<h3>📡 Source序列化器</h3>
<div id="source-types">加载中...</div>
<div class="test-buttons">
<button onclick="testAllSources()">测试所有Source</button>
<button onclick="testSourceTypes()" class="secondary">显示支持类型</button>
</div>
<div id="source-status" class="status info">准备测试...</div>
</div>
<div class="test-section">
<h3>🗂️ Layer序列化器</h3>
<div id="layer-types">加载中...</div>
<div class="test-buttons">
<button onclick="testAllLayers()">测试所有Layer</button>
<button onclick="testLayerTypes()" class="secondary">显示支持类型</button>
</div>
<div id="layer-status" class="status info">准备测试...</div>
</div>
</div>
<div class="test-section">
<h3>🔄 完整序列化测试</h3>
<div class="test-buttons">
<button onclick="runCompleteTest()" class="success">运行完整测试</button>
<button onclick="testWithMap()" class="secondary">测试地图序列化</button>
<button onclick="clearOutput()" class="danger">清空输出</button>
</div>
<div id="complete-status" class="status info">点击运行完整测试...</div>
</div>
<div id="map-section" style="display: none;">
<div id="map" class="map-container"></div>
</div>
<div class="output" id="output">等待测试开始...\n</div>
<div class="summary" id="summary" style="display: none;">
<h2>🎯 重构成果总结</h2>
<div class="stats">
<div>Source类型: <span id="source-count">0</span></div>
<div>Layer类型: <span id="layer-count">0</span></div>
<div>测试通过: <span id="pass-count">0</span></div>
</div>
</div>
</div>
<script type="module">
import { Map, View } from 'ol';
import { Tile as TileLayer, Vector as VectorLayer } from 'ol/layer.js';
import { OSM, XYZ, Vector as VectorSource, TileDebug, StadiaMaps, TileWMS, ImageStatic, IIIF } from 'ol/source.js';
import { fromLonLat } from 'ol/proj.js';
import { Point } from 'ol/geom.js';
import { Feature } from 'ol';
import GeoJSON from 'ol/format/GeoJSON.js';
// 导入新的序列化功能
import {
serializeSource,
deserializeSource,
getSupportedSourceTypes
} from './src/serializer/source-new.js';
import {
serializeLayer,
deserializeLayer,
getSupportedLayerTypes
} from './src/serializer/layer-new.js';
let testResults = [];
let totalTests = 0;
let passedTests = 0;
// 显示支持的source类型
window.testSourceTypes = function() {
try {
const sourceTypes = getSupportedSourceTypes();
document.getElementById('source-types').innerHTML =
sourceTypes.map(type => `<span style="background:#e3f2fd;padding:4px 8px;margin:2px;border-radius:4px;display:inline-block;font-size:12px;">${type}</span>`).join('');
document.getElementById('source-count').textContent = sourceTypes.length;
log(`📡 支持的Source类型 (${sourceTypes.length}个):`, sourceTypes);
updateStatus('source-status', `发现 ${sourceTypes.length} 个Source序列化器`, 'success');
} catch (error) {
log('❌ 获取Source类型失败:', error);
updateStatus('source-status', '获取Source类型失败: ' + error.message, 'error');
}
};
// 显示支持的layer类型
window.testLayerTypes = function() {
try {
const layerTypes = getSupportedLayerTypes();
document.getElementById('layer-types').innerHTML =
layerTypes.map(type => `<span style="background:#e8f5e8;padding:4px 8px;margin:2px;border-radius:4px;display:inline-block;font-size:12px;">${type}</span>`).join('');
document.getElementById('layer-count').textContent = layerTypes.length;
log(`🗂️ 支持的Layer类型 (${layerTypes.length}个):`, layerTypes);
updateStatus('layer-status', `发现 ${layerTypes.length} 个Layer序列化器`, 'success');
} catch (error) {
log('❌ 获取Layer类型失败:', error);
updateStatus('layer-status', '获取Layer类型失败: ' + error.message, 'error');
}
};
// 测试所有source
window.testAllSources = function() {
log('🧪 开始测试所有Source序列化器...\n');
const sources = [
{ name: 'OSM', factory: () => new OSM() },
{ name: 'XYZ', factory: () => new XYZ({ url: 'https://example.com/{z}/{x}/{y}.png' }) },
{ name: 'Vector', factory: () => new VectorSource({
features: [new Feature({ geometry: new Point([0, 0]) })]
}) },
{ name: 'TileDebug', factory: () => new TileDebug() },
{ name: 'ImageStatic', factory: () => new ImageStatic({
url: 'https://example.com/image.jpg',
imageExtent: [0, 0, 1, 1]
}) },
];
let passed = 0;
let failed = 0;
sources.forEach(({ name, factory }) => {
try {
totalTests++;
log(` 测试 ${name}...`);
const source = factory();
source.set('id', `test-${name.toLowerCase()}-${Date.now()}`);
source.set('name', `Test ${name} Source`);
// 序列化
const serialized = serializeSource(source);
log(` ✅ ${name} 序列化成功`);
// 反序列化
const deserialized = deserializeSource(serialized);
log(` ✅ ${name} 反序列化成功`);
passed++;
passedTests++;
testResults.push({ type: 'Source', name, result: 'PASS' });
} catch (error) {
log(` ❌ ${name} 测试失败:`, error.message);
failed++;
testResults.push({ type: 'Source', name, result: 'FAIL', error: error.message });
}
});
updateStatus('source-status', `Source测试完成: ${passed}通过, ${failed}失败`, failed === 0 ? 'success' : 'error');
log(`\n📊 Source测试总结: ${passed}/${sources.length} 通过\n`);
};
// 测试所有layer
window.testAllLayers = function() {
log('🧪 开始测试所有Layer序列化器...\n');
const layers = [
{
name: 'TileLayer',
factory: () => new TileLayer({ source: new OSM() })
},
{
name: 'VectorLayer',
factory: () => new VectorLayer({
source: new VectorSource({
features: [new Feature({ geometry: new Point([0, 0]) })]
})
})
},
];
let passed = 0;
let failed = 0;
layers.forEach(({ name, factory }) => {
try {
totalTests++;
log(` 测试 ${name}...`);
const layer = factory();
layer.set('id', `test-${name.toLowerCase()}-${Date.now()}`);
layer.set('name', `Test ${name}`);
// 序列化
const serialized = serializeLayer(layer);
log(` ✅ ${name} 序列化成功`);
// 反序列化
const deserialized = deserializeLayer(serialized);
log(` ✅ ${name} 反序列化成功`);
passed++;
passedTests++;
testResults.push({ type: 'Layer', name, result: 'PASS' });
} catch (error) {
log(` ❌ ${name} 测试失败:`, error.message);
failed++;
testResults.push({ type: 'Layer', name, result: 'FAIL', error: error.message });
}
});
updateStatus('layer-status', `Layer测试完成: ${passed}通过, ${failed}失败`, failed === 0 ? 'success' : 'error');
log(`\n📊 Layer测试总结: ${passed}/${layers.length} 通过\n`);
};
// 运行完整测试
window.runCompleteTest = function() {
testResults = [];
totalTests = 0;
passedTests = 0;
log('🚀 开始运行完整测试套件...\n');
updateStatus('complete-status', '正在运行完整测试...', 'info');
// 先显示类型信息
testSourceTypes();
testLayerTypes();
setTimeout(() => {
// 测试源序列化器
testAllSources();
setTimeout(() => {
// 测试层序列化器
testAllLayers();
setTimeout(() => {
// 显示最终结果
showFinalResults();
}, 500);
}, 500);
}, 500);
};
// 测试地图序列化
window.testWithMap = function() {
document.getElementById('map-section').style.display = 'block';
// 创建简单地图
const map = new Map({
target: 'map',
layers: [
new TileLayer({
source: new OSM()
})
],
view: new View({
center: fromLonLat([116.4, 39.9]),
zoom: 10
})
});
log('🗺️ 创建了测试地图');
updateStatus('complete-status', '地图创建成功,可以进行地图级序列化测试', 'success');
};
// 清空输出
window.clearOutput = function() {
document.getElementById('output').textContent = '输出已清空...\n';
testResults = [];
totalTests = 0;
passedTests = 0;
document.getElementById('summary').style.display = 'none';
};
// 显示最终结果
function showFinalResults() {
const sourceTypes = getSupportedSourceTypes().length;
const layerTypes = getSupportedLayerTypes().length;
const successRate = totalTests > 0 ? ((passedTests / totalTests) * 100).toFixed(1) : 0;
log(`\n🎉 重构完成测试总结:`);
log(`📡 Source序列化器: ${sourceTypes} 个`);
log(`🗂️ Layer序列化器: ${layerTypes} 个`);
log(`✅ 测试通过率: ${successRate}% (${passedTests}/${totalTests})`);
log(`\n🎯 重构成果:`);
log(` ✅ 模块化架构 - 每个类型独立文件`);
log(` ✅ 类型安全 - 强类型约束和编译时检查`);
log(` ✅ 自动注册 - 新增类型无需修改现有代码`);
log(` ✅ 易于维护 - 清晰的职责分离`);
log(` ✅ 向后兼容 - 保留原有API接口`);
updateStatus('complete-status',
`完整测试完成!成功率: ${successRate}% (${passedTests}/${totalTests})`,
passedTests === totalTests ? 'success' : 'error'
);
// 显示总结
document.getElementById('summary').style.display = 'block';
document.getElementById('source-count').textContent = sourceTypes;
document.getElementById('layer-count').textContent = layerTypes;
document.getElementById('pass-count').textContent = `${passedTests}/${totalTests}`;
}
// 辅助函数
function updateStatus(elementId, message, type) {
const statusEl = document.getElementById(elementId);
statusEl.textContent = message;
statusEl.className = `status ${type}`;
}
function log(message, data = null) {
const output = document.getElementById('output');
const timestamp = new Date().toLocaleTimeString();
if (data) {
output.textContent += `[${timestamp}] ${message}\n${JSON.stringify(data, null, 2)}\n\n`;
} else {
output.textContent += `[${timestamp}] ${message}\n`;
}
output.scrollTop = output.scrollHeight;
console.log(message, data);
}
// 页面加载完成后初始化
document.addEventListener('DOMContentLoaded', function() {
log('🚀 重构完成测试页面启动');
log('🔧 新的模块化架构已就绪');
// 自动显示支持的类型
setTimeout(() => {
testSourceTypes();
testLayerTypes();
}, 100);
});
</script>
</body>
</html>