-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathus-map.html
More file actions
116 lines (102 loc) · 3.47 KB
/
us-map.html
File metadata and controls
116 lines (102 loc) · 3.47 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Interactive U.S. Map</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<style>
html, body {
height: 100%;
margin: 0;
background-color: #0f172a;
}
#us-map {
height: 100%;
width: 100%;
}
.leaflet-container {
font-family: 'Inter', sans-serif;
}
.custom-label {
font-weight: bold;
font-size: 0.85rem;
background: white;
padding: 2px 6px;
border-radius: 6px;
color: black;
box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
</style>
</head>
<body>
<div id="us-map"></div>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script>
// Initialize map
const map = L.map('us-map').setView([39.5, -98.35], 4);
// ✅ Remove Leaflet logo and Ukraine flag from attribution
map.attributionControl.setPrefix(false);
// Add OpenStreetMap tile layer with required attribution
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: '© <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap contributors</a>'
}).addTo(map);
// Load and render U.S. state borders
fetch('https://raw.githubusercontent.com/PublicaMundi/MappingAPI/master/data/geojson/us-states.json')
.then(res => res.json())
.then(data => {
L.geoJSON(data, {
style: {
color: '#38bdf8',
weight: 1,
fillColor: '#1e3a8a',
fillOpacity: 0.5
},
onEachFeature: (feature, layer) => {
const stateName = feature.properties.name;
const link = stateName.toLowerCase().replace(/ /g, '-') + '.html';
layer.bindTooltip(stateName); // Show full name on hover
layer.on('click', () => {
window.open(link, '_blank');
});
layer.on('mouseover', function () {
this.setStyle({ fillOpacity: 0.7 });
});
layer.on('mouseout', function () {
this.setStyle({ fillOpacity: 0.5 });
});
}
}).addTo(map);
});
// Marker data
const stateMarkers = [
{ name: "Wisconsin", abbr: "WI", lat: 44.5, lng: -89.5 },
{ name: "Illinois", abbr: "IL", lat: 40.0, lng: -89.0 },
{ name: "Iowa", abbr: "IA", lat: 42.0, lng: -93.0 },
{ name: "Colorado", abbr: "CO", lat: 39.0, lng: -105.5 },
{ name: "Nebraska", abbr: "NE", lat: 41.5, lng: -99.5 },
{ name: "Utah", abbr: "UT", lat: 39.3, lng: -111.5 },
{ name: "California", abbr: "CA", lat: 37.2, lng: -119.0 },
{ name: "Nevada", abbr: "NV", lat: 39.5, lng: -116.8 },
{ name: "New York", abbr: "NY", lat: 43.0, lng: -75.0 },
{ name: "Florida", abbr: "FL", lat: 27.7, lng: -81.5 },
{ name: "Michigan", abbr: "MI", lat: 44.0, lng: -85.5 },
{ name: "Indiana", abbr: "IN", lat: 39.9, lng: -86.3 }
];
// Add hover-only tooltips and clickable markers
stateMarkers.forEach(state => {
const marker = L.marker([state.lat, state.lng]).addTo(map);
marker.bindTooltip(`<div class="custom-label">${state.abbr}</div>`, {
permanent: false, // show only on hover
direction: 'top',
offset: [0, -10]
});
marker.on('click', () => {
const link = state.name.toLowerCase().replace(/ /g, '-') + '.html';
window.open(link, '_blank');
});
});
</script>
</body>
</html>