-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmapoperation.js
1108 lines (1007 loc) · 34.8 KB
/
mapoperation.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
!(function($) {
function MapOperation() {
}
var mapoperation = new MapOperation();
$.extend({
mapOperation : mapoperation
});
// 展示树结构
MapOperation.prototype.showMapStructureOnTree = function(data) {
var treedata = loadCampus(data);
if (treedata == undefined) {
return;
}
var remoteDateSource = new DataSourceTree({
data : treedata
});
remoteDateSource.multiChoiceTree($("#ale-tree-selectfloor"));
}
MapOperation.prototype.showDefaultDefaultMap = function() {
var defaultMap = [];
defaultMap["SHYC_B99_F12"] = "中机六院实验基地_外场实验室";
defaultMap["SHYC_B0_F1"] = "上海烟草浦东园区_鸟瞰";
requestForMultiMap(defaultMap, $("#ale-tree-selectfloor").data(
"mapcodes")
|| []); // 加载新地图
}
MapOperation.prototype.saveDefaultMap = function() {
saveDefaultMapMethod();
}
// 初始化隐藏元素
MapOperation.prototype.hideElement = function() {
$("#ale-mapviewmode-single").hide();
}
// 初始化点击事件
MapOperation.prototype.bindClickEvent = function() {
// 单图缩小至多图
$("#zoomOutMap").click(
function() {
$("#ale-mapviewmode-multi svg").each(
function() {// 全部置成初始值
var mapzoom = $(this).parents(".widget-box")
.find(".ale-mapzoom");
var svg = $(this).parents(".widget-box").find(
"svg");
resetSVGZoom(svg, mapzoom);
});
zoomInMapUnderTrack($(this));
$("#ale-mapviewmode-single").hide();
$("#ale-mapviewmode-multi").show();
// $("#ale-btn-selectfloor").parent().show();
});
// POI显隐
$("#ale-btn-controlPOI").click(function() {
var status = $(this).attr("data-ale-status");
controlPOI(status);
controlAleStatus($(this), status);
});
// 地理围栏显隐
$("#ale-btn-controlGeofencing").click(function() {
var status = $(this).attr("data-ale-status");
controlGeofencing(status);
controlAleStatus($(this), status);
});
// 选择楼层对话框-确认
$("#ale-dialog-selectfloor .ale-confirm").click(confirmTreeSelect);
// 单图模式缩小按钮
$("#ale-mapviewmode-single .ale-mapzoom-btn-out").click(function() {
operationSvgZoom($(this), true);
});
// 单图模式放大按钮
$("#ale-mapviewmode-single .ale-mapzoom-btn-in").click(function() {
operationSvgZoom($(this), false);
});
// 单图恢复
$("#ale-mapviewmode-single .ale-mapzoom-btn-recover").click(function() {
var svg = $("#ale-mapviewmode-single").find("svg");
var mapzoom = $("#ale-mapviewmode-single .ale-mapzoom");
resetSVGZoom(svg, mapzoom);
});
// 监控模式
$("#ale-btn-monitoring").click(function() {
if ($("#ale-monitor-mode").attr("value") != "0") {
setMonitorModeMethod();
}
});
}
// 初始化绑定事件
MapOperation.prototype.bindEvent = function() {
// 显示框事件->选择楼层按钮->显示框后
$("#ale-dialog-selectfloor").on("shown.bs.modal", function(e) {
changeSelectFloorTreeStatus(false, "");
});
// treeview事件--第一次加载数据
$('#ale-tree-selectfloor').on('loaded', onloadTreeEvent);
// 单图模式平移
svgPan($("#ale-mapviewmode-single .ale-div-map"), false);
$('#ale-dialog-selectfloor').on('show.bs.modal', function(event) {
$.modalJs.adjustBody_beforeShow();
});
$('#ale-dialog-selectfloor').on('hidden.bs.modal', function(event) {
$.modalJs.adjustBody_afterShow();
});
}
MapOperation.prototype.setTrackMode = function() {
setTrackModeMethod();
}
MapOperation.prototype.getTrackTargetMap = function(mac, mapcode) {
getTrackTargetMapMethod(mac, mapcode);
}
MapOperation.prototype.reorderMultiMap = function() {
reorderMultiMapMethod();
}
MapOperation.prototype.removeDeviceFromMap = function(mac) {
removeDeviceFromMapMethod(mac);
}
/* 私有方法 */
var MULTI_SVGHEIGHT = 400;
var SINGLE_SVGHEIGHT = window.screen.availHeight - 265;
var SINGLE_SVGWEIGHT = window.screen.availWidth - 240;
// //////////////////////////////////////////请求服务/////////////////////////////////////////////
function requestForMultiMap(keyMap, state, $e) {
var keys = new Array();
for ( var p in keyMap) {
keys.push(p);
}
if (keys.length < 1) {
if ($e != undefined)
$e.trigger("maploaded");
return;
}
$.post(window.basePath + "/web/v0.2/map/floor", {
floorCode : keys[0]
}, function(data) {
if (data.code == 0) {
if (data.data.mapcontent == undefined
|| data.data.mapcontent == "")
return;
if (state == "left")// 放置在左侧
appendMapToMulti($(data.data.mapcontent),
data.data.mapcode, keyMap, 1);
else if (state == "right")// 放置在右侧
appendMapToMulti($(data.data.mapcontent),
data.data.mapcode, keyMap, 2);
else {// 均分放置
var count = $("#ale-multi-left").find(".widget-box").length
- $("#ale-multi-right").find(".widget-box").length;
appendMapToMulti($(data.data.mapcontent),
data.data.mapcode, keyMap, count);
}
delete (keyMap[keys[0]]);
requestForMultiMap(keyMap, state, $e);
}
}, "json");
}
// 获取单图,同步模式
function requestForMapSync(floorcode, arrFloorSelect) {
$.ajax({
type : "POST",
url : window.basePath + "/web/v0.2/map/floor",
async : false,
dataType : "json",
success : function(data) {
if (data.code == 0) {
if (data.data.mapcontent == undefined
|| data.data.mapcontent == "")
return;
// var count =
// $("#ale-multi-left").find(".widget-box").length -
// $("#ale-multi-right").find(".widget-box").length;
var count = getMultiMapCount();
appendMapToMulti($(data.data.mapcontent),
data.data.mapcode, arrFloorSelect, (count + 1));
}
}
});
}
// 获得单图,传入floorcode,id-name字典
function requestForMap(floorcode, arrFloorSelect) {
$.post(window.basePath + "/web/v0.2/map/floor", {
floorCode : floorcode
}, function(data) {
if (data.code == 0) {
if (data.data.mapcontent == undefined
|| data.data.mapcontent == "")
return;
var count = getMultiMapCount();
appendMapToMulti($(data.data.mapcontent), data.data.mapcode,
arrFloorSelect, (count + 1));
}
}, "json");
}
// 获得单图,传入floorcode,id-name字典
function requestForMapShowOnSingleMode(floorcode, arrFloorSelect, $e) {
$.post(window.basePath + "/web/v0.2/map/floor", {
floorCode : floorcode
}, function(data) {
if (data.code == 0) {
if (data.data.mapcontent == undefined
|| data.data.mapcontent == "")
return;
var count = getMultiMapCount();
appendMapToMulti($(data.data.mapcontent), data.data.mapcode,
arrFloorSelect, (count + 1));
openSingleMapViewModeByMapCode(floorcode);
if ($e != undefined)
$e.trigger("maploaded");
return;
}
}, "json");
}
// //////////////////////////////////////////地图操作/////////////////////////////////////////////
// 保存地图配置
function saveDefaultMapMethod() {
var crossfix = function(data, data1) {
var result = [];
var common = data.length < data1.length ? data.length
: data1.length;
var long_data = data.length > data1.length ? data : data1;
var max = long_data.length;
var j = 0;
for (var i = 0; i < common; i++) {
result[j++] = data[i];
result[j++] = data1[i];
}
for (var i = common; i < max; i++) {
result[j++] = long_data[i];
}
return result;
}
// 用户,监控模式下
if ($("#ale-user-id").attr("value") == "")
return;
if ($("#ale-monitor-mode").attr("value") != "0")
return;
var $leftMapCodes = [], $rightMapCodes = [];
getMultiMapCodes($leftMapCodes, $rightMapCodes);
var result = crossfix($leftMapCodes, $rightMapCodes);
$.get(window.basePath + "/web/v0.2/map/config/set", {
userid : $("#ale-user-id").attr("value"),
mapcodes : result.join(',')
}, function(data) {
}, "json");
}
function removeDeviceFromMapMethod(mac) {
var $device = $("g#Layer_Monitor #g" + mac);
var devicecount = $device.length;
var isTrackMode = $("#ale-monitor-mode").attr("value") == 1 ? true
: false;
for (var i = 0; i < devicecount; i++) {
var svgId = $($device[i]).parents("svg").attr("id");
var $targetcontainer = $($device[i]).parents(".widget-box");
var mapcode = $targetcontainer.find(
".widget-header .ale-mapview-title").attr("id");
d3.select("#" + svgId + " g#MapElement g#Layer_Monitor #g" + mac)
.remove();
if (isTrackMode) {
if ($targetcontainer.find("svg g#MapElement g#Layer_Monitor g").length <= 0) {
$("#ale-mapviewmode-multi #" + validateDotInId(mapcode))
.parents(".widget-box").hide();// 隐藏多图模式下的地图
reorderMultiMapMethod();// 地图重新排列
if ($targetcontainer.parent().parent().attr("id") == "ale-mapviewmode-single") {
$("#ale-mapviewmode-single").hide();
$("#ale-mapviewmode-multi").show();
}
}
}
}
}
function zoomInMapUnderTrack($e) {
var isTrackMode = $("#ale-monitor-mode").attr("value") == 1 ? true
: false;
if (isTrackMode) {
var $singlecontainer = $e.parents(".widget-box");
var mapcode = $singlecontainer.find(
".widget-header .ale-mapview-title").attr("id");
var $multicontainer = $(
"#ale-mapviewmode-multi #" + validateDotInId(mapcode))
.parents(".widget-box");
var $multiContainerSvgId = $multicontainer.find("svg").attr("id");
var $multiContainerSvgMonitor = $multicontainer
.find("svg g#MapElement g#Layer_Monitor");
$singlecontainer
.find("svg g#MapElement g#Layer_Monitor g")
.each(
function() {
var mac = $(this).attr("id").substring(1);
;
if (d3
.select(
"#"
+ $multiContainerSvgId
+ " g#MapElement g#Layer_Monitor #g"
+ mac).empty()) {
$(this).appendTo($multiContainerSvgMonitor);
d3
.select(
"#"
+ $multiContainerSvgId
+ " g#MapElement g#Layer_Monitor #accuracy"
+ mac)
.style(
'fill',
"url(#"
+ $multiContainerSvgId
+ "largeGradient"
+ ")");
}
});
}
}
// /显示追踪目标
function getTrackTargetMapMethod(mac, mapcode) {
// 检查原图是否有其他监控目标,若无,则删除该地图;换图时,先判断是单图还是多图模式,并加载相应地图至场景
// 多图模式:自动删除没有监控目标的楼层;
// 单图模式:若当前楼层,仍有其他目标,则不删除;若无其他目标则,切图;
var targetid = "g#MapElement g#Layer_Monitor #g" + mac;
var showMapUnderMultiMode = function() {
var mapcodeid = "#" + mapcode.replace(/[.]/g, "\\.");
if ($("#ale-mapviewmode-multi").find(mapcodeid).length == 0) {
requestForMap(mapcode, $("#ale-tree-selectfloor").data(
"mapcodes")); // 加载新地图
}
if ($("#ale-mapviewmode-multi").find(mapcodeid).parents(
".widget-box").css("display") == "none") {
var $tragetmap = $("#ale-mapviewmode-multi").find(mapcodeid)
.parents(".widget-box");// 显示已加载过的的地图
var count = getMultiMapCount();
if (count >= 1) {
$tragetmap.appendTo($("#ale-multi-right"));
} else if (count < 1) {
$tragetmap.appendTo($("#ale-multi-left"));
}
$tragetmap.show();
}
var $targets = $("svg " + targetid);// 查找目标
var count = $targets.length;
for (var i = 0; i < count; i++) {
var $targetcontainer = $($targets[i]).parents(".widget-box");
var comparemapcode = $targetcontainer.find(
".widget-header .ale-mapview-title").attr("id");
if (mapcode != comparemapcode) {
var svgId2 = $targetcontainer.find("svg").attr("id");
d3.select(
"#" + svgId2 + " g#MapElement g#Layer_Monitor #g"
+ mac).remove();// 删除此图中的监控目标
if ($targetcontainer
.find("svg g#MapElement g#Layer_Monitor g").length <= 0) {
// $targetcontainer.hide();//隐藏地图
$(
"#ale-mapviewmode-multi #"
+ validateDotInId(comparemapcode))
.parents(".widget-box").hide();// 隐藏多图模式下的地图
reorderMultiMapMethod();// 地图重新排列
}
}
}
}
var showMapUnderSingleMode = function() {
var comparemapcode = $("#ale-mapviewmode-single").find(
".widget-header .ale-mapview-title").attr("id");
var svgId = $("#ale-mapviewmode-single").find("svg").attr("id");
if (mapcode != comparemapcode) {
d3.select(
"#" + svgId + " g#MapElement g#Layer_Monitor #g" + mac)
.remove();
if ($("#ale-mapviewmode-single").find(
"svg g#MapElement g#Layer_Monitor g").length <= 0) {
var $e = $("#" + validateDotInId(mapcode)).parents(
"#ale-mapviewmode-multi .widget-box");
if ($e.length == 0) {
setTimeout(
function() {
if ($("#ale-mapviewmode-single").css(
"display") == "block"
&& $("#ale-mapviewmode-single")
.find(
"svg g#MapElement g#Layer_Monitor g").length <= 0) {
$("#ale-mapviewmode-single").hide();
$("#ale-mapviewmode-multi").show();
$(
"#ale-mapviewmode-multi #"
+ validateDotInId(comparemapcode))
.parents(".widget-box").hide();
}
}, 2000);
} else {
var floorname = $e.find(
".widget-header .ale-mapview-title").text();
var floorid = $e.find(
".widget-header .ale-mapview-title").attr("id");
var compass = $e.find(".ale-compass");
var svg = $e.find("svg");
openSingleMapViewMode(svg, floorname, floorid, compass);
}
}
}
}
showMapUnderMultiMode();
if ($("#ale-mapviewmode-single").css("display") == "block") {// 单图模式
showMapUnderSingleMode();
}
}
function getMultiMapCount() {
var $leftMap = [], $rightMap = [];
return countMultiMap($leftMap, $rightMap);
}
function getMultiMapCodes($leftMapCodes, $rightMapCodes) {
var $leftMap = [], $rightMap = [];
countMultiMap($leftMap, $rightMap);
for (var i = 0; i < $leftMap.length; i++) {
$leftMapCodes[i] = $($leftMap[i]).find(
".widget-header .ale-mapview-title").attr("id");
}
for (var i = 0; i < $rightMap.length; i++) {
$rightMapCodes[i] = $($rightMap[i]).find(
".widget-header .ale-mapview-title").attr("id");
}
}
function countMultiMap($leftMap, $rightMap) {
var k = 0;
$("#ale-multi-left").find(".widget-box").each(
function() {
var e = $(this);
if (!e.hasClass("ale-multi-maptemplate")
&& e.css("display") == "block") {
$leftMap[k] = e;
k++;
}
});
k = 0;
$("#ale-multi-right").find(".widget-box").each(
function() {
var e = $(this);
if (!e.hasClass("ale-multi-maptemplate")) {
if (!e.hasClass("ale-multi-maptemplate")
&& e.css("display") == "block") {
$rightMap[k] = e;
k++;
}
}
});
return ($leftMap.length - $rightMap.length);
}
function reorderMultiMapMethod() {
var $leftMap = [], $rightMap = [];
var count = countMultiMap($leftMap, $rightMap);
if (count > 1) {
$($leftMap[$leftMap.length - 1]).appendTo($("#ale-multi-right"));
reorderMultiMapMethod();
} else if (count < 0) {
$($rightMap[$rightMap.length - 1]).appendTo($("#ale-multi-left"));
reorderMultiMapMethod();
}
}
function resetMapMode() {// 重置地图模式
$("#ale-mapviewmode-multi").find(".widget-box").each(function() {
var e = $(this);
if (!e.hasClass("ale-multi-maptemplate")) {
e.remove();
}
});
$("#ale-mapviewmode-single").hide();
$("#ale-mapviewmode-multi").show();
}
function setTrackModeMethod() {
// info primary
$("#ale-btn-tracking").removeClass("btn-info").addClass("btn-primary");
if ($("#ale-btn-monitoring").hasClass("btn-primary")) {
$("#ale-btn-monitoring").removeClass("btn-primary").addClass(
"btn-info");
}
// storeMonitorModeMapView();//存监控模式下的地图
resetMapMode();
$("#ale-btn-selectfloor").parent().hide();
$("#ale-monitor-mode").attr("value", "1");
$("#ale-title-sub").text("目标追踪");
}
function setMonitorModeMethod() {
$("#ale-btn-monitoring").removeClass("btn-info")
.addClass("btn-primary");
if ($("#ale-btn-tracking").hasClass("btn-primary")) {
$("#ale-btn-tracking").removeClass("btn-primary").addClass(
"btn-info");
}
resetMapMode();
// parseMonitorModeMapView();//恢复监控模式下的地图
$("#ale-btn-selectfloor").parent().show();
$("#ale-monitor-mode").attr("value", "0");
$("#ale-title-sub").text("全局监控");
}
// //////////////////////////////////////////Map至多图模式/////////////////////////////////////////////
// 删除id中.
function validateDotInId(id) {
return id.replace(/[.]/g, "\\.");
}
// 替换id中.为dot
function replaceDotInId(id) {
return id.replace(/[.]/g, "dot");
}
function appendMapToMulti(svgmap, mapcode, mapdictionary, count) {
var newmap = $("#ale-mapviewmode-multi .ale-multi-maptemplate").clone();
$(newmap).removeClass("ale-multi-maptemplate");
// $.mapOperation.bindMultiClickEvent($(newmap));
bindMultiClickEvent($(newmap));
// 平移事件
svgPan(newmap.find(".ale-div-map"), true);
appendSVGMapToMapContainer(newmap, svgmap, mapcode,
mapdictionary[mapcode]);
// 添加SVG至相应widget-box下
if ($("#ale-mapviewmode-multi #" + validateDotInId(mapcode)).length > 0)// 防止重复添加
return;
if (count <= 1) {
$(newmap).appendTo($("#ale-multi-left"));
} else {
$(newmap).appendTo($("#ale-multi-right"));
}
}
// 绑定多图模式下,控件的点击事件
function bindMultiClickEvent(e) {
var tool_zoomin = e.find(".zoomInMap");
bindMulti_ZoomInClick($(tool_zoomin));
e.on("closed.ace.widget", function(evt, data) {
saveDefaultMapMethod();
});
e.find(".collapseMap").click(
function() {
if ($(this).parents(".widget-box").hasClass(
"ui-sortable-helper")) {
return; // 防止误操作
}
var status = $(this).parents(".widget-box").hasClass(
"collapsed");
var mapzoom = $(this).parents(".widget-box").find(
".ale-mapzoom-multi");
if (status) {
setTimeout(function() {
mapzoom.show();
}, 150);
} else {
mapzoom.hide();
}
});
var zoomBtnGroup = e.find(".ale-mapzoom");
zoomBtnGroup.data("zoom", 1);
// 多图模式缩小按钮
e.find(".ale-mapzoom-btn-out").click(function() {
operationSvgZoom($(this), true);
});
// 多图模式放大按钮
e.find(".ale-mapzoom-btn-in").click(function() {
operationSvgZoom($(this), false);
});
// 多图模式恢复按钮
e.find(".ale-mapzoom-btn-recover").click(function() {
var svg = $(this).parents(".widget-box").find("svg");
var mapzoom = $(this).parents(".widget-box").find(".ale-mapzoom");
resetSVGZoom(svg, mapzoom);
});
}
// 添加,并设置svg地图至widget-box
function appendSVGMapToMapContainer(container, svgmap, mapcode, mapName) {
// var mapcode = svgmap.attr("id").replace("_Map", "");
// var mapName = mapdictionary[mapcode];
var mapDirection = svgmap.attr("northdirection");
// 设置widget-box id name compass
$(container).find(".widget-header .ale-mapview-title").attr("id",
mapcode);
$(container).find(".widget-header .ale-mapview-title").text(mapName);
$(container).find(".ale-compass img").css("transform",
"rotate(" + mapDirection + "deg)");
// 设置SVG属性
var svgid = svgmap.attr("id");
var width = svgmap.attr("width");
var height = svgmap.attr("height");
var dwidth = SINGLE_SVGWEIGHT / 2;
var dheight = MULTI_SVGHEIGHT;
//
svgmap.attr("svgDom", computeSVGDisplayScale(width, dwidth,
height, dheight));
svgmap.attr("id", "Multi_" + replaceDotInId(mapcode));
svgmap.attr("width", dwidth);
svgmap.attr("height", dheight);
svgmap.find("defs image").each(
function() {
var imagepath = $(this).attr("xlink:href");
var strs = imagepath.split("/");
var imagename = strs[strs.length - 1].split(".")[0];
$(this).attr(
"xlink:href",
window.basePath + "/data/MapResource/" + imagename
+ ".svg");
});
var geostatus = $("#ale-btn-controlGeofencing").attr("data-ale-status");
var poistatus = $("#ale-btn-controlPOI").attr("data-ale-status");
if (geostatus == "false")
svgmap.find("g#Layer_Geofencing").attr("visibility", "hidden");
else
svgmap.find("g#Layer_Geofencing").attr("visibility", "visible");
if (poistatus == "false")
svgmap.find("g#POIElement").attr("visibility", "hidden");
else
svgmap.find("g#POIElement").attr("visibility", "visible");
svgmap.appendTo($(container).find(".widget-main .ale-div-map"));
}
// 计算缩放比例
function computeSVGDisplayScale(width, dwidth, height, dheight) {
var w = parseInt(width) / dwidth;
w = parseInt((w + 0.05) * 100) / 100.0
var h = parseInt(height) / dheight;
h = parseInt((h + 0.05) * 100) / 100.0
return w > h ? w : h;
}
// 绑定多图放大按钮事件
function bindMulti_ZoomInClick(e) {
e.click(function() {
var floor = e.parents(".widget-header").children("h5");
var floorname = $(floor).text();
var floorid = $(floor).attr("id");
var compass = e.parents(".widget-box").find(".ale-compass");
var svg = e.parents(".widget-box").find("svg");
var mapzoom = e.parents(".widget-box").find(".ale-mapzoom");
resetSVGZoom(svg, mapzoom);// 置初始值
openSingleMapViewMode(svg, floorname, floorid, compass);
});
}
// 通过MapCode打开单图模式
function openSingleMapViewModeByMapCode(mapcode) {
var $e = $("#" + validateDotInId(mapcode)).parents(
"#ale-mapviewmode-multi .widget-box");
if ($e.length > 0) {
var floorname = $e.find(".widget-header .ale-mapview-title").text();
var floorid = $e.find(".widget-header .ale-mapview-title").attr(
"id");
var compass = $e.find(".ale-compass");
var svg = $e.find("svg");
openSingleMapViewMode(svg, floorname, floorid, compass);
}
}
// 打开单图模式
function openSingleMapViewMode(e, floorname, floorid, compass) {
var singlemode = $("#ale-mapviewmode-single").find("h5");
singlemode.text(floorname);
singlemode.attr("id", floorid);
$("#ale-mapviewmode-single .ale-compass").empty();
$("#ale-mapviewmode-single .ale-compass").html($(compass).html());
var svg = e.clone();
$("#ale-mapviewmode-single .ale-div-map").empty();
// var svg=$(this).parent().parent().parent().find("svg").clone();
var svgid = svg.attr("id");
var svgwidth = svg.attr("width");
var svgheight = svg.attr("height");
var width = SVG(svgid).viewbox().width; // 可取已加载过的SVG,改变了原有svgid的宽度
var height = SVG(svgid).viewbox().height;
var dwidth = SINGLE_SVGWEIGHT;
var dheight = SINGLE_SVGHEIGHT;
svg.attr("displayscale", computeSVGDisplayScale(width, dwidth, height,
dheight));
svg.attr("width", dwidth);
svg.attr("height", dheight);
svg.attr("id", "Single_" + replaceDotInId(floorid)); // 区别SVG id
svg.appendTo("#ale-mapviewmode-single .ale-div-map");
$("#ale-mapviewmode-single .ale-mapzoom").data("zoom", 1); // 设置缩放比例
$("#ale-mapviewmode-multi").hide();
$("#ale-mapviewmode-single").show();
e.attr("width", svgwidth);
e.attr("height", svgheight);
}
// //////////////////////////////////////////树操作/////////////////////////////////////////////
var confirmTreeSelect = function() {
var datas = $("#ale-tree-selectfloor").find(".tree-item.tree-selected");
var arrFloorSelect = {}; // 树的选择状态
for (var i = 0; i < datas.length; i++) {
if ($(datas[i]).css("display") == "none") {
continue;
}
var floorname = $(datas[i]).find(".tree-item-name").text();
var buildingname = $(datas[i]).parent().parent().find(
".tree-folder-header").find(".tree-folder-name").text();
var mapcode = $(datas[i]).data("mapcode");
var mapname = buildingname + "_" + floorname;
arrFloorSelect[mapcode] = mapname;
}
var count = 0;
for ( var key in arrFloorSelect) {
if (arrFloorSelect.hasOwnProperty(key))
count++;
}
// 先删除ale-mapviewmode-multi中不存在元素,显示唯一元素
var floors = $("#ale-mapviewmode-multi").find(".widget-box");
for (var j = 0; j < floors.length; j++) {
if ($(floors[j]).hasClass("ale-multi-maptemplate"))
continue;
var floorid = $(floors[j]).find(".ale-mapview-title").attr("id");
if (!!!arrFloorSelect[floorid]) { // 如果不包含此key
$(floors[j]).remove(); // 删除相应图层
} else {
delete (arrFloorSelect[floorid]);
if (count == 1) {
openSingleMapViewModeByMapCode(floorid);
}
}
}
if (count == 0) {
$("#ale-tree-selectfloor").trigger("maploaded");
$("#ale-mapviewmode-single").hide();
$("#ale-mapviewmode-multi").show();
} else if (count == 1) {
for ( var key in arrFloorSelect) {
requestForMapShowOnSingleMode(key, arrFloorSelect,
$("#ale-tree-selectfloor"));
}
} else {
requestForMultiMap(arrFloorSelect, "", $("#ale-tree-selectfloor"));
$("#ale-mapviewmode-single").hide();
$("#ale-mapviewmode-multi").show();
}
$("#ale-dialog-selectfloor").modal("hide");
}
var onloadTreeEvent = function(evt, data) {
var targetbuilding = data.data.context.textContent.trim(); // 当前点击框名称
var datas = $("#ale-tree-selectfloor").children(".tree-folder");
for (var i = 0; i < datas.length; i++) {
if ($(datas[i]).children(".tree-folder-header").text().trim() == targetbuilding
&& $(datas[i]).children(".tree-folder-content").text()
.trim() == "") {
$(datas[i]).children(".tree-folder-header").trigger("click");
}
var datachildren = $(datas[i]).children(".tree-folder-content")
.children(".tree-folder");
for (var ii = 0; ii < datachildren.length; ii++) {
if ($(datachildren[ii]).children(".tree-folder-header").text()
.trim() == targetbuilding) {
// 不再执行建筑的点击命令,在园区点击已经执行完毕了
return;
}
}
for (var j = 0; j < datachildren.length; j++) {
if ($(datachildren[j]).children(".tree-folder-content").css(
"display") == "block"
&& $(datachildren[j]).children(".tree-folder-content")
.text().trim() == "") {
$(datachildren[j]).children(".tree-folder-header").trigger(
"click");
}
}
}
}
// 改变树的选择状态
function changeSelectFloorTreeStatus(bfirst, targetbuilding) {
var floors = $("#ale-mapviewmode-multi").find(".widget-box");
var floorArray = [];
for (var j = 0; j < floors.length; j++) {
if ($(floors[j]).css("display") == "none") {
continue;
}
floorArray.push($(floors[j]).find(".ale-mapview-title").attr("id"));
}
// var floors = $("#ale-mapviewmode-multi").find(".ale-mapview-title");
var datas = $("#ale-tree-selectfloor").find(".tree-item");
for (var i = 0; i < datas.length; i++) {
if ($(datas[i]).css("display") == "none") {
continue;
}
// var floorname = $(datas[i]).find(".tree-item-name").text();
var buildingname = $(datas[i]).parent().parent().find(
".tree-folder-header").find(".tree-folder-name").text();
if (bfirst) {
if (buildingname != targetbuilding)
continue;
}
var floor = $(datas[i]).data("mapcode");
var a = $(datas[i]);
if (isFloorExist(floor, floorArray)) {
if (!a.hasClass("tree-item tree-selected")) {
a.trigger("click");
}
} else {
if (a.hasClass("tree-item tree-selected")) {
a.trigger("click");
}
}
}
}
// 检测楼层是否存在
function isFloorExist(floor, floors) {
if (floors.indexOf(floor) >= 0)
return true;
return false;
}
// //////////////////////////////////////////
// SVG缩放平移////////////////////////////////////////////
// 操作SVG缩放,in->-0.1,out->0.1;in-fasle,out-true
function operationSvgZoom(e, status) {
var svg = e.parents(".widget-body").find("svg");
var zoom = e.parent().data("zoom");
var step = status ? 0.1 : (-0.1);
if (zoom <= 0.1 && status)
// if ((zoom >= 10 && !status) || (zoom <= 0.1 && status))
return;
var scale = svgZoom(svg, zoom, step);
e.parent().data("zoom", scale);
}
// SVG缩放具体方法
function svgZoom(svg, zoom, step) {
// 控制
var scale = parseInt((zoom - step + 0.0001) * 10) / 10.0;
var translate = svg.find("g#MapElement").attr("transform");
var width = svg.attr("width"); // viewBox会改变大小width,height大小
var height = svg.attr("height");
var svgid = svg.attr("id");
var vwidth = SVG(svgid).viewbox().width * step / 2;
var vheight = SVG(svgid).viewbox().height * step / 2;
var newtranslate = panandZoom(parseInt(vwidth), parseInt(vheight),
scale, translate);
svg.find("#Backgroundcolor").attr("transform", newtranslate);
svg.find("g#MapElement").attr("transform", newtranslate);
svg.attr("width", width);
svg.attr("height", height);
return scale;
}
// svg恢复初始状态
function resetSVGZoom(svg, mapzoom) {
// var zoom = mapzoom.data("zoom");
var newtranslate = panandZoom(0, 0, 1, undefined);
svg.find("#Backgroundcolor").attr("transform", newtranslate);
svg.find("g#MapElement").attr("transform", newtranslate);
mapzoom.data("zoom", 1);
}
function panandZoom(x, y, scale, translate) {
if (translate == undefined)
return "translate(" + x + "," + y + ") scale(" + scale + ")";
// var old = translate.replace("translate(", "").replace(")",
// "").replace("scale(", ",").replace(")", "").split(",");
var old = translate.match(/[-]?\d+(\.\d+)?/g);
// console.log("OLDMOVE=="+parseInt(old[0])+"---"+parseInt(old[1]));
var newx = parseInt(x) + parseInt(old[0]);
var newy = parseInt(y) + parseInt(old[1])
return "translate(" + newx + "," + newy + ") scale(" + scale + ")";
}
// svg平移
function svgPan(svgContainer, isMulti) {
svgContainer.mousedown(function(event) {
if (isMulti) {
$(this).parents(".widget-container-span").sortable('disable');
}
$(this).css("cursor",
"url(" + window.basePath + "/data/openhand.png), default");
var svg = $(this).find("svg");
var startX, startY, movingX, movingY, endX, endY;
startX = event.pageX;
startY = event.pageY;
var zoom = svg.parents(".widget-box").find(".ale-mapzoom").data(
"zoom");
var translate = svg.find("g#MapElement").attr("transform");
var panScale = svg.attr("displayscale");
$(this).bind("mousemove", function(evt) {
movingX = evt.pageX;
movingY = evt.pageY;
moveX = (movingX - startX) * panScale;
moveY = (movingY - startY) * panScale;
moveX = parseInt(moveX);
moveY = parseInt(moveY);
var newtranslate = panandZoom(moveX, moveY, zoom, translate);
svg.find("#Backgroundcolor").attr("transform", newtranslate);
svg.find("g#MapElement").attr("transform", newtranslate);
});
});
svgContainer.mouseup(function(event) {
$(this).css("cursor", "default");
$(this).unbind("mousemove");
if (isMulti) {
$(this).parents(".widget-container-span").sortable('enable');
}
});
svgContainer.mouseout(function() {
$(this).css("cursor", "default");
$(this).unbind("mousemove");
if (isMulti) {
$(this).parents(".widget-container-span").sortable('enable');
}
});
}
// //////////////////////////////////////////
// 控制POI,地理围栏状态////////////////////////////////////////////
// 控制POI状态
function controlPOI(status) {
$("svg g#POIElement").each(function() {
if (status == "true")
$(this).attr("visibility", "hidden");
else
$(this).attr("visibility", "visible");
});
}
// 控制地理围栏状态
function controlGeofencing(status) {
$("svg g#Layer_Geofencing").each(function() {
if (status == "true")
$(this).attr("visibility", "hidden");
else
$(this).attr("visibility", "visible");
});
}
// 控制显示隐藏