-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.html
More file actions
1230 lines (1037 loc) · 48 KB
/
index.html
File metadata and controls
1230 lines (1037 loc) · 48 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FLOCK Surveillance Network Map - 336,708 Cameras</title>
<link rel="icon" type="image/svg+xml" href="favicon.svg">
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/MarkerCluster.css" />
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/MarkerCluster.Default.css" />
<style>
body { margin: 0; padding: 0; font-family: Arial, sans-serif; }
#map { position: absolute; top: 0; bottom: 0; width: 100%; }
.info-panel {
position: absolute;
top: 10px;
right: 10px;
background: rgba(0, 0, 0, 0.9);
color: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 15px rgba(0,0,0,0.5);
max-width: 350px;
max-height: 85vh;
overflow-y: auto;
z-index: 1000;
font-size: 13px;
transition: transform 0.3s ease;
}
.info-panel.collapsed {
transform: translateX(calc(100% + 10px));
}
.panel-toggle {
position: absolute;
top: 10px;
right: 10px;
background: rgba(0, 0, 0, 0.9);
color: #ff8c00;
border: 2px solid #ff8c00;
padding: 12px 15px;
border-radius: 8px;
cursor: pointer;
z-index: 1001;
font-weight: bold;
font-size: 20px;
display: none;
box-shadow: 0 4px 15px rgba(0,0,0,0.5);
}
.panel-toggle:hover {
background: rgba(255, 140, 0, 0.2);
}
/* Mobile styles */
@media (max-width: 768px) {
.panel-toggle {
display: block;
}
.info-panel {
max-width: 90vw;
max-height: 70vh;
top: 60px;
}
.info-panel.collapsed {
transform: translateX(calc(100% + 10px));
}
.legend {
bottom: 5px;
left: 5px;
right: 5px;
font-size: 9px;
padding: 6px 8px;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-around;
gap: 4px;
}
.legend h4 {
display: none;
}
.legend-item {
margin: 0;
padding: 4px;
flex: 1;
justify-content: center;
font-size: 9px;
}
.legend-dot {
width: 10px;
height: 10px;
margin-right: 3px;
border-width: 1px;
}
.legend-text-full {
display: none;
}
.legend-text-short {
display: inline;
}
}
/* Desktop - show full text, hide short */
.legend-text-full {
display: inline;
}
.legend-text-short {
display: none;
}
.info-panel h3 {
margin: 0 0 15px 0;
font-size: 18px;
color: #ff8c00;
border-bottom: 2px solid #ff8c00;
padding-bottom: 8px;
}
.stat-row {
margin: 10px 0;
display: flex;
justify-content: space-between;
}
.stat-label { color: #ccc; }
.stat-value { font-weight: 700; color: #ff8c00; font-size: 16px; }
.button-group {
margin-top: 15px;
display: flex;
gap: 8px;
flex-direction: column;
}
.btn {
padding: 10px 15px;
border: none;
border-radius: 4px;
cursor: pointer;
font-weight: 600;
font-size: 12px;
}
.btn-primary { background: #ff8c00; color: white; }
.btn-primary:hover { background: #ff6600; }
.btn-danger { background: #ff4444; color: white; }
.btn-danger:hover { background: #cc0000; }
.network-notice {
background: rgba(255, 140, 0, 0.2);
border: 1px solid #ff8c00;
padding: 12px;
border-radius: 4px;
margin-top: 15px;
font-size: 11px;
line-height: 1.6;
}
.legend {
position: absolute;
bottom: 30px;
right: 10px;
background: rgba(0, 0, 0, 0.9);
color: white;
padding: 15px;
border-radius: 8px;
box-shadow: 0 4px 15px rgba(0,0,0,0.5);
z-index: 1000;
font-size: 12px;
}
.legend h4 { margin: 0 0 10px 0; font-size: 14px; color: #ff8c00; }
.legend-item {
margin: 8px 0;
display: flex;
align-items: center;
cursor: pointer;
transition: opacity 0.2s, background 0.2s;
padding: 5px;
border-radius: 4px;
}
.legend-item:hover { background: rgba(255, 255, 255, 0.1); }
.legend-item.disabled {
opacity: 0.3;
text-decoration: line-through;
}
.legend-dot {
width: 16px;
height: 16px;
border-radius: 50%;
margin-right: 10px;
border: 2px solid white;
}
/* Glowing animation for Flock cameras */
@keyframes pulse {
0%, 100% {
opacity: 0.9;
filter: brightness(1.2) drop-shadow(0 0 3px #ff0000);
}
50% {
opacity: 1;
filter: brightness(1.8) drop-shadow(0 0 8px #ff0000) drop-shadow(0 0 12px #ff0000);
}
}
.pulse-marker {
animation: pulse 1.5s ease-in-out infinite;
}
/* Loading Spinner Animation */
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
/* Search Bar Styles */
.search-container {
position: absolute;
top: 10px;
left: 10px;
z-index: 1000;
display: flex;
gap: 8px;
}
.search-box {
background: white;
border-radius: 8px;
box-shadow: 0 4px 15px rgba(0,0,0,0.3);
display: flex;
overflow: hidden;
}
#searchInput {
border: none;
padding: 12px 15px;
font-size: 14px;
width: 280px;
outline: none;
}
#searchBtn {
background: #ff8c00;
color: white;
border: none;
padding: 12px 20px;
cursor: pointer;
font-weight: 600;
transition: background 0.2s;
}
#searchBtn:hover {
background: #ff6600;
}
#locationBtn {
background: white;
border: none;
border-radius: 8px;
padding: 12px 15px;
cursor: pointer;
box-shadow: 0 4px 15px rgba(0,0,0,0.3);
font-size: 18px;
transition: all 0.2s;
}
#locationBtn:hover {
background: #f0f0f0;
transform: scale(1.05);
}
.search-results {
position: absolute;
top: 52px;
left: 0;
background: white;
border-radius: 8px;
box-shadow: 0 4px 15px rgba(0,0,0,0.3);
max-height: 300px;
overflow-y: auto;
display: none;
width: 360px;
}
.search-result-item {
padding: 12px 15px;
cursor: pointer;
border-bottom: 1px solid #eee;
transition: background 0.2s;
}
.search-result-item:hover {
background: #f5f5f5;
}
.search-result-item:last-child {
border-bottom: none;
}
.result-name {
font-weight: 600;
color: #333;
}
.result-details {
font-size: 12px;
color: #666;
margin-top: 4px;
}
@media (max-width: 768px) {
.search-container {
flex-direction: column;
}
#searchInput {
width: 220px;
}
.search-results {
width: 280px;
}
}
</style>
</head>
<body>
<div id="map"></div>
<!-- Search Bar -->
<div class="search-container">
<div class="search-box">
<input type="text" id="searchInput" placeholder="Search city, address, or place..." />
<button id="searchBtn" onclick="searchLocation()">🔍 Search</button>
</div>
<button id="locationBtn" onclick="useMyLocation()" title="Use my location">📍</button>
<div class="search-results" id="searchResults"></div>
</div>
<div class="panel-toggle" id="panelToggle" onclick="togglePanel()">☰</div>
<div class="info-panel" id="infoPanel">
<h3>🕸️ FLOCK Network</h3>
<div class="stat-row">
<span class="stat-label">Cameras:</span>
<span class="stat-value" id="cameraCount">Loading...</span>
</div>
<div class="stat-row">
<span class="stat-label">Network Lines:</span>
<span class="stat-value">113,829</span>
</div>
<div class="button-group">
<button class="btn btn-danger" onclick="showAllLines()">Show ALL Lines (Chaos!)</button>
<button class="btn btn-primary" onclick="clearHighlight()">Clear & Restore All</button>
</div>
<div class="network-notice" id="defaultNotice">
<strong>💡 How to use:</strong><br>
• Click any camera → ALL others disappear<br>
• See ONLY that camera's network connections<br>
• Click "Clear & Restore All" to see all cameras again<br>
• Dotted lines = data sharing to other agencies
</div>
<!-- Network Details Panel (shown when camera clicked) -->
<div id="networkDetails" style="display: none; margin-top: 15px;">
<div style="border-top: 2px solid #ff8c00; padding-top: 15px;">
<h4 style="margin: 0 0 10px 0; color: #ff8c00; font-size: 16px;" id="networkTitle">📹 Camera Network</h4>
<div id="networkInfo" style="font-size: 12px; line-height: 1.8;"></div>
</div>
</div>
</div>
<div class="legend">
<h4>Device Type (Click to Toggle)</h4>
<div class="legend-item" id="legend-flock" onclick="toggleDeviceType('flock')">
<div class="legend-dot" style="background: #ff0000; animation: pulse 1.5s ease-in-out infinite; box-shadow: 0 0 8px #ff0000;"></div>
<span class="legend-text-full">Flock Safety (Glowing)</span>
<span class="legend-text-short">Flock</span>
</div>
<div class="legend-item" id="legend-alpr" onclick="toggleDeviceType('alpr')">
<div class="legend-dot" style="background: #9933ff;"></div>
<span class="legend-text-full">ALPR Cameras</span>
<span class="legend-text-short">ALPR</span>
</div>
<div class="legend-item" id="legend-other" onclick="toggleDeviceType('other')">
<div class="legend-dot" style="background: #3388ff;"></div>
<span class="legend-text-full">Other Surveillance</span>
<span class="legend-text-short">Other</span>
</div>
<div class="legend-item" id="legend-police" style="display: none;">
<div class="legend-dot" style="background: #00ff00;"></div>
<span class="legend-text-full">Police Stations</span>
<span class="legend-text-short">Police</span>
</div>
</div>
<!-- Loading Status (Bottom Left) -->
<div id="loadingStatus" style="position: absolute; bottom: 10px; left: 10px; background: rgba(0,0,0,0.85); color: white; padding: 12px 18px; border-radius: 6px; font-size: 12px; z-index: 1000; display: none; box-shadow: 0 4px 15px rgba(0,0,0,0.5);">
<div style="display: flex; align-items: center; gap: 10px;">
<div style="width: 16px; height: 16px; border: 3px solid #333; border-top: 3px solid #ff8c00; border-radius: 50%; animation: spin 1s linear infinite;"></div>
<span id="loadingText">Loading...</span>
</div>
</div>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src="https://unpkg.com/[email protected]/dist/leaflet.markercluster.js"></script>
<script>
// Global state
const state = {
map: null,
cameraData: null,
networkData: null,
markerClusters: {},
allMarkers: {},
networkLines: [],
linesLayer: null,
connectionCounts: {},
networkViewActive: false, // Track if we're in network view mode
tileIndex: null, // Tile index for on-demand loading
loadedTiles: new Set(), // Track which tiles are loaded
visibleLayers: {
alpr: true,
flock: true,
other: true
}
};
// Generate a unique color for each network based on camera location
function getNetworkColor(lat, lon, name) {
// Create a hash from coordinates and name
const str = `${lat.toFixed(4)},${lon.toFixed(4)},${name}`;
let hash = 0;
for (let i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
hash = hash & hash; // Convert to 32-bit integer
}
// Generate vibrant colors (avoid too dark or too light)
const hue = Math.abs(hash % 360);
const saturation = 70 + (Math.abs(hash >> 8) % 20); // 70-90%
const lightness = 50 + (Math.abs(hash >> 16) % 15); // 50-65%
return `hsl(${hue}, ${saturation}%, ${lightness}%)`;
}
// Initialize map immediately
state.map = L.map('map').setView([39.8283, -98.5795], 4);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap'
}).addTo(state.map);
// Collapse panel on mobile by default
if (window.innerWidth <= 768) {
document.getElementById('infoPanel').classList.add('collapsed');
document.getElementById('panelToggle').textContent = '📊';
}
// Create lines layer
state.linesLayer = L.featureGroup().addTo(state.map);
// Create marker clusters - uncluster when zoomed in
const clusterOptions = {
chunkedLoading: true,
maxClusterRadius: 40, // Smaller radius = breaks apart sooner
spiderfyOnMaxZoom: true,
showCoverageOnHover: false,
disableClusteringAtZoom: 13 // Show individual points at zoom 13+ (closer zoom)
};
state.markerClusters.alpr = L.markerClusterGroup(clusterOptions);
state.markerClusters.flock = L.markerClusterGroup(clusterOptions);
state.markerClusters.other = L.markerClusterGroup(clusterOptions);
// Add clusters to map
Object.values(state.markerClusters).forEach(cluster => state.map.addLayer(cluster));
// Show loading status
document.getElementById('loadingStatus').style.display = 'block';
document.getElementById('loadingText').textContent = 'Loading camera data...';
document.getElementById('cameraCount').textContent = 'Loading...';
// TILE-BASED LOADING: Load only visible tiles instead of all 178K cameras
console.log('Starting tile-based data load...');
// Initialize tile state
state.tileIndex = null;
state.loadedTiles = new Set();
state.cameraData = { type: 'FeatureCollection', features: [] };
state.networkData = [];
// Load tile index first
fetch('data/tiles/index.json')
.then(r => r.json())
.then(tileIndex => {
console.log('Tile index loaded:', Object.keys(tileIndex.tiles).length, 'tiles available');
state.tileIndex = tileIndex;
// Load initial tiles based on current viewport
loadVisibleTiles();
// Load more tiles when map moves or zooms
state.map.on('moveend', loadVisibleTiles);
state.map.on('zoomend', loadVisibleTiles);
document.getElementById('loadingStatus').style.display = 'none';
document.getElementById('cameraCount').textContent = tileIndex.total_cameras.toLocaleString();
console.log('MAP READY with tile-based loading!');
})
.catch(error => {
console.error('ERROR loading tile index:', error);
document.getElementById('cameraCount').textContent = 'ERROR: ' + error.message;
document.getElementById('loadingText').textContent = 'ERROR: ' + error.message;
alert('Failed to load map data: ' + error.message);
});
function latLonToTile(lat, lon, zoom) {
const latRad = lat * Math.PI / 180;
const n = Math.pow(2, zoom);
const xtile = Math.floor((lon + 180) / 360 * n);
const ytile = Math.floor((1 - Math.asinh(Math.tan(latRad)) / Math.PI) / 2 * n);
return { x: xtile, y: ytile };
}
function getVisibleTiles() {
if (!state.tileIndex) return [];
const bounds = state.map.getBounds();
const zoom = state.tileIndex.zoom; // Always use zoom 6 for tiles
const nw = latLonToTile(bounds.getNorth(), bounds.getWest(), zoom);
const se = latLonToTile(bounds.getSouth(), bounds.getEast(), zoom);
const tiles = [];
for (let x = nw.x; x <= se.x; x++) {
for (let y = nw.y; y <= se.y; y++) {
const tileKey = `${zoom}/${x}/${y}`;
if (state.tileIndex.tiles[tileKey]) {
tiles.push(tileKey);
}
}
}
return tiles;
}
function loadVisibleTiles() {
const visibleTiles = getVisibleTiles();
const tilesToLoad = visibleTiles.filter(tile => !state.loadedTiles.has(tile));
if (tilesToLoad.length === 0) {
console.log('All visible tiles already loaded');
return;
}
console.log(`Loading ${tilesToLoad.length} new tiles...`);
document.getElementById('loadingStatus').style.display = 'block';
document.getElementById('loadingText').textContent = `Loading ${tilesToLoad.length} tiles...`;
Promise.all(tilesToLoad.map(tileKey => {
const tilePath = state.tileIndex.tiles[tileKey].path;
return fetch(tilePath)
.then(r => r.json())
.then(tileData => {
state.loadedTiles.add(tileKey);
return tileData;
})
.catch(err => {
console.error(`Failed to load tile ${tileKey}:`, err);
return null;
});
})).then(tiles => {
// Merge tile data
tiles.forEach(tileData => {
if (!tileData) return;
// Add cameras
state.cameraData.features.push(...tileData.features);
// Add networks
state.networkData.push(...tileData.networks);
});
// Rebuild connection counts
state.connectionCounts = {};
state.networkData.forEach(network => {
const key = network.from[0].toFixed(4) + ',' + network.from[1].toFixed(4);
state.connectionCounts[key] = network.connections?.length || 0;
});
// Add new cameras to map
addCamerasToMapByPriority();
document.getElementById('loadingStatus').style.display = 'none';
console.log(`Loaded ${tilesToLoad.length} tiles. Total cameras: ${state.cameraData.features.length}`);
});
}
function updateCameraCount() {
const totalCount = state.cameraData.features.length;
document.getElementById('cameraCount').textContent = totalCount.toLocaleString();
}
function getCameraType(props) {
const manufacturer = (props.manufacturer || props.brand || '').toLowerCase();
const survType = (props['surveillance:type'] || '').toUpperCase();
if (manufacturer.includes('flock')) return 'flock';
if (survType === 'ALPR') return 'alpr';
return 'other';
}
function getCameraColor(type) {
if (type === 'flock') return '#ff0000'; // RED for Flock (pulsing)
if (type === 'alpr') return '#9933ff'; // PURPLE for ALPR
return '#3388ff'; // BLUE for other surveillance
}
function addCamerasToMapByPriority() {
// Separate NEW cameras by type (skip already-added cameras)
const flockCams = [];
const alprCams = [];
const otherCams = [];
state.cameraData.features.forEach(feature => {
const coords = feature.geometry.coordinates;
const markerKey = coords[1].toFixed(4) + ',' + coords[0].toFixed(4);
// Skip if already added
if (state.allMarkers[markerKey]) return;
const props = feature.properties || {};
const type = getCameraType(props);
if (type === 'flock') flockCams.push(feature);
else if (type === 'alpr') alprCams.push(feature);
else otherCams.push(feature);
});
// Only process if there are new cameras
if (flockCams.length === 0 && alprCams.length === 0 && otherCams.length === 0) {
return;
}
// Load in priority order with messages
if (flockCams.length > 0) {
document.getElementById('loadingText').textContent = `Adding ${flockCams.length} Flock cameras...`;
addCamerasByType(flockCams, 'flock');
}
setTimeout(() => {
if (alprCams.length > 0) {
document.getElementById('loadingText').textContent = `Adding ${alprCams.length} ALPR cameras...`;
addCamerasByType(alprCams, 'alpr');
}
setTimeout(() => {
if (otherCams.length > 0) {
document.getElementById('loadingText').textContent = `Adding ${otherCams.length} other cameras...`;
addCamerasByType(otherCams, 'other');
}
}, 50);
}, 50);
}
function addCamerasByType(features, cameraType) {
features.forEach(feature => {
const props = feature.properties || {};
const coords = feature.geometry.coordinates;
const sharingCount = parseInt(props.pe_sharing_count) || 0;
const color = getCameraColor(cameraType);
const marker = L.circleMarker([coords[1], coords[0]], {
radius: cameraType === 'flock' ? 7 : 5, // Flock cameras larger
fillColor: color,
color: '#fff',
weight: cameraType === 'flock' ? 2 : 1, // Flock has thicker border
opacity: 1,
fillOpacity: cameraType === 'flock' ? 0.95 : 0.7, // Flock more opaque
className: cameraType === 'flock' ? 'pulse-marker' : ''
});
// Add random animation delay to Flock cameras so they don't all pulse at once
if (cameraType === 'flock') {
const randomDelay = Math.random() * 1.5; // Random delay between 0-1.5s
marker.on('add', function() {
const element = this.getElement();
if (element) {
element.style.animationDelay = randomDelay + 's';
}
});
}
// Build detailed popup - EXACT COPY from original
let popup = '<div style="font-size: 13px; line-height: 1.6;">';
popup += '<div style="font-weight: 700; font-size: 16px; margin-bottom: 12px; color: #1a1a1a; border-bottom: 2px solid #ff8c00; padding-bottom: 6px;">';
popup += (props.operator || 'Unknown Agency');
popup += '</div>';
// Network stats if available
if (props.pe_cameras) {
popup += '<div style="margin: 12px 0; padding: 10px; background: #f5f5f5; border-radius: 4px; border-left: 3px solid #ff8c00;">';
popup += '<div style="font-weight: 600; color: #666; font-size: 11px; text-transform: uppercase; margin-bottom: 8px;">Agency Statistics</div>';
popup += '<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 8px;">';
popup += '<div style="background: white; padding: 8px; border-radius: 4px; text-align: center;">';
popup += '<div style="font-size: 20px; font-weight: bold; color: #ff8c00;">' + props.pe_cameras + '</div>';
popup += '<div style="font-size: 10px; color: #666;">Cameras</div>';
popup += '</div>';
popup += '<div style="background: white; padding: 8px; border-radius: 4px; text-align: center;">';
popup += '<div style="font-size: 20px; font-weight: bold; color: #ff8c00;">' + sharingCount + '</div>';
popup += '<div style="font-size: 10px; color: #666;">Partners</div>';
popup += '</div>';
if (props.pe_vehicles_detected && props.pe_vehicles_detected !== '0') {
const vehicles = parseInt(props.pe_vehicles_detected).toLocaleString();
popup += '<div style="background: white; padding: 8px; border-radius: 4px; text-align: center;">';
popup += '<div style="font-size: 18px; font-weight: bold; color: #ff8c00;">' + vehicles + '</div>';
popup += '<div style="font-size: 10px; color: #666;">Vehicles/Month</div>';
popup += '</div>';
}
if (props.pe_searches && props.pe_searches !== '0') {
const searches = parseInt(props.pe_searches).toLocaleString();
popup += '<div style="background: white; padding: 8px; border-radius: 4px; text-align: center;">';
popup += '<div style="font-size: 18px; font-weight: bold; color: #ff8c00;">' + searches + '</div>';
popup += '<div style="font-size: 10px; color: #666;">Searches/Month</div>';
popup += '</div>';
}
popup += '</div>';
if (sharingCount > 0) {
const connKey = coords[1].toFixed(4) + ',' + coords[0].toFixed(4);
const actualConnections = state.connectionCounts[connKey] || 0;
popup += '<div style="background: #fff3cd; border: 1px solid #ffc107; padding: 10px; border-radius: 4px; margin-top: 10px; font-size: 12px; color: #856404;">';
popup += '<strong>⚠️ Network:</strong> Shares with <strong>' + sharingCount + ' agencies</strong>';
if (actualConnections > 0 && actualConnections < sharingCount) {
popup += '<br><span style="font-size: 11px; color: #666;">Can show ' + actualConnections + ' of ' + sharingCount + ' connections (locations known)</span>';
} else if (actualConnections === 0) {
popup += '<br><span style="font-size: 11px; color: #666;">No partner locations found (vendors/demos/unknown agencies)</span>';
}
popup += '<br><em style="font-size: 11px;">Click camera to show network lines</em>';
popup += '</div>';
}
// Show ALL partners in scrollable list
if (props.pe_external_orgs && props.pe_external_orgs !== 'NA') {
const partners = props.pe_external_orgs.split(',');
popup += '<div style="margin-top: 10px; font-weight: 600; color: #666; font-size: 11px;">All Partners (' + partners.length + '):</div>';
popup += '<div style="max-height: 250px; overflow-y: auto; font-size: 11px; background: white; padding: 8px; border-radius: 4px; margin-top: 5px; border: 1px solid #ddd;">';
partners.forEach(p => {
popup += '• ' + p.trim() + '<br>';
});
popup += '</div>';
}
if (props.pe_portal_url) {
popup += '<a href="' + props.pe_portal_url + '" target="_blank" style="display: inline-block; margin-top: 12px; padding: 10px 16px; background: #ff8c00; color: white; text-decoration: none; border-radius: 4px; font-weight: 600; font-size: 12px;">View Transparency Portal →</a>';
}
popup += '</div>';
} else if (sharingCount > 0) {
popup += '<div style="margin: 10px 0; padding: 10px; background: #f5f5f5; border-radius: 4px;">';
popup += 'Shares with: <strong>' + sharingCount + ' agencies</strong><br>';
popup += '<em style="font-size: 11px;">Click to show network lines</em>';
popup += '</div>';
}
// Camera details
if (props['surveillance:type'] || props.manufacturer) {
popup += '<div style="margin: 12px 0; padding: 10px; background: #f5f5f5; border-radius: 4px;">';
popup += '<div style="font-weight: 600; color: #666; font-size: 11px; margin-bottom: 5px;">Camera Details</div>';
if (props['surveillance:type']) {
popup += '<div><strong>Type:</strong> ' + props['surveillance:type'] + '</div>';
}
if (props.manufacturer || props.brand) {
popup += '<div><strong>Manufacturer:</strong> ' + (props.manufacturer || props.brand) + '</div>';
}
popup += '</div>';
}
popup += '</div>';
marker.bindPopup(popup, { maxWidth: 500, minWidth: 400 });
// Add network line drawing on click for ANY camera with network data
if (sharingCount > 0) {
marker.on('click', function() {
showCameraNetwork(coords[1], coords[0]);
});
}
// Store with 4-decimal precision for matching with network data
const markerId = coords[1].toFixed(4) + ',' + coords[0].toFixed(4);
state.allMarkers[markerId] = { marker, props, type: cameraType };
// Add to cluster group
state.markerClusters[cameraType].addLayer(marker);
});
}
// Police stations are created dynamically when showing network (not loaded upfront for speed)
function showCameraNetwork(cameraLat, cameraLon) {
clearLines();
// Find this camera's network
const network = state.networkData.find(net =>
Math.abs(net.from[0] - cameraLat) < 0.0001 &&
Math.abs(net.from[1] - cameraLon) < 0.0001
);
if (!network || !network.connections) {
console.log('No network data for this camera');
return;
}
console.log('Drawing', network.connections.length, 'connections for', network.from_name);
// Mark that we're in network view mode
state.networkViewActive = true;
// Generate unique color for this network
const networkColor = getNetworkColor(cameraLat, cameraLon, network.from_name);
console.log('Network color:', networkColor);
// Update the info panel with network details
updateNetworkDetailsPanel(network, networkColor);
// HIDE ALL CLUSTERS
Object.values(state.markerClusters).forEach(cluster => {
state.map.removeLayer(cluster);
});
// ALSO remove any individual markers still on map from previous views
Object.values(state.allMarkers).forEach(item => {
state.map.removeLayer(item.marker);
});
// SHOW the source camera first
const sourceCameraKey = cameraLat.toFixed(4) + ',' + cameraLon.toFixed(4);
const sourceMarker = state.allMarkers[sourceCameraKey];
if (sourceMarker) {
sourceMarker.marker.addTo(state.map);
}
// Track if we show any police stations
let policeStationsShown = false;
// Process each connection
network.connections.forEach(conn => {
const destKey = conn.to[0].toFixed(4) + ',' + conn.to[1].toFixed(4);
// Draw network line with unique color
const line = L.polyline([network.from, conn.to], {
color: networkColor,
weight: 3,
opacity: 0.95,
dashArray: '5, 10'
});
line.bindPopup(
'<strong>' + network.from_name + '</strong><br>' +
'⇄ shares data with ⇄<br>' +
'<strong>' + conn.to_name + '</strong>'
);
state.linesLayer.addLayer(line);
state.networkLines.push(line);
// Check if this destination is a camera we already have
const destMarker = state.allMarkers[destKey];
if (destMarker) {
// It's a camera - show it
destMarker.marker.addTo(state.map);
} else {
// It's a police station or unknown location - create marker dynamically
policeStationsShown = true;
const policeMarker = L.circleMarker([conn.to[0], conn.to[1]], {
radius: 6,
fillColor: '#00ff00',
color: '#fff',
weight: 2,
opacity: 1,
fillOpacity: 0.8
});
const popup = `<strong>📍 ${conn.to_name}</strong><br>
<span style="color: #666; font-size: 12px;">Receives data from Flock camera network</span>`;
policeMarker.bindPopup(popup);
policeMarker.addTo(state.map);
state.networkLines.push(policeMarker); // Store for cleanup
}
});
// Show police station legend item if any police stations were displayed
if (policeStationsShown) {
document.getElementById('legend-police').style.display = 'flex';
}
console.log('Showing network:', network.connections.length, 'connections');
}
function updateNetworkDetailsPanel(network, networkColor) {
// Hide default notice, show network details
document.getElementById('defaultNotice').style.display = 'none';
document.getElementById('networkDetails').style.display = 'block';
// Update title with color indicator
document.getElementById('networkTitle').innerHTML =
'📹 ' + network.from_name +
' <span style="display: inline-block; width: 12px; height: 12px; background: ' + networkColor +
'; border-radius: 50%; margin-left: 8px; vertical-align: middle;"></span>';
// Build connections list
let html = '';
html += '<div style="margin-bottom: 12px;">';
html += '<strong style="color: ' + networkColor + ';">Total Connections: ' + network.connections.length + '</strong>';
html += '</div>';
html += '<div style="max-height: 400px; overflow-y: auto; background: rgba(255,255,255,0.05); padding: 10px; border-radius: 4px;">';
html += '<div style="font-weight: 600; margin-bottom: 8px; color: #ccc;">Data Sharing With:</div>';
network.connections.forEach((conn, idx) => {
html += '<div style="padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,0.1);">';
html += '<div style="color: #fff; font-weight: 500;">' + (idx + 1) + '. ' + conn.to_name + '</div>';
html += '<div style="color: #999; font-size: 11px; margin-top: 2px;">📍 ' + conn.to[0].toFixed(4) + ', ' + conn.to[1].toFixed(4) + '</div>';
html += '</div>';
});
html += '</div>';
document.getElementById('networkInfo').innerHTML = html;
}
function showAllLines() {
clearLines();
console.log('Drawing ALL network lines progressively...');
// Show loading indicator
document.getElementById('loadingStatus').style.display = 'block';
document.getElementById('loadingText').textContent = 'Drawing network lines...';
let networkIndex = 0;
const batchSize = 500; // Draw 500 lines at a time
function drawBatch() {
const endIndex = Math.min(networkIndex + batchSize, state.networkData.length);
for (let i = networkIndex; i < endIndex; i++) {
const network = state.networkData[i];
if (network.connections) {
// Generate unique color for this network
const networkColor = getNetworkColor(network.from[0], network.from[1], network.from_name);
network.connections.forEach(conn => {
const line = L.polyline([network.from, conn.to], {
color: networkColor,
weight: 2,
opacity: 0.65,
dashArray: '5, 10'
});
state.linesLayer.addLayer(line);
state.networkLines.push(line);
});
}
}
networkIndex = endIndex;
// Update progress
const progress = Math.round((networkIndex / state.networkData.length) * 100);
document.getElementById('loadingText').textContent = `Drawing network lines... ${progress}%`;
if (networkIndex < state.networkData.length) {
// Continue drawing in next frame
setTimeout(drawBatch, 10);
} else {
// Done
document.getElementById('loadingStatus').style.display = 'none';