## Leaflet.js maps ### Basic map setup ```html
``` ### Map application with clustering ```javascript // js/app.js class MapApp { constructor() { this.map = null; this.markers = null; this.data = []; this.filters = { year: null, county: null, status: null }; } async init() { this.setupMap(); await this.loadData(); this.renderMarkers(); this.setupFilters(); } setupMap() { // Initialize map centered on NJ this.map = L.map('map', { center: [40.0583, -74.4057], zoom: 8, scrollWheelZoom: false, // Disable mouse wheel zoom zoomControl: false // We'll add custom controls }); // Add tile layer (CARTO Voyager) L.tileLayer('https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}{r}.png', { attribution: '© OpenStreetMap, © CARTO', maxZoom: 19 }).addTo(this.map); // Add custom zoom control (top-right) L.control.zoom({ position: 'topright' }).addTo(this.map); // Initialize marker cluster group this.markers = L.markerClusterGroup({ spiderfyOnMaxZoom: true, showCoverageOnHover: false, maxClusterRadius: 50, spiderLegPolylineOptions: { weight: 1.5, color: '#2dc8d2' } }); this.map.addLayer(this.markers); } async loadData() { const response = await fetch('data/grantees.json'); this.data = await response.json(); } renderMarkers() { this.markers.clearLayers(); const filtered = this.data.filter(item => { if (this.filters.year && item.year !== this.filters.year) return false; if (this.filters.county && item.county !== this.filters.county) return false; if (this.filters.status && item.status !== this.filters.status) return false; return true; }); filtered.forEach(item => { if (!item.lat || !item.lng) return; const marker = L.marker([item.lat, item.lng], { icon: this.createIcon(item.status) }); marker.bindPopup(this.createPopup(item)); this.markers.addLayer(marker); }); // Update count display document.getElementById('count').textContent = filtered.length; } createIcon(status) { const colors = { 'Active': '#2dc8d2', 'Completed': '#666666', 'Pending': '#f34213' }; return L.divIcon({ html: ``, className: 'custom-marker', iconSize: [16, 16], iconAnchor: [8, 8] }); } createPopup(item) { return `${item.county} County
${item.description || ''}