-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.js
More file actions
1342 lines (1252 loc) · 58.6 KB
/
map.js
File metadata and controls
1342 lines (1252 loc) · 58.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* This module:
* - handles all drawing, events etc relative to the map. The map is a canvas where all items are drawn on.
* - draws the plan image and the items positions on the plan.
* - handles all the events occuring on the map.
* - handles the behavior of the various map tools.
*/
/** text to display on the top left of the canvas - for debugging purposes mainly on mobile devices. it is not a class property in order to be visible from the event listeners */
var text_to_display = "";
class Map {
/**
* Initializes the map object based on a html-canvas
* @arg canvas_html_id is the id of the canvas element at the html file.
*/
constructor( canvas_html_id ) {
// -------------- class members:
/** the canvas html object. */
this.canvas = null;
/** the canvas context. */
this.context;
/** if the plan image is not downloaded yet, then a loading message is displayed in its place */
this.PlanIsLoading;
/** Remembers the selected tool. Possible values: zoomin, zoomout, drag, select, selectplus, selectminus, polygon, polygonplus, polygonminus, pencil, pencilplus, pencilminus, crosssection. */
this.CanvasState = "select";
/** Keeps track of how many visual elements have been drawn on the canvas */
this.num_of_drawables_OnCanvas = 0;
/** If true then only the items which the user has selected will be displayed on the map. If false then all the items listed in the items-list will be displayed on the map.*/
this.DisplayOnlySelectedItemsOnMap = true;
/** If true then distances of the plan and the selected item's polygons will be displayed on the map */
this.DisplayDistances = false;
/** Remembers whether the Ctrl is pressed or not */
this.CtrlKeyIsDown = false;
/** If true then the user can click on the map to set the coordinates of an item */
this.ManualCoordinatesMode = false;
/** The itemUUID of the item for which the coorinates are being set when in ManualCoordinatesMode */
this.ItemUUID_forManualCoordinates = "";
/** The Identifier of the item for which the coorinates are being set when in ManualCoordinatesMode */
this.ItemIdentifier_forManualCoordinates = "";
/** The coordinates set manually when in defining-coordinates-manually state */
this.ManualCoordinates = [];
/** The UUID of the item to be highlihted - usually the newly selected item */
this.Highlight_itemUUID = "";
/** The current transparency of the highlight animation */
this.currentHighlightAlpha = 1.0;
/** The interval id of the highlight animation */
this.Highlight_interval_ID;
/** The UUID of the item (or its locus, in case the item has no Location data) the information of which the user is currently displaying */
var Focused_itemUUID = "";
// -------------- init
this.canvas = document.getElementById( canvas_html_id );
this.context = this.canvas.getContext('2d');
document.getElementById("canvas").style.cursor = "wait";
if (this.context) {
// draw plan and items
this.drawWorld();
}
// add event listeners for canvas handling
canvas.addEventListener('keydown',this.Canvas_KeyDownHandler,false);
canvas.addEventListener('keyup',this.Canvas_KeyUpHandler,false);
canvas.addEventListener('mousedown',this.Canvas_MouseDownHandler,false);
canvas.addEventListener('mousemove',this.Canvas_MouseMoveHandler,false);
canvas.addEventListener('mouseup',this.Canvas_MouseUpHandler,false);
canvas.addEventListener('mouseout',this.Canvas_MouseUpHandler,false);
canvas.addEventListener('wheel',this.Canvas_WheelHandler,false);
canvas.addEventListener('dblclick',this.Canvas_DoubleclickHandler,false);
// for mobile devices:
// https://web.dev/mobile-touchandmouse/
// https://bencentra.com/code/2014/12/05/html5-canvas-touch-events.html
// https://gist.github.com/bencentra/91350fe91c377c1ca574
canvas.addEventListener('touchstart',this.Canvas_MouseDownHandler,false);
canvas.addEventListener('touchmove',this.Canvas_MouseMoveHandler,false);
canvas.addEventListener('touchend',this.Canvas_MouseUpHandler,false);
document.body.addEventListener("touchstart", function (e) {
if (e.target == canvas) { e.preventDefault(); }
}, false);
document.body.addEventListener("touchend", function (e) {
if (e.target == canvas) { e.preventDefault(); }
}, false);
document.body.addEventListener("touchmove", function (e) {
if (e.target == canvas) { e.preventDefault(); }
}, false);
}
/**
* Returns the canvas html elemenet, on which the Map object draws
*/
get_canvas() {
return this.canvas;
}
/**
* @arg s is the string to be displayed at the top left of the map for debugging purposes, mainly in mobile devices
*/
set_text_to_display( s ) {
text_to_display = s;
}
/**
* @arg s is the string to be added to the text to be displayed at the top left of the map for debugging purposes, mainly in mobile devices
*/
addto_text_to_display( s ) {
text_to_display += s;
}
/**
* Sets a flag which guides the map to display the selected-by-the-user items or the included-in-the-items-list items.
* @param {boolean} b
*/
set_DisplayOnlySelectedItemsOnMap( b ) {
this.DisplayOnlySelectedItemsOnMap = b;
}
/**
* The focused item will be displayed with a special color on the map. It usually is the item which the user has selected and is seeing its info.
* @param {String} UUID: the unique identifier of the item
*/
set_Focused_itemUUID( UUID ) {
this.Focused_itemUUID = UUID;
}
/**
* zooms in the canvas by increasing the ZommFactor state-variable and redrawing everything. This is called from other functions in order to zoom.
*/
ZoomIn( step=1 ) {
//CanvasOffsetX -= (MouseX/(PlanImageWidth*ZoomFactor)) * step*0.01* PlanImageWidth * ZoomFactor;
//CanvasOffsetY -= (MouseY/(PlanImageHeight*ZoomFactor)) * step*0.01* PlanImageHeight * ZoomFactor;
ZoomFactor += step*0.01;
this.drawWorld();
}
/**
* zooms out the canvas by dereasing the ZommFactor state-variable and redrawing everything. This is called from other functions in order to zoom.
*/
ZoomOut( step=1 ) {
ZoomFactor -= step*0.01;
if( ZoomFactor <= 0 ) ZoomFactor = 0.01;
this.drawWorld();
}
/**
* zooms 100%
*/
Zoom_OriginalSize() {
ZoomFactor = 1;
this.drawWorld();
}
/**
* zooms 10%
*/
Zoom_SmallSize() {
ZoomFactor = 0.1;
this.drawWorld();
}
/**
* Draws all elements on the canvas, based on selected tool, selected items etc.
*/
drawWorld() {
var x, y;
// make the canvas size equal to its drawing size
this.canvas.width = this.canvas.offsetWidth;
this.canvas.height = this.canvas.offsetHeight;
// clear canvas
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
// draw the background plan
this.displayPlan ( document.getElementById("AvailablePlansCombo").value );
// display a map-loading message
if(this.PlanIsLoading) {
this.context.beginPath();
this.context.font = "14px Arial";
this.context.fillStyle = "lightseagreen";
this.context.lineWidth = 1;
this.context.strokeStyle = "lightseagreen";
if( document.getElementById("AvailablePlansCombo").value.length > 0 ) {
this.context.fillText( "The Plan '"+document.getElementById("AvailablePlansCombo").value+"' is loading. Please wait.", 20, 20);
}
this.context.closePath();
this.context.fill();
this.context.stroke();
}
// draw dimensions of the plan
if( this.DisplayDistances && PlanImageWidth>0) {
var W = PlanImageWidth * ZoomFactor;
var H = PlanImageHeight * ZoomFactor;
this.context.beginPath();
this.context.strokeStyle = COLOR_distances;
this.context.fillStyle = COLOR_distances;
this.context.lineWidth = 3;
this.context.font = "bold 22px Arial";
// vertical line
this.context.moveTo(CanvasOffsetX+W+2, CanvasOffsetY); this.context.lineTo(CanvasOffsetX+W+18, CanvasOffsetY);
this.context.moveTo(CanvasOffsetX+W+10, CanvasOffsetY); this.context.lineTo(CanvasOffsetX+W+10, CanvasOffsetY+H/2-20);
this.context.moveTo(CanvasOffsetX+W+10, CanvasOffsetY+H/2+20); this.context.lineTo(CanvasOffsetX+W+10, CanvasOffsetY+H);
this.context.moveTo(CanvasOffsetX+W+2, CanvasOffsetY+H); this.context.lineTo(CanvasOffsetX+W+18, CanvasOffsetY+H);
this.context.fillText( +(PlanMaxY-PlanMinY).toFixed(2)+"m", CanvasOffsetX+W+4, CanvasOffsetY+H/2+4);
// horizontal line
this.context.moveTo(CanvasOffsetX, CanvasOffsetY+H+2); this.context.lineTo(CanvasOffsetX, CanvasOffsetY+H+18);
this.context.moveTo(CanvasOffsetX, CanvasOffsetY+H+10); this.context.lineTo(CanvasOffsetX+W/2-56, CanvasOffsetY+H+10);
this.context.moveTo(CanvasOffsetX+W/2+56, CanvasOffsetY+H+10); this.context.lineTo(CanvasOffsetX+W, CanvasOffsetY+H+10);
this.context.moveTo(CanvasOffsetX+W, CanvasOffsetY+H+2); this.context.lineTo(CanvasOffsetX+W, CanvasOffsetY+H+18);
this.context.fillText( +(PlanMaxX-PlanMinX).toFixed(2)+"m", CanvasOffsetX+W/2-44, CanvasOffsetY+H+14);
// draw
this.context.closePath();
this.context.fill();
this.context.stroke();
}
// draw the trench items
if( ExcData != null ) {
for (let i = 0; i < ExcData.length; i++) {
try {
/// check if this item should be displayed on the map or not
var display_current_item = false;
var focus_on_current_item = false;
if( typeof ExcData[i]["Location"]!="undefined" && ExcData[i]["Location"].length > 0 ) {
if( this.DisplayOnlySelectedItemsOnMap ) {
if( ExcData[i]["Selected"] ) display_current_item = true;
} else {
if( ExcData[i]["Visible"] ) display_current_item = true;
}
if( ExcData[i]["IdentifierUUID"].localeCompare(this.Focused_itemUUID) == 0 ) {
display_current_item = true;
focus_on_current_item = true;
}
if( display_current_item && ExcData[i].hasOwnProperty("InPlan") ) {
if( ExcData[i]["InPlan"]==false ) {
display_current_item = false;
focus_on_current_item = false;
}
}
}
///
if( display_current_item ) {
var LocationMatrix = ExcData[i]["Location"];
// set type-related properties
var itemcolor = getItemColor( ExcData[i]["Type"], ExcData[i]["Category"] );
var x=0, y=0, map_x=0, map_y=0;
// draw
if( LocationMatrix.length == 1 ) { // it is just a point on the map
x = parseFloat( LocationMatrix[0]["X"] );
y = parseFloat( LocationMatrix[0]["Y"] );
this.context.fillStyle = itemcolor;
if( focus_on_current_item ) {
this.context.strokeStyle = COLOR_focused;
this.context.lineWidth = 5;
} else if( ExcData[i]["Selected"] ) {
this.context.strokeStyle = COLOR_selected;
this.context.lineWidth = 3;
} else {
this.context.strokeStyle = itemcolor;
this.context.lineWidth = 1;
}
this.context.beginPath();
map_x = this.map_range(x, PlanMinX, PlanMaxX, 0 , PlanImageWidth) * ZoomFactor + CanvasOffsetX;
map_y = this.map_range(y, PlanMinY, PlanMaxY, PlanImageHeight, 0) * ZoomFactor + CanvasOffsetY;
this.context.arc(map_x, map_y, 4, 0, 2*Math.PI);
this.context.fill();
this.context.stroke();
this.num_of_drawables_OnCanvas++;
} else if( LocationMatrix.length > 1 ) { // it is a shape on the map
// **************** draw the polygon ****************
x = LocationMatrix[0]["X"];
y = LocationMatrix[0]["Y"];
map_x = this.map_range(x, PlanMinX, PlanMaxX, 0 , PlanImageWidth) * ZoomFactor + CanvasOffsetX;
map_y = this.map_range(y, PlanMinY, PlanMaxY, PlanImageHeight, 0) * ZoomFactor + CanvasOffsetY;
if( this.currentHighlightAlpha > 0 && ExcData[i]["IdentifierUUID"].localeCompare(this.Highlight_itemUUID)==0 ) {
this.context.globalAlpha = 0.20 + this.currentHighlightAlpha;
this.context.fillStyle = COLOR_highlight;
} else {
this.context.globalAlpha = 0.20;
this.context.fillStyle = itemcolor;
}
this.context.beginPath();
this.context.moveTo(map_x, map_y);
for(let pointIdx=1; pointIdx<LocationMatrix.length; pointIdx++) {
x = LocationMatrix[pointIdx]["X"];
y = LocationMatrix[pointIdx]["Y"];
map_x = this.map_range(x, PlanMinX, PlanMaxX, 0 , PlanImageWidth) * ZoomFactor + CanvasOffsetX;
map_y = this.map_range(y, PlanMinY, PlanMaxY, PlanImageHeight, 0) * ZoomFactor + CanvasOffsetY;
this.context.lineTo(map_x, map_y);
this.num_of_drawables_OnCanvas++;
}
// connect final and starting point together
x = LocationMatrix[0]["X"];
y = LocationMatrix[0]["Y"];
map_x = this.map_range(x, PlanMinX, PlanMaxX, 0 , PlanImageWidth) * ZoomFactor + CanvasOffsetX;
map_y = this.map_range(y, PlanMinY, PlanMaxY, PlanImageHeight, 0) * ZoomFactor + CanvasOffsetY;
this.context.lineTo(map_x, map_y);
this.num_of_drawables_OnCanvas++;
// fill shape with semitransparent color
this.context.closePath();
this.context.fill();
// decide opaque border color and draw it
if( focus_on_current_item ) {
this.context.strokeStyle = COLOR_focused;
this.context.lineWidth = 5;
} else if( ExcData[i]["Selected"] ) {
this.context.strokeStyle = COLOR_selected;
this.context.lineWidth = 3;
} else {
this.context.strokeStyle = itemcolor;
this.context.lineWidth = 2;
}
this.context.globalAlpha = 1;
this.context.stroke();
// **************** Display lengths of edges of the selected items ****************
this.context.beginPath();
this.context.font = "bold 22px Arial";
this.context.lineWidth = 1;
this.context.strokeStyle = COLOR_distances;
this.context.fillStyle = "white";
if( this.DisplayDistances && ExcData[i]["Selected"] && LocationMatrix.length>=3 ) {
x = LocationMatrix[0]["X"];
y = LocationMatrix[0]["Y"];
map_x = this.map_range(x, PlanMinX, PlanMaxX, 0 , PlanImageWidth) * ZoomFactor + CanvasOffsetX;
map_y = this.map_range(y, PlanMinY, PlanMaxY, PlanImageHeight, 0) * ZoomFactor + CanvasOffsetY;
var prev_map_x = map_x;
var prev_map_y = map_y;
for(let pointIdx=1; pointIdx<LocationMatrix.length; pointIdx++) {
if( pointIdx > 1 ) { prev_map_x = map_x; prev_map_y = map_y; }
x = LocationMatrix[pointIdx]["X"];
y = LocationMatrix[pointIdx]["Y"];
map_x = this.map_range(x, PlanMinX, PlanMaxX, 0 , PlanImageWidth) * ZoomFactor + CanvasOffsetX;
map_y = this.map_range(y, PlanMinY, PlanMaxY, PlanImageHeight, 0) * ZoomFactor + CanvasOffsetY;
var txt = +Lines.CalculateDistance(x, y, LocationMatrix[pointIdx-1]["X"], LocationMatrix[pointIdx-1]["Y"]).toFixed(2) + "m";
var txt_x = prev_map_x + (map_x-prev_map_x)/2;
var txt_y = prev_map_y + (map_y-prev_map_y)/2;
this.context.fillText( txt, txt_x, txt_y );
this.context.strokeText( txt, txt_x, txt_y );
this.num_of_drawables_OnCanvas++;
}
}
this.context.closePath();
this.context.fill();
this.context.stroke();
}
//// ~~~~~~~~~~~~~~~~ draw Highlight of a point on map ~~~~~~~~~~~~~~~~~~~~
if( this.currentHighlightAlpha > 0 && ExcData[i]["IdentifierUUID"].localeCompare(this.Highlight_itemUUID)==0 ) {
// move map so that the highlighted item is visible
if(map_x > this.canvas.width-20) CanvasOffsetX = CanvasOffsetX + map_x - this.canvas.width - this.canvas.width/2;
if(map_y > this.canvas.height-20) CanvasOffsetY = CanvasOffsetY + map_y - this.canvas.height - this.canvas.height/2;
if(map_x < 0) CanvasOffsetX = CanvasOffsetX - map_x + this.canvas.width/2;
if(map_y < 0) CanvasOffsetY = CanvasOffsetY - map_y + this.canvas.height/2;
// draw a vertical and a horizontal line towards the item
this.context.beginPath();
this.context.globalAlpha = this.currentHighlightAlpha;
this.context.strokeStyle = COLOR_highlight;
if( LocationMatrix.length == 1 ) { // a point on the map
this.context.lineWidth = 8;
this.context.moveTo(map_x, 0);
this.context.lineTo(map_x, map_y);
this.context.moveTo(0, map_y);
this.context.lineTo(map_x, map_y);
} else { // a shape on the map
var min_x = +999999;
var min_y = +999999;
var max_x = -999999;
var max_y = -999999;
for(let pointIdx=1; pointIdx<LocationMatrix.length; pointIdx++) {
if( min_x > LocationMatrix[pointIdx]["X"] ) min_x = LocationMatrix[pointIdx]["X"];
if( max_x < LocationMatrix[pointIdx]["X"] ) max_x = LocationMatrix[pointIdx]["X"];
if( min_y > LocationMatrix[pointIdx]["Y"] ) min_y = LocationMatrix[pointIdx]["Y"];
if( max_y < LocationMatrix[pointIdx]["Y"] ) max_y = LocationMatrix[pointIdx]["Y"];
}
min_x = this.map_range(min_x, PlanMinX, PlanMaxX, 0 , PlanImageWidth) * ZoomFactor + CanvasOffsetX;
max_x = this.map_range(max_x, PlanMinX, PlanMaxX, 0 , PlanImageWidth) * ZoomFactor + CanvasOffsetX;
min_y = this.map_range(min_y, PlanMinY, PlanMaxY, PlanImageHeight, 0) * ZoomFactor + CanvasOffsetY;
max_y = this.map_range(max_y, PlanMinY, PlanMaxY, PlanImageHeight, 0) * ZoomFactor + CanvasOffsetY;
this.context.lineWidth = 4;
this.context.moveTo(min_x, 0);
this.context.lineTo(min_x, max_y);
this.context.moveTo(max_x, 0);
this.context.lineTo(max_x, max_y);
this.context.moveTo(0, min_y);
this.context.lineTo(max_x, min_y);
this.context.moveTo(0, max_y);
this.context.lineTo(max_x, max_y);
}
this.context.stroke();
this.context.globalAlpha = 1;
}
}
} catch(ex) { }
}
}
// draw cross section line
if( this.CanvasState.localeCompare("crosssection")==0 ) {
if( CrossSectionX1 >= 0 && CrossSectionX2 < 0 ) {
this.context.fillStyle = COLOR_crosssection;
this.context.strokeStyle = COLOR_crosssection;
this.context.lineWidth = 2;
// draw starting point as dot
this.context.beginPath();
this.context.arc(CrossSectionX1, CrossSectionY1, 5, 0, 2*Math.PI);
this.context.closePath();
this.context.stroke();
this.context.fill();
// draw line
this.context.beginPath();
this.context.moveTo(CrossSectionX1, CrossSectionY1);
this.context.lineTo(MouseX, MouseY);
this.context.closePath();
this.context.stroke();
// draw finish point as dot
this.context.beginPath();
this.context.arc(MouseX, MouseY, 5, 0, 2*Math.PI);
this.context.closePath();
this.context.stroke();
this.context.fill();
// draw distance between the two points
var dist = (PlanMaxX-PlanMinX) / (PlanImageWidth*ZoomFactor) * Lines.CalculateDistance(CrossSectionX1, CrossSectionY1, MouseX, MouseY);
var txt_x = CrossSectionX1 + (MouseX-CrossSectionX1)/2 + 6; //var txt_x = Math.min(CrossSectionX1, MouseX) + (MouseX - CrossSectionX1)/2;
var txt_y = CrossSectionY1 + (MouseY-CrossSectionY1)/2 - 6; //var txt_y = Math.min(CrossSectionY1, MouseY) + (MouseY - CrossSectionY1)/2;
this.context.beginPath();
this.context.font = "bold 22px Arial";
this.context.fillStyle = "white";
this.context.lineWidth = 1;
this.context.strokeStyle = COLOR_distances;
this.context.fillText( (+dist).toFixed(2)+"m", txt_x, txt_y);
this.context.strokeText( (+dist).toFixed(2)+"m", txt_x, txt_y);
this.context.closePath();
this.context.fill();
this.context.stroke();
} else if( CrossSectionX1 >= 0 && CrossSectionX2 >= 0 ) {
this.CalcAndDrawCrossSection( CrossSectionX1, CrossSectionY1, CrossSectionX2, CrossSectionY2 );
}
}
//// draw mouse selection
if( MouseIsDown && this.CanvasState.startsWith("select") ) {
this.context.globalAlpha = 0.28;
this.context.fillStyle = "lightseagreen";
this.context.fillRect(MouseStartX, MouseStartY, MouseX-MouseStartX, MouseY-MouseStartY);
this.context.globalAlpha = 1;
//
this.context.beginPath();
this.context.strokeStyle = "teal";
this.context.rect(MouseStartX, MouseStartY, MouseX-MouseStartX, MouseY-MouseStartY);
this.context.stroke();
} else if( this.CanvasState.startsWith("polygon") && PolygonPoints.length > 1) {
this.context.strokeStyle = "teal";
this.context.lineWidth = 3;
this.context.beginPath();
this.context.moveTo(PolygonPoints[0]["x"], PolygonPoints[0]["y"]);
if( PolygonPoints.length > 1 ) {
for(let i=1; i<PolygonPoints.length; i++) {
this.context.lineTo(PolygonPoints[i]["x"], PolygonPoints[i]["y"]);
}
}
this.context.arc(PolygonPoints[PolygonPoints.length-1]["x"], PolygonPoints[PolygonPoints.length-1]["y"], 4, 0, 2*Math.PI);
this.context.stroke();
this.context.globalAlpha = 0.28;
this.context.fillStyle = "lightseagreen";
this.context.fill();
this.context.globalAlpha = 1;
}
// draw some info text
//if( text_to_display.length > 0 && this.DisplayDistances ) { // TODO: remove this.DisplayDistances
if( text_to_display.length > 0 ) {
this.context.beginPath();
this.context.font = "bold 13px Arial black";
this.context.fillStyle = "black";
this.context.fillText( text_to_display, 10, 80 );
this.context.closePath();
this.context.fill();
}
//
if( map != null && map.ManualCoordinatesMode ) {
// display help message
this.context.beginPath();
this.context.font = "bold 16px Arial";
this.context.strokeStyle = "mediumvioletred";
this.context.fillStyle = "mediumvioletred";
this.context.fillText(this.ItemIdentifier_forManualCoordinates+": Defining coordinates manually: Use the Target button above to define points on the map. ESC=cancel ENTER=finish DEL=clear", 10, 20);
this.context.closePath();
this.context.fill();
// display indicative border
this.context.beginPath();
this.context.strokeStyle = "mediumvioletred";
this.context.lineWidth = 6;
this.context.rect(0, 0, this.canvas.width, this.canvas.height);
this.context.stroke();
// Transform ManualCoordinates so that they can be displayed on Map
var ManualCoordinates_onMap = [];
for(var i=0; i<this.ManualCoordinates.length; i++ ) {
var map_x = this.map_range(this.ManualCoordinates[i]["X"], PlanMinX, PlanMaxX, 0 , PlanImageWidth) * ZoomFactor + CanvasOffsetX;
var map_y = this.map_range(this.ManualCoordinates[i]["Y"], PlanMinY, PlanMaxY, PlanImageHeight, 0) * ZoomFactor + CanvasOffsetY;
ManualCoordinates_onMap.push( {"X":map_x, "Y":map_y} );
}
// display ManualCoordinates_onMap
if( ManualCoordinates_onMap.length > 0 ) {
this.context.beginPath();
this.context.strokeStyle = "mediumvioletred";
this.context.lineWidth = 2;
this.context.arc(ManualCoordinates_onMap[0]["X"], ManualCoordinates_onMap[0]["Y"], 3, 0, 2*Math.PI);
this.context.moveTo( ManualCoordinates_onMap[0]["X"], ManualCoordinates_onMap[0]["Y"] );
for(var i=1; i<ManualCoordinates_onMap.length; i++ ) {
this.context.lineTo( ManualCoordinates_onMap[i]["X"], ManualCoordinates_onMap[i]["Y"] );
}
this.context.lineTo( ManualCoordinates_onMap[0]["X"], ManualCoordinates_onMap[0]["Y"] );
this.context.stroke();
}
}
}
/**
* Displays an image as background of the canvas
* @param {String} PlanTitle the plan's name as is written inside the JSON data of the trench.
**/
displayPlan( PlanTitle ) {
if( ExcData == null ) { return; } // <<<< data has not been loaded yet
////
var PlanData;
// display the image on the canvas and remember it, so that it is not oaded again
if( currentPlanTitle==PlanTitle && PlanImage!=null && PlanImage!=undefined) { // image file has already been loaded
try {
this.context.drawImage(PlanImage, CanvasOffsetX, CanvasOffsetY, PlanImage.width * ZoomFactor, PlanImage.height * ZoomFactor );
} catch( ex ) {
this.context.fillStyle = "red";
this.context.fillText( "Plan image was not found", 10, 36);
this.context.fill();
document.getElementById("canvas").style.cursor = "default";
if( PlanData != null && PlanData.hasOwnProperty("FormatImage") ) console.log( "!!! Plan images not found:" + PlanData["FormatImage"] );
}
} else {
// find the plan's JSON data
for (let i = 0; i <ExcData.length; i++) {
if( ExcData[i]["Type"].localeCompare("Plan")==0 && ExcData[i]["Title"].localeCompare(PlanTitle)==0 ) {
PlanData = ExcData[i];
break;
}
}
if( typeof PlanData == "undefined" ) { return; } // <<<<
// load the image
document.getElementById("canvas").style.cursor = "wait";
currentPlanTitle = PlanTitle;
PlanImage = new Image();
PlanImage.src = "plans/" + PlanData["FormatImage"];
console.log("Plan requested: " + PlanData["FormatImage"]);
this.PlanIsLoading = true; // for displaying a map-loading message
PlanImage.onload = function() {
console.log("Plan was loaded: " + PlanData["FormatImage"]);
map.PlanIsLoading = false;
// fill the Plan's parameters
var Plan_GeoReferencing_field = "FormatImageEnvelopeGEO";
if( ExcavationPreferences.hasOwnProperty("Plan_GeoReferencing_field") && ExcavationPreferences["Plan_GeoReferencing_field"].length>0 ) {
Plan_GeoReferencing_field = ExcavationPreferences["Plan_GeoReferencing_field"];
}
var s = PlanData[ Plan_GeoReferencing_field ];
var coords = s.substring( s.indexOf("(")+1 );
coords = coords.replaceAll( ")", "" );
coords = coords.replaceAll( " ", "" );
coords = coords.split(",");
PlanMinX = parseFloat( coords[0] );
PlanMaxX = parseFloat( coords[1] );
PlanMinY = parseFloat( coords[3] ); // !!!!!!!! y becomes maximum at the top of the plan
PlanMaxY = parseFloat( coords[2] );
PlanImageWidth = PlanImage.width;
PlanImageHeight = PlanImage.height;
// calculate zoom factor, so that new plan is fully visible
map.ZoomToFitScreen();
// draw
map.context.drawImage(PlanImage, 0, 0, PlanImage.width * ZoomFactor, PlanImage.height * ZoomFactor );
//console.log(PlanMinX + " " + PlanMaxX + " " + PlanMinY + " " + PlanMaxY + " : " + PlanImageWidth + " " +PlanImageHeight );
map.drawWorld();
document.getElementById("canvas").style.cursor = "default";
}
}
}
/**
* calulates the zommfactor so that the plan is fully visible
*/
ZoomToFitScreen() {
CanvasOffsetX = 0;
CanvasOffsetY = 0;
ZoomFactor = Math.min( this.context.canvas.width/PlanImageWidth, this.context.canvas.height/PlanImageHeight );
//console.log(ZoomFactor+" >> " + this.context.canvas.width + "/" + PlanImageWidth + " " + this.context.canvas.height + "/" + PlanImageHeight );
}
/**
* Calculates the coordinates of the intersection points between the cross-section line defined by the arguments and each polygon side of the the selected items.
* @param {int} section_x1 horizontal coordinate of the 1st point of the cross-section line segment
* @param {int} section_y1 vertical coordinate of the 1st point of the cross-section line segment
* @param {int} section_x2 horizontal coordinate of the 2nd point of the cross-section line segment
* @param {int} section_y2 vertical coordinate of the 2nd point of the cross-section line segment
* @returns {Array} an array of JSON entities. Each entity represents a shape and contains a name/id and the coordinates of the corners. Format example: { ID: 'LK-973', POLYGON: [ { X: 3, Y: 4 }, { X: 7, Y: 6 } ] }
*/
CalcAndDrawCrossSection( section_x1, section_y1, section_x2, section_y2 ) {
if( ExcData == null ) return;
CrossSectionShapes = [];
// draw cross section line
this.context.strokeStyle = COLOR_crosssection;
this.context.beginPath();
this.context.moveTo(CrossSectionX1, CrossSectionY1);
this.context.lineTo(CrossSectionX2, CrossSectionY2);
this.context.closePath();
this.context.stroke();
// calculate intersections with selected items and draw them
var num_of_intersections = 0;
for (let i = 0; i < ExcData.length; i++) {
try {
if( ExcData[i]["Selected"] && typeof ExcData[i]["Location"] != "undefined" && ExcData[i]["Location"].length > 1 ) { // this is a visible locus
var json_shape = {};
json_shape["ID"] = ExcData[i]["Identifier"];
json_shape["POLYGON"] = [];
for(let pointIdx=1; pointIdx<ExcData[i]["Location"].length; pointIdx++) {
// calculate the coordinates of each edge of the item
var edge_x1 = ExcData[i]["Location"][pointIdx-1]["X"];
var edge_y1 = ExcData[i]["Location"][pointIdx-1]["Y"];
var edge_x2 = ExcData[i]["Location"][pointIdx]["X"];
var edge_y2 = ExcData[i]["Location"][pointIdx]["Y"];
var edge_x1 = this.map_range(edge_x1, PlanMinX, PlanMaxX, 0, PlanImageWidth) * ZoomFactor + CanvasOffsetX;
var edge_y1 = this.map_range(edge_y1, PlanMinY, PlanMaxY, PlanImageHeight, 0) * ZoomFactor + CanvasOffsetY;
var edge_x2 = this.map_range(edge_x2, PlanMinX, PlanMaxX, 0, PlanImageWidth) * ZoomFactor + CanvasOffsetX;
var edge_y2 = this.map_range(edge_y2, PlanMinY, PlanMaxY, PlanImageHeight, 0) * ZoomFactor + CanvasOffsetY;
// check if and where the item's edge and the user-drawn cross-section intersect
var [intersectionX, intersectionY] = Lines.CalculateIntersection( edge_x1, edge_y1, edge_x2, edge_y2, section_x1, section_y1, section_x2, section_y2 );
// draw the intersection point on the map
if( intersectionX != null ) { // the cross-section intersects with this edge
num_of_intersections += 1;
this.context.fillStyle = COLOR_crosssection;
this.context.strokeStyle = COLOR_crosssection;
this.context.beginPath();
this.context.arc(intersectionX, intersectionY, 3, 0, 2*Math.PI);
this.context.closePath();
this.context.fill();
this.context.stroke();
}
// calculate the underground intersection points
if( intersectionX != null ) { // the cross-section intersects with this edge
var edge_z1 = ExcData[i]["Location"][pointIdx-1]["Z"];
var edge_z2 = ExcData[i]["Location"][pointIdx]["Z"];
var intersectionZ = (edge_z2-edge_z1)*(intersectionX-edge_x1)/(edge_x2-edge_x1) + edge_z1;
json_shape["POLYGON"].push( {X:intersectionX, Y:intersectionY, Z:intersectionZ} );
}
}
if( json_shape["POLYGON"].length > 0 ) CrossSectionShapes.push( json_shape );
}
} catch( ex ) { console.log(ex); }
}
}
/**
* remaps a number from one range to another
*/
map_range(value, low1, high1, low2, high2) {
return low2 + (high2 - low2) * (value - low1) / (high1 - low1);
}
/**
* Highlights the position of an item on the map, in order to draw the attention of the user on that point.
* @param {string} UUID the identification number of the item to be highlighted.
*/
HighlightItempOnMap( UUID ) {
if( typeof UUID != "undefined" ) {
this.Highlight_itemUUID = UUID;
this.currentHighlightAlpha = 1.0;
var self = this;
this.Highlight_interval_ID = setInterval(function() {
self.drawWorld();
self.currentHighlightAlpha = self.currentHighlightAlpha - 0.05; // fade out the vertical and horizontal lines
if( self.currentHighlightAlpha <= 0 ) clearInterval(self.Highlight_interval_ID);
}, 150);
}
}
/***************************************** EVENT HANDLERS **********************************/
/** Event Handler: Handles the mouse down event on the map */
Canvas_MouseDownHandler(e) {
this.PlanIsLoading = false; // sometimes the onLoad event didn't work
// figure out where the user clicked
var eventX, eventY;
if( Utils.Am_I_running_on_mobile_device() ) {
eventX = e.touches[0].clientX;
eventY = e.touches[0].clientY;
} else {
eventX = e.clientX;
eventY = e.clientY;
}
MouseX = eventX - map.canvas.getBoundingClientRect().left;
MouseY = eventY - map.canvas.getBoundingClientRect().top;
MouseStartX = MouseX;
MouseStartY = MouseY;
// act on mouse down depending on canvas state
MouseIsDown = true;
if( map.CanvasState.startsWith("polygon") ) {
PolygonPoints.push( {"x":MouseX, "y":MouseY} );
map.drawWorld();
} else if( map.CanvasState.localeCompare("crosssection")==0 ) {
if ( CrossSectionX1 < 0 && CrossSectionX2 < 0 ) {
CrossSectionX1 = MouseX;
CrossSectionY1 = MouseY;
} else if ( CrossSectionX1 >= 0 && CrossSectionX2 >= 0 ) {
CrossSectionX1 = MouseX;
CrossSectionY1 = MouseY;
CrossSectionX2 = -1;
CrossSectionY2 = -1;
map.drawWorld();
}
}
// for defining the coordinates points when ManualCoordinatesMode and the target button is active
if( map.ManualCoordinatesMode && map.CanvasState.localeCompare("defining-coordinates-manually") == 0 ) {
// calculate the manually designated coordinates
var tmp = "";
tmp += "(" + MouseX + ", " + MouseY + ") ";
var map_x = map.map_range(MouseX-CanvasOffsetX, 0, PlanImageWidth * ZoomFactor, PlanMinX, PlanMaxX);
var map_y = map.map_range(MouseY-CanvasOffsetY, 0, PlanImageHeight * ZoomFactor, PlanMaxY, PlanMinY);
tmp += " --> (" + map_x + " " + map_y + ") Offset: " + CanvasOffsetX + " " + CanvasOffsetY;
// remember the manually designated coordinate
map.ManualCoordinates.push( {"X":map_x, "Y":map_y} );
// print the manually designated coordinates and refresh
console.log(tmp);
map.drawWorld();
}
}
/** Event Handler: Handles the mouse up event on the map */
Canvas_MouseUpHandler(e) {
if( e.ctrlKey ) {
// do something in the future
}
////
if( MouseIsDown && map.CanvasState.localeCompare("zoomin") == 0 ) {
if( e.ctrlKey ) { map.ZoomIn(4); } else { map.ZoomIn(); }
} else if( MouseIsDown && map.CanvasState.localeCompare("zoomout") == 0 ) {
if( e.ctrlKey ) { map.ZoomOut(4); } else { map.ZoomOut(); }
} else if( MouseIsDown && map.CanvasState.startsWith("select") ) {
MouseIsDown = false;
if( MouseStartX==MouseX && MouseStartY==MouseY) { // it is just a click, select close neighbors
MouseStartX -= 6;
MouseX += 6;
MouseStartY -= 6;
MouseY += 6;
}
let minX = Math.min(MouseX, MouseStartX);
let maxX = Math.max(MouseX, MouseStartX);
let minY = Math.min(MouseY, MouseStartY);
let maxY = Math.max(MouseY, MouseStartY);
if( map.CanvasState.localeCompare("select") == 0 ) num_of_selected_items = 0;
// select all items inside the rectangular area defined by the mouse
for (let i = 0; i<ExcData.length; i++) {
if( map.CanvasState.localeCompare("select") == 0 ) ExcData[i]["Selected"] = false;
try {
// check if this item is displayed on the map or not
var current_item_is_displayed_on_map = false;
if( ExcData[i]["Location"].length > 0 ) {
if( map.DisplayOnlySelectedItemsOnMap ) {
if( ExcData[i]["Selected"] ) current_item_is_displayed_on_map = true;
} else {
if( ExcData[i]["Visible"] ) current_item_is_displayed_on_map = true;
}
if( current_item_is_displayed_on_map && ExcData[i].hasOwnProperty("InPlan") ) {
if( ExcData[i]["InPlan"]==false ) current_item_is_displayed_on_map = false;
}
}
// check if the item's Selected-state has to be altered
if( current_item_is_displayed_on_map ) {
for(let j=0; j<ExcData[i]["Location"].length; j++ ) {
let X = ExcData[i]["Location"][j]["X"];
let Y = ExcData[i]["Location"][j]["Y"];
X = map.map_range(X, PlanMinX, PlanMaxX, 0, PlanImageWidth) * ZoomFactor + CanvasOffsetX;
Y = map.map_range(Y, PlanMinY, PlanMaxY, PlanImageHeight, 0) * ZoomFactor + CanvasOffsetY;
if( X >= minX && X <= maxX && Y >= minY && Y <= maxY ) {
if( map.CanvasState.localeCompare("select") == 0 || map.CanvasState.localeCompare("selectplus") == 0 ) {
if( ExcData[i]["Selected"] != true ) {
ExcData[i]["Selected"] = true;
num_of_selected_items += 1;
}
// scroll list to the first selected item
if( num_of_selected_items == 1 ) {
Scroll_ItemsList( ExcData[i]["IdentifierUUID"] );
}
} else if( map.CanvasState.localeCompare("selectminus") == 0 ) {
if( ExcData[i]["Selected"] == true ) {
ExcData[i]["Selected"] = false;
num_of_selected_items -= 1;
}
}
break;
}
}
}
} catch( ex ) { }
}
updateInfoBar();
map.drawWorld();
updateSelectedItemsOnList();
} else if( MouseIsDown && map.CanvasState.startsWith("pencil") ) {
if( map.CanvasState.localeCompare("pencil") == 0 ) num_of_selected_items = 0;
for (let i = 0; i<ExcData.length; i++) {
if( map.CanvasState.localeCompare("pencil") == 0 ) ExcData[i]["Selected"] = false;
try {
// check if this item is displayed on the map or not
var current_item_is_displayed_on_map = false;
if( ExcData[i]["Location"].length > 0 ) {
if( map.DisplayOnlySelectedItemsOnMap ) {
if( ExcData[i]["Selected"] ) current_item_is_displayed_on_map = true;
} else {
if( ExcData[i]["Visible"] ) current_item_is_displayed_on_map = true;
}
if( current_item_is_displayed_on_map && ExcData[i].hasOwnProperty("InPlan") ) {
if( ExcData[i]["InPlan"]==false ) current_item_is_displayed_on_map = false;
}
}
// check if the item's Selected-state has to be altered
if( current_item_is_displayed_on_map ) {
for(let j=0; j<ExcData[i]["Location"].length; j++ ) {
for(let idx=0; idx<PencilPath.length; idx++) {
var X = ExcData[i]["Location"][j]["X"];
var Y = ExcData[i]["Location"][j]["Y"];
X = map.map_range(X, PlanMinX, PlanMaxX, 0 , PlanImageWidth) * ZoomFactor + CanvasOffsetX;
Y = map.map_range(Y, PlanMinY, PlanMaxY, PlanImageHeight, 0) * ZoomFactor + CanvasOffsetY;
var Distance = Math.sqrt( (X-PencilPath[idx]["x"])**2 + (Y-PencilPath[idx]["y"])**2 );
if( Distance < PencilSelectionWidth/2 ) {
if( map.CanvasState.localeCompare("pencil") == 0 || map.CanvasState.localeCompare("pencilplus") == 0 ) {
if( ExcData[i]["Selected"] != true ) {
ExcData[i]["Selected"] = true;
num_of_selected_items += 1;
}
// scroll list to the first selected item
if( num_of_selected_items == 1 ) {
Scroll_ItemsList( ExcData[i]["IdentifierUUID"] );
}
} else if( map.CanvasState.localeCompare("pencilminus") == 0 ) {
if( ExcData[i]["Selected"] == true ) {
ExcData[i]["Selected"] = false;
num_of_selected_items -= 1;
}
}
break;
}
}
//// break again here if item has been selected
}
}
} catch( ex ) { }
}
updateInfoBar();
map.drawWorld();
updateSelectedItemsOnList();
PencilPath = [];
} else if( map.CanvasState.localeCompare("crosssection")==0 ) {
if ( CrossSectionX1 >= 0 && CrossSectionX2 < 0 ) {
CrossSectionX2 = MouseX;
CrossSectionY2 = MouseY;
}
map.drawWorld();
// ############ Display stratigraphy ############
if( MouseIsDown ) {
Dialog.DisplayCrossSectionDialog( CrossSectionX1, CrossSectionY1, CrossSectionX2, CrossSectionY2 );
}
}
MouseIsDown = false;
}
/** Event Handler: Handles the mouse move event on the map */
Canvas_MouseMoveHandler(e) {
// figure out where the user clicked
var eventX, eventY;
if( Utils.Am_I_running_on_mobile_device() ) {
eventX = e.touches[0].clientX;
eventY = e.touches[0].clientY;
} else {
eventX = e.clientX;
eventY = e.clientY;
}
// act
if( MouseIsDown ) {
if( map.CanvasState.localeCompare("drag") == 0 ) {
CanvasOffsetX = CanvasOffsetX + eventX - MouseX - map.canvas.getBoundingClientRect().left;
CanvasOffsetY = CanvasOffsetY + eventY - MouseY - map.canvas.getBoundingClientRect().top;
}
MouseX = eventX - map.canvas.getBoundingClientRect().left;
MouseY = eventY - map.canvas.getBoundingClientRect().top;
if( map.CanvasState.startsWith("pencil") ) {
// save the pencil's path
PencilPath.push( {"x":MouseX, "y":MouseY} );
// draw path on canvas
map.context.beginPath();
map.context.fillStyle = "lightseagreen";
map.context.strokeStyle = "lightseagreen";
map.context.moveTo(MouseX, MouseY);
map.context.arc(MouseX, MouseY, PencilSelectionWidth/2, 0, 2*Math.PI);
map.context.fill();
map.context.stroke();
map.context.closePath();
} else if( map.CanvasState.localeCompare("crosssection")==0 ) {
map.drawWorld();
} else {
map.drawWorld();
}
}
}
/** Event Handler: handles the middle mouse button-wheel for the canvas and zooms in and out of the map */
Canvas_WheelHandler(e) {
event.preventDefault();
if( e.deltaY > 0 ) {
map.ZoomOut();
} else {
map.ZoomIn();
}
}
/** Event Handler: handles keyboard events for the canvas. The behavior is different depending on the currently selected tool. */
Canvas_KeyDownHandler(e) {
if( map.CanvasState.startsWith("zoom") ) {
if(e.key == '+') {
map.ZoomIn();
map.drawWorld();
} else if(e.key == '-') {
map.ZoomOut();
map.drawWorld();
}
} else if( map.CanvasState.startsWith("drag") ) {
if(e.key == 'ArrowUp') {
if( e.ctrlKey ) { CanvasOffsetY -= 16; } else { CanvasOffsetY -= 1; }
map.drawWorld();
} else if(e.key == 'ArrowDown') {
if( e.ctrlKey ) { CanvasOffsetY += 16; } else { CanvasOffsetY += 1; }
map.drawWorld();
} else if(e.key == 'ArrowLeft') {
if( e.ctrlKey ) { CanvasOffsetX -= 16; } else { CanvasOffsetX -= 1; }
map.drawWorld();
} else if(e.key == 'ArrowRight') {
if( e.ctrlKey ) { CanvasOffsetX += 16; } else { CanvasOffsetX += 1; }
map.drawWorld();
}
} else if( map.CanvasState.startsWith("select") ) {
if(e.key == '+') {
if( map.CanvasState.localeCompare("selectplus")==0 ) {
map.activate_Select();
} else {
map.activate_SelectPlus();
}
} else if(e.key == '-') {
if( map.CanvasState.localeCompare("selectminus")==0 ) {
map.activate_Select();
} else {
map.activate_SelectMinus();
}
}
} else if( map.CanvasState.startsWith("polygon") ) {
if(e.key == '+') {
if( map.CanvasState.localeCompare("polygonplus")==0 ) {
map.activate_Polygon();
} else {
map.activate_PolygonPlus();
}
} else if(e.key == '-') {
if( map.CanvasState.localeCompare("polygonminus")==0 ) {
map.activate_Polygon();
} else {
map.activate_PolygonMinus();
}