duheng
2025-04-03 82f8a7ead37ff50dec3d0d40e572d4331f14a8b2
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>消火栓测试</title>
    <link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css" />
    <link href="../css/public.css" rel="stylesheet" />
    <script src="http://cache.amap.com/lbs/static/es5.min.js"></script>
    <script src="http://webapi.amap.com/maps?v=2.0&key=3627ed9deaac2622e26a7169f0c36b1b&plugin=AMap.Geocoder"></script>
    <script src="../js/jquery-2.1.1.min.js"></script>
    <script src="../js/public.js"></script>
    <script src="../js/tools.js"></script>
    <script src="../js/base64.js"></script>
</head>
 
<body>
    <div id="container"></div>
 
    <div class="search-box" id="search_box">
        <input class="search-text" id="search_text" type="text" placeholder="请输入详细地址" onkeypress="keySearchAddress()" />
        <input class="search-button" id="search_button" type="button" onclick="searchAddress()" />
    </div>
 
    <div class=" info-box" id="info_box">
        信息提示
        <hr>
        <div id="info_text">
        </div>
    </div>
 
 
    <div class="button-group draw-button-group" id="edit_draw_box" style=" display:none;">
        <input id="btnEditDrawFinish" class="button draw-button" onclick="finishEditDraw()" type="button" value="完成" />
        <input id="btnEditDrawCancel" class="button draw-button" onclick="cancelEditDraw()" type="button" value="取消" />
    </div>
 
    <div class="draw-button-group button-group" id="draw_marker_box" style=" display:none;">
        <input id="btnDrawMarkerFinish" class="draw-button button" onclick="finishDrawMarker()" type="button" value="完成" />
        <input id="btnDrawMarkerCancel" class="draw-button button" onclick="cancelDrawMarker()" type="button" value="取消" />
    </div>
 
    <div id='location_box' class="location-box" title="定位" style="display: none;" onclick="backLocateMarker()"></div>
 
    <script>
 
        let map;//地图对象 使用 ToolBar时,地图对象需要定义为map 否则会报错
        let _map;//地图对象
        let _layer;//图层对象
        let _status = map_status.Normal;//状态
        let _locateMarker;//定位覆盖物点
        let _allSignObjs = [];//所有标记对象
        let _selectedOverlay;//选择的覆盖物
        let _drawSignObj;//绘制的标记对象
        let _drawOverlay;//绘制的覆盖物
        let _editDrawOverlay ;//编辑绘制的覆盖物
        let _paras = {
            PolygonDefaultParas:
            {
                //区域默认的样式
                BorderColor: "#3366ff",
                BorderWidth: 3,
                BorderOpacity: 1,
                BackgroundColor: "#e57505",
                BackgroundOpacity: 0.5
            },
            PolygonSelectedParas:
            {
                //区域选中的样式
                BorderColor: "#e57505",
                BorderWidth: 6,
                BorderOpacity: 1,
                BackgroundColor: "#e57505",
                BackgroundOpacity: 0.5
            },
            LineTempParas:
            {
                //线选中的样式
                Width: 6,
                Opacity: 1,
                Color: "#e57505"
            },
            LineDefaultParas:
            {
                //线默认的样式
                Width: 3,
                Opacity: 1,
                Color: "#3366ff"
            }
        };//参数
 
 
        $(document).ready(function () {
 
            try {
                map = _map = new AMap.Map('container', {
                    resizeEnable: true,
                    expandZoomRange: true,
                    zoom: 10,
                    zooms: [3, 20]
                });
 
                //缩放停止时触发
                _map.on("zoomend", function () {
                    setTimeOutBoundsChanged(100);
                });
 
                //停止拖拽地图停止时触发
                _map.on("dragend", function () {
                    setTimeOutBoundsChanged(100);
                });
 
                //地图移动后触发
                _map.on("moveend", function () {
                    setTimeOutBoundsChanged(100);
                });
 
                //地图容器尺寸改变后触发
                _map.on("resize", function () {
                    setTimeOutBoundsChanged(200);
                });
 
 
                //地图点击事件
                _map.on('click', function (e) {
                    cancelSelectSignObj();
                });
 
                //地图点击时关闭搜索面板
                _map.on("click", function () {
                    if ($("#search_text").css("display") == 'block') {
                        $("#search_text").hide();
                    }
                });
 
                //地图加载完成
                _map.on("complete", function () {
 
                    //图层
                    _layer = new AMap.LabelsLayer({
                        zooms: [3, 20],
                        zIndex: 1000,
                        // 该层内标注是否避让
                        collision: false,
                    });
                    _map.add(_layer);
 
                    callbackObj.loadCompleted();
                });
 
            }
            catch (e) {
                callbackObj.loadFailed();
            }
        })
 
        //加载参数
        function loadParas(paras) {
            if (isEmpty(paras)) {
                return false;
            }
            _paras = paras;
            return true;
        }
 
        //设置消火栓
        function setSignObjs(signObjs) {
            if (_status != map_status.Normal) {
                return false;
            }
            if (isEmpty(signObjs)) {
                _allSignObjs = [];
            }
            else {
                _allSignObjs = signObjs;
            }
            
            //标记标识列表
            let signIds = _allSignObjs.map(function (x) { return x.SignId; });
 
            //覆盖物列表
            let overlays = _layer.getAllOverlays();
 
            //移除不在标记列表中的覆盖物
            let overlays_remove = overlays.filter(function (x) { return signIds.indexOf(x.objInfo.SignId) < 0; });
            _layer.remove(overlays_remove);
 
            //更新已有覆盖物
            let overlays_exist = overlays.filter(function (x) { return signIds.indexOf(x.objInfo.SignId) > -1; });
            if (overlays_exist.length > 0) {
                overlays_exist.forEach(function (x) {
                    let signObj = _allSignObjs.find(function (t) { return t.SignId == x.objInfo.SignId; });
                    if (signObj.SignName != x.objInfo.SignName) {
                        let text = {
                            // 要展示的文字内容
                            content: signObj.SignName,
                            // 文字方向,有 icon 时为围绕文字的方向,没有 icon 时,则为相对 position 的位置
                            direction: 'right',
                            // 在 direction 基础上的偏移量
                            offset: [0, 0],
                            // 文字样式
                            style: {
                                // 字体大小
                                fontSize: 12,
                                // 字体颜色
                                fillColor: '#22886f',
                                // 描边颜色
                                strokeColor: '#fff',
                                // 描边宽度
                                strokeWidth: 2,
                            }
                        };
                        x.setText(text);
                    }
                    x.objInfo = signObj;
                });
            }
 
            //添加覆盖物
            let signIds_overlay = overlays_exist.map(function (x) { return x.objInfo.SignId; });
            let signObjs_new = _allSignObjs.filter(function (x) { return signIds_overlay.indexOf(x.SignId) < 0; });
            if (signObjs_new.length > 0) {
                let icon = {
                    // 图标类型,现阶段只支持 image 类型
                    type: 'image',
                    // 图片 url
                    image: sign_type_base64.FireHydrant,
                    // 图片尺寸
                    size: [32, 32],
                    // 图片相对 position 的锚点,默认为 bottom-center
                    anchor: 'bottom-center',
                };
                let markers = signObjs_new.map(function (x) {
                    let text = {
                        // 要展示的文字内容
                        content: x.SignName,
                        // 文字方向,有 icon 时为围绕文字的方向,没有 icon 时,则为相对 position 的位置
                        direction: 'right',
                        // 在 direction 基础上的偏移量
                        offset: [0, 0],
                        // 文字样式
                        style: {
                            // 字体大小
                            fontSize: 12,
                            // 字体颜色
                            fillColor: '#22886f',
                            // 描边颜色
                            strokeColor: '#fff',
                            // 描边宽度
                            strokeWidth: 2,
                        }
                    };
                    let marker = new AMap.LabelMarker({
                        position: [x.Point.X, x.Point.Y],
                        // 将第一步创建的 icon 对象传给 icon 属性
                        icon: icon,
                        // 将第二步创建的 text 对象传给 text 属性
                        text: text,
                    });
                    marker.objInfo = x;
                    marker.on("click", function (e) {
                        setSelectStyle(e.target);
                        callbackObj.selectSignObj(e.target.objInfo.SignId);
                    });
                    return marker;
                });
                _layer.add(markers);
            }
 
            if (_selectedOverlay) {
                let signObj = _allSignObjs.find(function (x) { return x.SignId == _selectedOverlay.objInfo.SignId; });
                if (signObj) {
                    setSelectStyle(_selectedOverlay);
                }
                else {
                    cancelSelectSignObj();
                }
            }
 
            setInfoText();
            return true;
        }
 
        //添加单个标记对象
        function appendSignObj(signObj) {
            if (_status != map_status.Normal) {
                return false;
            }
            if (isEmpty(signObj)) {
                return false;
            }
            if (isEmpty(_allSignObjs)) {
                _allSignObjs = [];
            }
 
            _allSignObjs.push(signObj);
 
            let icon = {
                // 图标类型,现阶段只支持 image 类型
                type: 'image',
                // 图片 url
                image: sign_type_base64.FireHydrant,
                // 图片尺寸
                size: [32, 32],
                // 图片相对 position 的锚点,默认为 bottom-center
                anchor: 'bottom-center',
            };
 
            let text = {
                // 要展示的文字内容
                content: signObj.SignName,
                // 文字方向,有 icon 时为围绕文字的方向,没有 icon 时,则为相对 position 的位置
                direction: 'right',
                // 在 direction 基础上的偏移量
                offset: [0, 0],
                // 文字样式
                style: {
                    // 字体大小
                    fontSize: 12,
                    // 字体颜色
                    fillColor: '#22886f',
                    // 描边颜色
                    strokeColor: '#fff',
                    // 描边宽度
                    strokeWidth: 2,
                }
            };
 
            let marker = new AMap.LabelMarker({
                position: [signObj.Point.X, signObj.Point.Y],
                // 将第一步创建的 icon 对象传给 icon 属性
                icon: icon,
                // 将第二步创建的 text 对象传给 text 属性
                text: text,
            });
            marker.objInfo = signObj;
            marker.on("click", function (e) {
                setSelectStyle(e.target);
                callbackObj.selectSignObj(e.target.objInfo.SignId);
            });
            _layer.add(marker);
 
            setInfoText();
            return true;
        }
 
        //添加多个标记对象
        function appendSignObjs(signObjs) {
            if (_status != map_status.Normal) {
                return false;
            }
            if (isEmpty(signObjs)) {
                return false;
            }
            if (signObjs.length < 1) {
                return false;
            }
            if (isEmpty(_allSignObjs)) {
                _allSignObjs = [];
            }
 
            signObjs.forEach(function (x) { _allSignObjs.push(x); });
 
            let icon = {
                // 图标类型,现阶段只支持 image 类型
                type: 'image',
                // 图片 url
                image: sign_type_base64.FireHydrant,
                // 图片尺寸
                size: [32, 32],
                // 图片相对 position 的锚点,默认为 bottom-center
                anchor: 'bottom-center',
            };
 
            let markers = signObjs.map(function (x) {
                let text = {
                    // 要展示的文字内容
                    content: x.SignName,
                    // 文字方向,有 icon 时为围绕文字的方向,没有 icon 时,则为相对 position 的位置
                    direction: 'right',
                    // 在 direction 基础上的偏移量
                    offset: [0, 0],
                    // 文字样式
                    style: {
                        // 字体大小
                        fontSize: 12,
                        // 字体颜色
                        fillColor: '#22886f',
                        // 描边颜色
                        strokeColor: '#fff',
                        // 描边宽度
                        strokeWidth: 2,
                    }
                };
                let lnglat = [x.Point.X, x.Point.Y];
                let marker = new AMap.LabelMarker({
                    position: lnglat,
                    // 将第一步创建的 icon 对象传给 icon 属性
                    icon: icon,
                    // 将第二步创建的 text 对象传给 text 属性
                    text: text,
                });
                marker.objInfo = x;
                marker.on("click", function (e) {
                    setSelectStyle(e.target);
                    callbackObj.selectSignObj(e.target.objInfo.SignId);
                });
                return marker;
            });
            _layer.add(markers);
 
 
            setInfoText();
            return true;
        }
 
        //更新标记对象
        function updateSignObj(signObj) {
            if (_status != map_status.Normal) {
                return false;
            }
            if (isEmpty(signObj)) {
                return false;
            }
            if (isEmpty(_allSignObjs)) {
                _allSignObjs = [];
            }
            let exist = _allSignObjs.find(function (x) { return x.SignId == signObj.SignId });
            if (exist) {
                let index = _allSignObjs.indexOf(exist);
                _allSignObjs.splice(index, 1, signObj);
                let allOverlays = _layer.getAllOverlays();
                let marker = allOverlays.find(function (x) { return x.objInfo && x.objInfo.SignId == signObj.SignId; });
                if (marker) {
                    if (marker.objInfo.Point.X != signObj.Point.X || marker.objInfo.Point.Y != signObj.Point.Y) {
                        marker.setPosition([signObj.Point.X, signObj.Point.Y]);
                    }
                    if (marker.objInfo.SignName != signObj.SignName) {
                        let text = {
                            // 要展示的文字内容
                            content: signObj.SignName,
                            // 文字方向,有 icon 时为围绕文字的方向,没有 icon 时,则为相对 position 的位置
                            direction: 'right',
                            // 在 direction 基础上的偏移量
                            offset: [-0, -0],
                            // 文字样式
                            style: {
                                // 字体大小
                                fontSize: 12,
                                // 字体颜色
                                fillColor: '#22886f',
                                // 描边颜色
                                strokeColor: '#fff',
                                // 描边宽度
                                strokeWidth: 2,
                            }
                        };
                        marker.setText(text);
 
                        if (_selectedOverlay) {
                            if (_selectedOverlay.objInfo) {
                                if (_selectedOverlay.objInfo.SignId == signObj.SignId) {
                                    setSelectStyle(marker);
                                }
                            }
                        }
                    }
                    marker.objInfo = signObj;
                }
            }
            return false;
        }
 
        //批量更新标记对象
        function updateSignObjs(signObjs) {
            if (_status != map_status.Normal) {
                return false;
            }
            if (isEmpty(signObjs)) {
                return false;
            }
 
            let bol = true;
            for (let i = 0; i < signObjs.length; i++) {
                bol = updateSignObj(signObjs[i]);
                if (!bol) {
                    break;
                }
            }
            return bol;
        }
 
        //删除单个标记对象
        function removeSignObj(signId) {
            if (_status != map_status.Normal) {
                return false;
            }
            if (isEmpty(signId)) {
                return false;
            }
            if (isEmpty(_allSignObjs)) {
                _allSignObjs = [];
            }
 
            let signObj = _allSignObjs.find(function (x) { return x.SignId == signId; });
            if (!signObj) {
                return false;
            }
 
            let overlays = _layer.getAllOverlays();
            let overlay = overlays.find(function (x) {
                return x.objInfo && x.objInfo.SignId == signId;
            });
            if (!overlay) {
                return false;
            }
 
            _layer.remove(overlay);
 
            let index = _allSignObjs.indexOf(signObj);
            _allSignObjs.splice(index,1);
         
            if (_selectedOverlay) {
                if (_selectedOverlay.objInfo) {
                    if (_selectedOverlay.objInfo.SignId == signId) {
                        cancelSelectSignObj();
                    }
                }
            }
 
            setInfoText();
        }
 
        //删除多个标记对象
        function removeSignObjs(signIds) {
            if (_status != map_status.Normal) {
                return false;
            }
            if (isEmpty(signIds)) {
                return false;
            }
            if (signIds.length < 1) {
                return false;
            }
            if (isEmpty(_allSignObjs)) {
                _allSignObjs = [];
            }
 
            let signObjs = _allSignObjs.filter(function (x) {
                return signIds.indexOf(x.SignId) > -1;
            });
            if (!signObjs) {
                return false;
            }
            if (signObjs.length < 1) {
                return false;
            }
            if (signObjs.length != signIds.length) {
                return false;
            }
 
            let allOverlays = _layer.getAllOverlays();
            let overlays = allOverlays.filter(function (x) { return x.objInfo && signIds.indexOf(x.objInfo.SignId) > -1; });
            _layer.remove(overlays);
 
            signObjs.forEach(function (x) {
                let index = _allSignObjs.indexOf(x);
                _allSignObjs.splice(index,1);
            });
 
            if (_selectedOverlay) {
                if (_selectedOverlay.objInfo) {
                    if (signIds.indexOf(_selectedOverlay.objInfo.SignId) > -1) {
                        cancelSelectSignObj();
                    }
                }
            }
 
            setInfoText();
 
            return true;
        }
 
        //清除所有覆盖物
        function clearAllSignObjs() {
            _allSignObjs = [];
            _layer.clear();
 
            cancelSelectSignObj();
            setInfoText();
            return true;
        }
 
        //开始绘制
        function startDraw(signObj) {
            if (_status != map_status.Normal) {
                return false;
            }
            if (isEmpty(signObj)) {
                return false;
            }
 
            _status = map_status.Draw;
            _drawSignObj = signObj;
 
            if (_locateMarker) {
                let position = _locateMarker.getPosition();
                let lnglat = [position.getLng(), position.getLat()];
                _drawOverlay = new AMap.Marker(
                    {
                        position: lnglat,
                        icon: new AMap.Icon({ size: new AMap.Size(32, 32), image: "../img/XiaoHuoShuan_blue.png", imageOffset: new AMap.Pixel(0, 0) }),
                        offset: new AMap.Pixel(-0, -0),
                        anchor: 'bottom-center'
                    });
                _drawOverlay.setMap(_map);
                _drawOverlay.objInfo = null;
                _drawOverlay.setDraggable(true);
            }
            else {
                _map.on("click", onMapDrawMarkerClick, true);//地图添加绘制点击事件
            }
            $("#draw_marker_box").show();
            judgeDrawMarkerButtons();
 
            setInfoText();
            return true;
        }
 
        //取消绘制
        function cancelDraw() {
            if (_status != map_status.Draw) {
                return false;
            }
            if (!_drawSignObj) {
                return false;
            }
            if (_drawOverlay) {
                _map.remove(_drawOverlay)
            }
            _drawSignObj = null;
            _drawOverlay = null;
            _status = map_status.Normal;
            setInfoText();
            $("#draw_marker_box").hide();
            return true;
        }
 
        //结束绘制点
        function finishDrawMarker() {
            if (_status != map_status.Draw) {
                return;
            }
            if (!_drawSignObj) {
                return;
            }
            if (!_drawOverlay) {
                return;
            }
 
            _drawOverlay.setDraggable(false);
 
            let position = _drawOverlay.getPosition();
            let lnglat = [position.getLng(), position.getLat()];
            let point = { X: lnglat[0], Y: lnglat[1] };
            _drawSignObj.Point = point;
            let geocoder = new AMap.Geocoder({});
            geocoder.getAddress(lnglat, function (status, result) {
                if (status === 'complete' && result.info === 'OK') {
                    let address = result.regeocode.formattedAddress;
                    _drawSignObj.Address = address;
                }
                let json = JSON.stringify(_drawSignObj);
                callbackObj.finishDraw(json);
            });
        }
 
        //取消绘制点
        function cancelDrawMarker() {
            if (_status != map_status.Draw) {
                return;
            }
            if (!_drawSignObj) {
                return;
            }
            if (_drawOverlay) {
                _drawOverlay.setDraggable(false);
                _map.remove(_drawOverlay);
            }
            else {
                _map.off("click", onMapDrawMarkerClick);
            }
 
            _drawSignObj = null;
            _drawOverlay = null;
            _status = map_status.Normal;
            setInfoText();
            $("#draw_marker_box").hide();
            callbackObj.cancelDraw();
        }
 
        //判断绘制按钮
        function judgeDrawMarkerButtons() {
            if (_status != map_status.Draw) {
                return;
            }
            //完成
            if (_drawOverlay) {
                $("#btnDrawMarkerFinish").attr("disabled", false);
            }
            else {
                $("#btnDrawMarkerFinish").attr("disabled", true);
            }
            //取消
            $("#btnDrawMarkerCancel").attr("disabled", false);
        }
 
        //地图绘制点标记点击事件
        function onMapDrawMarkerClick(e) {
            if (_status != map_status.Draw) {
                return;
            }
            if (!_drawSignObj) {
                return;
            }
            if (_drawOverlay) {
                return;
            }
 
            _map.off("click", onMapDrawMarkerClick);
            let lnglat = [e.lnglat.getLng(), e.lnglat.getLat()];
 
            _drawOverlay = new AMap.Marker(
                {
                    position: lnglat,
                    icon: new AMap.Icon({ size: new AMap.Size(32, 32), image: "../img/XiaoHuoShuan_blue.png", imageOffset: new AMap.Pixel(0, 0) }),
                    offset: new AMap.Pixel(-0, -0),
                    anchor: 'bottom-center'
                });
            _drawOverlay.objInfo = null;
            _drawOverlay.setMap(_map);
            _drawOverlay.setDraggable(true);
            judgeDrawMarkerButtons();
        }
 
        //开始编辑
        function startEditDraw() {
            if (_status != map_status.Normal) {
                return false;
            }
            if (!_selectedOverlay) {
                return false;
            }
            if (!_selectedOverlay.objInfo) {
                return false;
            }
            if (_editDrawOverlay) {
                return false;
            }
            _map.clearInfoWindow();
            let position = _selectedOverlay.getPosition();
            let lnglat = [position.getLng(), position.getLat()];
            _selectedOverlay.hide();
            _editDrawOverlay = new AMap.Marker(
                {
                    position: lnglat,
                    icon: new AMap.Icon({ size: new AMap.Size(32, 32), image: "../img/XiaoHuoShuan_blue.png", imageOffset: new AMap.Pixel(0, 0) }),
                    offset: new AMap.Pixel(-0, -0),
                    anchor: 'bottom-center'
                });
            _editDrawOverlay.setMap(_map);
            _editDrawOverlay.objInfo = null;
            _editDrawOverlay.setDraggable(true);
 
            _status = map_status.Edit;
            setInfoText();
            $("#edit_draw_box").show();
            return true;
        }
 
        //结束编辑
        function finishEditDraw() {
            if (_status != map_status.Edit) {
                return;
            }
            if (!_selectedOverlay) {
                return;
            }
            if (!_selectedOverlay.objInfo) {
                return;
            }
            if (!_editDrawOverlay) {
                return;
            }
            
            let position = _editDrawOverlay.getPosition();
            let lnglat = [position.getLng(), position.getLat()];
            _editDrawOverlay.setDraggable(false);
            _map.remove(_editDrawOverlay);
            _editDrawOverlay = null;
 
            _selectedOverlay.setPosition(lnglat);
            _selectedOverlay.objInfo.Point = { X: lnglat[0], Y: lnglat[1] };
            
            getAddressByLnglat(lnglat, function (address) {
                if (!isEmpty(address)) {
                    _selectedOverlay.objInfo.Address = address;
                }
                _selectedOverlay.show();
                _status = map_status.Normal;
                setInfoText();
                $("#edit_draw_box").hide();
                callbackObj.updateSignObj(JSON.stringify(_selectedOverlay.objInfo));
            });
            
        }
 
        //取消编辑
        function cancelEditDraw() {
            if (_status != map_status.Edit) {
                return;
            }
            if (!_selectedOverlay) {
                return;
            }
            if (!_selectedOverlay.objInfo) {
                return;
            }
            if (!_editDrawOverlay) {
                return;
            }
            _map.remove(_editDrawOverlay);
            _editDrawOverlay = null;
            _selectedOverlay.show();
 
            _status = map_status.Normal;
            setInfoText();
            $("#edit_draw_box").hide();
            callbackObj.cancelEditDraw();
        }
 
        //选择标记对象
        function selectSignObj(signId) {
            if (isEmpty(signId)) {
                return;
            }
            if (isEmpty(_allSignObjs)) {
                _allSignObjs = [];
            }
            let signObj = _allSignObjs.find(function (x) { return x.SignId == signId; });
            if (signObj) {
                let overlays = _layer.getAllOverlays();
                overlay = overlays.filter(function (x) { return x.objInfo && x.objInfo.SignId == signId });
                if (overlay) {
                    setSelectStyle(overlay);
                    callbackObj.selectSignObj(signId);
                }
            }
        }
 
        //设置选择样式
        function setSelectStyle(overlay) {
            setCancelSelectStyle();
            if (overlay.objInfo) {
                let info = [];
                info.push("<div className='input-card'>");
                info.push("<label style=\"color: blue\">");
                info.push("消火栓");
                info.push("</label>");
                info.push("<p class='input-item'>名称:");
                info.push(overlay.objInfo.SignName);
                info.push("</p>");
                info.push("<p class='input-item'>经纬度:");
                info.push(overlay.objInfo.Point.X + "," + overlay.objInfo.Point.Y);
                info.push("</p>");
                info.push("<p class='input-item'>地址:");
                info.push(overlay.objInfo.address);
                info.push("</p>");
                info.push("</div>");
                infoWindow = new AMap.InfoWindow({
                    anchor: 'bottom-center',
                    content: info.join(""),
                    offset: new AMap.Pixel(0, -32)
                });
 
                infoWindow.open(_map, overlay.getPosition());
            }
            _selectedOverlay = overlay;
        }
 
        //取消选择标记对象
        function cancelSelectSignObj() {
            if (_selectedOverlay) {
                setCancelSelectStyle();
                callbackObj.selectSignObj("");
            }
        }
 
        //设置取消选择样式
        function setCancelSelectStyle() {
            if (_selectedOverlay) {
                _map.clearInfoWindow();
                _selectedOverlay = null;
            }
        }
 
        //设置搜索面板的可见性
        function setSearchPanelVisibility() {
            document.getElementById('search_box').hidden = !document.getElementById('search_box').hidden;
        }
 
        //设置信息提示面板的可见性
        function setInfoPanelVisibility() {
            document.getElementById('info_box').hidden = !document.getElementById('info_box').hidden;
        }
 
        //设置信息面板提示信息
        function setInfoText() {
            var level = _map.getZoom();
            if (level <= _paras.LevelParas.HideSignUpperLimit) {
                var info1 = "地图显示区域过广,地图信息处于隐藏状态" + "\n";
                var info2 = "当前状态:"
                var info3 = "";
                if (_status == map_status.Normal) {
                    info3 = "正常";
                }
                else if (_status == map_status.Draw) {
                    info3 = "绘制";
                }
                else {
                    info3 = "编辑";
                }
 
                var info = info1 + info2 + info3;
                document.getElementById('info_text').innerText = info;
            }
            else {
                if (isEmpty(_allSignObjs)) {
                    _allSignObjs = [];
                }
                var info1 = "消火栓:" + _allSignObjs.length + "\n";
                var info2 = "当前状态:"
                var info3 = "";
                if (_status == map_status.Normal) {
                    info3 = "正常";
                }
                else if (_status == map_status.Draw) {
                    info3 = "绘制";
                }
                else {
                    info3 = "编辑";
                }
                var info = info1 + info2 + info3;
                document.getElementById('info_text').innerText = info;
            }
        }
 
        //根据点获取地址
        getAddressByLnglat = function (lnglat, callback) {
            let geocoder = new AMap.Geocoder({});
            geocoder.getAddress(lnglat, function (status, result) {
                let address = null;
                if (status === 'complete' && result.info === 'OK') {
                    address = result.regeocode.formattedAddress; //返回地址描述
                }
                callback(address);
            });
        }
 
        //根据详细地址查看地图(pc调用)
        function locateByAddress(address) {
            if (isEmpty(address)) {
                return;
            }
            let geocoder = new AMap.Geocoder({});
            //地理编码,返回地理编码结果
            geocoder.getLocation(address, function (status, result) {
                if (status === 'complete' && result.info === 'OK') {
                    let geocode = result.geocodes;
                    let lnglat = [geocode[0].location.getLng(), geocode[0].location.getLat()];
                    let marker = new AMap.Marker({ position: lnglat });
                    _map.setFitView(marker);
                }
                else {
                    let error = { ErrorType: error_type.locate_address, Message: "根据详细地址定位地图失败" };
                    callbackObj.handingError(JSON.stringify(error));
                }
            });
        }
 
        //搜索地址
        function searchAddress() {
            if ($("#search_text").css("display") == 'block') {
                let address = $("#search_text").val();
                if (!isEmpty(address)) {
                    locateByAddress(address);
                }
                $("#search_text").hide();
            }
            else {
                $("#search_text").show();
            }
        }
 
        //enter搜索地址
        function keySearchAddress() {
            if (event.keyCode == 13) {
                searchAddress();
            }
        }
 
        //地图模板样式
        function setMapStyle(enName) {
            _map.setMapStyle('amap://styles/' + enName);
        }
 
        //添加定位点
        function addLocateMarker(lnglat) {
            _locateMarker = new AMap.Marker({
                position: lnglat,
                icon: new AMap.Icon({
                    size: new AMap.Size(32, 32),  //图标大小
                    image: "../img/current.png"
                }),
                offset: new AMap.Pixel(-0, -0),
                anchor: 'bottom-center'
            });
            _locateMarker.objInfo = null;
            _locateMarker.setMap(_map);
            _map.setFitView(_locateMarker);
            $("#location_box").show();
        }
 
        //移除定位点
        function removeLocateMarker() {
            if (_locateMarker) {
                _map.remove(_locateMarker);
            }
            _locateMarker = null;
            $("#location_box").hide();
        }
 
        //移动定位点
        function moveLocateMarker(lnglat) {
            if (_locateMarker) {
                _locateMarker.setPosition(lnglat);
            }
        }
 
        //设置定位点
        function setLocateMarker(p) {
            if (isEmpty(p)) {
                removeLocateMarker();
            }
            else {
                let lnglat = [p.X, p.Y];
                if (!_locateMarker) {
                    addLocateMarker(lnglat);
                }
                else {
                    moveLocateMarker(lnglat);
                }
            }
        }
 
        //设置GPS定位点
        function setGpsLocateMarker(p) {
            if (isEmpty(p)) {
                removeLocateMarker();
            }
            else {
                let lnglat = new AMap.LngLat(p.X, p.Y);
                AMap.convertFrom(lnglat, 'gps', function (status, result) {
                    if (result.info === 'ok') {
                        var resLnglat = result.locations[0];
                        if (!_locateMarker) {
                            addLocateMarker(resLnglat);
                        }
                        else {
                            moveLocateMarker(resLnglat);
                        }
                    }
                });
            }
        }
 
        //返回定位区域
        function backLocateMarker() {
            if (_locateMarker) {
                _map.setFitView(_locateMarker);
            }
        }
 
        //延迟执行地图边界改变
        function setTimeOutBoundsChanged(millseconds) {
            setTimeout("boundsChanged()", millseconds);
        }
 
        //地图界面改变
        function boundsChanged() {
            try {
                let level = _map.getZoom();
                let cp = _map.getCenter();
                //地图可视区域
                let bs = _map.getBounds();
                //可视区域左下角
                let bslb = bs.getSouthWest();
                //可视区域右上角
                let bsrt = bs.getNorthEast();
                let jsonObj = { Level: level, CenterPoint: { X: cp.getLng(), Y: cp.getLat() }, LeftBottomPoint: { X: bslb.getLng(), Y: bslb.getLat() }, RightTopPoint: { X: bsrt.getLng(), Y: bsrt.getLat() } };
                callbackObj.boundsChanged(JSON.stringify(jsonObj));
            }
            catch (e) {
            }
        }
 
 
 
    </script>
</body>
 
</html>