2024-01-14 12:01:33 +00:00
|
|
|
function emoji_icon(emoji) {
|
2024-01-14 21:28:56 +00:00
|
|
|
var iconStyle = "<div style='background-color: white; border-radius: 50%; width: 30px; height: 30px; display: flex; justify-content: center; align-items: center; border: 1px solid black;'> <div style='font-size: 18px;'>" + emoji + "</div></div>";
|
|
|
|
|
2024-01-14 12:01:33 +00:00
|
|
|
return L.divIcon({
|
|
|
|
className: 'custom-div-icon',
|
2024-01-14 21:28:56 +00:00
|
|
|
html: iconStyle,
|
|
|
|
iconSize: [60, 60],
|
|
|
|
iconAnchor: [15, 15],
|
2024-01-14 12:01:33 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-01-14 21:00:19 +00:00
|
|
|
var icons = {
|
|
|
|
"station": emoji_icon("🚉"),
|
|
|
|
"airport": emoji_icon("✈️"),
|
|
|
|
"accommodation": emoji_icon("🏨"),
|
2024-01-14 21:43:10 +00:00
|
|
|
"conference": emoji_icon("🎤"),
|
2024-01-14 21:00:19 +00:00
|
|
|
}
|
2024-01-14 12:01:33 +00:00
|
|
|
|
|
|
|
function build_map(map_id, coordinates, routes) {
|
|
|
|
// Initialize the map
|
|
|
|
var map = L.map(map_id).fitBounds(coordinates.map(function(station) {
|
|
|
|
return [station.latitude, station.longitude];
|
|
|
|
}));
|
|
|
|
|
|
|
|
// Set up the tile layer
|
|
|
|
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
|
|
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
|
|
|
}).addTo(map);
|
|
|
|
|
|
|
|
// Add markers with appropriate icons to the map
|
|
|
|
coordinates.forEach(function(item) {
|
2024-01-14 21:00:19 +00:00
|
|
|
var marker = L.marker([item.latitude, item.longitude], { icon: icons[item.type] }).addTo(map);
|
2024-01-14 12:01:33 +00:00
|
|
|
marker.bindPopup(item.name);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Draw routes
|
|
|
|
routes.forEach(function(route) {
|
2024-01-14 16:50:16 +00:00
|
|
|
var color = {"train": "blue", "flight": "red"}[route.type];
|
|
|
|
var style = { weight: 3, opacity: 0.5, color: color };
|
2024-01-14 12:01:33 +00:00
|
|
|
if (route.geojson) {
|
|
|
|
// If route is defined as GeoJSON
|
|
|
|
L.geoJSON(JSON.parse(route.geojson), {
|
2024-01-14 16:50:16 +00:00
|
|
|
style: function(feature) { return style; }
|
2024-01-14 12:01:33 +00:00
|
|
|
}).addTo(map);
|
|
|
|
} else if (route.type === "flight") {
|
2024-01-14 16:50:16 +00:00
|
|
|
var flightPath = new L.Geodesic([[route.from, route.to]], style).addTo(map);
|
2024-01-14 12:01:33 +00:00
|
|
|
} else {
|
|
|
|
// If route is defined by 'from' and 'to' coordinates
|
2024-01-14 16:50:16 +00:00
|
|
|
L.polyline([route.from, route.to], style).addTo(map);
|
2024-01-14 12:01:33 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return map;
|
|
|
|
}
|