-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathleaflet.js
2642 lines (2220 loc) · 100 KB
/
leaflet.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _util = require("./util");
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var ClusterLayerStore = function () {
function ClusterLayerStore(group) {
_classCallCheck(this, ClusterLayerStore);
this._layers = {};
this._group = group;
}
_createClass(ClusterLayerStore, [{
key: "add",
value: function add(layer, id) {
if (typeof id !== "undefined" && id !== null) {
if (this._layers[id]) {
this._group.removeLayer(this._layers[id]);
}
this._layers[id] = layer;
}
this._group.addLayer(layer);
}
}, {
key: "remove",
value: function remove(id) {
if (typeof id === "undefined" || id === null) {
return;
}
id = (0, _util.asArray)(id);
for (var i = 0; i < id.length; i++) {
if (this._layers[id[i]]) {
this._group.removeLayer(this._layers[id[i]]);
delete this._layers[id[i]];
}
}
}
}, {
key: "clear",
value: function clear() {
this._layers = {};
this._group.clearLayers();
}
}]);
return ClusterLayerStore;
}();
exports.default = ClusterLayerStore;
},{"./util":17}],2:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var ControlStore = function () {
function ControlStore(map) {
_classCallCheck(this, ControlStore);
this._controlsNoId = [];
this._controlsById = {};
this._map = map;
}
_createClass(ControlStore, [{
key: "add",
value: function add(control, id, html) {
if (typeof id !== "undefined" && id !== null) {
if (this._controlsById[id]) {
this._map.removeControl(this._controlsById[id]);
}
this._controlsById[id] = control;
} else {
this._controlsNoId.push(control);
}
this._map.addControl(control);
}
}, {
key: "get",
value: function get(id) {
var control = null;
if (this._controlsById[id]) {
control = this._controlsById[id];
}
return control;
}
}, {
key: "remove",
value: function remove(id) {
if (this._controlsById[id]) {
var control = this._controlsById[id];
this._map.removeControl(control);
delete this._controlsById[id];
}
}
}, {
key: "clear",
value: function clear() {
for (var i = 0; i < this._controlsNoId.length; i++) {
var control = this._controlsNoId[i];
this._map.removeControl(control);
}
this._controlsNoId = [];
for (var key in this._controlsById) {
var _control = this._controlsById[key];
this._map.removeControl(_control);
}
this._controlsById = {};
}
}]);
return ControlStore;
}();
exports.default = ControlStore;
},{}],3:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getCRS = getCRS;
var _leaflet = require("./global/leaflet");
var _leaflet2 = _interopRequireDefault(_leaflet);
var _proj4leaflet = require("./global/proj4leaflet");
var _proj4leaflet2 = _interopRequireDefault(_proj4leaflet);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// Helper function to instanciate a ICRS instance.
function getCRS(crsOptions) {
var crs = _leaflet2.default.CRS.EPSG3857; // Default Spherical Mercator
switch (crsOptions.crsClass) {
case "L.CRS.EPSG3857":
crs = _leaflet2.default.CRS.EPSG3857;
break;
case "L.CRS.EPSG4326":
crs = _leaflet2.default.CRS.EPSG4326;
break;
case "L.CRS.EPSG3395":
crs = _leaflet2.default.CRS.EPSG3395;
break;
case "L.CRS.Simple":
crs = _leaflet2.default.CRS.Simple;
break;
case "L.Proj.CRS":
if (crsOptions.options && crsOptions.options.bounds) {
crsOptions.options.bounds = _leaflet2.default.bounds(crsOptions.options.bounds);
}
if (crsOptions.options && crsOptions.options.transformation) {
crsOptions.options.transformation = new _leaflet2.default.Transformation(crsOptions.options.transformation[0], crsOptions.options.transformation[1], crsOptions.options.transformation[2], crsOptions.options.transformation[3]);
}
crs = new _proj4leaflet2.default.CRS(crsOptions.code, crsOptions.proj4def, crsOptions.options);
break;
case "L.Proj.CRS.TMS":
if (crsOptions.options && crsOptions.options.bounds) {
crsOptions.options.bounds = _leaflet2.default.bounds(crsOptions.options.bounds);
}
if (crsOptions.options && crsOptions.options.transformation) {
crsOptions.options.transformation = _leaflet2.default.Transformation(crsOptions.options.transformation[0], crsOptions.options.transformation[1], crsOptions.options.transformation[2], crsOptions.options.transformation[3]);
}
// L.Proj.CRS.TMS is deprecated as of Leaflet 1.x, fall back to L.Proj.CRS
//crs = new Proj4Leaflet.CRS.TMS(crsOptions.code, crsOptions.proj4def, crsOptions.projectedBounds, crsOptions.options);
crs = new _proj4leaflet2.default.CRS(crsOptions.code, crsOptions.proj4def, crsOptions.options);
break;
}
return crs;
}
},{"./global/leaflet":10,"./global/proj4leaflet":11}],4:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _util = require("./util");
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var DataFrame = function () {
function DataFrame() {
_classCallCheck(this, DataFrame);
this.columns = [];
this.colnames = [];
this.colstrict = [];
this.effectiveLength = 0;
this.colindices = {};
}
_createClass(DataFrame, [{
key: "_updateCachedProperties",
value: function _updateCachedProperties() {
var _this = this;
this.effectiveLength = 0;
this.colindices = {};
this.columns.forEach(function (column, i) {
_this.effectiveLength = Math.max(_this.effectiveLength, column.length);
_this.colindices[_this.colnames[i]] = i;
});
}
}, {
key: "_colIndex",
value: function _colIndex(colname) {
var index = this.colindices[colname];
if (typeof index === "undefined") return -1;
return index;
}
}, {
key: "col",
value: function col(name, values, strict) {
if (typeof name !== "string") throw new Error("Invalid column name \"" + name + "\"");
var index = this._colIndex(name);
if (arguments.length === 1) {
if (index < 0) return null;else return (0, _util.recycle)(this.columns[index], this.effectiveLength);
}
if (index < 0) {
index = this.colnames.length;
this.colnames.push(name);
}
this.columns[index] = (0, _util.asArray)(values);
this.colstrict[index] = !!strict;
// TODO: Validate strictness (ensure lengths match up with other stricts)
this._updateCachedProperties();
return this;
}
}, {
key: "cbind",
value: function cbind(obj, strict) {
var _this2 = this;
Object.keys(obj).forEach(function (name) {
var coldata = obj[name];
_this2.col(name, coldata);
});
return this;
}
}, {
key: "get",
value: function get(row, col, missingOK) {
var _this3 = this;
if (row > this.effectiveLength) throw new Error("Row argument was out of bounds: " + row + " > " + this.effectiveLength);
var colIndex = -1;
if (typeof col === "undefined") {
var rowData = {};
this.colnames.forEach(function (name, i) {
rowData[name] = _this3.columns[i][row % _this3.columns[i].length];
});
return rowData;
} else if (typeof col === "string") {
colIndex = this._colIndex(col);
} else if (typeof col === "number") {
colIndex = col;
}
if (colIndex < 0 || colIndex > this.columns.length) {
if (missingOK) return void 0;else throw new Error("Unknown column index: " + col);
}
return this.columns[colIndex][row % this.columns[colIndex].length];
}
}, {
key: "nrow",
value: function nrow() {
return this.effectiveLength;
}
}]);
return DataFrame;
}();
exports.default = DataFrame;
},{"./util":17}],5:[function(require,module,exports){
"use strict";
var _leaflet = require("./global/leaflet");
var _leaflet2 = _interopRequireDefault(_leaflet);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// In RMarkdown's self-contained mode, we don't have a way to carry around the
// images that Leaflet needs but doesn't load into the page. Instead, we'll set
// data URIs for the default marker, and let any others be loaded via CDN.
if (typeof _leaflet2.default.Icon.Default.imagePath === "undefined") {
// if in a local file, support http
switch (window.location.protocol) {
case "http:":
// don't force http site to be done with https
_leaflet2.default.Icon.Default.imagePath = "http://cdn.leafletjs.com/leaflet/v1.3.1/images/";
break;
default:
// file
// https
// otherwise use https as it works on files and https
_leaflet2.default.Icon.Default.imagePath = "https://unpkg.com/[email protected]/dist/images/";
break;
}
// don't know how to make this dataURI work since
// will be appended to Defaul.imagePath above
/*
if (L.Browser.retina) {
L.Icon.Default.prototype.options.iconUrl = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAABSCAYAAAAWy4frAAAPiElEQVR42t1bCVCU5xkmbabtZJJOO+l0mhgT0yQe0WXZgz2570NB8I6J6UzaTBoORRFEruVGDhWUPRAQRFFREDnVxCtEBRb24DBNE3Waaatpkmluo4m+fd9v999olGVBDu3OPLj+//s+7/W93/f9//6/EwA4/T9g3AlFOUeeUGR2uMqzOyJk2R2x0qyOAmnmkS3SrCPrZJlHlsqzjypcs49OX1Jf//P7KhD885A0u10my2ovQscvybI6wEF8ivI7pFntAV6qkw9PWSBK1bEnZRltm2WZ7R8h4FbI0VG33GPgXXgCAra+A4EIn8KT4JH/FigoiJ/IIz6TZbVVKLLan5u0QESqlkckWW3p0sy2bxDAgZwO13TDytoB+NPe9+zild2DEFGuB7/NpzDodriF55o0o7XIRXXoNxMaiCSj9VU09C8E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ppnhNmY8WkJXXcFnSMZSY6e3cO1ruKxU/7+CGUSnbnCti4bWjHbOAvlGOApdPrJ9beDjtE5khFsaOaq8dHzMaW/vC/e6KGMWm4flYMku4cNnVmpPej8udtA1aBzrll47RGjs/aG+vX75tUkyihl1lKVZnDFrIuy+2AaOv9EvAX0nY7ROZeEJq4aF+g3zPvqHStejOYvlvGuA1FmNxtCM1P18AcMgjALv9MxYWaX9WcBktWuuu9eFqPM4mbvAzbEEg5h9tHpLIOtP+g7HeMnNHLVeG/JkvF7YWxc33jDqqy0ZhoEKovzM1P0DPSdjtFvG5ZVXLP0vn19z3KrVTvIHF3fYHHeCvruHN/AbdNN3PO69+17iLgzjrRux8El/SwIMg0M9P3HG9HqsPv+hUrrJXEvczj+AAbRx+AcX88F0v1AvBnKAnlTG8Rln5/6LuLHW5/zorT+D0wg1qq8y5xfu88CSyCnH5h3dW/ZGXve8uOMZRWP0no8cIFY7+YfswURrT36QL09ffsMppHYegW/P7CBWHvlMOGBe5/9jtdjY7R8wkTb+R9meZA6n2oJWAAAAABJRU5ErkJggg==";
} else {
L.Icon.Default.prototype.options.iconUrl = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAApCAYAAADAk4LOAAAGmklEQVRYw7VXeUyTZxjvNnfELFuyIzOabermMZEeQC/OclkO49CpOHXOLJl/CAURuYbQi3KLgEhbrhZ1aDwmaoGqKII6odATmH/scDFbdC7LvFqOCc+e95s2VG50X/LLm/f4/Z7neY/ne18aANCmAr5E/xZf1uDOkTcGcWR6hl9247tT5U7Y6SNvWsKT63P58qbfeLJG8M5qcgTknrvvrdDbsT7Ml+tv82X6vVxJE33aRmgSyYtcWVMqX97Yv2JvW39UhRE2HuyBL+t+gK1116ly06EeWFNlAmHxlQE0OMiV6mQCScusKRlhS3QLeVJdl1+23h5dY4FNB3thrbYboqptEFlphTC1hSpJnbRvxP4NWgsE5Jyz86QNNi/5qSUTGuFk1gu54tN9wuK2wc3o+Wc13RCmsoBwEqzGcZs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oxSwUk75ggqsYJ7VicsnwGIkZBSXKOUww73WGXyqP+J2/b9c+gi1YAg/xpwck3gJuucNrh5JvDPvQr0WFXf0piyt8f8/WI0hV4pRxxkQZdJDfDJNOAmM0Ag8jyT6hz0WGXWuP94Yh2jcfjmXAGvHCMslRimDHYuHuDsy2QtHuIavznhbYURq5R57KpzBBRZKPJi8eQg48h4j8SDdowifdIrEVdU+gbO6QNvRRt4ZBthUaZhUnjlYObNagV3keoeru3rU7rcuceqU1mJBxy+BWZYlNEBH+0eH4vRiB+OYybU2hnblYlTvkHinM4m54YnxSyaZYSF6R3jwgP7udKLGIX6r/lbNa9N6y5MFynjWDtrHd75ZvTYAPO/6RgF0k76mQla3FGq7dO+cH8sKn0Vo7nDllwAhqwLPkxrHwWmHJOo+AKJ4rab5OgrM7rVu8eWb2Pu0Dh4eDgXoOfvp7Y7QeqknRmvcTBEyq9m/HQQSCSz6LHq3z0yzsNySRfMS253wl2KyRDbcZPcfJKjZmSEOjcxyi+Y8dUOtsIEH6R2wNykdqrkYJ0RV92H0W58pkfQk7cKevsLK10Py8SdMGfXNXATY+pPbyJR/ET6n9nIfztNtZYRV9XniQu9IA2vOVgy4ir7GCLVmmd+zjkH0eAF9Po6K61pmCXHxU5rHMYd1ftc3owjwRSVRzLjKvqZEty6cRUD7jGqiOdu5HG6MdHjNcNYGqfDm5YRzLBBCCDl/2bk8a8gdbqcfwECu62Fg/HrggAAAABJRU5ErkJggg==";
}
*/
}
},{"./global/leaflet":10}],6:[function(require,module,exports){
"use strict";
var _leaflet = require("./global/leaflet");
var _leaflet2 = _interopRequireDefault(_leaflet);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// add texxtsize, textOnly, and style
_leaflet2.default.Tooltip.prototype.options.textsize = "10px";
_leaflet2.default.Tooltip.prototype.options.textOnly = false;
_leaflet2.default.Tooltip.prototype.options.style = null;
// copy original layout to not completely stomp it.
var initLayoutOriginal = _leaflet2.default.Tooltip.prototype._initLayout;
_leaflet2.default.Tooltip.prototype._initLayout = function () {
initLayoutOriginal.call(this);
this._container.style.fontSize = this.options.textsize;
if (this.options.textOnly) {
_leaflet2.default.DomUtil.addClass(this._container, "leaflet-tooltip-text-only");
}
if (this.options.style) {
for (var property in this.options.style) {
this._container.style[property] = this.options.style[property];
}
}
};
},{"./global/leaflet":10}],7:[function(require,module,exports){
"use strict";
var _leaflet = require("./global/leaflet");
var _leaflet2 = _interopRequireDefault(_leaflet);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var protocolRegex = /^\/\//;
var upgrade_protocol = function upgrade_protocol(urlTemplate) {
if (protocolRegex.test(urlTemplate)) {
if (window.location.protocol === "file:") {
// if in a local file, support http
// http should auto upgrade if necessary
urlTemplate = "http:" + urlTemplate;
}
}
return urlTemplate;
};
var originalLTileLayerInitialize = _leaflet2.default.TileLayer.prototype.initialize;
_leaflet2.default.TileLayer.prototype.initialize = function (urlTemplate, options) {
urlTemplate = upgrade_protocol(urlTemplate);
originalLTileLayerInitialize.call(this, urlTemplate, options);
};
var originalLTileLayerWMSInitialize = _leaflet2.default.TileLayer.WMS.prototype.initialize;
_leaflet2.default.TileLayer.WMS.prototype.initialize = function (urlTemplate, options) {
urlTemplate = upgrade_protocol(urlTemplate);
originalLTileLayerWMSInitialize.call(this, urlTemplate, options);
};
},{"./global/leaflet":10}],8:[function(require,module,exports){
(function (global){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = global.HTMLWidgets;
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],9:[function(require,module,exports){
(function (global){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = global.jQuery;
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],10:[function(require,module,exports){
(function (global){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = global.L;
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],11:[function(require,module,exports){
(function (global){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = global.L.Proj;
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],12:[function(require,module,exports){
(function (global){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = global.Shiny;
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],13:[function(require,module,exports){
"use strict";
var _jquery = require("./global/jquery");
var _jquery2 = _interopRequireDefault(_jquery);
var _leaflet = require("./global/leaflet");
var _leaflet2 = _interopRequireDefault(_leaflet);
var _shiny = require("./global/shiny");
var _shiny2 = _interopRequireDefault(_shiny);
var _htmlwidgets = require("./global/htmlwidgets");
var _htmlwidgets2 = _interopRequireDefault(_htmlwidgets);
var _util = require("./util");
var _crs_utils = require("./crs_utils");
var _controlStore = require("./control-store");
var _controlStore2 = _interopRequireDefault(_controlStore);
var _layerManager = require("./layer-manager");
var _layerManager2 = _interopRequireDefault(_layerManager);
var _methods = require("./methods");
var _methods2 = _interopRequireDefault(_methods);
require("./fixup-default-icon");
require("./fixup-default-tooltip");
require("./fixup-url-protocol");
var _dataframe = require("./dataframe");
var _dataframe2 = _interopRequireDefault(_dataframe);
var _clusterLayerStore = require("./cluster-layer-store");
var _clusterLayerStore2 = _interopRequireDefault(_clusterLayerStore);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
window.LeafletWidget = {};
window.LeafletWidget.utils = {};
var methods = window.LeafletWidget.methods = _jquery2.default.extend({}, _methods2.default);
window.LeafletWidget.DataFrame = _dataframe2.default;
window.LeafletWidget.ClusterLayerStore = _clusterLayerStore2.default;
window.LeafletWidget.utils.getCRS = _crs_utils.getCRS;
// Send updated bounds back to app. Takes a leaflet event object as input.
function updateBounds(map) {
var id = map.getContainer().id;
var bounds = map.getBounds();
_shiny2.default.onInputChange(id + "_bounds", {
north: bounds.getNorthEast().lat,
east: bounds.getNorthEast().lng,
south: bounds.getSouthWest().lat,
west: bounds.getSouthWest().lng
});
_shiny2.default.onInputChange(id + "_center", {
lng: map.getCenter().lng,
lat: map.getCenter().lat
});
_shiny2.default.onInputChange(id + "_zoom", map.getZoom());
}
function preventUnintendedZoomOnScroll(map) {
// Prevent unwanted scroll capturing. Similar in purpose to
// https://github.com/CliffCloud/Leaflet.Sleep but with a
// different set of heuristics.
// The basic idea is that when a mousewheel/DOMMouseScroll
// event is seen, we disable scroll wheel zooming until the
// user moves their mouse cursor or clicks on the map. This
// is slightly trickier than just listening for mousemove,
// because mousemove is fired when the page is scrolled,
// even if the user did not physically move the mouse. We
// handle this by examining the mousemove event's screenX
// and screenY properties; if they change, we know it's a
// "true" move.
// lastScreen can never be null, but its x and y can.
var lastScreen = { x: null, y: null };
(0, _jquery2.default)(document).on("mousewheel DOMMouseScroll", "*", function (e) {
// Disable zooming (until the mouse moves or click)
map.scrollWheelZoom.disable();
// Any mousemove events at this screen position will be ignored.
lastScreen = { x: e.originalEvent.screenX, y: e.originalEvent.screenY };
});
(0, _jquery2.default)(document).on("mousemove", "*", function (e) {
// Did the mouse really move?
if (lastScreen.x !== null && e.screenX !== lastScreen.x || e.screenY !== lastScreen.y) {
// It really moved. Enable zooming.
map.scrollWheelZoom.enable();
lastScreen = { x: null, y: null };
}
});
(0, _jquery2.default)(document).on("mousedown", ".leaflet", function (e) {
// Clicking always enables zooming.
map.scrollWheelZoom.enable();
lastScreen = { x: null, y: null };
});
}
_htmlwidgets2.default.widget({
name: "leaflet",
type: "output",
factory: function factory(el, width, height) {
var map = null;
return {
// we need to store our map in our returned object.
getMap: function getMap() {
return map;
},
renderValue: function renderValue(data) {
// Create an appropriate CRS Object if specified
if (data && data.options && data.options.crs) {
data.options.crs = (0, _crs_utils.getCRS)(data.options.crs);
}
// As per https://github.com/rstudio/leaflet/pull/294#discussion_r79584810
if (map) {
map.remove();
map = function () {
return;
}(); // undefine map
}
if (data.options.mapFactory && typeof data.options.mapFactory === "function") {
map = data.options.mapFactory(el, data.options);
} else {
map = _leaflet2.default.map(el, data.options);
}
preventUnintendedZoomOnScroll(map);
// Store some state in the map object
map.leafletr = {
// Has the map ever rendered successfully?
hasRendered: false,
// Data to be rendered when resize is called with area != 0
pendingRenderData: null
};
// Check if the map is rendered statically (no output binding)
if (_htmlwidgets2.default.shinyMode && /\bshiny-bound-output\b/.test(el.className)) {
map.id = el.id;
// Store the map on the element so we can find it later by ID
(0, _jquery2.default)(el).data("leaflet-map", map);
// When the map is clicked, send the coordinates back to the app
map.on("click", function (e) {
_shiny2.default.onInputChange(map.id + "_click", {
lat: e.latlng.lat,
lng: e.latlng.lng,
".nonce": Math.random() // Force reactivity if lat/lng hasn't changed
});
});
var groupTimerId = null;
map.on("moveend", function (e) {
updateBounds(e.target);
}).on("layeradd layerremove", function (e) {
// If the layer that's coming or going is a group we created, tell
// the server.
if (map.layerManager.getGroupNameFromLayerGroup(e.layer)) {
// But to avoid chattiness, coalesce events
if (groupTimerId) {
clearTimeout(groupTimerId);
groupTimerId = null;
}
groupTimerId = setTimeout(function () {
groupTimerId = null;
_shiny2.default.onInputChange(map.id + "_groups", map.layerManager.getVisibleGroups());
}, 100);
}
});
}
this.doRenderValue(data, map);
},
doRenderValue: function doRenderValue(data, map) {
// Leaflet does not behave well when you set up a bunch of layers when
// the map is not visible (width/height == 0). Popups get misaligned
// relative to their owning markers, and the fitBounds calculations
// are off. Therefore we wait until the map is actually showing to
// render the value (we rely on the resize() callback being invoked
// at the appropriate time).
//
// There may be an issue with leafletProxy() calls being made while
// the map is not being viewed--not sure what the right solution is
// there.
if (el.offsetWidth === 0 || el.offsetHeight === 0) {
map.leafletr.pendingRenderData = data;
return;
}
map.leafletr.pendingRenderData = null;
// Merge data options into defaults
var options = _jquery2.default.extend({ zoomToLimits: "always" }, data.options);
if (!map.layerManager) {
map.controls = new _controlStore2.default(map);
map.layerManager = new _layerManager2.default(map);
} else {
map.controls.clear();
map.layerManager.clear();
}
var explicitView = false;
if (data.setView) {
explicitView = true;
map.setView.apply(map, data.setView);
}
if (data.fitBounds) {
explicitView = true;
methods.fitBounds.apply(map, data.fitBounds);
}
if (data.flyTo) {
if (!explicitView && !map.leafletr.hasRendered) {
// must be done to give a initial starting point
map.fitWorld();
}
explicitView = true;
map.flyTo.apply(map, data.flyTo);
}
if (data.flyToBounds) {
if (!explicitView && !map.leafletr.hasRendered) {
// must be done to give a initial starting point
map.fitWorld();
}
explicitView = true;
methods.flyToBounds.apply(map, data.flyToBounds);
}
if (data.options.center) {
explicitView = true;
}
// Returns true if the zoomToLimits option says that the map should be
// zoomed to map elements.
function needsZoom() {
return options.zoomToLimits === "always" || options.zoomToLimits === "first" && !map.leafletr.hasRendered;
}
if (!explicitView && needsZoom() && !map.getZoom()) {
if (data.limits && !_jquery2.default.isEmptyObject(data.limits)) {
// Use the natural limits of what's being drawn on the map
// If the size of the bounding box is 0, leaflet gets all weird
var pad = 0.006;
if (data.limits.lat[0] === data.limits.lat[1]) {
data.limits.lat[0] = data.limits.lat[0] - pad;
data.limits.lat[1] = data.limits.lat[1] + pad;
}
if (data.limits.lng[0] === data.limits.lng[1]) {
data.limits.lng[0] = data.limits.lng[0] - pad;
data.limits.lng[1] = data.limits.lng[1] + pad;
}
map.fitBounds([[data.limits.lat[0], data.limits.lng[0]], [data.limits.lat[1], data.limits.lng[1]]]);
} else {
map.fitWorld();
}
}
for (var i = 0; data.calls && i < data.calls.length; i++) {
var call = data.calls[i];
if (methods[call.method]) methods[call.method].apply(map, call.args);else (0, _util.log)("Unknown method " + call.method);
}
map.leafletr.hasRendered = true;
if (_htmlwidgets2.default.shinyMode) {
setTimeout(function () {
updateBounds(map);
}, 1);
}
},
resize: function resize(width, height) {
if (map) {
map.invalidateSize();
if (map.leafletr.pendingRenderData) {
this.doRenderValue(map.leafletr.pendingRenderData, map);
}
}
}
};
}
});
if (_htmlwidgets2.default.shinyMode) {
_shiny2.default.addCustomMessageHandler("leaflet-calls", function (data) {
var id = data.id;
var el = document.getElementById(id);
var map = el ? (0, _jquery2.default)(el).data("leaflet-map") : null;
if (!map) {
(0, _util.log)("Couldn't find map with id " + id);
return;
}
for (var i = 0; i < data.calls.length; i++) {
var call = data.calls[i];
if (call.dependencies) {
_shiny2.default.renderDependencies(call.dependencies);
}
if (methods[call.method]) methods[call.method].apply(map, call.args);else (0, _util.log)("Unknown method " + call.method);
}
});
}
},{"./cluster-layer-store":1,"./control-store":2,"./crs_utils":3,"./dataframe":4,"./fixup-default-icon":5,"./fixup-default-tooltip":6,"./fixup-url-protocol":7,"./global/htmlwidgets":8,"./global/jquery":9,"./global/leaflet":10,"./global/shiny":12,"./layer-manager":14,"./methods":15,"./util":17}],14:[function(require,module,exports){
(function (global){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _jquery = require("./global/jquery");
var _jquery2 = _interopRequireDefault(_jquery);
var _leaflet = require("./global/leaflet");
var _leaflet2 = _interopRequireDefault(_leaflet);
var _util = require("./util");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var LayerManager = function () {
function LayerManager(map) {
_classCallCheck(this, LayerManager);
this._map = map;
// BEGIN layer indices
// {<groupname>: {<stamp>: layer}}
this._byGroup = {};
// {<categoryName>: {<stamp>: layer}}
this._byCategory = {};
// {<categoryName_layerId>: layer}
this._byLayerId = {};
// {<stamp>: {
// "group": <groupname>,
// "layerId": <layerId>,
// "category": <category>,
// "container": <container>
// }
// }
this._byStamp = {};
// {<crosstalkGroupName>: {<key>: [<stamp>, <stamp>, ...], ...}}
this._byCrosstalkGroup = {};
// END layer indices
// {<categoryName>: L.layerGroup}
this._categoryContainers = {};
// {<groupName>: L.layerGroup}
this._groupContainers = {};
}
_createClass(LayerManager, [{
key: "addLayer",
value: function addLayer(layer, category, layerId, group, ctGroup, ctKey) {
var _this = this;
// Was a group provided?
var hasId = typeof layerId === "string";
var grouped = typeof group === "string";
var stamp = _leaflet2.default.Util.stamp(layer) + "";
// This will be the default layer group to add the layer to.
// We may overwrite this let before using it (i.e. if a group is assigned).
// This one liner creates the _categoryContainers[category] entry if it
// doesn't already exist.
var container = this._categoryContainers[category] = this._categoryContainers[category] || _leaflet2.default.layerGroup().addTo(this._map);
var oldLayer = null;
if (hasId) {
// First, remove any layer with the same category and layerId
var prefixedLayerId = this._layerIdKey(category, layerId);
oldLayer = this._byLayerId[prefixedLayerId];
if (oldLayer) {
this._removeLayer(oldLayer);
}
// Update layerId index
this._byLayerId[prefixedLayerId] = layer;
}
// Update group index
if (grouped) {
this._byGroup[group] = this._byGroup[group] || {};
this._byGroup[group][stamp] = layer;
// Since a group is assigned, don't add the layer to the category's layer
// group; instead, use the group's layer group.
// This one liner creates the _groupContainers[group] entry if it doesn't
// already exist.
container = this.getLayerGroup(group, true);
}
// Update category index
this._byCategory[category] = this._byCategory[category] || {};
this._byCategory[category][stamp] = layer;
// Update stamp index
var layerInfo = this._byStamp[stamp] = {
layer: layer,
group: group,
ctGroup: ctGroup,
ctKey: ctKey,
layerId: layerId,
category: category,
container: container,
hidden: false
};
// Update crosstalk group index
if (ctGroup) {
if (layer.setStyle) {
// Need to save this info so we know what to set opacity to later
layer.options.origOpacity = typeof layer.options.opacity !== "undefined" ? layer.options.opacity : 0.5;
layer.options.origFillOpacity = typeof layer.options.fillOpacity !== "undefined" ? layer.options.fillOpacity : 0.2;
}
var ctg = this._byCrosstalkGroup[ctGroup];
if (!ctg) {
ctg = this._byCrosstalkGroup[ctGroup] = {};
var crosstalk = global.crosstalk;
var handleFilter = function handleFilter(e) {
if (!e.value) {
var groupKeys = Object.keys(ctg);
for (var i = 0; i < groupKeys.length; i++) {
var key = groupKeys[i];
var _layerInfo = _this._byStamp[ctg[key]];
_this._setVisibility(_layerInfo, true);
}
} else {
var selectedKeys = {};
for (var _i = 0; _i < e.value.length; _i++) {
selectedKeys[e.value[_i]] = true;
}
var _groupKeys = Object.keys(ctg);
for (var _i2 = 0; _i2 < _groupKeys.length; _i2++) {
var _key = _groupKeys[_i2];
var _layerInfo2 = _this._byStamp[ctg[_key]];
_this._setVisibility(_layerInfo2, selectedKeys[_groupKeys[_i2]]);
}
}
};
var filterHandle = new crosstalk.FilterHandle(ctGroup);
filterHandle.on("change", handleFilter);
var handleSelection = function handleSelection(e) {
if (!e.value || !e.value.length) {
var groupKeys = Object.keys(ctg);
for (var i = 0; i < groupKeys.length; i++) {
var key = groupKeys[i];
var _layerInfo3 = _this._byStamp[ctg[key]];
_this._setOpacity(_layerInfo3, 1.0);
}
} else {
var selectedKeys = {};
for (var _i3 = 0; _i3 < e.value.length; _i3++) {
selectedKeys[e.value[_i3]] = true;
}
var _groupKeys2 = Object.keys(ctg);
for (var _i4 = 0; _i4 < _groupKeys2.length; _i4++) {
var _key2 = _groupKeys2[_i4];
var _layerInfo4 = _this._byStamp[ctg[_key2]];
_this._setOpacity(_layerInfo4, selectedKeys[_groupKeys2[_i4]] ? 1.0 : 0.2);
}
}
};
var selHandle = new crosstalk.SelectionHandle(ctGroup);
selHandle.on("change", handleSelection);
setTimeout(function () {
handleFilter({ value: filterHandle.filteredKeys });
handleSelection({ value: selHandle.value });
}, 100);
}
if (!ctg[ctKey]) ctg[ctKey] = [];
ctg[ctKey].push(stamp);
}
// Add to container
if (!layerInfo.hidden) container.addLayer(layer);
return oldLayer;
}
}, {
key: "brush",
value: function brush(bounds, extraInfo) {
var _this2 = this;
/* eslint-disable no-console */
// For each Crosstalk group...