-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapTitleCard.html
More file actions
140 lines (125 loc) · 4.42 KB
/
mapTitleCard.html
File metadata and controls
140 lines (125 loc) · 4.42 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Upper Arlington Title Card – Dark</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="https://api.mapbox.com/mapbox-gl-js/v3.3.0/mapbox-gl.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
<script src="https://api.mapbox.com/mapbox-gl-js/v3.3.0/mapbox-gl.js"></script>
<script src="https://unpkg.com/@turf/turf@^7/turf.min.js"></script>
<style>
html,body,#container,#map{margin:0;padding:0;height:100%;width:100%;}
/* ――― Popup dark shell ――― */
.mapboxgl-popup{
font:12px/20px 'Roboto',sans-serif;
background:#1c1f24; /* 📌 CHANGED */
color:#fff; /* 🆕 force white text */
box-shadow:0 0 10px rgba(0,0,0,.4); /* stronger shadow on dark */
width:175px;
z-index:9999;
padding:0;margin:0;
}
.mapboxgl-popup .mapboxgl-popup-tip{display:none;}
.mapboxgl-popup-close-button{
top:2px;right:4px;width:10px;height:10px;
color:#fff; /* 📌 CHANGED */
}
.mapboxgl-popup-header{margin:0;font-size:16px;font-weight:700;padding:5px;}
.mapboxgl-popup-content{
font-size:12px;line-height:1.25;
background:#272b31; /* 📌 CHANGED */
color:#d0d4db; /* light-grey body text */
padding:8px;margin-left:0;
}
</style>
</head>
<body>
<div id="container"><div id="map"></div></div>
<script>
/* ―― constants ―― */
const INITIAL_LOC = [-83.22, 40.04];
const INITIAL_ZOOM = 10.9;
const communityScaleGray = "#9aa4b1"; /* lighter stroke for dark bg 📌 CHANGED */
const placeOfInterest = "Upper Arlington";
mapboxgl.accessToken =
'pk.eyJ1IjoiZW10em90MDEiLCJhIjoiY20zZ2kyd3RpMDRnajJscHoyMG5neGJldyJ9.poXi4pgd2CoXKV2B4kg1Cw';
const map = new mapboxgl.Map({
container:'map',
style:'mapbox://styles/mapbox/dark-v11', /* 📌 CHANGED to Mapbox Dark */
center: INITIAL_LOC,
zoom: INITIAL_ZOOM
});
map.on('load', () => {
/* —— GeoJSON source —— */
map.addSource('ohioPlaces',{
type:'geojson',
data:'https://raw.githubusercontent.com/emtzot/mapSources/main/ohioPlacesCensus2020.geojson',
promoteId:'GEOID'
});
/* —— base fill layer —— */
map.addLayer({
id:'places-layer',
type:'fill',
source:'ohioPlaces',
paint:{
'fill-color':'#38424d', /* 🆕 muted slate */
'fill-opacity':[
'case',['boolean',['feature-state','hover'],false],0.7,0.25]
}
},'settlement-major-label');
/* —— outlines —— */
map.addLayer({
id:'places-boundaries',
type:'line',
source:'ohioPlaces',
paint:{
'line-color':communityScaleGray,
'line-width':1.2,
'line-opacity':0.6 /* 📌 dark-friendly */
}
},'settlement-major-label');
/* —— highlight UA —— */
map.addLayer({
id:'placeOfInterest-layer',
type:'fill',
source:'ohioPlaces',
filter:['==','NAME',placeOfInterest],
paint:{
'fill-color':communityScaleGray,
'fill-opacity':0.5
}
},'settlement-major-label');
});
/* —— hover state —— */
let hoveredPlaceId=null;
map.on('mousemove','places-layer',e=>{
if(e.features.length){
if(hoveredPlaceId!==null){
map.setFeatureState({source:'ohioPlaces',id:hoveredPlaceId},{hover:false});
}
hoveredPlaceId=e.features[0].id;
map.setFeatureState({source:'ohioPlaces',id:hoveredPlaceId},{hover:true});
}
});
map.on('mouseleave','places-layer',()=>{
if(hoveredPlaceId!==null){
map.setFeatureState({source:'ohioPlaces',id:hoveredPlaceId},{hover:false});
}
hoveredPlaceId=null;
});
/* —— click popup —— */
map.on('click',e=>{
const [selected]=map.queryRenderedFeatures(e.point,{layers:['places-layer']});
if(selected){
new mapboxgl.Popup({closeButton:true})
.setLngLat(selected.geometry.coordinates[0][0])
.setHTML(`
<div class="mapboxgl-popup-header">${selected.properties.NAME}</div>
`)
.addTo(map);
}
});
</script>
</body>
</html>