-
Notifications
You must be signed in to change notification settings - Fork 288
Expand file tree
/
Copy path01_chartService.html
More file actions
1296 lines (1199 loc) · 47.2 KB
/
01_chartService.html
File metadata and controls
1296 lines (1199 loc) · 47.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
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!--********************************************************************
* 该示例需要引入
* turf (https://github.com/Turfjs/turf)
* mapbox-gl-enhance (https://iclient.supermap.io/web/libs/mapbox-gl-js-enhance/1.12.1-12/mapbox-gl-enhance.js)
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<title data-i18n="resources.title_chartService"></title>
<style>
#toolbar {
position: absolute;
top: 0px;
right: 10px;
width: 330px;
height: 100%;
z-index: 999;
border-radius: 4px;
}
.tab-content {
height: calc(100% - 80px);
overflow: auto;
}
.setting-title {
padding: 4px;
text-align: left;
}
#settings .input-group-addon:first-child {
min-width: 165px;
text-align: left;
}
#sql .input-group-addon:first-child {
min-width: 100px;
text-align: left;
}
#groups {
max-height: 290px;
overflow: auto;
padding: 0;
}
#queryResults {
max-height: 360px;
overflow: auto;
padding: 0;
}
#tablePanel td,
#tablePanel th {
border: 1px solid black;
width: 130px;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
padding: 2px 6px;
}
#tablePanel .nav {
margin-bottom: 4px;
}
.fascTable table {
margin-bottom: 10px;
}
#queryResults a,
#groups a,
a:hover,
a:focus {
color: #333 !important;
text-decoration: none !important;
}
#queryResults li>a,
#groups li>a {
display: inline-block;
width: 100%;
padding: 3px 8px;
}
#queryResults li,
#groups li {
display: flex;
align-items: center;
padding: 0 20px;
}
#queryResults li img,
#groups li img {
width: 12px;
height: 12px;
opacity: 0.8;
}
#queryResults li:hover,
#queryResults li.active,
#groups li:hover,
#groups li.active {
background-color: #eee;
}
.attrs-btns {
display: flex;
justify-content: center;
padding: 10px;
}
#toolbar .panel-heading {
padding: 0;
}
#water .optionsWithLabel {
margin: 10px;
}
#water .optionsWithLabel>span {
width: 110px;
padding-right: 6px;
}
#wlaUnit {
padding: 0;
}
#water .unit {
width: 50px;
margin-left: 4px;
}
#water .optionsWithLabel :nth-child(2) {
flex: 1;
}
.wlaPanel .optionsWithLabel>span {
/* width: 100px; */
text-align: right;
}
#chartContainer {
position: absolute;
top: 5px;
left: 5px;
background: white;
color: #333;
box-shadow: 0 3px 14px rgba(0, 0, 0, 0.4);
display: none;
z-index: 9999;
}
.header {
display: flex;
justify-content: space-between;
padding: 6px;
border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}
.optionsWithLabel {
display: flex;
align-items: center;
}
.optionsWithLabel>span {
text-wrap: nowrap;
}
#chart {
margin-top: 10px;
width: 480px;
height: 330px;
}
#datetimepicker {
width: 160px;
}
#settings .chartseting-panel-heading {
margin: 10px 0;
font-weight: bold;
cursor: pointer;
}
.chartseting-panel-heading:not(.collapsed) .collapse-icon {
display: inline-block;
rotate: 90deg;
}
</style>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div id="map" style="width: 100%;height:100%"></div>
<div id="chartContainer">
<div class="header">
<div class="optionsWithLabel">
<span data-i18n="resources.text_currentTime"></span>
<input type="text" id="datetimepicker" class='form-control'>
</div>
<div class="optionsWithLabel">
<span data-i18n="resources.text_queryCondition"></span>
<select id="timeOption" class='form-control' onchange="createEchart()">
<option value="3-hours" data-i18n="resources.text_inFuture3hours"></option>
<option value="6-hours" data-i18n="resources.text_inFuture6hours"></option>
<option value="12-hours" data-i18n="resources.text_inFuture12hours"></option>
<option value="1-days" data-i18n="resources.text_inFuture1days"></option>
<option value="3-days" data-i18n="resources.text_inFuture3days"></option>
<option value="5-days" data-i18n="resources.text_inFuture5days"></option>
<option value="7-days" data-i18n="resources.text_inFuture7days"></option>
<option value="all" data-i18n="resources.text_inFutureAll"></option>
</select>
</div>
<div class="close" onclick="closeChart()">×</div>
</div>
<div id="chart"></div>
</div>
<div id="toolbar" class="panel panel-primary">
<ul class='panel-heading nav nav-tabs'>
<li class="panel-title active"><a href="#settings" data-toggle="tab" data-i18n="resources.text_chartSetting"></a></li>
<li class="panel-title"><a href="#attrs" data-toggle="tab" data-i18n="resources.text_selectQuery"></a></li>
<li class="panel-title"><a href="#sql" data-toggle="tab" data-i18n="resources.text_sqlQuery"></a></li>
<li class="panel-title"><a href="#water" data-toggle="tab" data-i18n="resources.text_water"></a></li>
</ul>
<div class="tab-content">
<!-- 海图设置面板 -->
<div class='panel-body content tab-pane active' id="settings">
</div>
<!-- 点选查询面板 -->
<div class="panel-body tab-pane" id="attrs">
<ul id="groups"></ul>
<div id="tablePanel" class="tab-content"></div>
<div id="queryTips" style="text-align: center;"></div>
<div class="attrs-btns">
<input type="button" class="btn btn-default" data-i18n="[value]resources.btn_select" onclick="clickToDraw()"/>
<input type="button" class="btn btn-default" data-i18n="[value]resources.btn_cancel" onclick="cancelClickDraw()"/>
</div>
</div>
<!-- SQL查询面板 -->
<div class="panel-body tab-pane" id="sql">
<div class='panel'>
<div class='input-group'>
<span class='input-group-addon' data-i18n="resources.text_chartLayers"></span>
<select id='chartLayers' class='form-control'></select>
</div>
</div>
<div class='panel'>
<div class='input-group'>
<span class='input-group-addon' data-i18n="resources.text_featuresType"></span>
<select id='featuresList' class='form-control'></select>
</div>
</div>
<div class='panel'>
<div class='input-group'>
<span class='input-group-addon' data-i18n="resources.text_attributeFilter"></span>
<input type='text' class='form-control' id='attributeFilter' value='SMID > 0' />
</div>
</div>
<!-- S57生效 -->
<div class='panel'>
<div class='input-group'>
<span class='input-group-addon' data-i18n="resources.text_isQueryPoint"></span>
<select id='isQueryPoint' class='form-control'>
<option value="true" data-i18n="resources.text_true" selected></option>
<option value="false" data-i18n="resources.text_false"></option>
</select>
</div>
</div>
<div class='panel'>
<div class='input-group'>
<span class='input-group-addon' data-i18n="resources.text_isQueryLine"></span>
<select id='isQueryLine' class='form-control'>
<option value="true" data-i18n="resources.text_true" selected></option>
<option value="false" data-i18n="resources.text_false"></option>
</select>
</div>
</div>
<div class='panel'>
<div class='input-group'>
<span class='input-group-addon' data-i18n="resources.text_isQueryRegion"></span>
<select id='isQueryRegion' class='form-control'>
<option value="true" data-i18n="resources.text_true" selected></option>
<option value="false" data-i18n="resources.text_false"></option>
</select>
</div>
</div>
<div class='panel'>
<div class="attrs-btns">
<input type="button" class="btn btn-default" data-i18n="[value]resources.text_query" onclick="sqlQuery()" />
<input type="button" class="btn btn-default" data-i18n="[value]resources.btn_clear" onclick="removeSqlRes()"/>
</div>
</div>
<ul id="queryResults"></ul>
</div>
<!-- 水深与水位面板 -->
<div class="panel-body tab-pane" id="water">
<div class="optionsWithLabel">
<span data-i18n="resources.text_S102query"></span>
<div>
<input type="button" class="btn btn-default" data-i18n="[value]resources.text_queryDepth" onclick="S102GridQuery()"/>
<input type="button" class="btn btn-default" data-i18n="[value]resources.btn_cancel" onclick="cancelS102GridQuery()"/>
</div>
</div>
<div class="optionsWithLabel">
<span data-i18n="resources.text_S104query"></span>
<div>
<input type="button" class="btn btn-default" data-i18n="[value]resources.text_queryLevel" onclick="S104ClickToSelect()"/>
<input type="button" class="btn btn-default" data-i18n="[value]resources.btn_cancel" onclick="cancelS104ClickToSelect()"/>
</div>
</div>
<!-- 水位调整WLA -->
<div class="wlaPanel">
<div class="optionsWithLabel">
<span data-i18n="resources.text_wla"></span>
<select id='wlaEnable' class='form-control' onchange="changeWLA()">
<option value="true" data-i18n="resources.text_true"></option>
<option value="false" data-i18n="resources.text_false" selected></option>
</select>
</div>
<!-- 起始终止时间 -->
<div class="optionsWithLabel">
<span data-i18n="resources.text_beginTime"></span>
<input type="text" id="datetimepickerBegin" class='form-control wlaState'>
</div>
<div class="optionsWithLabel">
<span data-i18n="resources.text_endTime"></span>
<input type="text" id="datetimepickerEnd" class='form-control wlaState'>
</div>
<!-- 间隔时间 -->
<div class="optionsWithLabel">
<span data-i18n="resources.text_intervalTime"></span>
<input type='number' class='form-control wlaState' id='walIntervalTime' value='1' />
<select id='wlaUnit' class='form-control unit wlaState'>
<option value="days" data-i18n="resources.text_day"></option>
<option value="hours" data-i18n="resources.text_hour" selected></option>
<option value="minutes" data-i18n="resources.text_minute"></option>
<option value="seconds" data-i18n="resources.text_second"></option>
</select>
</div>
<!-- 播放间隔 -->
<div class="optionsWithLabel">
<span data-i18n="resources.text_playInterval"></span>
<input type='number' class='form-control wlaState' id='walPlayInterval' value='1'/>
<div data-i18n="resources.text_second" class="unit"></div>
</div>
<!-- 当前时间 -->
<div class="optionsWithLabel">
<span data-i18n="resources.text_currentTime"></span>
<div id="wlaCurrentTime"></div>
</div>
<!-- 播放暂停 -->
<div class="attrs-btns">
<input type="button" class="btn btn-default wlaState" data-i18n="[value]resources.btn_play" onclick="wlaPlay()"/>
<input type="button" class="btn btn-default wlaState" data-i18n="[value]resources.btn_pause" onclick="wlaPause()"/>
<input type="button" class="btn btn-default wlaState" data-i18n="[value]resources.btn_stop" onclick="wlaEnd()"/>
</div>
</div>
</div>
</div>
</div>
<!-- 物标分类列表 -->
<div class="panel panel-primary" style="width:160px;position: absolute;bottom:5px;left:5px;z-index: 999;">
<div class="panel-heading">
<h5 class='panel-title text-center'>
<span data-i18n="resources.text_classify"></span>
</h5>
</div>
<div class="panel-body" id="classify"></div>
</div>
</script>
<script type="text/javascript" include="bootstrap,moment,bootstrap-datetimepicker,jquery-treegrid" src="../js/include-web.js"></script>
<script type="text/javascript" include="mapbox-gl-enhance,turf,lodash,echarts" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
<script type="text/javascript">
var url = "https://iserver.supermap.io/iserver/services/map-chart/rest/maps/GB4X0000_52000";
// var url = "http://localhost:8090/iserver/services/map-WorkSpace1-2/rest/maps/S104S102_1";
var dataUrl = "http://localhost:8090/iserver/services/data-WorkSpace1-2/rest/data";
var s104dataSource = 'nanbaoS104v200';
var s104dataSet = 'S104Position4326';
var s104dataSetWaterLevel = 'S104WaterLevel';
var s104dataSetTime = 'S104Time';
var chartService = new mapboxgl.supermap.ChartService(url, dataUrl);
var featureInfos;
var imgSrc = {
"Point": "../img/point1.png",
"MultiPoint": "../img/point1.png",
"LineString": "../img/line.png",
"MultiLineString": "../img/line.png",
"Polygon": "../img/polygon.png",
"MultiPolygon": "../img/polygon.png",
};
// S104水位查询,某个站点的全部时间要素
var stationFeatures = [];
var overlayPopup = new mapboxgl.Popup({ maxWidth: 'none' });
var chartContainer = document.getElementById('chartContainer');
var displayableAcronymClassify = {};
// var chartSetting = getChartSetting();
var map = new mapboxgl.Map({
container: 'map',
style: {
version: 8,
sources: {
'raster-tiles': {
type: 'raster',
tileSize: 256,
tiles: [url+ '/tileimage.png?scale={scale}&x={x}&y={y}&width={width}&height={height}&origin={"x":-180,"y":90}'],
}
},
layers: [
{
id: 'simple-tiles',
type: 'raster',
source: 'raster-tiles',
minzoom: 0,
maxzoom: 22
}
]
},
crs: 'EPSG:4326',
center: [61.0, -32.51],
maxZoom: 20,
zoom: 12
});
changeDisplayModeChart();
function changeDisplayModeChart() {
// 当将显示模式设置为OTHER时,是否显示水深点、是否显示元物标、是否显示其他等深线标注 才有效
var displayModeChart = document.getElementById("displayModeChart").value;
document.getElementById("displaySounding").disabled = displayModeChart !== 'OTHER';
document.getElementById("displayMetaObject").disabled = displayModeChart !== 'OTHER';
document.getElementById("displayOtherContourLabel").disabled = displayModeChart !== 'OTHER';
}
function createChartSettingPanel(defaultChartSetting, maritimePcInfo) {
const container = document.getElementById('settings');
let htmlContent = '';
const chartTypes = Object.keys(defaultChartSetting && defaultChartSetting.contextParameters || {});
chartTypes.forEach((type, index) => {
const collapseId = `collapse-${type}-${index}`; // 为每个类型生成唯一 ID
htmlContent += `
<div data-toggle='collapse'
data-target='#${collapseId}'
aria-expanded='true'
class='chartseting-panel-heading'>
<i class="collapse-icon"> > </i> Maritime${type}
</div>
<div id='${collapseId}' class='collapse in'> `;
const PCVersion = defaultChartSetting.contextParameters[type].PCVersion;
const S100Parameter = maritimePcInfo[PCVersion];
S100Parameter.sort((a, b) => a.type.localeCompare(b.type));
S100Parameter.forEach(item => {
const domId = type + item.id;
// 1. 开始构建 input-group 容器
htmlContent += `<div class='input-group'>`;
htmlContent += `<span class='input-group-addon'>${item.name}</span>`;
// 2. 判断渲染逻辑
// 情况 A: 有枚举值 或者 类型是布尔值 -> 渲染 Select
if (item.contextParameterEnums || item.type === 'Boolean') {
htmlContent += `<select id='${domId}' class='form-control'>`;
let options = [];
if (item.contextParameterEnums) {
// 使用提供的枚举值
options = item.contextParameterEnums.map(opt => ({
value: opt.id,
text: opt.description
}));
} else if (item.type === 'Boolean') {
// 基础布尔值,没有提供枚举时默认 TRUE/FALSE
options = [
{ value: "TRUE", text: "TRUE" },
{ value: "FALSE", text: "FALSE" }
];
}
// 循环生成 Option
options.forEach(opt => {
const isSelected = item.defaultValue.toUpperCase() === opt.value.toUpperCase() ? 'selected' : '';
htmlContent += `<option value="${opt.value}" ${isSelected}>${opt.text}</option>`;
});
htmlContent += `</select>`;
}
// 情况 B: 类型是数值 (Double) -> 渲染 Input Number
else if (item.type === 'Double') {
htmlContent += `<input type='number' class='form-control' id='${domId}' value='${item.defaultValue}' />`;
}
htmlContent += `</div>`;
});
htmlContent += `</div>`; // 闭合 collapse 容器
});
htmlContent += `
<div class='panel'>
<div data-i18n="resources.text_filterSetting" class="setting-title">互操作设置</div>
<div class='input-group'>
<span class='input-group-addon'>互操作</span>
<select id='s98InteroperableEnable' class='form-control'>
<option value="true" >是</option>
<option value="false" selected>否</option>
</select>
</div>
<div class='input-group'>
<span class='input-group-addon'>互操作等级</span>
<select id='interoperabilityLevel' class='form-control'>
<option value="0" selected>L0</option>
<option value="1">L1</option>
</select>
</div>
</div>
<input type="button" class="btn btn-default" onclick="updateChartSetting()" value="应用" />
`;
container.innerHTML = htmlContent;
}
// 获取地图默认chartSetting
function getMapDefaultChartSetting() {
return new ol.supermap.MapService(url).getMapInfo().then(function(res) {
return res.result && res.result.chartSetting;
});
}
function getChartMaritimePcInfo() {
getMapDefaultChartSetting().then(defaultChartSetting => {
DefaultChartSetting = defaultChartSetting;
chartService.getChartMaritimePcInfo().then(function(maritimePcInfo) {
MaritimePcInfo = maritimePcInfo.result;
createChartSettingPanel(defaultChartSetting, maritimePcInfo.result);
updateChartSetting();
});
})
}
getChartMaritimePcInfo()
function getChartSetting() {
const getValue = (id, type) => {
const el = document.getElementById(id);
if (!el) return undefined;
const val = el.value;
switch (type) {
case 'Double': return parseFloat(val);
case 'Boolean': return val.toUpperCase() === "TRUE";
default: return val;
}
};
const chartTypes = Object.keys(DefaultChartSetting.contextParameters || {});
const contextParameters = {};
chartTypes.forEach(type => {
const PCVersion = DefaultChartSetting.contextParameters[type].PCVersion;
const S100Parameter = MaritimePcInfo[PCVersion];
contextParameters[type] = {};
S100Parameter.forEach(item => {
contextParameters[type][item.id] = getValue(type + item.id, item.type);
});
})
// 其余属性
var s98InteroperableEnable = document.getElementById("s98InteroperableEnable").value.toUpperCase() === "TRUE";
var interoperabilityLevel = parseFloat(document.getElementById("interoperabilityLevel").value);
var chartSetting = new ol.supermap.ChartSettingS100({
contextParameters: contextParameters,
s98InteroperableEnable: s98InteroperableEnable,
// edit 新增互操作等级
interoperabilityLevel: interoperabilityLevel
})
return chartSetting;
}
function updateChartSetting() {
var newChartSetting = getChartSetting();
map.getSource('raster-tiles').tiles=[url + '/tileimage.png?scale={scale}&x={x}&y={y}&width={width}&height={height}&origin={"x":-180,"y":90}&chartSetting='+ JSON.stringify(newChartSetting)]
map.style.sourceCaches['raster-tiles'].clearTiles()
map.style.sourceCaches['raster-tiles'].update(map.transform)
map.triggerRepaint();
}
// 创建SQL查询的物标类型下拉框
function createChartFeatureInfoSelect() {
var featuresList = document.getElementById('featuresList');
for (var i = 0; i < featureInfos.length; i++) {
const optionElement = document.createElement('option');
optionElement.value = featureInfos[i]['code'];
optionElement.textContent = featureInfos[i]['localName'] || featureInfos[i]['name'];
featuresList.appendChild(optionElement);
}
}
function getChartFeatureInfo() {
chartService.getChartFeatureInfo().then(function (serviceResult) {
featureInfos = serviceResult.result;
createChartFeatureInfoSelect();
})
}
getChartFeatureInfo();
function getClassify() {
var classifications = document.getElementById('classify')
// 获取海图物标分类信息
chartService.getChartAcronymClassify().then(function (serviceResult) {
// 创建分类信息复选框
serviceResult.result && serviceResult.result.forEach(function (element) {
displayableAcronymClassify[element.name] = true
updateChartSetting();
var checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.value = element.name;
checkbox.checked = true;
checkbox.id = element.name;
var label = document.createElement('label');
label.textContent = element.aliasName;
label.style.marginLeft = "15px";
label.htmlFor = element.name;
classifications.appendChild(checkbox);
classifications.appendChild(label);
var brElement = document.createElement('br');
classifications.appendChild(brElement);
checkbox.addEventListener("click", function () {
displayableAcronymClassify[checkbox.value] = checkbox.checked;
updateChartSetting();
});
});
})
}
getClassify();
// 基于tree-grid插件,添加特定的类名,实现树状表格
var index = 0;
function clickQueryHandler(event) {
var coordinates = [event.lngLat.lng, event.lngLat.lat];
var pixelCoor = event.point;
var b1 = map.unproject([pixelCoor.x-15,pixelCoor.y+15]);
var b2 = map.unproject([pixelCoor.x+15,pixelCoor.y-15]);
// 清除上一个点
if (map.getLayer('markerLayer')) {
map.removeLayer('markerLayer');
map.removeSource('markerSource');
}
// 创建新的点图层和数据源
map.addSource('markerSource', {
type: 'geojson',
data: {
type: 'Feature',
geometry: {
type: 'Point',
coordinates: coordinates
}
}
});
map.addLayer({
id: 'markerLayer',
type: 'circle',
source: 'markerSource',
paint: {
'circle-radius': 6,
'circle-color': '#FF0000'
}
});
hasMarker = true;
var parms = new mapboxgl.supermap.ChartQueryParameters({
queryMode: "ChartFeatureBoundsQuery",
bounds: new mapboxgl.LngLatBounds(b1, b2)
});
var groups = document.getElementById('groups');
var tablePanel = document.getElementById('tablePanel');
var queryTips = document.querySelector('#queryTips');
groups.innerHTML = '';
tablePanel.innerHTML = '';
queryTips.innerHTML = resources.text_isQuerying;
new mapboxgl.supermap.ChartService(url, { parseProperties: true }).queryChart(parms).then(res => {
var queryRes = res.result.recordsets;
if (queryRes.length) {
showClickQueryResults(queryRes, groups, tablePanel, queryTips);
} else {
queryTips.innerHTML = resources.text_queryEmpty;
}
})
}
function clickToDraw() {
map.getCanvas().style.cursor = 'crosshair';
map.on('click', clickQueryHandler);
}
function cancelClickDraw() {
map.getCanvas().style.cursor = 'default';
map.off('click', clickQueryHandler);
if (map.getLayer('markerLayer')) {
map.removeLayer('markerLayer');
map.removeSource('markerSource');
}
}
function _createTreeTable(obj, tbody, parent) {
var propertiesKeys = Object.keys(obj);
propertiesKeys.forEach(function (fieldName) {
index++;
var fieldValue = obj[fieldName];
// 复杂属性
if (typeof (fieldValue) === 'object' && fieldValue !== null) {
var tr2 = document.createElement('tr');
tr2.className = 'treegrid-' + index + (parent ? ' treegrid-parent-' + parent : '');
tr2.innerHTML = '<td title=' + fieldName + '>' + fieldName + '</td> <td></td>';
tbody.append(tr2);
var parIndex = index;
_createTreeTable(fieldValue, tbody, parIndex);
} else {
// index ++;
var tr = document.createElement('tr');
tr.className = 'treegrid-' + index + (parent ? ' treegrid-parent-' + parent : '');
tr.innerHTML = '<td title=' + fieldName + '>' + fieldName + '</td> <td title="' + fieldValue + '">' +
fieldValue + '</td>';
tbody.append(tr);
}
})
}
// 创建关联要素的Table,标题为字段
function showAssociations(tableParent, featureProp) {
const parsedData = featureProp;
var table = document.createElement('table');
var propertiesKeys = Object.keys(parsedData[0]);
var thead = document.createElement('thead');
var tr = document.createElement('tr');
thead.append(tr);
table.append(thead);
propertiesKeys.forEach(key => {
var th = document.createElement('th');
th.innerHTML = key;
tr.append(th);
});
var tbody = document.createElement('tbody');
parsedData.forEach(item => {
const row = document.createElement("tr");
propertiesKeys.forEach(key => {
const td = document.createElement("td");
td.textContent = item[key];
row.appendChild(td);
});
tbody.appendChild(row);
})
table.append(tbody);
tableParent.append(table);
}
// 点选查询属性表
function showProperties(tableParent, featureProp) {
var table = document.createElement('table');
table.className = 'tab-pane tree';
var thead = document.createElement('thead');
thead.innerHTML = `<tr><th>${resources.text_propertyName}</th><th>${resources.text_propertyValue}</th></tr>`;
table.append(thead);
tableParent.append(table);
var tbody = document.createElement('tbody');
table.append(tbody);
_createTreeTable(featureProp, tbody);
}
// 创建点选后的UI
function showClickQueryResults(queryRes, groups, tablePanel, queryTips) {
queryTips.innerHTML = '';
queryRes.forEach(recordset => {
// 图幅
var groupName = document.createElement('div');
groupName.innerHTML = recordset.datasetGroupName;
groupName.style.fontWeight = 600;
groups.append(groupName);
recordset.chartRecordsets.forEach((chartFeatureRecordset, recordsetIndex) => {
var matchFeatureInfo = featureInfos.find(function (featureInfo) {
return featureInfo.acronym === chartFeatureRecordset.acronym;
});
var localName = matchFeatureInfo && matchFeatureInfo.localName || chartFeatureRecordset
.acronym || 'chartFeature';
var datasetName = chartFeatureRecordset.datasetName;
chartFeatureRecordset.features.features.forEach((feature, featureIndex) => {
// 图幅下的物标
var type = feature.geometry.type;
var acronym = document.createElement('li');
var idIndex = recordsetIndex + '-' + featureIndex;
acronym.innerHTML =
`<img src=${imgSrc[type]}></img><a href="#panel${idIndex}" data-toggle="tab">${localName}</a>`;
document.getElementById('groups').append(acronym);
// 创建tab栏和table的容器
var tabPanel = document.createElement('div');
tabPanel.className = "tab-pane";
tabPanel.id = 'panel' + idIndex;
tablePanel.append(tabPanel);
// 创建属性、关联信息、关联要素的tab栏
var tabUl = `
<li class="active"><a href="#ATTR${idIndex}" data-toggle="tab">${resources.text_attribute}</a></li>
`
// 创建属性、关联信息、关联要素的tab栏对应的表格内容区
var tabContent = `
<div id="ATTR${idIndex}" style="max-height: 460px;overflow: auto;" class="tab-pane active"></div>
`
if (feature.infoAssociations) {
tabUl += `<li><a href="#INAS${idIndex}" data-toggle="tab" ><span>${resources.text_infoAssociations}</span></a></li>`
tabContent +=
`<div id="INAS${idIndex}" style="max-height: 400px;overflow: auto;" class="tab-pane fascTable">
<div id="INAS-feature${idIndex}"></div>
<div id="INAS-featreAttr${idIndex}"></div>
</div>`
}
if (feature.featureAssociations) {
tabUl += `<li><a href="#FASC${idIndex}" data-toggle="tab" ><span>${resources.text_featureAssociations}</span></a></li>`
tabContent +=
`<div id="FASC${idIndex}" style="max-height: 400px;overflow: auto;" class="tab-pane fascTable">
<div id="FASC-feature${idIndex}"></div>
<div id="FASC-featreAttr${idIndex}"></div>
</div>`
}
var tabheaderUl = document.createElement('ul');
tabheaderUl.className = 'nav nav-tabs';
tabheaderUl.innerHTML = tabUl;
var tabContentDiv = document.createElement('div');
tabContentDiv.className = 'tab-pane tab-content';
tabContentDiv.innerHTML = tabContent;
tabPanel.append(tabheaderUl);
tabPanel.append(tabContentDiv);
// 物标属性表格
var ATTR = document.getElementById('ATTR' + idIndex);
showProperties(ATTR, feature.properties);
// 关联信息表格
var INAS = document.getElementById('INAS-feature' + idIndex);
INAS && showAssociations(INAS, feature.infoAssociations);
// 关联要素表格
var FASC = document.getElementById('FASC-feature' + idIndex);
FASC && showAssociations(FASC, feature.featureAssociations);
})
})
})
$('.tree').treegrid();
document.querySelector('#groups li').classList.add('active');
document.querySelector('#tablePanel .tab-pane').classList.add('active');
}
function getLayers() {
new mapboxgl.supermap.LayerInfoService(url).getLayersInfo().then(function (serviceResult) {
const chartLayers = serviceResult.result.subLayers.layers.map(function (layer) {
return layer.name;
});
var selectElement = document.getElementById('chartLayers');
for (var i = 0; i < chartLayers.length; i++) {
const optionElement = document.createElement('option');
optionElement.value = chartLayers[i];
optionElement.textContent = chartLayers[i];
selectElement.appendChild(optionElement);
}
})
}
getLayers();
function showSqlQueryResults(queryRes, queryResults) {
var allFeatures = {
features: [],
type: "FeatureCollection"
};
var featuresListEle = document.getElementById("featuresList");
var localName = featuresListEle.options[featuresListEle.selectedIndex].text;
queryResults.innerHTML = queryRes.length ? '' : resources.text_queryEmpty;
queryRes.forEach(function (recordset) {
allFeatures.features.push(...recordset.features.features);
recordset.features.features.forEach(function (feature) {
var type = feature.geometry.type;
var acronym = document.createElement('li');
acronym.addEventListener('click', addLayerAndFlyTo);
// 点击列表物标,创建图层高亮显示
function addLayerAndFlyTo() {
removeSqlRes(false);
addSourceAndLayer(feature);
var bounds = turf.bbox(feature);
map.fitBounds(bounds, {
padding: 200
});
}
acronym.innerHTML = '<img src=' + imgSrc[type] + '></img><a data-toggle="tab">' + localName + '</a>';
queryResults.append(acronym);
})
})
addSourceAndLayer(allFeatures);
}
function addSourceAndLayer(features) {
map.addSource('sqlResultSource', {
type: 'geojson',
data: features
});
map.addLayer({
'id': 'sql-layer-fill',
'type': 'fill',
'source': 'sqlResultSource',
'paint': {
'fill-outline-color': 'red',
'fill-color': 'rgba(255, 0, 0, 0.1)'
},
'filter': ['==', '$type', 'Polygon']
});
map.addLayer({
'id': 'sql-layer-line',
'type': 'line',
'source': 'sqlResultSource',
'paint': {
'line-color': 'red',
'line-width': 3
},
'filter': ['==', '$type', 'LineString']
});
map.addLayer({
'id': 'sql-layer-point',
'type': 'symbol',
'source': 'sqlResultSource',
'layout': {
'icon-image': 'icon_name'
},
'filter': ['==', '$type', 'Point']
});
}
map.loadImage(
'../img/point2.png',
function(error, image) {
if (error) throw error;
map.addImage('icon_name', image);
});
function sqlQuery() {
var chartLayerNames = document.getElementById("chartLayers").value;
var featureCode = document.getElementById("featuresList").value;
var attributeFilter = document.getElementById("attributeFilter").value;
var isQueryPoint = document.getElementById("isQueryPoint").value === "true";
var isQueryLine = document.getElementById("isQueryLine").value === "true";
var isQueryRegion = document.getElementById("isQueryRegion").value === "true";
var chartQueryFilterParameter = new mapboxgl.supermap.ChartQueryFilterParameter({
attributeFilter,
featureCode,
// 以下为S57参数
// chartFeatureInfoSpecCode: featureCode,
// isQueryPoint,
// isQueryLine,
// isQueryRegion
});
var chartQueryParameters = new mapboxgl.supermap.ChartQueryParameters({
queryMode: "ChartAttributeQuery",
chartLayerNames: [chartLayerNames],
startRecord: 0,
expectCount: 1000,
returnContent: true,
chartQueryFilterParameters: [chartQueryFilterParameter]
});
var queryResults = document.getElementById('queryResults')
queryResults.innerHTML = resources.text_isQuerying;
removeSqlRes();
chartService.queryChart(chartQueryParameters).then(function (res) {
var queryRes = res?.result?.recordsets || [];
showSqlQueryResults(queryRes, queryResults);
})
}
function removeSqlRes(clearHTML = true) {
if (clearHTML) {
document.getElementById('queryResults').innerHTML = '';
}
var layers = ['sql-layer-fill', 'sql-layer-line', 'sql-layer-point'];
layers.forEach(function(layer) {
if (map.getLayer(layer)) {
map.removeLayer(layer);
}
});
if (map.getSource('sqlResultSource')) {
map.removeSource('sqlResultSource');
}
}
function S102GridQueryDebounceFun(X, Y) {
var chartWaterDepthParameter = new mapboxgl.supermap.ChartWaterDepthParameter({
X: X,
Y: Y
})
chartService.getChartWaterDepth(chartWaterDepthParameter).then(function (res) {
const topDatasetQuery = res.depth;
if (topDatasetQuery) {
var content = topDatasetQuery.result;
var { datasetName, dataSourceName } = topDatasetQuery.options.scope;