function emoji_icon(emoji) { var iconStyle = "
" + emoji + "
"; return L.divIcon({ className: 'custom-div-icon', html: iconStyle, iconSize: [60, 60], iconAnchor: [15, 15], }); } var icons = { "station": emoji_icon("🚉"), "airport": emoji_icon("✈️"), "accommodation": emoji_icon("🏨"), "conference": emoji_icon("🎤"), } 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: '© OpenStreetMap contributors' }).addTo(map); // Add markers with appropriate icons to the map coordinates.forEach(function(item) { var marker = L.marker([item.latitude, item.longitude], { icon: icons[item.type] }).addTo(map); marker.bindPopup(item.name); }); // Draw routes routes.forEach(function(route) { var color = {"train": "blue", "flight": "red"}[route.type]; var style = { weight: 3, opacity: 0.5, color: color }; if (route.geojson) { // If route is defined as GeoJSON L.geoJSON(JSON.parse(route.geojson), { style: function(feature) { return style; } }).addTo(map); } else if (route.type === "flight") { var flightPath = new L.Geodesic([[route.from, route.to]], style).addTo(map); } else { // If route is defined by 'from' and 'to' coordinates L.polyline([route.from, route.to], style).addTo(map); } }); return map; }