-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBeenThere.js
884 lines (779 loc) · 37.9 KB
/
BeenThere.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
// ==UserScript==
// @name WME BeenThere
// @namespace https://greasyfork.org/users/30701-justins83-waze
// @description This lets you drop boxes around the map to help visualize where you have been editing
// @include https://www.waze.com/editor*
// @include https://www.waze.com/*/editor*
// @include https://beta.waze.com/*
// @exclude https://www.waze.com/*/user/editor*
// @require https://greasyfork.org/scripts/24851-wazewrap/code/WazeWrap.js
// @require https://greasyfork.org/scripts/27023-jscolor/code/JSColor.js
// @require https://greasyfork.org/scripts/27254-clipboard-js/code/clipboardjs.js
// @require https://greasyfork.org/scripts/28687-jquery-ui-1-11-4-custom-min-js/code/jquery-ui-1114customminjs.js
// @resource jqUI_CSS https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css
// @version 2020.06.02.02
// ==/UserScript==
//---------------------------------------------------------------------------------------
/* global W */
/* global OpenLayers */
/* ecmaVersion 2017 */
/* global $ */
/* global jscolor */
/* global _ */
/* global WazeWrap */
/* global require */
/* global Clipboard */
/* eslint curly: ["warn", "multi-or-nest"] */
var beenTheresettings = [];
var attributes = {
name: ""
};
var layerFuture = [];
var pointStyle = {
pointRadius: 3,
fillOpacity: 50,
strokeColor: '#00ece3',
strokeWidth: '2',
strokeLinecap: 'round'
};
var clickCount = 0;
var userRectPoint1 = null;
var userCircleCenter = null;
var currColor;
const updateMessage = "";
(function() {
//var jqUI_CssSrc = GM_getResourceText("jqUI_CSS");
//GM_addStyle(jqUI_CssSrc);
function bootstrap(tries = 1) {
if (W && W.map &&
W.model && W.loginManager.user &&
$ && window.jscolor &&
WazeWrap.Ready && W.model.users)
init();
else if (tries < 1000)
setTimeout(function () {bootstrap(++tries);}, 200);
}
bootstrap();
function AddExtent() {
var point = W.map.getExtent();
var groupPoints2 = {
topLeft : {
lon:point.left,
lat:point.top
},
botLeft : {
lon: point.left,
lat: point.bottom
},
botRight: {
lon: point.right,
lat: point.bottom
},
topRight:{
lon: point.right,
lat: point.top
},
color: currColor,
type: "rectangle",
radius: null
};
beenTheresettings.Groups[beenTheresettings.CurrentGroup].push(groupPoints2);
DrawFeature(groupPoints2);
}
function DrawFeature(obj){
var pnt = [];
//var pnt2 = [];
//var pnt4326;
var feature;
var style = {
strokeColor: obj.color, strokeOpacity: 1, strokeWidth: 5, fillColor: obj.color, fillOpacity: 0.0,
label: "", labelOutlineColor: "black", labelOutlineWidth: 3, fontSize: 14,
fontColor: "orange", fontOpacity: 1, fontWeight: "bold"};
if(beenTheresettings.DrawShapeBorder)
style.strokeOpacity = 1;
else
style.strokeOpacity = 0;
if(beenTheresettings.FillShape)
style.fillOpacity = 1;
else
style.fillOpacity = 0;
if(obj.type === "rectangle"){
var convPoint = new OpenLayers.Geometry.Point(obj.topLeft.lon, obj.topLeft.lat);
pnt.push(convPoint);
//pnt4326 = WazeWrap.Geometry.ConvertTo4326(obj.topLeft.lon,obj.topLeft.lat);
//pnt2.push(new OpenLayers.Geometry.Point(pnt4326.lon, pnt4326.lat));
convPoint = new OpenLayers.Geometry.Point(obj.botLeft.lon, obj.botLeft.lat);
pnt.push(convPoint);
//pnt4326 = WazeWrap.Geometry.ConvertTo4326(obj.botLeft.lon,obj.botLeft.lat);
//pnt2.push(new OpenLayers.Geometry.Point(pnt4326.lon, pnt4326.lat));
convPoint = new OpenLayers.Geometry.Point(obj.botRight.lon, obj.botRight.lat);
pnt.push(convPoint);
//pnt4326 = WazeWrap.Geometry.ConvertTo4326(obj.botRight.lon,obj.botRight.lat);
//pnt2.push(new OpenLayers.Geometry.Point(pnt4326.lon, pnt4326.lat));
convPoint = new OpenLayers.Geometry.Point(obj.topRight.lon, obj.topRight.lat);
pnt.push(convPoint);
//pnt4326 = WazeWrap.Geometry.ConvertTo4326(obj.topRight.lon,obj.topRight.lat);
//pnt2.push(new OpenLayers.Geometry.Point(pnt4326.lon, pnt4326.lat));
convPoint = new OpenLayers.Geometry.Point(obj.topLeft.lon, obj.topLeft.lat);
pnt.push(convPoint);
//pnt4326 = WazeWrap.Geometry.ConvertTo4326(obj.topLeft.lon,obj.topLeft.lat);
//pnt2.push(new OpenLayers.Geometry.Point(pnt4326.lon, pnt4326.lat));
var ring = new OpenLayers.Geometry.LinearRing(pnt);
var polygon = new OpenLayers.Geometry.Polygon([ring]);
feature = new OpenLayers.Feature.Vector(polygon, attributes, style);
}
else{ //circle
var poly = new OpenLayers.Geometry.Polygon.createRegularPolygon(obj.centerPoint, obj.radius, 40, 0);
feature = new OpenLayers.Feature.Vector(poly, attributes, style);
}
mapLayers.addFeatures([feature]);
updateTotalRectCount();
/*
var ring2 = new OpenLayers.Geometry.LinearRing(pnt2);
var polygon2 = new OpenLayers.Geometry.Polygon([ring2]);
var feature2 = new OpenLayers.Feature.Vector(polygon2);
var pnt3 = [];
pnt3.push(new OpenLayers.Geometry.Point(-84.3197299999999,40.100960000000285));
pnt3.push(new OpenLayers.Geometry.Point(-84.3197299999999,40.04566000000004));
pnt3.push(new OpenLayers.Geometry.Point(-84.24969999999959,40.04566000000004));
pnt3.push(new OpenLayers.Geometry.Point(-84.24969999999959,40.100960000000285));
pnt3.push(new OpenLayers.Geometry.Point(-84.3197299999999,40.100960000000285));
var ring3 = new OpenLayers.Geometry.LinearRing(pnt3);
var polygon3 = new OpenLayers.Geometry.Polygon([ring3]);
var feature3 = new OpenLayers.Feature.Vector(polygon3);
var geoJSON = new OpenLayers.Format.GeoJSON();
//var geoJSONText = geoJSON.write(feature3, true);
//var geoJSONText2 = geoJSON.write(feature2, true);
//console.log("geoJSONText = " + geoJSONText);
//console.log("geoJSONText2 = " + geoJSONText2);
var turfpolygon = turf.polygon([[
[-84.3197299999999, 40.100960000000285],
[-84.3197299999999, 40.04566000000004],
[-84.24969999999959, 40.04566000000004],
[-84.24969999999959, 40.100960000000285],
[-84.3197299999999, 40.100960000000285]
]]);
var turfpoly2 = turf.polygon([[
[-84.3034299999997, 40.11526999999987],
[-84.3034299999997, 40.085729999999806],
[-84.24437, 40.085729999999806],
[-84.24437, 40.11526999999987],
[-84.3034299999997, 40.11526999999987]
]]);
var union = turf.union(turfpolygon, turfpoly2);
console.log("Justin");
console.log(union);*/
}
function updateTotalRectCount(){
$('#rectCount')[0].innerHTML = mapLayers.features.length;
}
function NewBox(e) {
e.stopPropagation();
AddExtent();
saveSettings();
}
function NewUserRect(e){
e.stopPropagation();
EndUserCircleMode();
clickCount = 0;
clearLayer();
$(".olMapViewport").on('mousemove', MouseMoveHandlerRect);
document.addEventListener('keyup', keyUpHandler, false);
$(".olMapViewport").click(ClickHandler);
}
function NewUserCircle(e){
e.stopPropagation();
EndUserRectMode();
clickCount = 0;
clearLayer();
$(".olMapViewport").on('mousemove', MouseMoveHandlerCircle);
document.addEventListener('keyup', keyUpHandler, false);
$(".olMapViewport").click(ClickHandlerCircle);
}
function ClickHandlerCircle(){
if(clickCount === 0){
userCircleCenter = getMousePos900913();
clickCount++;
}
else{
var point2 = getMousePos900913();
var points = [new OpenLayers.Geometry.Point(userCircleCenter.lon, userCircleCenter.lat), new OpenLayers.Geometry.Point(point2.lon, point2.lat)];
var radius = WazeWrap.Geometry.calculateDistance(points);
var circleData = {
centerPoint : new OpenLayers.Geometry.Point(userCircleCenter.lon, userCircleCenter.lat),
radius : radius,
color: currColor,
type : "circle"
};
beenTheresettings.Groups[beenTheresettings.CurrentGroup].push(circleData);
saveSettings();
DrawFeature(circleData);
EndUserCircleMode();
}
}
function ClickHandler(){
if(clickCount === 0){ //first point chosen - draw rectangle as the mouse moves
userRectPoint1 = getMousePos900913();
clickCount++;
}
else{ //second point chose - take both coordinates and draw a rectangle on the BeenThere layer
var point2 = getMousePos900913();
var groupPoints2 = {
topLeft : {
lon: userRectPoint1.lon,
lat: userRectPoint1.lat
},
botLeft : {
lon: userRectPoint1.lon,
lat: point2.lat
},
botRight: {
lon: point2.lon,
lat: point2.lat
},
topRight:{
lon: point2.lon,
lat: userRectPoint1.lat
},
color: currColor,
type: "rectangle"
};
beenTheresettings.Groups[beenTheresettings.CurrentGroup].push(groupPoints2);
saveSettings();
DrawFeature(groupPoints2);
EndUserRectMode();
}
}
function MouseMoveHandlerRect(e){
clearLayer();
drawPointer(getMousePos900913(), false);
drawRect(userRectPoint1);
}
function MouseMoveHandlerCircle(e){
clearLayer();
var currMousePos = getMousePos900913();
drawPointer(currMousePos, true);
if(userCircleCenter){
var points = [new OpenLayers.Geometry.Point(userCircleCenter.lon, userCircleCenter.lat), new OpenLayers.Geometry.Point(currMousePos.lon, currMousePos.lat)];
var radius = WazeWrap.Geometry.calculateDistance(points);
drawCircle(userCircleCenter, radius);
}
}
function clearLayer() {
var layer = W.map.getLayersByName("BeenThereUserRect")[0];
layer.removeAllFeatures();
}
function drawRect(e){
if(e !== null){
var color = currColor;
var style = {
strokeColor: color, strokeOpacity: 1, strokeWidth: 5, fillColor: color, fillOpacity: 0.0,
label: "", labelOutlineColor: "black", labelOutlineWidth: 3, fontSize: 14,
fontColor: color, fontOpacity: 0.85, fontWeight: "bold"};
if(beenTheresettings.DrawShapeBorder)
style.strokeOpacity = 1;
else
style.strokeOpacity = 0;
if(beenTheresettings.FillShape)
style.fillOpacity = 1;
else
style.fillOpacity = 0;
var point2 = getMousePos900913();
var pnt = [];
var convPoint = new OpenLayers.Geometry.Point(e.lon, e.lat);
pnt.push(convPoint);
convPoint = new OpenLayers.Geometry.Point(e.lon, point2.lat);
pnt.push(convPoint);
convPoint = new OpenLayers.Geometry.Point(point2.lon, point2.lat);
pnt.push(convPoint);
convPoint = new OpenLayers.Geometry.Point(point2.lon, e.lat);
pnt.push(convPoint);
convPoint = new OpenLayers.Geometry.Point(e.lon, e.lat);
pnt.push(convPoint);
var ring = new OpenLayers.Geometry.LinearRing(pnt);
var polygon = new OpenLayers.Geometry.Polygon([ring]);
var feature = new OpenLayers.Feature.Vector(polygon, attributes, style);
W.map.getLayersByName("BeenThereUserRect")[0].addFeatures([feature]);
}
}
function drawCircle(e, radius){
if(e !== null){
var color = currColor;
var style = {
strokeColor: color, strokeOpacity: 0.8, strokeWidth: 5, fillColor: color, fillOpacity: 0.0,
label: "", labelOutlineColor: "black", labelOutlineWidth: 3, fontSize: 14,
fontColor: color, fontOpacity: 0.85, fontWeight: "bold"};
if(beenTheresettings.DrawShapeBorder)
style.strokeOpacity = 1;
else
style.strokeOpacity = 0;
if(beenTheresettings.FillShape)
style.fillOpacity = 1;
else
style.fillOpacity = 0;
var point2 = getMousePos900913();
var pt = new OpenLayers.Geometry.Point(e.lon, e.lat);
var polygon = new OpenLayers.Geometry.Polygon.createRegularPolygon(pt,radius, 40, 0);
var feature = new OpenLayers.Feature.Vector(polygon, attributes, style);
W.map.getLayersByName("BeenThereUserRect")[0].addFeatures([feature]);
}
}
function drawPointer(e, circle){
var color = currColor;
pointStyle.strokeColor = color;
pointStyle.fillColor = color;
if(circle && circle === true)
pointStyle.fillOpacity = 0;
else
pointStyle.fillOpacity = 1;
var pointFeature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(e.lon, e.lat), {}, pointStyle);
W.map.getLayersByName("BeenThereUserRect")[0].addFeatures([pointFeature]);
}
function getMousePos900913(){
var mousePosition = $('.WazeControlMousePosition').text().split(" ");
[mousePosition[0], mousePosition[1]] = [mousePosition[1], mousePosition[0]];
return WazeWrap.Geometry.ConvertTo900913(mousePosition[0], mousePosition[1]);
}
function keyUpHandler(e){
if (e.keyCode == 27){
EndUserRectMode();
EndUserCircleMode();
}
}
function EndUserRectMode(){
$('.olMapViewport').css('cursor', 'initial');
$(".olMapViewport").off('click');
$(".olMapViewport").off('mousemove', MouseMoveHandlerRect);
clearLayer();
document.removeEventListener('keyup', keyUpHandler);
clickCount = 0;
userRectPoint1 = null;
}
function EndUserCircleMode(){
$(".olMapViewport").off('click');
$(".olMapViewport").off('mousemove', MouseMoveHandlerCircle);
clearLayer();
document.removeEventListener('keyup', keyUpHandler);
clickCount = 0;
userCircleCenter = null;
}
function RemoveLastBox() {
var mro_mapLayers = W.map.getLayersBy("uniqueName", "__beenThere");
var mro_mapLayers_mapLayerLength = mro_mapLayers[0].features.length;
if (mro_mapLayers_mapLayerLength > 0)
mro_mapLayers[0].features[mro_mapLayers_mapLayerLength - 1].destroy();
if(beenTheresettings.Groups[beenTheresettings.CurrentGroup].length > 0)
layerFuture.push(beenTheresettings.Groups[beenTheresettings.CurrentGroup].pop());
saveSettings();
updateTotalRectCount();
}
function RedoLastBox(){
if(layerFuture.length >0){
var rect = layerFuture.pop();
beenTheresettings.Groups[beenTheresettings.CurrentGroup].push(rect);
DrawFeature(rect);
}
}
function RemoveAllBoxes() {
if(beenTheresettings.Groups[beenTheresettings.CurrentGroup].length > 0)
if(confirm("Clearing all boxes cannot be undone.\nPress OK to clear all boxes.")){
var mro_mapLayers = W.map.getLayersBy("uniqueName", "__beenThere");
var mro_mapLayers_mapLayerLength = mro_mapLayers[0].features.length;
if (mro_mapLayers_mapLayerLength > 0)
mro_mapLayers[0].destroyFeatures();
beenTheresettings.Groups[beenTheresettings.CurrentGroup] = [];
layerFuture = [];
saveSettings();
updateTotalRectCount();
}
}
var mapLayers;
var userRectLayer;
function init() {
LoadSettingsObj();
mapLayers = new OpenLayers.Layer.Vector("Been There", {
displayInLayerSwitcher: true,
uniqueName: "__beenThere"
});
userRectLayer = new OpenLayers.Layer.Vector("BeenThereUserRect", {
displayInLayerSwitcher: false,
uniqueName: "__beenThereUserRect"
});
//$.getScript('https://npmcdn.com/@turf/[email protected]/turf.min.js');
W.map.addLayer(mapLayers);
mapLayers.setVisibility(beenTheresettings.layerVisible);
mapLayers.setOpacity(0.6);
W.map.addLayer(userRectLayer);
userRectLayer.setOpacity(0.6);
userRectLayer.setVisibility(beenTheresettings.layerVisible);
WazeWrap.Interface.AddLayerCheckbox("display", "Been There", beenTheresettings.layerVisible, LayerToggled, [mapLayers, userRectLayer]);
//append our css to the head
var g = '.beenThereButtons {font-size:26px; color:#59899e; cursor:pointer;} .flex-container {display: -webkit-flex; display: flex; background-color:black;}';
$("head").append($('<style type="text/css">' + g + '</style>'));
//add controls to the map
var $section = $("<div>", {style:"padding:8px 16px", id:"WMEBeenThere"});
$section.html([
'<div id="beenThere" class="flex-container" style="width:65px; position: absolute;top:' + beenTheresettings.LocTop + '; left: ' + beenTheresettings.LocLeft + '; z-index: 1040 !important; border-radius: 5px; padding: 4px; background-color: #000000;">',
'<div class="flex-container" style="width:32px; flex-wrap:wrap;" >',//left side container
'<div id="NewBox" class="waze-icon-plus_neg beenThereButtons" style="margin-top:-10px; display:block; float:left;" title="Draw a box around the visible area"></div>',
'<div id="UserRect" class="fa fa-pencil-square-o" style="display:block; float:left; margin-left:3px; color:#59899e; cursor:pointer; font-size:25px;"></div>',
'<div id="UserCirc" class="fa-stack" style="margin-top:10px; display:block; float:left; color:#59899e; cursor:pointer;"><span class="fa fa-circle-thin fa-stack-2x"></span><span class="fa fa-pencil" style="font-size:20px; margin-left:8px;"></span></div>',
'<div id="RemoveLastBox" class="waze-icon-undo beenThereButtons" style="display:block;margin-bottom:-10px;" title="Remove last shape"></div>',
'<div id="Redo" class="waze-icon-redo beenThereButtons" style="display:block;margin-bottom:-10px;" title="Redo last shape"></div>',
'<div id="TrashBox" class="waze-icon-trash beenThereButtons" style="margin-bottom:-5px; display:block;" title="Remove all shapes">',
'<span id="rectCount" style="position:absolute; top:150px; right:16px;font-size:12px;">0</span></div>',
'<div id="Settings" class="fa fa-cog" style="display:block; float:left; margin-left:3px; color:#59899e; cursor:pointer; font-size:20px;"></div>',
'</div>',//close left side container
'<div class="flex-container" style="width:30px; height:90px; flex-wrap:wrap; justify-content:flex-start;">', //right side container
'<input type="radio" name="currColor" value="btcolorPicker1" style="width:10px;" checked="checked">',
'<button class="jscolor {valueElement:null,hash:true,closable:true}" style="float:right;width:15px; height:15px;border:2px solid black" id="btcolorPicker1"></button>',
'<input type="radio" name="currColor" value="btcolorPicker2" style="width:10px;">',
'<button class="jscolor {valueElement:null,hash:true,closable:true}" style="float:right;width:15px; height:15px;border:2px solid black" id="btcolorPicker2"></button>',
'<input type="radio" name="currColor" value="btcolorPicker3" style="width:10px;">',
'<button class="jscolor {valueElement:null,hash:true,closable:true}" style="float:right;width:15px; height:15px;border:2px solid black" id="btcolorPicker3"></button>',
'<input type="radio" name="currColor" value="btcolorPicker4" style="width:10px;">',
'<button class="jscolor {valueElement:null,hash:true,closable:true}" style="float:right;width:15px; height:15px;border:2px solid black" id="btcolorPicker4"></button>',
'</div>' //close right side container
].join(' '));
$("#WazeMap").append($section.html());
BuildSettingsInterface();
//set up listeners
$("#NewBox").click(NewBox);
$('#UserRect').click(NewUserRect);
$('#UserCirc').click(NewUserCircle);
$("#RemoveLastBox").click(RemoveLastBox);
$('#Redo').click(RedoLastBox);
$("#TrashBox").click(RemoveAllBoxes);
$('#Settings').click(function(){
$('#BTSettings')[0].innerHTML = localStorage.beenThere_Settings;
setChecked('chkBTShapeBorder',beenTheresettings.DrawShapeBorder);
setChecked('chkBTShapeFill',beenTheresettings.FillShape);
$('#BeenThereSettings').css({'visibility':'visible'});
});
new WazeWrap.Interface.Shortcut('NewBoxShortcut', 'Draw a box around the visible area', 'wmebt', 'Been There', beenTheresettings.NewBoxShortcut, NewBox, null).add();
new WazeWrap.Interface.Shortcut('NewUserRectShortcut', 'Draw a rectangle', 'wmebt', 'Been There', beenTheresettings.NewUserRectShortcut, NewUserRect, null).add();
new WazeWrap.Interface.Shortcut('NewUserCircleShortcut', 'Draw a circle', 'wmebt', 'Been There', beenTheresettings.NewUserCircleShortcut, NewUserCircle, null).add();
new WazeWrap.Interface.Shortcut('RemoveLastShapeShortcut', 'Remove last shape', 'wmebt', 'Been There', beenTheresettings.RemoveLastShapeShortcut, RemoveLastBox, null).add();
new WazeWrap.Interface.Shortcut('RedoLastShapeShortcut', 'Redo last shape', 'wmebt', 'Been There', beenTheresettings.RedoLastShapeShortcut, RedoLastBox, null).add();
new WazeWrap.Interface.Shortcut('RemoveAllShapesShortcut', 'Remove all shapes', 'wmebt', 'Been There', beenTheresettings.RemoveAllShapesShortcut, RemoveAllBoxes, null).add();
//necessary to catch changes to the keyboard shortcuts
window.onbeforeunload = function() {
checkShortcutsChanged();
};
$('[name="currColor"]').change(function() {
currColor = '#' + $('#' + this.value)[0].jscolor.toString();
});
if($.ui){
$('#beenThere').draggable({
stop: function(event, ui) {
beenTheresettings.LocLeft = $('#beenThere').css('left');
beenTheresettings.LocTop = $('#beenThere').css('top');
saveSettings();
}
});
$('#BeenThereSettings').draggable({
stop: function(event, ui) {
beenTheresettings.SettingsLocLeft = $('#BeenThereSettings').css('left');
beenTheresettings.SettingsLocTop = $('#BeenThereSettings').css('top');
saveSettings();
}
});
}
initColorPicker();
LoadSettings();
WazeWrap.Interface.ShowScriptUpdate("WME BeenThere", GM_info.script.version, updateMessage, "https://greasyfork.org/scripts/27035-wme-beenthere", "https://www.waze.com/forum/viewtopic.php?f=819&t=218182");
}
function LayerToggled(checked){
userRectLayer.setVisibility(checked);
mapLayers.setVisibility(checked);
beenTheresettings.layerVisible = checked;
saveSettings();
}
/*
Takes the settings loaded into the settings obj and loads them into the interface and draws any features that were saved
*/
function LoadSettings(){
loadGroup(beenTheresettings.CurrentGroup);
if ($('#btcolorPicker1')[0].jscolor && $('#btcolorPicker2')[0].jscolor && $('#btcolorPicker3')[0].jscolor && $('#btcolorPicker4')[0].jscolor){
$('#btcolorPicker1')[0].jscolor.fromString(beenTheresettings.CP1);
$('#btcolorPicker2')[0].jscolor.fromString(beenTheresettings.CP2);
$('#btcolorPicker3')[0].jscolor.fromString(beenTheresettings.CP3);
$('#btcolorPicker4')[0].jscolor.fromString(beenTheresettings.CP4);
}
}
function loadGroup(group){
for(var i=0;i<beenTheresettings.Groups[group].length;i++)
DrawFeature(beenTheresettings.Groups[group][i]);
}
function BuildSettingsInterface(){
var $section = $("<div>", {style:"padding:8px 16px", id:"WMEBeenThereSettings"});
$section.html([
`<div id="BeenThereSettings" style="visibility:hidden; position:fixed; top:${beenTheresettings.SettingsLocTop}; left:${beenTheresettings.SettingsLocLeft}; z-index:1000; background-color:white; border-width:3px; border-style:solid; border-radius:10px; padding:4px;">`,
'<div>', //top div - split left/right
'<div style="width:328px; height:240px; display:inline-block; float:left;">', //left side div
'<div><h3>Drawing</h3>',
'<input type="radio" name="DrawOptions" class="btOptions" id="chkBTShapeBorder">Draw shape border</br>',
'<input type="radio" name="DrawOptions" class="btOptions" id="chkBTShapeFill">Fill shape</br>',
'</div></br>',//close drawing div
'<div><h3>Export/Import</h3>',
'<div><button class="fa fa-upload fa-2x" aria-hidden="true" id="btnBTCopySettings" style="cursor:pointer;border: 1; background: none; box-shadow:none;" title="Copy BeenThere settings to the clipboard" data-clipboard-target="#BTSettings"></button>',
'<textarea rows="4" cols="30" readonly id="BTSettings" style="resize:none;"></textarea>',
'</div>',//end export div
'<div>', // import div
'<button class="fa fa-download fa-2x" aria-hidden="true" id="btnBTImportSettings" style="cursor:pointer;border: 1; background: none; box-shadow:none;" title="Import copied settings"></button>',
'<textarea rows="4" cols="30" id="txtBTImportSettings" style="resize:none;"></textarea>',
'</div>',//end import div
'</div>',//close import/export div
'</div>', //close left side div
'<div style="display:inline-block; height:240px;">', //right side div
'<h3>Groups</h3>',
'<div id="BeenThereGroups">',
'<div id="BeenThereGroupsList">',
'</div>',
'<div style="float:left;">',//textboxes div
'<label for="btGroupName" style="display:inline-block; width:40px;">Name </label><input type="text" id="btGroupName" size="10" style="border: 1px solid #000000; height:20px;"/></br>',
'</div>', //End textboxes div
'<div style="float:right; text-align:center;">',//button div
'<button id="btAddGroup">Add</button>',
'</div>',//close button div
'</div>', //close BeenThereGroups
'</div>', //close right side div
'</div>', //close top div
'<div style="float: right; top:10px;">', //save/cancel buttons
'<button id="BeenThereSettingsClose" class="btn btn-default">Close</button>',
'</div>',//end save/cancel buttons
'</div>'
].join(' '));
$("#WazeMap").append($section.html());
$('.btOptions').change(function(){
beenTheresettings.DrawShapeBorder = isChecked('chkBTShapeBorder');
beenTheresettings.FillShape = isChecked('chkBTShapeFill');
saveSettings();
});
$("#BeenThereSettingsClose").click(function(){
$('#BeenThereSettings').css({'visibility':'hidden'}); //hide the settings window
});
$('#btnBTImportSettings').click(function(){
if($('#txtBTImportSettings')[0].value !== ""){
localStorage.beenThere_Settings = $('#txtBTImportSettings')[0].value;
LoadSettingsObj();
LoadSettings();
}
});
LoadCustomGroups();
$('#btAddGroup').click(function(){
if($('#btGroupName').val() !== ""){
let name = $('#btGroupName').val();
let exists = beenTheresettings.Groups[name];
if(exists == null){
beenTheresettings.Groups[name] = [];
$('#btGroupsName').val("");
LoadCustomGroups();
saveSettings();
}
}
});
new Clipboard('#btnBTCopySettings');
}
function LoadCustomGroups(){
$('#BeenThereGroupsList').empty();
var groups = "";
$.each(beenTheresettings.Groups, function(k, v){
groups += '<div style="position:relative;">' + k + '<i id="BTGroupsClose' + k + '" style="position:absolute; right:0; top:0;" class="fa fa-times" title="Remove group"></i></div>';
});
groups += 'Current group: <select id="btCurrGroup">';
$.each(beenTheresettings.Groups, function(val, obj){
groups += `<option value="${val}">${val}</option>`;
});
groups += '</select>';
$('#BeenThereGroupsList').prepend(groups);
$('#btCurrGroup')[0].value = beenTheresettings.CurrentGroup;
$('#btCurrGroup').change(function(){
beenTheresettings.CurrentGroup = $(this)[0].value;
clearLayer();
mapLayers.removeAllFeatures();
loadGroup(beenTheresettings.CurrentGroup);
saveSettings();
});
$('[id^="BTGroupsClose"]').click(function(){
if(getObjectPropertyCount(beenTheresettings.Groups) > 1){
delete beenTheresettings.Groups[this.id.replace('BTGroupsClose','')];
saveSettings();
LoadCustomGroups();
}
else
alert("There must be at least one group");
});
}
function isChecked(checkboxId) {
return $('#' + checkboxId).is(':checked');
}
function setChecked(checkboxId, checked) {
$('#' + checkboxId).prop('checked', checked);
}
function initColorPicker(tries = 1){
if ($('#btcolorPicker1')[0].jscolor && $('#btcolorPicker2')[0].jscolor) {
$('#btcolorPicker1')[0].jscolor.fromString(beenTheresettings.CP1);
$('#btcolorPicker2')[0].jscolor.fromString(beenTheresettings.CP2);
$('#btcolorPicker3')[0].jscolor.fromString(beenTheresettings.CP3);
$('#btcolorPicker4')[0].jscolor.fromString(beenTheresettings.CP4);
$('[id^="colorPicker"]')[0].jscolor.closeText = 'Close';
$('#btcolorPicker1')[0].jscolor.onChange = jscolorChanged;
$('#btcolorPicker2')[0].jscolor.onChange = jscolorChanged;
$('#btcolorPicker3')[0].jscolor.onChange = jscolorChanged;
$('#btcolorPicker4')[0].jscolor.onChange = jscolorChanged;
} else if (tries < 1000)
setTimeout(function () {initColorPicker(tries++);}, 200);
}
function jscolorChanged(){
beenTheresettings.CP1 = "#" + $('#btcolorPicker1')[0].jscolor.toString();
beenTheresettings.CP2 = "#" + $('#btcolorPicker2')[0].jscolor.toString();
beenTheresettings.CP3 = "#" + $('#btcolorPicker3')[0].jscolor.toString();
beenTheresettings.CP4 = "#" + $('#btcolorPicker4')[0].jscolor.toString();
//In case they changed the color of the currently selected color, re-set currColor
currColor = '#' + $('#' + $("input[type='radio'][name='currColor']:checked").val())[0].jscolor.toString();
saveSettings();
}
function objectHasProperties(object) {
for (var prop in object) {
if (object.hasOwnProperty(prop))
return true;
}
return false;
}
function getObjectPropertyCount(object){
let count = 0;
for (var prop in object) {
if (object.hasOwnProperty(prop))
count++;
}
return count;
}
async function LoadSettingsObj() {
var loadedSettings;
try{
loadedSettings = $.parseJSON(localStorage.getItem("beenThere_Settings"));
}
catch(err){
loadedSettings = null;
}
var defaultSettings = {
layerHistory: [],
LocLeft: "6px",
LocTop: "280px",
CP1: "#FDA400",
CP2: "#fd0303",
CP3: "#1303fd",
CP4: "#00fd22",
DrawShapeBorder: true,
FillShape: false,
NewBoxShortcut: "",
NewUserRectShortcut: "",
NewUserCircleShortcut: "",
RemoveLastShapeShortcut: "",
RedoLastShapeShortcut: "",
RemoveAllShapesShortcut: "",
SettingsLocTop: "40%",
SettingsLocLeft: "50%",
Groups: {"default": []},
CurrentGroup: "default",
layerVisible: true,
lastSaved: 0
};
beenTheresettings = $.extend({}, defaultSettings, loadedSettings);
let serverSettings = await WazeWrap.Remote.RetrieveSettings("BeenThere");
if(serverSettings && serverSettings.lastSaved > beenTheresettings.lastSaved)
$.extend(beenTheresettings, serverSettings);
if(parseInt(beenTheresettings.LocLeft.replace('px', '')) < 0)
beenTheresettings.LocLeft = "6px";
if(parseInt(beenTheresettings.LocTop.replace('px','')) < 0)
beenTheresettings.LocTop = "280px";
currColor = beenTheresettings.CP1;
if(beenTheresettings.layerHistory.length > 0){ //move our old layers into the default group
beenTheresettings.Groups.default = [...beenTheresettings.layerHistory];
beenTheresettings.layerHistory = [];
saveSettings();
}
}
function saveSettings() {
if (localStorage) {
var localsettings = {
layerHistory: beenTheresettings.layerHistory,
LocLeft: beenTheresettings.LocLeft,
LocTop: beenTheresettings.LocTop,
CP1: beenTheresettings.CP1,
CP2: beenTheresettings.CP2,
CP3: beenTheresettings.CP3,
CP4: beenTheresettings.CP4,
DrawShapeBorder: beenTheresettings.DrawShapeBorder,
FillShape: beenTheresettings.FillShape,
NewBoxShortcut: beenTheresettings.NewBoxShortcut,
NewUserRectShortcut: beenTheresettings.NewUserRectShortcut,
NewUserCircleShortcut: beenTheresettings.NewUserCircleShortcut,
RemoveLastShapeShortcut: beenTheresettings.RemoveLastShapeShortcut,
RedoLastShapeShortcut: beenTheresettings.RedoLastShapeShortcut,
RemoveAllShapesShortcut: beenTheresettings.RemoveAllShapesShortcut,
SettingsLocTop: beenTheresettings.SettingsLocTop,
SettingsLocLeft: beenTheresettings.SettingsLocLeft,
Groups: beenTheresettings.Groups,
CurrentGroup: beenTheresettings.CurrentGroup,
layerVisible: beenTheresettings.layerVisible,
lastSaved: Date.now()
};
if(parseInt(localsettings.LocLeft.replace('px', '')) < 0)
localsettings.LocLeft = "6px";
if(parseInt(localsettings.LocTop.replace('px','')) < 0)
localsettings.LocTop = "280px";
for (var name in W.accelerators.Actions) {
let TempKeys = "";
if (W.accelerators.Actions[name].group == 'wmebt') {
console.log(name);
if (W.accelerators.Actions[name].shortcut) {
if (W.accelerators.Actions[name].shortcut.altKey === true)
TempKeys += 'A';
if (W.accelerators.Actions[name].shortcut.shiftKey === true)
TempKeys += 'S';
if (W.accelerators.Actions[name].shortcut.ctrlKey === true)
TempKeys += 'C';
if (TempKeys !== "")
TempKeys += '+';
if (W.accelerators.Actions[name].shortcut.keyCode)
TempKeys += W.accelerators.Actions[name].shortcut.keyCode;
} else
TempKeys = "-1";
localsettings[name] = TempKeys;
}
}
localStorage.setItem("beenThere_Settings", JSON.stringify(localsettings));
WazeWrap.Remote.SaveSettings("BeenThere", localsettings);
}
}
function checkShortcutsChanged(){
let triggerSave = false;
for (let name in W.accelerators.Actions) {
let TempKeys = "";
if (W.accelerators.Actions[name].group == 'wmepie') {
if (W.accelerators.Actions[name].shortcut) {
if (W.accelerators.Actions[name].shortcut.altKey === true)
TempKeys += 'A';
if (W.accelerators.Actions[name].shortcut.shiftKey === true)
TempKeys += 'S';
if (W.accelerators.Actions[name].shortcut.ctrlKey === true)
TempKeys += 'C';
if (TempKeys !== "")
TempKeys += '+';
if (W.accelerators.Actions[name].shortcut.keyCode)
TempKeys += W.accelerators.Actions[name].shortcut.keyCode;
} else
TempKeys = "-1";
if(beenTheresettings[name] != TempKeys){
beenTheresettings[name] = TempKeys;
triggerSave = true;
break;
}
}
}
if(triggerSave)
saveSettings();
}
})();