1// Objeto neoMap para la gestión del mapa 2var neoMap = { 3 map: null, 4 lat: 42.3441186, 5 lng: -3.7358927, 6 zoom: 13, 7 currentPopup: null, // Variable para rastrear el popup actualmente abierto 8 9 // Inicializa el mapa 10 init: function (ajaxHotels) { 11 if ($("#interactive-map__map").length != 0) { 12 this.map = L.map('interactive-map__map', { 13 scrollWheelZoom: false 14 }).setView([this.lat, this.lng], this.zoom); 15 16 L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { 17 attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' 18 }).addTo(this.map); 19 20 this.initializeBookingHotelsMarkers(ajaxHotels.hotel); // Carga los marcadores 21 this.initializeBookingHotelsMarkers(globals.cmsMapsHotels); // Carga los marcadores CMS 22 } 23 }, 24 25 // Inicializa los marcadores en el mapa de los hoteles del motor 26 initializeBookingHotelsMarkers: function (hotels) { 27 var self = this; 28 29 if(hotels.length == 0) { 30 return; 31 } 32 33 // Verificar si hotels es un array o un solo objeto 34 if (Array.isArray(hotels)) {
35 hotels.forEach(function (hotel) { 36 self.createMarker(hotel); 37 }); 38 } else { 39 self.createMarker(hotels); 40 } 41 }, 42 43 // Crea un marcador en el mapa 44 createMarker: function (hotel) { 45 var self = this; 46 var name = hotel.name; 47 var address = hotel.address; 48 var phone = hotel.phone; 49 var latitud = parseFloat(hotel.latitude); 50 var longitud = parseFloat(hotel.longitude); 51 var id = hotel["@attributes"] ? hotel["@attributes"].id : undefined; 52 var image = this.getImageTag(hotel.pictures.picture); 53 var link = ''; 54 55 if (isNaN(latitud) || isNaN(longitud)) { 56 return; 57 } 58 59 //Comprueba si el hotel se recibe del motor o del CMS a partir del id (CMS --> undefined / Motor --> No undefined) 60 if (id === undefined) { // CMS 61 image = hotel.pictures; 62 if (image != '' && image != undefined) { 63 image = '<img src="' + hotel.pictures + '" loading="lazy" class="interactive-map__hotel-image" alt="hotel image"/>'; 64 } 65 66 //Se implementa el enlace a la página del Hotel si hay una relacionada activa 67 var seo = hotel.seo; 68 if (seo != '') { 69 link = `<a href='/${seo}' class='interactive-map__hotel__content__link'>${globals.common["booking"]}</a>`; 70 } 71 } 72 else { //MOTOR 73 link = `<a href='${globals.common["bookingStep1"]}${id}' class='interactive-map__hotel__content__link' target='_blank'>${globals.common["booking"]}</a>`; 74 } 75 76 var contentHTML = ` 77 <div class='interactive-map__hotel__content'> 78 <span class='interactive-map__hotel__content__name'>${name}</span> 79 <span class='interactive-map__hotel__content__address'>${address}</span> 80 <span class='interactive-map__hotel__content__Via Romana, 8, 07800 Eivissa, Illes Balearsphone'>${phone}</span> 81 ${link} 82 </div>`; 83 84 var hotelBlock = `<div class='interactive-map__hotel'>${image}${contentHTML}</div>`; 85 86 // Crear el marcador 87 var marker = L.marker([latitud, longitud]).addTo(this.map).bindPopup(hotelBlock); 88 89 // Abrir el popup al hacer clic en el marcador 90 marker.on('click', function (e) { 91 self.handleMarkerClick(e.target.getPopup()); // Pasa el popup como argumento 92 }); 93 }, 94 95 // Maneja el clic en un marcador 96 handleMarkerClick: function (popup) { 97 if (this.currentPopup) { 98 this.currentPopup.closePopup(); 99 } 100 101 this.currentPopup = popup; 102 popup.openPopup(); 103 }, 104 105 // Crea una etiqueta de imagen HTML para la primera imagen del hotel 106 getImageTag: function (picture) { 107 let imageSrc; 108 109 if (Array.isArray(picture)) { 110 imageSrc = picture[0]["@attributes"]["thumb"]; 111 } else if (typeof picture !== "undefined") { 112 imageSrc = picture["@attributes"]["thumb"]; 113 } 114 115 if (imageSrc) { 116 // Reemplazar la cadena en la variable imageSrc 117 imageSrc = imageSrc.replace("images.neobookings", "images2.neobookings"); 118 119 return `<img src="${imageSrc}" loading="lazy" class="interactive-map__hotel-image" alt="hotel image"/>`; 120 } 121 122 return ""; 123 } 124};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.