-
Notifications
You must be signed in to change notification settings - Fork 1
/
western-attractions.html
98 lines (79 loc) · 3.46 KB
/
western-attractions.html
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
<!DOCTYPE html>
<html>
<head>
<title>Western Attractions</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
<link href="https://unpkg.com/[email protected]/dist/leaflet.css" rel="stylesheet"/>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src="https://d3js.org/d3.v3.min.js"></script>
<style>
html, body {
margin: 20px;
}
p {
font-size: 10;
font-weight: normal;
}
#westernAttractionsMap {
width: 800px;
height: 500px;
}
</style>
</head>
<body>
<div id="westernAttractionsMap"></div>
<script>
let westernAttractionsMap = L.map('westernAttractionsMap').setView([40.84706,-93.25195], 4);
L.tileLayer('https://api.mapbox.com/styles/v1/mapbox/light-v9/tiles/256/{z}/{x}/{y}?access_token=YOUR_MAPBOX_ACCESS_TOKEN', {
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
minZoom: 3,
maxZoom: 18,
zoomControl: false,
id: 'mapbox.streets'
}).addTo(westernAttractionsMap);
d3.json('western_attractions_geocoded.geojson', function(error, westernAttractionsData) {
let myStyle = {};
function onEachFeature(feature, layer) {
let popupContent = "<p style=color:" + color_state(feature.properties.state) + ";\">" +
(feature.properties.title != null ? capitalizeWords(feature.properties.title) : "") +
"<br>" +
(feature.properties.cost != null ? feature.properties.cost : "") +
"<br>" +
(feature.properties.address_geo != null ? feature.properties.address_geo : "") +
"<br>" +
(feature.properties.website != null ? "<a href='" + feature.properties.website + "'>" + feature.properties.website + "</a>" : "") + "</p>";
if (feature.properties && feature.properties.popupContent) {
popupContent += feature.properties.popupContent;
}
layer.bindPopup(popupContent);
}
L.geoJSON(westernAttractionsData, {
style: myStyle,
onEachFeature: onEachFeature,
}).addTo(westernAttractionsMap);
});
function capitalizeWords(str) {
return str.replace(/\w\S*/g, function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
}
function color_state(state) {
switch (state) {
case 'AZ': return "Blue";
case 'CA': return "Crimson";
case 'CO': return "DarkGreen";
case 'ID': return "DarkOrange";
case 'MT': return "DarkSlateBlue";
case 'NM': return "ForestGreen";
case 'NV': return "Gold";
case 'OR': return "HotPink";
case 'UT': return "MediumOrchid";
case 'WA': return "YellowGreen";
case 'WY': return "Sienna";
}
}
</script>
</body>
</html>