77 lines
1.4 KiB
JavaScript
77 lines
1.4 KiB
JavaScript
// public/js/map/markerFactory.js
|
|
// ===============================
|
|
// FACTORY MARKER FOTO
|
|
// ===============================
|
|
|
|
(function () {
|
|
"use strict";
|
|
|
|
const photoMarkerCache = new Map();
|
|
|
|
function createPhotoIcon(photo) {
|
|
const thumb = toAbsoluteUrl(
|
|
photo.thub1 || photo.thub2 || photo.path,
|
|
photo.name,
|
|
"thumbs",
|
|
photo.cartella,
|
|
);
|
|
|
|
return L.icon({
|
|
iconUrl: thumb,
|
|
iconSize: [46, 46],
|
|
iconAnchor: [23, 23],
|
|
className: "photo-marker",
|
|
});
|
|
}
|
|
|
|
function getPhotoMarker(photo) {
|
|
let marker = photoMarkerCache.get(photo.id);
|
|
|
|
if (marker) {
|
|
return marker;
|
|
}
|
|
|
|
const lat = Number(photo.gps.lat);
|
|
const lng = Number(photo.gps.lng);
|
|
|
|
marker = L.marker([lat, lng], {
|
|
icon: createPhotoIcon(photo),
|
|
title: photo.display_name || photo.name || "",
|
|
});
|
|
|
|
marker.__item = photo;
|
|
|
|
marker.__thumb = toAbsoluteUrl(
|
|
photo.thub1 || photo.thub2 || photo.path,
|
|
photo.name,
|
|
"thumbs",
|
|
photo.cartella,
|
|
);
|
|
|
|
marker.on("click", () => {
|
|
window.openPhotoMapItem(photo);
|
|
});
|
|
|
|
photoMarkerCache.set(photo.id, marker);
|
|
|
|
return marker;
|
|
}
|
|
|
|
window.PhotoMarkerFactory = {
|
|
|
|
get(photo) {
|
|
return getPhotoMarker(photo);
|
|
},
|
|
|
|
clear() {
|
|
photoMarkerCache.clear();
|
|
},
|
|
|
|
size() {
|
|
return photoMarkerCache.size;
|
|
},
|
|
|
|
};
|
|
|
|
})();
|
|
|