-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
3794 lines (3480 loc) · 121 KB
/
index.js
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
import "ol/ol.css";
import * as ol from "ol";
import { Map, View, Overlay } from "ol";
import XYZ from "ol/source/XYZ";
import { OSM, TileArcGISRest, ImageArcGISRest, TileImage, Vector as VectorSource, WMTS, ImageStatic } from "ol/source";
import WMTSTileGrid from 'ol/tilegrid/WMTS';
import TileWMS from 'ol/source/TileWMS';
import ImageWMS from 'ol/source/ImageWMS';
import TileGrid from "ol/tilegrid/TileGrid"
import { tile as tileStrategy } from 'ol/loadingstrategy';
import { createXYZ } from 'ol/tilegrid';
import * as proj from "ol/proj";
import { Tile as TileLayer, Vector as VectorLayer, Image as ImageLayer, Heatmap } from 'ol/layer';
import { Circle as CircleStyle, Fill, Stroke, Style, Icon, Text } from 'ol/style';
import GeoJSON from 'ol/format/GeoJSON.js';
import EsriJSON from 'ol/format/EsriJSON';
import * as extent from 'ol/extent';
import { defaults as defaultControls, ScaleLine, OverviewMap } from 'ol/control';
import Draw from 'ol/interaction/Draw';
//import {unByKey} from 'ol/Observable';
import * as sphere from 'ol/sphere';
import * as Observable from 'ol/Observable';
import Projection from 'ol/proj/Projection';
import Feature from 'ol/Feature';
import { fromCircle as makeCircle } from "ol/geom/Polygon";
import { bbox as bboxStrategy } from 'ol/loadingstrategy';
import { Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, Circle } from 'ol/geom';
import { DEVICE_PIXEL_RATIO } from 'ol/has.js';
import WindyStn from "./widgets/WindyStn"
import WindyGrid from "./widgets/WindyGrid"
import ADLayer from "./widgets/echart.es5"
import * as turf from "@turf/turf"
import proj4 from 'proj4'
import jsonConverters from './widgets/jsonConverters'
import { saveAs } from 'file-saver';
import html2canvas from 'html2canvas'
import lidw from "./widgets/lidw"
import lidwraster from "./widgets/lidwraster_ol"
import lcolor from "./widgets/lcolor"
import ldraw from "./widgets/ldraw_ol"
import llineChunk from "./widgets/llinechunk"
import lgaussAir from "./widgets/lgaussair"
import projcn from './widgets/proj'
let lgis = function () {
var map = null;
let view = null;
this.layerlist = [];
this.eventlist = [];
this.overlist = [];
this.mapEvents = [];
this.basemaps = {
//天地图-矢量-底图
tdt_vec_w: { id: "tdt_vec_w", type: "tdt", url: "http://t{0-7}.tianditu.com/DataServer?T=vec_w&x={x}&y={y}&l={z}&tk=619944c64ea5110052ab50df192eb202" },
//天地图-矢量-注记
tdt_cva_w: { id: "tdt_cva_w", type: "tdt", url: "http://t{0-7}.tianditu.com/DataServer?T=cva_w&x={x}&y={y}&l={z}&tk=619944c64ea5110052ab50df192eb202" },
//天地图-影像-底图
tdt_img_w: { id: "tdt_img_w", type: "tdt", url: "http://t{0-7}.tianditu.com/DataServer?T=img_w&x={x}&y={y}&l={z}&tk=619944c64ea5110052ab50df192eb202" },
//天地图-影像-注记
tdt_cia_w: { id: "tdt_cia_w", type: "tdt", url: "http://t{0-7}.tianditu.com/DataServer?T=cia_w&x={x}&y={y}&l={z}&tk=619944c64ea5110052ab50df192eb202" },
//天地图-地形-底图
tdt_ter_w: { id: "tdt_ter_w", type: "tdt", url: "http://t{0-7}.tianditu.com/DataServer?T=ter_w&x={x}&y={y}&l={z}&tk=619944c64ea5110052ab50df192eb202" },
//天地图-地形-注记
tdt_cta_w: { id: "tdt_cta_w", type: "tdt", url: "http://t{0-7}.tianditu.com/DataServer?T=cta_w&x={x}&y={y}&l={z}&tk=619944c64ea5110052ab50df192eb202" },
//天地图-矢量-底图-wmts
tdt_vec_w_wmts: { id: "tdt_vec_w_wmts", type: "wmts", url: "http://t{0-7}.tianditu.gov.cn/vec_w/wmts?tk=619944c64ea5110052ab50df192eb202", format: 'tiles', layer: 'vec', matrixSet: 'w' },
//天地图-矢量-注记-wmts
tdt_cva_w_wmts: { id: "tdt_cva_w_wmts", type: "wmts", url: "http://t{0-7}.tianditu.gov.cn/cva_w/wmts?tk=619944c64ea5110052ab50df192eb202", format: 'tiles', layer: 'cva', matrixSet: 'w' },
//天地图-影像-底图-wmts
tdt_img_w_wmts: { id: "tdt_img_w_wmts", type: "wmts", url: "http://t{0-7}.tianditu.gov.cn/img_w/wmts?tk=619944c64ea5110052ab50df192eb202", format: 'tiles', layer: 'img', matrixSet: 'w' },
//天地图-影像-注记-wmts
tdt_cia_w_wmts: { id: "tdt_cia_w_wmts", type: "wmts", url: "http://t{0-7}.tianditu.gov.cn/cia_w/wmts?tk=619944c64ea5110052ab50df192eb202", format: 'tiles', layer: 'cia', matrixSet: 'w' },
//天地图-地形-底图-wmts
tdt_ter_w_wmts: { id: "tdt_ter_w_wmts", type: "wmts", url: "http://t{0-7}.tianditu.gov.cn/ter_w/wmts?tk=619944c64ea5110052ab50df192eb202", format: 'tiles', layer: 'ter', matrixSet: 'w' },
//天地图-地形-注记-wmts
tdt_cta_w_wmts: { id: "tdt_cta_w_wmts", type: "wmts", url: "http://t{0-7}.tianditu.gov.cn/cta_w/wmts?tk=619944c64ea5110052ab50df192eb202", format: 'tiles', layer: 'cta', matrixSet: 'w' },
//天地图-矢量-底图-经纬度
tdt_vec_c: { id: "tdt_vec_c", type: "tdt", url: "http://t{0-7}.tianditu.com/DataServer?T=vec_c&x={x}&y={y}&l={z}&tk=619944c64ea5110052ab50df192eb202", crs: 'EPSG:4326' },
//天地图-矢量-注记-经纬度
tdt_cva_c: { id: "tdt_cva_c", type: "tdt", url: "http://t{0-7}.tianditu.com/DataServer?T=cva_c&x={x}&y={y}&l={z}&tk=619944c64ea5110052ab50df192eb202", crs: 'EPSG:4326' },
//天地图-影像-底图-经纬度
tdt_img_c: { id: "tdt_img_c", type: "tdt", url: "http://t{0-7}.tianditu.com/DataServer?T=img_c&x={x}&y={y}&l={z}&tk=619944c64ea5110052ab50df192eb202", crs: 'EPSG:4326' },
//天地图-影像-注记-经纬度
tdt_cia_c: { id: "tdt_cia_c", type: "tdt", url: "http://t{0-7}.tianditu.com/DataServer?T=cia_c&x={x}&y={y}&l={z}&tk=619944c64ea5110052ab50df192eb202", crs: 'EPSG:4326' },
//天地图-地形-底图-经纬度
tdt_ter_c: { id: "tdt_ter_c", type: "tdt", url: "http://t{0-7}.tianditu.com/DataServer?T=ter_c&x={x}&y={y}&l={z}&tk=619944c64ea5110052ab50df192eb202", crs: 'EPSG:4326' },
//天地图-地形-注记-经纬度
tdt_cta_c: { id: "tdt_cta_c", type: "tdt", url: "http://t{0-7}.tianditu.com/DataServer?T=cta_c&x={x}&y={y}&l={z}&tk=619944c64ea5110052ab50df192eb202", crs: 'EPSG:4326' },
//天地图-矢量-底图-wmts-经纬度
tdt_vec_c_wmts: { id: "tdt_vec_c_wmts", type: "wmts", url: "http://t{0-7}.tianditu.gov.cn/vec_c/wmts?tk=619944c64ea5110052ab50df192eb202", format: 'tiles', layer: 'vec', matrixSet: 'c', crs: 'EPSG:4326' },
//天地图-矢量-注记-wmts-经纬度
tdt_cva_c_wmts: { id: "tdt_cva_c_wmts", type: "wmts", url: "http://t{0-7}.tianditu.gov.cn/cva_c/wmts?tk=619944c64ea5110052ab50df192eb202", format: 'tiles', layer: 'cva', matrixSet: 'c', crs: 'EPSG:4326' },
//天地图-影像-底图-wmts-经纬度
tdt_img_c_wmts: { id: "tdt_img_c_wmts", type: "wmts", url: "http://t{0-7}.tianditu.gov.cn/img_c/wmts?tk=619944c64ea5110052ab50df192eb202", format: 'tiles', layer: 'img', matrixSet: 'c', crs: 'EPSG:4326' },
//天地图-影像-注记-wmts-经纬度
tdt_cia_c_wmts: { id: "tdt_cia_c_wmts", type: "wmts", url: "http://t{0-7}.tianditu.gov.cn/cia_c/wmts?tk=619944c64ea5110052ab50df192eb202", format: 'tiles', layer: 'cia', matrixSet: 'c', crs: 'EPSG:4326' },
//天地图-地形-底图-wmts-经纬度
tdt_ter_c_wmts: { id: "tdt_ter_c_wmts", type: "wmts", url: "http://t{0-7}.tianditu.gov.cn/ter_c/wmts?tk=619944c64ea5110052ab50df192eb202", format: 'tiles', layer: 'ter', matrixSet: 'c', crs: 'EPSG:4326' },
//天地图-地形-注记-wmts-经纬度
tdt_cta_c_wmts: { id: "tdt_cta_c_wmts", type: "wmts", url: "http://t{0-7}.tianditu.gov.cn/cta_c/wmts?tk=619944c64ea5110052ab50df192eb202", format: 'tiles', layer: 'cta', matrixSet: 'c', crs: 'EPSG:4326' },
//OSM
osm: { id: "osm", type: "osm" },
//高德-矢量-底图
gaode_vec: { id: "gaode_vec", type: "gaode", url: 'http://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={x}&y={y}&z={z}' },
//高德-矢量-底图
gaode_img: { id: "gaode_img", type: "gaode", url: 'http://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=6&x={x}&y={y}&z={z}' },
//高德-矢量-底图
gaode_road: { id: "gaode_road", type: "gaode", url: 'http://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=8&x={x}&y={y}&z={z}' },
//GeoQ-暖色-底图
geoq_vec: { id: "geoq_vec", type: "geoq", url: 'https://map.geoq.cn/arcgis/rest/services/ChinaOnlineCommunity/MapServer/tile/{z}/{y}/{x}' },
//GeoQ-灰色-底图
geoq_gray: { id: "geoq_gray", type: "geoq", url: 'https://map.geoq.cn/arcgis/rest/services/ChinaOnlineStreetGray/MapServer/tile/{z}/{y}/{x}' },
//GeoQ-深蓝-底图
geoq_blue: { id: "geoq_blue", type: "geoq", url: 'https://map.geoq.cn/arcgis/rest/services/ChinaOnlineStreetPurplishBlue/MapServer/tile/{z}/{y}/{x}' },
//百度-默认地图
baidu: { id: "baidu", type: "baidu", url: "http://api0.map.bdimg.com/customimage/tile?&x={x}&y={y}&z={z}&scale=1&ak=yI5xHIM4KRSSgOGgvfiKBiVaGwa34Epi" },
//百度-午夜蓝黑
baidu_midnight: { id: "baidu_midnight", type: "baidu", url: "http://api0.map.bdimg.com/customimage/tile?&x={x}&y={y}&z={z}&udt=20190528&scale=1&ak=E4805d16520de693a3fe707cdc962045&customid=midnight" },
//百度-黑色
baidu_dark: { id: "baidu_dark", type: "baidu", url: "http://api0.map.bdimg.com/customimage/tile?&x={x}&y={y}&z={z}&udt=20190528&scale=1&ak=E4805d16520de693a3fe707cdc962045&customid=dark" },
//百度-绿色
baidu_grassgreen: { id: "baidu_grassgreen", type: "baidu", url: "http://api0.map.bdimg.com/customimage/tile?&x={x}&y={y}&z={z}&udt=20190528&scale=1&ak=E4805d16520de693a3fe707cdc962045&customid=grassgreen" },
//百度-灰色
baidu_grayscale: { id: "baidu_grayscale", type: "baidu", url: "http://api0.map.bdimg.com/customimage/tile?&x={x}&y={y}&z={z}&udt=20190528&scale=1&ak=E4805d16520de693a3fe707cdc962045&customid=grayscale" },
//谷歌-矢量-底图
google_vec: { id: "google_vec", type: "google_vec", url: 'http://www.google.cn/maps/vt?lyrs=m@189&gl=cn&x={x}&y={y}&z={z}' },
//谷歌-影像-底图
google_img: { id: "google_img", type: "google_img", url: "http://www.google.cn/maps/vt?lyrs=s@189&gl=cn&x={x}&y={y}&z={z}" },
//mapbox-矢量-底图
mapbox_hypso: { id: "mapbox_hypso", type: "mapbox_hypso", url: 'https://b.tiles.mapbox.com/v3/mapbox.natural-earth-hypso-bathy/{z}/{x}/{y}' },
//mapbox-影像-底图
mapbox_ter: { id: "mapbox_ter", type: "mapbox_ter", url: "https://b.tiles.mapbox.com/v3/mapbox.natural-earth-1/{z}/{x}/{y}.png" },
//mapbox-矢量-底图
mapbox_dark: { id: "mapbox_dark", type: "mapbox_dark", url: 'https://b.tiles.mapbox.com/v3/mapbox.world-dark/{z}/{x}/{y}.png' },
//mapbox-影像-底图
mapbox_black: { id: "mapbox_black", type: "mapbox_black", url: "https://b.tiles.mapbox.com/v3/mapbox.world-black/{z}/{x}/{y}.png" },
//超图-矢量
supermap_vec: { id: "supermap_vec", type: "supermap", url: 'http://t1.supermapcloud.com/FileService/image?x={x}&y={y}&z={z}' },
//超图-深色
supermap_dark: { id: "supermap_dark", type: "supermap", url: "http://t3.supermapcloud.com/MapService/getGdp?map=quanguo&type=web&x={x}&y={y}&z={z}" },
}
this.imgLayer = null;
this.tmpLayers = [];
this.popup, this.popupDom;
this.basemapConfig;
this.baselayers = [];
this.drawLayer;
this.drawInteraction = null;
this.isMeasure = false;
this.addMeasureInteraction = addMeasureInteraction;
this.addMeasureSource = addMeasureSource;
this.clearMeasure = clearMeasure;
this.MeasureDraw = null;
this.MeasureSource = null;
this.MeasureVector = null;
this.Measurelistener = null;//绑定交互绘制工具开始绘制的事件
this.MeasureSketch = null;
this.initMap = initMap;
this.setMapCenter = setMapCenter
this.setLayerVisible = setLayerVisible;
this.addPoints = addPoints;
this.addLines = addLines;
this.addPolygons = addPolygons;
this.addWindy = addWindy;
this.addImage = addImage;
this.addHeatmap = addHeatmap;
this.addOverlays = addOverlays;
this.addServerLayer = addServerLayer;
this.addPointlink = addPointlink;
this.addMapEvent = addMapEvent;
this.removeMapEvent = removeMapEvent;
this.addScale = addScale;
this.addOverview = addOverview;
this.fromLonLat = fromLonLat;
this.toLonLat = toLonLat;
this.flyTo = flyTo;
this.fitLayerExtent=fitLayerExtent;
this.draw0 = draw0;
this.draw = draw;
this.drawStop = drawStop;
this.drawClear = drawClear;
this.buffer = buffer;
this.interpolate = interpolate;
this.lineChunk = lineChunk;
this.lineColorful = lineColorful;
this.setSize = setSize;
this.showInfo = showInfo;
this.hideInfo = hideInfo;
this.layerClear = layerClear;
this.layerOrder = layerOrder;
this.drawAnalysisPoint = drawAnalysisPoint;
this.ExplosiveAnalysis = ExplosiveAnalysis;
this.EsriJsonToGeoJson = EsriJsonToGeoJson;
this.GeoJsonToEsriJson = GeoJsonToEsriJson;
this.isInsidePolygon = isInsidePolygon;
this.createCircle = createCircle;
this.CreateEllipse = CreateEllipse;
this.CreateSector = CreateSector;
this.CreateArrow = CreateArrow;
this.createBuffer = createBuffer;
this.mapShot = mapShot;
this.getLength = getLength;
this.getExtent = getExtent;
this.updateFeatureText = updateFeatureText
this.updateFeatureSymbol = updateFeatureSymbol;
this.gradientColor = lcolor.gradientColor;
this.getPOI = getPOI;
this.getGeoCode = getGeoCode;
this.getLayerById = getLayerById;
this.showDirectionLabel = showDirectionLabel;
this.gaussAir = gaussAir;
this.union = union;
this.getLayerBorder = getLayerBorder;
this.distance = distance;
this.projcn = projcn;
this.getProjection = getProjection;
this.addLabelToLayer = addLabelToLayer;
this.clearLabelLayer = clearLabelLayer;
this.addMarkingToLayer = addMarkingToLayer;
this.clearMarkingLayer = clearMarkingLayer;
this.PathAnimation = PathAnimation;
var _this = this;
var image = new CircleStyle({
radius: 5,
fill: new Fill({ color: 'red' }),
stroke: new Stroke({ color: 'orange', width: 1 })
});
var styles = {
'Point': new Style({
image: image
}),
'LineString': new Style({
stroke: new Stroke({
color: 'red',
width: 1
})
}),
'MultiLineString': new Style({
stroke: new Stroke({
color: 'red',
width: 10
})
}),
'MultiPoint': new Style({
image: image
}),
'MultiPolygon': new Style({
stroke: new Stroke({
color: 'rgba(255, 255, 255, 0.7)',
width: 2
}),
fill: new Fill({
color: 'rgba(255, 0, 0, 0.3)'
})
}),
'Polygon': new Style({
stroke: new Stroke({
color: 'rgba(255, 255, 255, 0.7)',
lineDash: [1],
width: 2
}),
fill: new Fill({
color: 'rgba(255, 0, 0, 0.3)'
})
}),
'GeometryCollection': new Style({
stroke: new Stroke({
color: 'magenta',
width: 2
}),
fill: new Fill({
color: 'magenta'
}),
image: new CircleStyle({
radius: 10,
fill: null,
stroke: new Stroke({
color: 'magenta'
})
})
}),
'Circle': new Style({
stroke: new Stroke({
color: 'red',
width: 2
}),
fill: new Fill({
color: 'rgba(255,0,0,0.2)'
})
})
};
this._MapConfig = {
container: "map"
}
var Resolutions = [
156543.03392800014,
78271.51696399994,
39135.75848200009,
19567.87924099992,
9783.93962049996,
4891.96981024998,
2445.98490512499,
1222.992452562495,
611.4962262813797,
305.74811314055756,
152.87405657041106,
76.43702828507324,
38.21851414253662,
19.10925707126831,
9.554628535634155,
4.77731426794937,
2.388657133974685,
1.1943285668550503,
0.5971642835598172,
0.29858214164761665
]
//初始化地图容器
function initMap(options) {
this._MapConfig = Object.assign(this._MapConfig, options);
this.basemapConfig = options.basemaps;
if (this.basemapConfig) {
this.basemapConfig.forEach(basemap => {
let layer = getLayerByType(basemap.type, basemap);
_this.baselayers.push(layer);
})
_this.layerlist = _this.baselayers;
options.baselayers = _this.baselayers;
createMap(options);
} else {
//未设置底图,留空
}
}
function setMapCenter(x, y) {
var center = [x, y];
view.setCenter(center);
}
//创建地图
function createMap(options) {
let container = options.container;
let baselayers = options.baselayers;
let center = options.center;
let zoom = options.zoom;
let minZoom = options.minZoom;
let maxZoom = options.maxZoom;
// 设置地图坐标系
var projection = baselayers.length > 0 ? baselayers[0].getSource().getProjection() : null;
if (!center) center = [0, 0]
var projectionCode;
if (projection) projectionCode = projection.getCode()
else if (options.basemaps.length > 0 && options.basemaps[0].crs) projectionCode = options.basemaps[0].crs;
else projectionCode = 'EPSG:3857'
// 中心点坐标计算
if (projectionCode == 'EPSG:3857') center = proj.fromLonLat(center)
let p = proj4.defs(projectionCode, coordtrsf[projectionCode.replace('EPSG:', '')])
view = new View({
center: center,
zoom: zoom ? zoom : 1,
minZoom: minZoom ? minZoom : 0,
maxZoom: maxZoom ? maxZoom : 28,
projection: projection ? projection : proj.get(projectionCode)
})
map = new Map({
target: container ? container : "map",
layers: baselayers,
view: view,
});
_this.map = map;
//兼容mapv
//window.ol = ol;
window.map = map;
//气泡初始化
var popupDiv = document.createElement("div");
popupDiv.id = "ol-popup";
popupDiv.className = "ol-popup";
popupDiv.innerHTML = '<a href="#" id="ol-popup-closer" class="ol-popup-closer"></a><div id="ol-popup-title" class="index-body">11</div><div id="ol-popup-content">11</div>';
document.body.appendChild(popupDiv);
_this.popupDom = {
container: document.getElementById('ol-popup'),
title: document.getElementById('ol-popup-title'),
content: document.getElementById('ol-popup-content'),
closer: document.getElementById('ol-popup-closer')
}
_this.popup = new Overlay({
element: _this.popupDom.container,
autoPan: true,
autoPanAnimation: {
duration: 250
}
});
_this.popupDom.closer.onclick = function () {
_this.popup.setPosition(undefined);
_this.popupDom.closer.blur();
return false;
};
//地图单机事件
map.on('singleclick', function (e) {
var pixel = map.getEventPixel(e.originalEvent);
var featureInfo = map.forEachFeatureAtPixel(pixel, function (feature, layer) {
return { feature: feature, layer: layer };
});
if (featureInfo !== undefined && featureInfo !== null && featureInfo.layer !== null) {
// console.log(featureInfo.feature);
// console.log(featureInfo.layer);
//查找监听点击事件的图层
for (let i = 0; i < _this.eventlist.length; i++) {
const eventLayer = _this.eventlist[i];
if (eventLayer == featureInfo.layer) {
var popupinfo = eventLayer.popupFunction({
event: e.originalEvent,
attributes: featureInfo.feature.getProperties(),
properties: featureInfo.feature.getProperties(),
layerId: featureInfo.layer.get('id')
});
if (popupinfo) {
showInfo(featureInfo.feature, popupinfo.title, popupinfo.content);
}
}
}
let feature = featureInfo.feature;
var type = feature.getGeometry().getType();
var property = feature.getProperties();
return;
}
})
//tooltip要素
let tipDiv = document.createElement('div');
tipDiv.className = 'mapTooltip';
tipDiv.style.position = 'absolute';
_this.tooltip = tipDiv;
document.body.appendChild(tipDiv);
let tooltip_waitClose = false;
//地图绑定鼠标移出事件,鼠标移出时为帮助提示框设置隐藏样式
map.getViewport().addEventListener('mouseout', function () {
if (helpTooltipElement != null) {
helpTooltipElement.className = "ol-tooltip hidden";
}
});
//地图滑过事件
map.on('pointermove', function (e) {
if (this.isMeasure) {
pointerMoveHandler(e);
return;
}
var pixel = map.getEventPixel(e.originalEvent);
var featureInfo = map.forEachFeatureAtPixel(pixel, function (feature, layer) {
return { feature: feature, layer: layer };
});
if (featureInfo !== undefined && featureInfo !== null && featureInfo.layer !== null) {
// console.log(featureInfo.feature);
// console.log(featureInfo.layer);
//查找监听点击事件的图层
for (let i = 0; i < _this.overlist.length; i++) {
const eventLayer = _this.overlist[i];
if (eventLayer == featureInfo.layer) {
var tooltipinfo = eventLayer.tooltipFunction(featureInfo.feature.getProperties());
if (tooltipinfo) {
showTooltip(featureInfo.feature, tooltipinfo);
tooltip_waitClose = true;
return;
}
}
}
if (tooltip_waitClose) {
hideTooltip();
tooltip_waitClose = false;
}
let feature = featureInfo.feature;
var type = feature.getGeometry().getType();
var property = feature.getProperties();
return;
}
if (tooltip_waitClose) {
hideTooltip();
tooltip_waitClose = false;
}
})
map.on('postcompose', function (e) {
if (options.callback) {
options.callback(e);
}
})
}
var AnalysisLyr = null;
var AnalysisResultLyr = null;
var AnalysisPointCoord = null;
var AnalysisDrawTool = null;
//设置分析绘点图层
function AnalysisPointLayer() {
AnalysisLyr = new VectorLayer({
source: new VectorSource(),
style: new Style({
image: new CircleStyle({
radius: 2,
fill: new Fill({
color: "rgba(0,0,0,0)"
})
})
}),
zIndex: 90
});
map.addLayer(AnalysisLyr);
}
//销毁分析图层与绘图工具
function destroyAnalysisLayer() {
if (AnalysisLyr) {
map.removeLayer(AnalysisLyr);
AnalysisLyr = null;
}
if (AnalysisResultLyr) {
map.removeLayer(AnalysisResultLyr);
AnalysisResultLyr = null;
}
if (AnalysisDrawTool) {
map.removeInteraction(AnalysisDrawTool);
AnalysisDrawTool = null;
}
};
//绘制分析点
function drawAnalysisPoint(drawCallback) {
destroyAnalysisLayer();
AnalysisPointLayer();
// 清空图层
AnalysisLyr.getSource().clear();
this.AnalysisLyr = AnalysisLyr
if (AnalysisResultLyr != null) {
AnalysisResultLyr.getSource().clear();
}
if (AnalysisDrawTool) return;
var vPointStyle = new Style({
image: new CircleStyle({
radius: 5,
fill: new Fill({ color: 'red' }),
stroke: new Stroke({ color: 'red', width: 1 })
})
});
// new Style({
// image: new Icon({
// src: require("@/assets/point.png"),
// anchor: [0.5, 1]
// })
// })
AnalysisDrawTool = new Draw({
source: AnalysisLyr.getSource(),
type: 'Point',
style: vPointStyle
});
map.addInteraction(AnalysisDrawTool);
AnalysisDrawTool.on('drawend', function (e) {
// body...
map.removeInteraction(AnalysisDrawTool);
AnalysisDrawTool = null;
var PointCoord = e.feature.getGeometry().getCoordinates();
drawCallback(PointCoord);
e.feature.setStyle(vPointStyle);
});
}
// V 气体体积 m3
// Hc 可燃气体高燃烧热值 kJ/m3
// Cs = [0.06, 0.15, 0.4];//经验常数,取决于伤害等级
//爆炸影响范围分析
function ExplosiveAnalysis(PointCoord, V, Hc, N) {
var ExplosivefeatureArr = [];
this.ExplosivefeatureArr = null;
this.ExplosivefeatureArr = [];
if (AnalysisResultLyr) {
map.removeLayer(AnalysisResultLyr);
AnalysisResultLyr = null;
}
AnalysisResultLyr = new VectorLayer({
source: new VectorSource(),
zIndex: 80
});
AnalysisResultLyr.set("id", "AnalysisResultLyr");
map.addLayer(AnalysisResultLyr);
if (!PointCoord) {
alert('请绘制爆炸发生位置!');
return ExplosivefeatureArr;
}
if (!V || V <= 0) {
alert('输入爆炸气体体积并且不能为负值!');
return ExplosivefeatureArr;
}
var features = [];
var Cs = [0.03, 0.06, 0.15, 0.4];//经验常数,取决于伤害等级
var colors = ["#4d1919", "#b40c08", "#e72319", "#f07675"];
var vLV = ["一级", "二级", "三级", "四级"];
for (var i = Cs.length - 1; i >= 0; i--) {
var boomR = (Cs[i] * Math.pow((N * V * Hc), 1 / 3)).toFixed(1);//损害半径 m
var r = boomR / (2 * Math.PI * 6378137.0) * 360;
var r = parseFloat(boomR);
var bufferCircle = new Circle(PointCoord, r, 'XY');
AnalysisResultLyr.getSource().clear();
var feature = new Feature({
geometry: bufferCircle,
zIndex: i
});
var featureObj = {
"feature": feature,
"roundHeart": PointCoord,
"伤害等级": vLV[i],
"经验常数": Cs[i],
"损失半径": boomR,
"单位": "m",
}
ExplosivefeatureArr.push(featureObj);
feature.setStyle(new Style({
stroke: new Stroke({
color: colors[i],
width: 10
})
}));
var polygon = makeCircle(bufferCircle);
var co = polygon.getCoordinates();
co = co[0][Math.floor(co[0].length / 4)];
var label = new Feature({
geometry: new Point(co),
zIndex: 500
})
label.setStyle(new Style({
text: new Text({
font: '14px 微软雅黑',
fill: new Fill({ color: '#075db3' }),
text: vLV[i] + ":" + boomR + 'm',
rotation: 0,
offsetY: 20,
textBaseline: 'bottom'
})
}));
features.push(feature);
features.push(label);
}
console.log(features, 'features')
AnalysisResultLyr.getSource().addFeatures(features);
map.getView().fit(features[0].getGeometry().getExtent(), map.getSize());
this.ExplosivefeatureArr = ExplosivefeatureArr;
return AnalysisResultLyr;
}
//添加标准图层
// var setLabelObj={
// text:"",
// color:"red",
// fontSize:14,
// fontfamily:"微软雅黑",
// rotation:0,
// offsetX:20,
// offsetY:20
// }
var vLabelLyr = null;
function addLabelToLayer(Coordinates, setLabelObj) {
if (setLabelObj.text == "") {
return;
}
if (vLabelLyr == null) {
vLabelLyr = new VectorLayer({
source: new VectorSource(),
zIndex: 80
});
vLabelLyr.set("id", "vLabelLyr");
map.addLayer(vLabelLyr);
}
var features = [];
var label = new Feature({
geometry: new Point(Coordinates),
zIndex: 500
})
var vTextObj = {
font: '14px 微软雅黑',
fill: new Fill({ color: '#e72319' }),
text: setLabelObj.text,
textBaseline: 'bottom'
};
if (setLabelObj.fontSize != null) {
if (setLabelObj.fontfamily != null) {
vTextObj["font"] = setLabelObj.fontSize + "px " + setLabelObj.fontfamily;
}
}
if (setLabelObj.color != null) {
var vFill = new Fill({ color: setLabelObj.color });
vTextObj["fill"] = vFill;
}
if (setLabelObj.rotation != null) {
vTextObj["rotation"] = setLabelObj.rotation;
}
if (setLabelObj.offsetX != null) {
vTextObj["offsetX"] = setLabelObj.offsetX;
}
if (setLabelObj.offsetY != null) {
vTextObj["offsetY"] = setLabelObj.offsetY;
}
label.setStyle(new Style({
text: new Text(vTextObj)
}));
features.push(label);
vLabelLyr.getSource().addFeatures(features);
}
function clearLabelLayer() {
if (vLabelLyr != null) {
vLabelLyr.getSource().clear();
}
}
var vMarkingLyr = null;
function addMarkingToLayer(Coordinates, MarkingObj) {
if (vMarkingLyr == null) {
vMarkingLyr = new VectorLayer({
source: new VectorSource(),
zIndex: 80
});
vMarkingLyr.set("id", "vMarkingLyr");
map.addLayer(vMarkingLyr);
}
var features = [];
var vFeature = new Feature({
geometry: new Point(Coordinates),
zIndex: 500
})
var vStyle = new Style({
image: new Icon({
anchor: [1, 1],
src: MarkingObj.img
})
})
vFeature.setStyle(vStyle);
features.push(vFeature);
vMarkingLyr.getSource().addFeatures(features);
}
function clearMarkingLayer() {
if (vMarkingLyr != null) {
vMarkingLyr.getSource().clear();
}
}
var measureDraw; // global so we can remove it later
var sketch;
var helpTooltipElement;
var helpTooltip;
var measureTooltipElement;
var measureTooltip;
var continuePolygonMsg = '双击结束绘面';
var continueLineMsg = '双击结束绘线';
function removeMeasureTooltip() {
var divlist = document.getElementsByClassName("ol-tooltip ol-tooltip-static");
var vlength = divlist.length;
for (var x = vlength - 1; x > -1; x--) {
document.getElementsByClassName("ol-tooltip ol-tooltip-static")[x].parentElement.remove();
}
}
function clearMeasure() {
if (this.MeasureSource != null) {
this.MeasureSource.clear();
//map.removeLayer(this.MeasureVector);
removeMeasureTooltip();
}
}
function stopMeasure() {
if (measureDraw != null) {
map.removeInteraction(measureDraw);
}
}
function addMeasureInteraction(DrawType) {
var _this = this;
if (_this.MeasureVector == null) {
this.addMeasureSource();
}
// if(measureDraw!=null){
// map.removeInteraction(measureDraw);
// }
stopMeasure();
//var type = (typeSelect== 'area' ? 'Polygon' : 'LineString');
//DrawType='Polygon' |'LineString'
measureDraw = new Draw({
source: this.MeasureSource,
type: DrawType,
style: new Style({
fill: new Fill({
color: 'rgba(255, 255, 255, 0.2)'
}),
stroke: new Stroke({
color: 'rgba(0, 0, 0, 0.5)',
lineDash: [10, 10],
width: 2
}),
image: new CircleStyle({
radius: 5,
stroke: new Stroke({
color: 'rgba(0, 0, 0, 0.7)'
}),
fill: new Fill({
color: 'rgba(255, 255, 255, 0.2)'
})
})
})
});
map.addInteraction(measureDraw);
createMeasureTooltip();
createHelpTooltip();
measureDraw.on('drawstart', function (evt) {
//var _this=this;
// set sketch
sketch = evt.feature;
var tooltipCoord = evt.coordinate;
_this.Measurelistener = sketch.getGeometry().on('change', function (evt) {
var geom = evt.target;
var output;
if (geom instanceof Polygon) {
// var geomproject = geom.transform('EPSG:4326','EPSG:3857');
output = formatArea(geom);
//output = formatArea(geom);
tooltipCoord = geom.getInteriorPoint().getCoordinates();
} else if (geom instanceof LineString) {
// var geomproject = geom.transform('EPSG:4326','EPSG:3857');
output = formatLength(geom);
//output = formatLength(geom);
tooltipCoord = geom.getLastCoordinate();
}
measureTooltipElement.innerHTML = output;
measureTooltip.setPosition(tooltipCoord);
});
});
measureDraw.on('drawend', function () {
//var _this=this;
measureTooltipElement.className = 'ol-tooltip ol-tooltip-static';
measureTooltip.setOffset([0, -7]);
// unset sketch
sketch = null;
// unset tooltip so that a new one can be created
measureTooltipElement = null;
createMeasureTooltip();
Observable.unByKey(this.Measurelistener);
stopMeasure();
});
}
function addMeasureSource() {
this.MeasureSource = new VectorSource();
this.MeasureVector = new VectorLayer({
source: this.MeasureSource,
style: new Style({
fill: new Fill({
color: 'rgba(255, 255, 255, 0.2)'
}),
stroke: new Stroke({
color: '#ffcc33',
width: 2
}),
image: new CircleStyle({
radius: 7,
fill: new Fill({
color: '#ffcc33'
})
})
})
});
map.addLayer(this.MeasureVector);
}
//Handle pointer move.
function pointerMoveHandler(evt) {
if (evt.dragging) {
return;
}
var helpMsg = '点击开始测量';
if (sketch) {
var geom = sketch.getGeometry();
if (geom instanceof Polygon) {
helpMsg = continuePolygonMsg;
} else if (geom instanceof LineString) {
helpMsg = continueLineMsg;
}
}
helpTooltipElement.innerHTML = helpMsg;
helpTooltip.setPosition(evt.coordinate);
helpTooltipElement.className = "ol-tooltip ";
};
// Format length output.
var formatLength = function (line) {
console.log("line", line)
var length = sphere.getLength(line);
var output;
length = length * 111000;
if (length > 100) {
output = (Math.round(length / 1000 * 100) / 100) +
' ' + 'km';
} else {
output = (Math.round(length * 100) / 100) +
' ' + 'm';
}
return output;
};
//Format area output.
var formatArea = function (polygon) {
console.log("polygon",polygon)
var area = sphere.getArea(polygon);
var output;
console.log(area,1213312)
if (area > 10000) {
output = (Math.round(area / 1000000 * 100) / 100) +
' ' + 'km<sup>2</sup>';
} else {
output = (Math.round(area * 100) / 100) +
' ' + 'm<sup>2</sup>';
}
return output;
};
//Creates a new help tooltip
function createHelpTooltip() {
if (helpTooltipElement) {
helpTooltipElement.parentNode.removeChild(helpTooltipElement);
}
helpTooltipElement = document.createElement('div');
helpTooltipElement.className = 'ol-tooltip hidden';
helpTooltip = new Overlay({
element: helpTooltipElement,
offset: [15, 0],
positioning: 'center-left'
});
map.addOverlay(helpTooltip);
}
// Creates a new measure tooltip
function createMeasureTooltip() {