-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
170 lines (158 loc) · 5.3 KB
/
index.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Travel Map</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" />
<link rel="stylesheet" href="Leaflet.BigImage.min.css">
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
#map {
width: 100%;
height: 100vh;
}
.legend {
background-color: white;
padding: 10px;
font-size: 14px;
line-height: 18px;
color: #555;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}
.legend i {
width: 18px;
height: 18px;
display: inline-block;
margin-right: 8px;
opacity: 0.7;
}
.legend label {
display: block;
}
.export-btn {
position: absolute;
top: 10px;
left: 10px;
padding: 10px 20px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
z-index: 1000;
}
.export-btn:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<div id="map"></div>
<!-- Include Leaflet and Leaflet.BigImage -->
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
<script src="Leaflet.BigImage.min.js"></script>
<script>
// Initialize the map
var map = L.map('map').setView([51.505, 10.09], 4); // Centered in Europe
// Using OpenStreetMap tiles to avoid CORS issues
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
L.control.bigImage({position: 'bottomleft'}).addTo(map);
// Color scheme based on visit count
function getColor(visits) {
if (visits === 0 || visits == null) {
return '#d3d3d3';
} else if (visits === 1) {
return '#ffeda0';
} else if (visits === 2) {
return '#feb24c';
} else if (visits === 3) {
return '#fd8d3c';
} else if (visits <= 6) {
return '#f03b20';
} else {
return '#bd0026';
}
}
// Style function for each country
function style(feature) {
var visits = feature.properties.visits || 0;
return {
fillColor: getColor(visits),
weight: 2,
opacity: 1,
color: 'white',
dashArray: '3',
fillOpacity: 0.7
};
}
// Function to set the number of visits and update the map
function setVisits(countryId, visits) {
geojsonLayer.eachLayer(function (layer) {
if (layer.feature.properties.id === countryId) {
layer.feature.properties.visits = visits;
layer.setStyle(style(layer.feature));
localStorage.setItem('country_' + countryId, visits);
layer.closePopup();
}
});
}
// When a country is clicked, allow the user to select how many times they visited
function onEachFeature(feature, layer) {
layer.on({
click: function (e) {
var popupContent = '<div><strong>' + feature.properties.name + '</strong><br>' +
'How many times have you visited?<br>' +
'<button onclick="setVisits(' + feature.properties.id + ', 0)">No visits</button><br>' +
'<button onclick="setVisits(' + feature.properties.id + ', 1)">1 visit</button><br>' +
'<button onclick="setVisits(' + feature.properties.id + ', 2)">2 visits</button><br>' +
'<button onclick="setVisits(' + feature.properties.id + ', 3)">3 visits</button><br>' +
'<button onclick="setVisits(' + feature.properties.id + ', 4)">4-6 visits</button><br>' +
'<button onclick="setVisits(' + feature.properties.id + ', 7)">More than 6 visits</button>' +
'</div>';
layer.bindPopup(popupContent).openPopup();
}
});
}
// Load GeoJSON data and add to the map
var geojsonUrl = 'https://raw.githubusercontent.com/datasets/geo-boundaries-world-110m/master/countries.geojson';
var geojsonLayer;
fetch(geojsonUrl)
.then(response => response.json())
.then(data => {
data.features.forEach((feature, index) => {
feature.properties.id = index;
var savedVisits = localStorage.getItem('country_' + feature.properties.id);
if (savedVisits !== null) {
feature.properties.visits = parseInt(savedVisits);
}
});
geojsonLayer = L.geoJson(data, {
style: style,
onEachFeature: onEachFeature
}).addTo(map);
});
// Custom Legend Control
var legend = L.control({ position: 'topright' });
legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'legend');
div.innerHTML = '<b>Visits:</b><br>' +
'<label><i style="background:#d3d3d3"></i> None</label>' +
'<label><i style="background:#ffeda0"></i> 1x</label>' +
'<label><i style="background:#feb24c"></i> 2x</label>' +
'<label><i style="background:#fd8d3c"></i> 3x</label>' +
'<label><i style="background:#f03b20"></i> 4-6x</label>' +
'<label><i style="background:#bd0026"></i> >6x</label>';
return div;
};
legend.addTo(map);
</script>
</body>
</html>