1,983 CRIMES22 CAMERAS
' +
'
OPEN CASE →
' +
''
);
crimeLayer.addLayer(m);
});
}
function addCameras(items){
items.forEach(function(cam){
if (cam.lat == null || cam.lon == null || cam.lat === 0 || cam.lon === 0) return;
var m = L.circleMarker([cam.lat, cam.lon], {
radius: 8, color: '#ffffff', fillColor: '#a0e4ff', fillOpacity: 0.95, weight: 2, opacity: 1, interactive: true, bubblingMouseEvents: false,
});
var name = String(cam.locationName || cam.nearbyPlace || 'Caltrans CCTV').replace(/' +
'' + name + '' +
'' +
'OPEN LIVE FEED →
' +
''
);
cameraLayer.addLayer(m);
});
}
function addAlpr(items){
items.forEach(function(cam){
if (cam.lat == null || cam.lon == null || cam.lat === 0 || cam.lon === 0) return;
var color = cam.isFlock ? '#ff3b30' : '#ff9500';
var m = L.circleMarker([cam.lat, cam.lon], {
radius: 5, color: color, fillColor: color, fillOpacity: 0.9, weight: 1.5, opacity: 1, interactive: true, bubblingMouseEvents: false,
});
var kind = String(cam.kind || '').replace(/' +
'' + title + '' +
(meta ? '' : '') +
(direction ? 'Facing: ' + direction + '°
' : '') +
'' +
''
);
alprLayer.addLayer(m);
});
}
fetch('/api/crimes?limit=2000').then(function(r){ return r.json(); }).then(function(d){
if (d && Array.isArray(d.items)) addCrimes(d.items);
}).catch(function(){});
fetch('/api/cameras').then(function(r){ return r.json(); }).then(function(d){
if (d && Array.isArray(d.items)) addCameras(d.items);
}).catch(function(){});
fetch('/api/alpr').then(function(r){ return r.json(); }).then(function(d){
if (d && Array.isArray(d.cameras)) addAlpr(d.cameras);
}).catch(function(){});
var crimeBtn = document.getElementById('nsmap-toggle-crime');
var camBtn = document.getElementById('nsmap-toggle-cam');
var alprBtn = document.getElementById('nsmap-toggle-alpr');
if (crimeBtn) crimeBtn.addEventListener('click', function(){
var on = this.getAttribute('aria-pressed') === 'true';
if (on) { map.removeLayer(crimeLayer); this.setAttribute('aria-pressed', 'false'); }
else { map.addLayer(crimeLayer); this.setAttribute('aria-pressed', 'true'); }
});
if (camBtn) camBtn.addEventListener('click', function(){
var on = this.getAttribute('aria-pressed') === 'true';
if (on) { map.removeLayer(cameraLayer); this.setAttribute('aria-pressed', 'false'); }
else { map.addLayer(cameraLayer); this.setAttribute('aria-pressed', 'true'); }
});
if (alprBtn) alprBtn.addEventListener('click', function(){
var on = this.getAttribute('aria-pressed') === 'true';
if (on) { map.removeLayer(alprLayer); this.setAttribute('aria-pressed', 'false'); }
else { map.addLayer(alprLayer); this.setAttribute('aria-pressed', 'true'); }
});
}
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init);
else init();
})();
