-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathDrawTool.js
More file actions
1973 lines (1856 loc) · 77.3 KB
/
DrawTool.js
File metadata and controls
1973 lines (1856 loc) · 77.3 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
import DrawTool_Drawing from './DrawTool_Drawing'
import DrawTool_Editing from './DrawTool_Editing'
import DrawTool_Files from './DrawTool_Files'
import DrawTool_History from './DrawTool_History'
import DrawTool_Publish from './DrawTool_Publish'
import DrawTool_Shapes from './DrawTool_Shapes'
import DrawTool_FileModal from './DrawTool_FileModal'
import DrawTool_Templater from './DrawTool_Templater'
import $ from 'jquery'
import * as d3 from 'd3'
import F_ from '../../Basics/Formulae_/Formulae_'
import L_ from '../../Basics/Layers_/Layers_'
import Map_ from '../../Basics/Map_/Map_'
import Globe_ from '../../Basics/Globe_/Globe_'
import Viewer_ from '../../Basics/Viewer_/Viewer_'
import ToolController_ from '../../Basics/ToolController_/ToolController_'
import CursorInfo from '../../Ancillary/CursorInfo'
import Description from '../../Ancillary/Description'
import TimeControl from '../../Ancillary/TimeControl'
import { Kinds } from '../../../pre/tools'
import turf from 'turf'
import calls from '../../../pre/calls'
import './DrawTool.css'
import tippy from 'tippy.js'
import hotkeys from 'hotkeys-js'
// Plugins
import DrawTool_Geologic from './Plugins/Geologic/DrawTool_Geologic'
import DrawTool_SetOperations from './Plugins/SetOperations/DrawTool_SetOperations'
// Plugins OFF
//const DrawTool_Geologic = null
const DrawTool_MTTTT = null
//const DrawTool_SetOperations = null
const DrawTool_ScienceIntent = null
//Add the tool markup if you want to do it this way
// prettier-ignore
var markup = [
"<div id='drawTool' style='width: 100%;'>",
"<div id='drawToolNotLoggedIn'>",
"<div>Please log in before drawing</div>",
"</div>",
"<div id='drawToolNav'>",
"<div type='draw' id='drawToolNavButtonDraw' class='drawToolNavButton' title='Draw'>",
"<i class='mdi mdi-lead-pencil mdi-18px'></i>",
"<div>Draw</div>",
"</div>",
"<div type='shapes' class='drawToolNavButton' title='Features'>",
"<i class='mdi mdi-shape mdi-18px'></i>",
"<div>Features</div>",
"</div>",
"<div type='history' class='drawToolNavButton' title='History'>",
"<i id='drawToolHistoryButton' class='mdi mdi-history mdi-18px'></i>",
"<div>History</div>",
"</div>",
"</div>",
"<div id='drawToolContents'>",
"<div id='drawToolDraw'>",
"<div id='drawToolDrawShapes'>",
//"<div id='drawToolDrawingInIndicator'>Choose a file to draw in</div>",
"<div id='drawToolDrawingCont'>",
"<div id='drawToolDrawingTypeDiv'>",
"<div class='drawToolDrawingTypePolygon' draw='polygon' title='Polygon'><i class='mdi mdi-vector-polygon mdi-18px'></i></div>",
"<div class='drawToolDrawingTypeCircle' draw='circle' title='Circle'><i class='mdi mdi-vector-circle mdi-18px'></i></div>",
"<div class='drawToolDrawingTypeRectangle' draw='rectangle' title='Rectangle'><i class='mdi mdi-vector-rectangle mdi-18px'></i></div>",
"<div class='drawToolDrawingTypeLine' draw='line' title='Line'><i class='mdi mdi-vector-line mdi-18px'></i></div>",
"<div class='drawToolDrawingTypePoint' draw='point' title='Point'><i class='mdi mdi-square-medium-outline mdi-24px'></i></div>",
"<div class='drawToolDrawingTypeText' draw='text' title='Text'><i class='mdi mdi-format-text mdi-18px'></i></div>",
"<div class='drawToolDrawingTypeArrow' draw='arrow' title='Arrow'><i class='mdi mdi-arrow-top-right mdi-18px'></i></div>",
"</div>",
"<div id='drawToolDrawingSettingsToggle' title='Draw Settings'><i class='mdi mdi-cog mdi-18px'></i></div>",
"</div>",
"<div id='drawToolDrawSettings'>",
"<div id='drawToolDrawSettingsBody'>",
"<ul>",
"<li>",
"<div title='Clip drawing of existing shapes'>Draw Clipping</div>",
"<div id='drawToolDrawSettingsTier' class='drawToolRadio'>",
"<div value='over'>Over</div>",
"<div value='under'>Under</div>",
"<div value='off'>Off</div>",
"</div>",
"</li>",
"<li>",
"<div title='Auto vertex spacing or click to add'>Draw Resolution</div>",
"<div id='drawToolDrawSettingsMode' class='drawToolRadio'>",
"<div value='on'><span>On</span><input id='drawToolDrawSettingsModeVertexRes' type='number' step='1' value='10'/></div>",
"<div class='active' value='off'>Off</div>",
"</div>",
"</li>",
"<li>",
"<div title='Enable snapping in edit mode'>Edit Snapping</div>",
"<div id='drawToolDrawSnapMode' class='drawToolRadio'>",
"<div value='on'>On</div>",
"<div class='active' value='off'>Off</div>",
"</div>",
"</li>",
"<li>",
"<div title='Force radius in meters when drawing circles'>Circle Radius</div>",
"<div id='drawToolDrawSettingsCircle' class='drawToolRadio'>",
"<div value='on'><span>On</span><input id='drawToolDrawSettingsCircleR' type='number' value='100'/></div>",
"<div class='active' value='off'>Off</div>",
"</div>",
"</li>",
"</ul>",
"</div>",
"</div>",
/*
"<div id='drawToolDrawIntentFilterDiv'>",
"<div intent='roi' tooltip='Region of Interest'>R</div>",
"<div intent='campaign' tooltip='Campaign'>C</div>",
"<div intent='campsite' tooltip='Campsite'>C</div>",
"<div intent='trail' tooltip='Trail'>T</div>",
"<div intent='signpost' tooltip='Signpost'>S</div>",
//"<div intent='note' tooltip='Note'>N</div>",
"<div intent='all' tooltip='Map'>M</div>",
"</div>",
*/
"<div id='drawToolDrawFilterDivToolTip'></div>",
"<div id='drawToolDrawFilterDiv2'>",
//"<div id='drawToolDrawFilterCount'></div>",
//"<div id='drawToolDrawFilterDiv'>",
`<input id='drawToolDrawFilter' type='text' placeholder='Filter Files' autocomplete='off' title="Filter over a file's name, author and description.\nUse '#{tag}' to search over keywords."/>`,
"<div id='drawToolDrawFilterClear'><i class='mdi mdi-close mdi-18px'></i></div>",
//"</div>",
/*
"<div class='drawToolFilterDropdown'>",
"<input type='checkbox' id='checkbox-toggle'>",
"<label for='checkbox-toggle'><i class='mdi mdi-dots-vertical mdi-18px'></i></label>",
"<ul>",
"<li intent='roi'><div id='drawToolFilterDropdownROI'>Regions of Interest</div><div class='drawToolFilterCheckbox'></div></li>",
"<li intent='campaign'><div id='drawToolFilterDropdownCampaign'>Campaigns</div><div class='drawToolFilterCheckbox'></div></li>",
"<li intent='campsite'><div id='drawToolFilterDropdownCampsite'>Campsites</div><div class='drawToolFilterCheckbox'></div></li>",
"<li intent='trail'><div id='drawToolFilterDropdownTrail'>Trails</div><div class='drawToolFilterCheckbox'></div></li>",
"<li intent='signpost'><div id='drawToolFilterDropdownSignpost'>Signposts</div><div class='drawToolFilterCheckbox'></div></li>",
"<li intent='all'><div id='drawToolFilterDropdownAll'>Maps</div><div class='drawToolFilterCheckbox'></div></li>",
"</ul>",
"</div>",
*/
"</div>",
"<div id='drawToolDrawFilterOptions'>",
"<div id='drawToolDrawGroupingDiv'>",
"<div type='folders' title='Group by Folder' class='active'><i class='mdi mdi-folder mdi-14px'></i></div>",
"<div type='tags' title='Group by Tag'><i class='mdi mdi-tag-text mdi-18px'></i></div>",
"<div type='author' title='Group by Author'><i class='mdi mdi-account-box-outline mdi-18px'></i></div>",
"<div type='alphabetical' title='Group Alphabetically'><i class='mdi mdi-alphabetical-variant mdi-18px'></i></div>",
"<div type='none' title='Files Ungrouped'><i class='mdi mdi-file-outline mdi-18px'></i></div>",
"</div>",
"<div id='drawToolDrawSortDiv'>",
"<div type='public' title='Public Only'><i class='mdi mdi-shield-outline mdi-14px'></i></div>",
"<div type='owned' title='Yours Only'><i class='mdi mdi-account mdi-18px'></i></div>",
"<div type='on' title='On Only'><i class='mdi mdi-eye mdi-18px'></i></div>",
"</div>",
"</div>",
"</div>",
"<div id='drawToolDrawFiles'>",
"<div id='drawToolDrawFilesContent'>",
"<div id='drawToolDrawPublished'>",
"<div class='flexbetween'>",
"<div>Latest Map</div>",
"<div class='drawToolDrawPublishedCheckbox'></div>",
"</div>",
"</div>",
"<div id='drawToolMaster'>",
"<div id='drawToolMasterHeader'>",
"<div class='flexbetween'>",
"<div class='drawToolMasterHeaderLeft'>",
"<div class='drawToolMasterHeaderLeftLeft'>",
"<div class='drawToolMasterHeaderIntent'></div>",
"<div class='drawToolMasterHeaderChevron'><i class='mdi mdi-folder-star mdi-18px'></i></div>",
"<div>Lead Maps</div>",
"</div>",
"<div class='drawToolMasterHeaderLeftRight'>",
"<div class='drawToolMasterReview'>Review</div>",
"</div>",
"</div>",
"<div class='drawToolFileMasterCheckbox'></div>",
"</div>",
"</div>",
"<ul id='drawToolDrawFilesListMaster' class='mmgisScrollbar2'>",
"</ul>",
"</div>",
"<ul id='drawToolDrawFilesList' class='mmgisScrollbar2'>",
"</ul>",
"<div id='drawToolFilesLoadingSpinner'>",
"<svg class='mmgis-spinner1' viewbox='0 0 50 50'>",
"<circle class='path' cx='25' cy='25' r='20' fill='none' stroke-width='5' />",
"</svg>",
"</div>",
"</div>",
"</div>",
"<div id='drawToolDrawFilesNewDiv'>",
//"<input id='drawToolDrawFilesNewName' type='text' placeholder='New File' />",
/*
"<select>",
"<option id='drawToolNewFileAll' value='all'>Map</option>",
"<option id='drawToolNewFileROI' value='roi'>ROI</option>",
"<option id='drawToolNewFileCampaign' value='campaign'>Campaign</option>",
"<option id='drawToolNewFileCampsite' value='campsite'>Campsite</option>",
"<option id='drawToolNewFileTrail' value='trail'>Trail</option>",
"<option id='drawToolNewFileSignpost' value='signpost'>Signpost</option>",
//"<option value='note'>Note</option>",
"</select>",
*/
"<div id='drawToolDrawFilesNewUpload'><div>UPLOAD</div><div><i class='mdi mdi-upload mdi-18px'></i></div></div>",
"<div id='drawToolDrawFilesNew'><div>CREATE</div><div><i class='mdi mdi-plus mdi-18px'></i></div></div>",
"</div>",
"</div>",
"<div id='drawToolShapes'>",
"<div id='drawToolShapesFilterDiv'>",
"<div id='drawToolShapesFilterAdvanced'><i class='mdi mdi-filter mdi-18px'></i></div>",
"<input id='drawToolShapesFilter' type='text' placeholder='Filter Shapes' />",
"<div id='drawToolShapesFilterClear'><i class='mdi mdi-close mdi-18px'></i></div>",
"<div id='drawToolShapesFilterCount'></div>",
"</div>",
"<div id='drawToolShapesFilterAdvancedDiv'>",
"<div id='drawToolShapes_filtering'>",
"<div id='drawToolShapes_filtering_header'>",
"<div id='drawToolShapes_filtering_title_left'>",
"<div id='drawToolShapes_filtering_title'>Advanced Filter</div>",
"</div>",
"<div id='drawToolShapes_filtering_adds'>",
"<div id='drawToolShapes_filtering_add_value' class='mmgisButton5' title='Add New Key-Value Filter'><div>Add</div><i class='mdi mdi-plus mdi-18px'></i></div>",
"</div>",
"</div>",
"<div id='drawToolShapes_filtering_filters'>",
"<ul id='drawToolShapes_filtering_filters_list'></ul>",
"</div>",
`<div id='drawToolShapes_filtering_footer'>`,
"<div id='drawToolShapes_filtering_clear' class='mmgisButton5'><div>Clear Filter</div></div>",
"<div id='drawToolShapes_filtering_submit' class='mmgisButton5'><div id='drawToolShapes_filtering_submit_loading'><div></div></div><div id='drawToolShapes_filtering_submit_text'>Submit</div><i class='mdi mdi-arrow-right mdi-18px'></i></div>",
"</div>",
"</div>",
"</div>",
"<div id='drawToolDrawShapesList' class='mmgisScrollbar2'>",
"<ul id='drawToolShapesFeaturesList' class='unselectable'>",
"</ul>",
"</div>",
"<div id='drawToolShapesCopyDiv'>",
"<div>Copy to</div>",
"<div id='drawToolShapesCopyDropdown'></div>",
"<div id='drawToolShapesCopyGo'>GO</div>",
"</div>",
"<div id='drawToolShapesCopyMessageDiv'></div>",
"</div>",
"<div id='drawToolHistory'>",
"<div id='drawToolHistoryFile'></div>",
"<div id='drawToolHistoryContent'>",
"<div id='drawToolHistoryToolbar'>",
"<input id='drawToolHistoryTime' />",
"<div id='drawToolHistoryNow'>Now</div>",
"</div>",
"<div id='drawToolHistoryViewer'>",
"<div id='drawToolHistorySequence'>",
"<div id='drawToolHistorySave'>",
"Nothing to Undo",
"</div>",
"<div id='drawToolHistorySequenceList'>",
"<ul></ul>",
"</div>",
"</div>",
"</div>",
"</div>",
"</div>",
"</div>",
"<div id='drawToolEdit'>",
"</div>",
"<div id='drawToolMouseoverText'>",
"</div>",
"</div>"
].join('\n');
var DrawTool = {
height: 0,
width: 260,
vars: {},
plugins: {},
//host: window.location.hostname,
open: true,
userGroups: [],
defaultColor: '#999',
hoverColor: '#000',
activeColor: '#fff',
activeBG: 'var(--color-a)',
files: {},
activeContent: 'draw',
intentType: null,
currentFileId: null,
_firstGetFiles: null,
filesOn: [],
allTags: {}, //<tag>: count, ...
tags: [],
labelsOn: [],
fileGeoJSONFeatures: {},
palettes: [
[
'#26a8ff',
'#26ff3f',
'#fff726',
'#ff2626',
'#dc26ff',
'#4626ff',
'#00538a',
'#008a10',
'#8a8500',
'#8a0000',
'#73008a',
'#15008a',
],
],
isEditing: false,
copyFileId: null,
copyFilename: null,
lastShapeIndex: null,
lastShapeIntent: null, //so that shapes can only be grouped by intent
lastContextLayerIndexFileId: {},
highlightColor: 'rgb(255, 221, 92)',
highlightBorder: '2px solid rgb(38, 255, 103)',
highlightGradient: 'linear-gradient( to left, #26ff67, rgb(127,255,0) )',
noteIcon: null,
contextMenuLayer: null,
contextMenuLayers: [],
contextMenuChanges: {
use: false,
props: {},
style: {},
},
snapping: false,
timeInHistory: null,
isReviewOpen: false,
masterFileIds: [],
MMGISInterface: null,
intents: [
'roi',
'campaign',
'campsite',
'trail',
'signpost',
'note',
'all',
],
intentOrder: [
'roi',
'campaign',
'campsite',
'all',
'trail',
'signpost',
'note',
'master',
], //how to maintain layer orders (first on bottom)
intentNameMapping: {
all: 'Map',
roi: 'L1 Polygon',
campaign: 'L2 Polygon',
campsite: 'L3 Polygon',
trail: 'Line',
signpost: 'Point',
note: 'Note',
master: 'master',
},
defaultStyle: {
color: 'rgb(255, 255, 255)',
opacity: 1,
fillColor: 'rgb(0, 0, 0)',
fillOpacity: 0.4,
weight: 2,
radius: 4,
},
categoryStyles: {
roi: {
color: 'rgb(190, 38, 51)',
opacity: 1,
fillColor: 'rgb(190, 38, 51)',
fillOpacity: 0.2,
weight: 2,
},
campaign: {
color: 'rgb(235, 137, 49)',
opacity: 1,
fillColor: 'rgb(235, 137, 49)',
fillOpacity: 0.2,
weight: 2,
},
campsite: {
color: 'rgb(247, 226, 107)',
opacity: 1,
fillColor: 'rgb(247, 226, 107)',
fillOpacity: 0.2,
weight: 2,
},
trail: {
color: 'rgb(163, 206, 39)',
weight: 5,
fillColor: 'rgb(163, 206, 39)',
opacity: 1,
},
signpost: {
color: 'rgb(39, 146, 206)',
radius: 6,
fillColor: 'rgb(39, 146, 206)',
weight: 2,
opacity: 1,
fillOpacity: 0.4,
},
note: {
color: 'rgb(0, 0, 0)',
fillColor: 'rgb(255, 255, 255)',
weight: 2,
opacity: 1,
fontSize: '18px',
},
all: {
color: 'rgb(255, 255, 255)',
radius: 2,
fillColor: 'rgb(255, 255, 255)',
weight: 2,
opacity: 1,
fillOpacity: 0.6,
},
polygon: {
color: 'rgb(255, 255, 255)',
radius: 2,
fillColor: 'rgb(255, 255, 255)',
weight: 2,
opacity: 1,
fillOpacity: 0.6,
},
line: {
color: 'rgb(255, 255, 255)',
radius: 2,
fillColor: 'rgb(255, 255, 255)',
weight: 2,
opacity: 1,
fillOpacity: 1,
},
point: {
color: 'rgb(255, 255, 255)',
radius: 6,
fillColor: 'rgb(255, 255, 255)',
weight: 2,
opacity: 1,
fillOpacity: 0.4,
},
text: {
color: 'rgb(0, 0, 0)',
fillColor: 'rgb(255, 255, 255)',
weight: 2,
opacity: 1,
fontSize: '18px',
},
arrow: {
color: 'rgb(0, 0, 0)',
radius: 20, //used as arrowhead limb pixel length
fillColor: 'rgb(255, 255, 255)',
width: 4, //width of line
length: 'Full', //length of line body
weight: 4, //outline
opacity: 1,
fillOpacity: 1,
dashArray: '',
lineCap: 'round', //'round' | 'butt' | 'square'
lineJoin: 'miter', //'bevel' | 'bevel' | 'miter'
},
master: {
color: '#fff',
},
},
initialize: function () {
DrawTool._firstGetFiles = null
this.vars = L_.getToolVars('draw')
//Set up intent mapping if any
// This just maps the internal intent names to whatever is configured
if (this.vars.intents) {
if (this.vars.intents[0])
this.intentNameMapping.roi = this.vars.intents[0]
if (this.vars.intents[1])
this.intentNameMapping.campaign = this.vars.intents[1]
if (this.vars.intents[2])
this.intentNameMapping.campsite = this.vars.intents[2]
if (this.vars.intents[3])
this.intentNameMapping.trail = this.vars.intents[3]
if (this.vars.intents[4])
this.intentNameMapping.signpost = this.vars.intents[4]
if (this.vars.intents[5])
this.intentNameMapping.all = this.vars.intents[5]
}
//Bring in other scripts
DrawTool_Drawing.init(DrawTool)
DrawTool_Editing.init(DrawTool)
DrawTool_Files.init(DrawTool)
DrawTool_History.init(DrawTool)
DrawTool_Publish.init(DrawTool)
DrawTool_Shapes.init(DrawTool)
// Plugins
if (DrawTool_Geologic) DrawTool_Geologic.init(DrawTool)
if (DrawTool_MTTTT) DrawTool_MTTTT.init(DrawTool)
if (DrawTool_ScienceIntent) DrawTool_ScienceIntent.init(DrawTool)
if (DrawTool_SetOperations) DrawTool_SetOperations.init(DrawTool)
//Turn on files from url
let hadDrawLayersOn = false
if (L_.FUTURES.tools) {
for (let t of L_.FUTURES.tools) {
const tUrl = t.split('$')
if (tUrl[0] == 'DrawTool') {
const tUrl2 = tUrl[1].split('-')
//fileson
const fileIds = tUrl2[0].split('.')
let finishedFileIdsCount = 0
for (let f of fileIds) {
this.toggleFile(
parseInt(f),
null,
null,
null,
null,
() => {
finishedFileIdsCount++
if (finishedFileIdsCount >= fileIds.length) {
// We want to make sure that users of the javascript api can still hit drawing files if
// they were deeplinked to but the tool was never opened/maked
if (hadDrawLayersOn) {
DrawTool.getFiles(function () {
//Populate masterFilesIds
DrawTool.masterFileIds = []
for (var f in DrawTool.files) {
if (DrawTool.files[f].is_master)
DrawTool.masterFileIds.push(
DrawTool.files[f].id
)
}
DrawTool.destroy()
})
}
}
}
)
}
hadDrawLayersOn = true
// default filters
const filtersOn = tUrl2[1]
if (filtersOn != null) {
window._toolStates = window._toolStates || {}
window._toolStates.draw = window._toolStates.draw || {}
window._toolStates.draw.filter =
window._toolStates.draw.filter || {}
window._toolStates.draw.filter.public =
filtersOn[0] == '1'
window._toolStates.draw.filter.owned =
filtersOn[1] == '1'
window._toolStates.draw.filter.on = filtersOn[2] == '1'
}
break
}
}
}
},
make: function () {
DrawTool.open = true
DrawTool.files = {}
DrawTool.activeContent = 'draw'
DrawTool.intentType = null
DrawTool.currentFileId = null
//DrawTool.filesOn = [];
DrawTool.isEditing = false
$('.drawToolContextMenuHeaderClose').click()
DrawTool.contextMenuLayers = []
DrawTool.copyFileId = null
DrawTool.copyFilename = null
DrawTool.lastShapeIndex = null
DrawTool.lastShapeIntent = null
DrawTool.lastContextLayerIndexFileId = {}
DrawTool.timeInHistory = null
var Icon = L.Icon.extend({
options: {
iconSize: [16, 37],
iconAnchor: [8, 18],
popupAnchor: [8, 18],
},
})
DrawTool.noteIcon = new Icon({
iconUrl: 'public/images/icons/beamcursor.png',
})
DrawTool.userGroups = []
if (
typeof mmgisglobal.groups === 'object' &&
mmgisglobal.groups !== null
) {
DrawTool.userGroups = mmgisglobal.groups
}
this.MMGISInterface = new interfaceWithMMGIS()
//Start on the draw tab
$('#drawToolNavButtonDraw').click()
DrawTool.getFiles(function () {
DrawTool.setDrawing(true)
DrawTool.populateFiles()
//Populate masterFilesIds
DrawTool.masterFileIds = []
for (var f in DrawTool.files) {
if (DrawTool.files[f].is_master)
DrawTool.masterFileIds.push(DrawTool.files[f].id)
}
})
$('#drawToolDrawPublished > div').on('click', function () {
$(this).toggleClass('on')
DrawTool.toggleFile('master', null, true, true)
})
if (DrawTool.userGroups.indexOf('mmgis-group') == -1) {
$('.drawToolMasterReview').remove()
} else {
$('.drawToolMasterReview').on('click', function () {
DrawTool.showReview()
})
}
$('#drawToolDrawSnapMode > div').on('click', function () {
var value = $(this).attr('value')
DrawTool.snapping = value === 'on' ? true : false
$(this).parent().find('div').removeClass('active')
$(this).addClass('active')
})
},
destroy: function () {
if (this.MMGISInterface) this.MMGISInterface.separateFromMMGIS()
for (var l in L_.layers.layer) {
var s = l.split('_')
var onId = s[1] != 'master' ? parseInt(s[1]) : s[1]
if (s[0] == 'DrawTool' && DrawTool.filesOn.indexOf(onId) != -1) {
for (var i = 0; i < L_.layers.layer[l].length; i++) {
var f = L_.layers.layer[l][i]
if (!f) continue
if (
!f.hasOwnProperty('feature') &&
f.hasOwnProperty('_layers')
) {
// If it's a non point layer
f = f._layers[Object.keys(f._layers)[0]]
}
var properties = f.feature.properties
if (f.hasOwnProperty('_layers')) f = f._layers
else f = { layer: f }
for (let elayer in f) {
let e = f[elayer]
e.off('click')
e.on(
'click',
(function (l) {
return function (d) {
if (
ToolController_.activeTool &&
ToolController_.activeTool
.disableLayerInteractions === true
)
return
let layer = d.target
let found = false
if (!d.target.hasOwnProperty('feature')) {
for (var _l in L_.layers.layer) {
if (!_l.startsWith('DrawTool_'))
continue
for (var x in L_.layers.layer[l]) {
var childLayer =
L_.layers.layer[l][x]
if ('hasLayer' in childLayer) {
if (
childLayer.hasOwnProperty(
'feature'
) &&
childLayer.feature
?.properties
?.arrow &&
childLayer.hasLayer(
d.target
)
) {
// This is the parent layer of the arrow
layer = childLayer
found = true
break
}
}
}
if (found) break
}
}
L_.setLastActiveFeature(layer)
L_.resetLayerFills()
L_.highlight(layer)
Map_.activeLayer = layer
if (Map_.activeLayer)
L_.Map_._justSetActiveLayer = true
Description.updatePoint(Map_.activeLayer)
Kinds.use(
'none',
Map_,
layer.feature,
layer,
l,
null,
d
)
Viewer_.changeImages(layer.feature, layer)
Globe_.highlight(
Globe_.findSpriteObject(
layer.options.layerName,
layer.feature.properties.name
),
false
)
Viewer_.highlight(layer)
}
})(l)
)
//Add a mouseover event to the layer
e.off('mouseover')
e.on(
'mouseover',
(function (l) {
return function (d) {
let name
// If the DrawTool layer that is hovered is an arrow, the parent arrow layer knows the name
if (!d.target.hasOwnProperty('feature')) {
for (var _l in L_.layers.layer) {
if (!_l.startsWith('DrawTool_')) {
continue
}
for (var x in L_.layers.layer[l]) {
var layer =
L_.layers.layer[l][x]
if ('hasLayer' in layer) {
if (
layer.hasOwnProperty(
'feature'
) &&
layer.feature
?.properties
?.arrow &&
layer.hasLayer(d.target)
) {
name =
layer.feature
.properties.name
}
}
}
}
} else {
name = d.target.feature.properties.name
}
//Make it turn on CursorInfo and show name and value
CursorInfo.update(
'Name: ' + name,
null,
false
)
}
})(l)
)
//Add a mouseout event
e.off('mouseout')
e.on('mouseout', function () {
//Make it turn off CursorInfo
CursorInfo.hide()
})
}
}
}
}
},
getUrlString: function () {
// Structure is fileOnId.fileOnId.fileOnId,filtersOnBinary
const publicFilterOn = $(
`#drawToolDrawSortDiv > [type="public"]`
).hasClass('active')
? 1
: 0
const yoursOnlyFilterOn = $(
`#drawToolDrawSortDiv > [type="owned"]`
).hasClass('active')
? 1
: 0
const onFilterOn = $(`#drawToolDrawSortDiv > [type="on"]`).hasClass(
'active'
)
? 1
: 0
return (
this.filesOn.toString().replace(/,/g, '.') +
`-${publicFilterOn}${yoursOnlyFilterOn}${onFilterOn}`
)
},
showContent: function (type) {
//Go to back to latest history after leaving history
if (DrawTool.activeContent === 'history' && type !== 'history')
DrawTool.refreshFile(DrawTool.currentFileId, null, true)
DrawTool.activeContent = type
$('.drawToolNavButton.active').removeClass('active')
$('#drawToolNav [type="' + type + '"]').addClass('active')
$('#drawToolContents > div').css('display', 'none')
switch (type) {
case 'draw':
$('.drawToolContextMenuHeaderClose').click()
DrawTool.setDrawing()
if (DrawTool.filesOn.length > 0) {
// This brings back all of the DrawTools mouse interactions
DrawTool.getFiles(function () {
DrawTool.populateFiles()
DrawTool.populateShapes()
//Populate masterFilesIds
DrawTool.masterFileIds = []
for (var f in DrawTool.files) {
if (DrawTool.files[f].is_master)
DrawTool.masterFileIds.push(
DrawTool.files[f].id
)
}
})
}
$('#drawToolDraw').css('display', 'flex')
break
case 'shapes':
DrawTool.lastShapeIntent = null
$('#drawToolShapesCopyDropdown *').remove()
DrawTool.endDrawing()
DrawTool.populateShapes()
$('#drawToolShapes').css('display', 'flex')
DrawTool.setSubmitButtonState(true)
break
case 'history':
$('.drawToolContextMenuHeaderClose').click()
DrawTool.endDrawing()
DrawTool.populateHistory()
$('#drawToolHistory').css('display', 'flex')
break
default:
}
},
getInnerLayers(obj, n) {
var innerLayers = obj
for (var i = 0; i < n; i++) {
if (innerLayers.hasOwnProperty('_layers'))
innerLayers = innerLayers._layers.getFirst()
}
return innerLayers
},
getFileObjectWithId(id) {
if (id === 'master')
return {
id: 'master',
public: '0',
intent: 'master',
file_owner: 'master',
file_name: 'published',
}
id = parseInt(id)
for (var i = 0; i < DrawTool.files.length; i++) {
if (DrawTool.files[i].id == id) return DrawTool.files[i]
}
},
// Return in pinned then last modified order
getAllTags(all) {
let tags = []
for (var i = 0; i < DrawTool.files.length; i++) {
tags = tags.concat(
DrawTool.getTagsFoldersFromFileDescription(
DrawTool.files[i],
true,
'all',
all ? 'all' : 'tags'
).map((t) => {
return {
tag: t,
modified: Date.parse(DrawTool.files[i].updated_on),
}
})
)
}
tags = tags.sort((a, b) => a.modified - b.modified)
tags = tags.map((t) => t.tag)
if (DrawTool.vars.preferredTags)
tags = DrawTool.vars.preferredTags.concat(tags.reverse())
else tags = tags.reverse()
let allTags = {}
tags.forEach((tag) => {
if (allTags[tag] != null) allTags[tag] = allTags[tag] + 1
else
allTags[tag] =
DrawTool.vars.preferredTags &&
DrawTool.vars.preferredTags.includes(tag)
? 0
: 1
})
return allTags
},
getTagsFoldersFromFileDescription(file, noDefaults, only, withTypePrefix) {
const file_name = file.file_name
const file_description = file.file_description
const file_owner = file.file_owner
const tagFolders = {
tags: [],
folders: [],
efolders: [],
author: [],
alphabetical: [],
}
if (typeof file_description !== 'string') return []
const tags = file_description.match(/~#([^\s])+/g) || []
const uniqueTags = [...tags]
// remove '#'s
tagFolders.tags = uniqueTags.map((t) => t.substring(2)) || []
const folders = file_description.match(/~@([^\s])+/g) || []
const uniqueFolders = [...folders]
// remove '@'s
tagFolders.folders = uniqueFolders.map((t) => t.substring(2)) || []
const efolders = file_description.match(/~\^([^\s])+/g) || []
const uniqueEFolders = [...efolders]
// remove '^'s
tagFolders.efolders = uniqueEFolders.map((t) => t.substring(2)) || []
// At least one folder
if (noDefaults !== true) {
if (tagFolders.tags.length === 0) tagFolders.tags = ['untagged']
if (tagFolders.folders.length === 0)
tagFolders.folders = ['unassigned']
tagFolders.alphabetical = ['a' + file_name.toLowerCase()[0]]
tagFolders.author = [file_owner]
}
// Sort all alphabetically
tagFolders.tags.sort(function (a, b) {
return a.length - b.length
})
tagFolders.folders.sort(function (a, b) {
return a.length - b.length
})
tagFolders.efolders.sort(function (a, b) {
return a.length - b.length
})
if (withTypePrefix) {
tagFolders.tags = tagFolders.tags.map((t) => `tag:${t}`)
tagFolders.folders = tagFolders.folders.map((t) => `folder:${t}`)
tagFolders.efolders = tagFolders.efolders.map(
(t) => `elevated-folder:${t}`
)