185 lines
3.9 KiB
JavaScript
185 lines
3.9 KiB
JavaScript
// public/js/mapPhotosLayer.js
|
|
// ===============================
|
|
// LAYER MAPPA FOTO
|
|
// ===============================
|
|
|
|
(function () {
|
|
let visiblePhotoMarkers = new Map();
|
|
|
|
window.photoMapDebug = {
|
|
cacheSize() {
|
|
return PhotoMarkerFactory.size();
|
|
},
|
|
|
|
visibleSize() {
|
|
return visiblePhotoMarkers.size;
|
|
},
|
|
|
|
clearCache() {
|
|
PhotoMarkerFactory.clear();
|
|
visiblePhotoMarkers.clear();
|
|
},
|
|
};
|
|
|
|
// ===============================
|
|
// APRI FOTO
|
|
// ===============================
|
|
window.openPhotoMapItem = function (item) {
|
|
const thumb = toAbsoluteUrl(
|
|
item.thub1 || item.thub2 || item.path,
|
|
item.name,
|
|
"thumbs",
|
|
item.cartella,
|
|
);
|
|
|
|
const original = toAbsoluteUrl(
|
|
item.path,
|
|
item.name,
|
|
"original",
|
|
item.cartella,
|
|
);
|
|
|
|
window.openModal(item);
|
|
//window.openModal?.(original, thumb, item);
|
|
};
|
|
|
|
// ===============================
|
|
// RENDER FOTO
|
|
// ===============================
|
|
window.renderPhotoMapLayer = function () {
|
|
if (!window.globalMap) {
|
|
return;
|
|
}
|
|
|
|
if (!window.MapEngine?.isReady?.()) {
|
|
console.warn("[mapPhotosLayer] MapEngine non pronto");
|
|
return;
|
|
}
|
|
|
|
const bounds = window.globalMap.getBounds();
|
|
|
|
if (!MapSpatialIndex.isBuilt()) {
|
|
MapSpatialIndex.build(getLocalItems());
|
|
}
|
|
|
|
const items = MapSpatialIndex.search(bounds);
|
|
|
|
const markers = [];
|
|
|
|
for (const entry of items) {
|
|
const lat = entry.lat;
|
|
const lng = entry.lng;
|
|
|
|
const photo = entry.item;
|
|
|
|
if (!Number.isFinite(lat) || !Number.isFinite(lng)) {
|
|
continue;
|
|
}
|
|
|
|
const marker = PhotoMarkerFactory.get(photo);
|
|
|
|
markers.push(marker);
|
|
}
|
|
|
|
visiblePhotoMarkers = MapLayerManager.sync(
|
|
window.globalMarkers,
|
|
visiblePhotoMarkers,
|
|
markers,
|
|
);
|
|
|
|
if (window.MapTerrain3D?.enabled?.()) {
|
|
const features = window.getPhotoMapGeoJSON?.() || [];
|
|
window.MapboxMarkers?.setPhotos(features);
|
|
}
|
|
|
|
console.log(
|
|
"[mapPhotosLayer]",
|
|
"visibili:",
|
|
visiblePhotoMarkers.size,
|
|
"cache:",
|
|
PhotoMarkerFactory.size(),
|
|
"indice:",
|
|
items.length,
|
|
);
|
|
};
|
|
|
|
// ===============================
|
|
// GEOJSON PER MAPBOX
|
|
// ===============================
|
|
window.getPhotoMapGeoJSON = function () {
|
|
if (!MapSpatialIndex.isBuilt()) {
|
|
MapSpatialIndex.build(getLocalItems());
|
|
}
|
|
|
|
const features = [];
|
|
|
|
let items = [];
|
|
|
|
/*
|
|
if (window.MapEngine?.isMapbox?.()) {
|
|
items = MapSpatialIndex.search({
|
|
getWest: () => -180,
|
|
getEast: () => 180,
|
|
getSouth: () => -90,
|
|
getNorth: () => 90,
|
|
});
|
|
} else {
|
|
const bounds = window.MapEngine?.getBounds?.();
|
|
|
|
items = bounds
|
|
? MapSpatialIndex.search(bounds)
|
|
: [];
|
|
}
|
|
*/
|
|
const bounds = window.MapEngine?.getBounds?.();
|
|
|
|
items = bounds ? MapSpatialIndex.search(bounds) : [];
|
|
|
|
console.log("[PhotoGeoJSON DEBUG bounds]", {
|
|
west: bounds?.getWest?.(),
|
|
east: bounds?.getEast?.(),
|
|
south: bounds?.getSouth?.(),
|
|
north: bounds?.getNorth?.(),
|
|
});
|
|
|
|
console.log("[PhotoGeoJSON DEBUG items]", items.length);
|
|
|
|
for (const entry of items) {
|
|
const lat = entry.lat;
|
|
const lng = entry.lng;
|
|
|
|
const photo = entry.item;
|
|
|
|
if (!Number.isFinite(lat) || !Number.isFinite(lng)) {
|
|
continue;
|
|
}
|
|
|
|
features.push({
|
|
type: "Feature",
|
|
geometry: {
|
|
type: "Point",
|
|
coordinates: [lng, lat],
|
|
},
|
|
/* properties: {
|
|
id: photo.id,
|
|
type: "photo",
|
|
name: photo.name || "",
|
|
},*/
|
|
properties: {
|
|
id: photo.id,
|
|
type: "photo",
|
|
name: photo.name || "",
|
|
|
|
thumb: toAbsoluteUrl(
|
|
photo.thub1 || photo.thub2 || photo.path,
|
|
photo.name,
|
|
"thumbs",
|
|
photo.cartella,
|
|
),
|
|
},
|
|
});
|
|
}
|
|
|
|
return features;
|
|
};
|
|
})();
|