server_photo_s85js/public/js/map/photos/photoSource.js.ok2
2026-08-11 08:45:04 +02:00

107 lines
1.9 KiB
Text

// public/js/map/photos/photoSource.js
// ===================================
// PHOTO SOURCE
// ===================================
(() => {
"use strict";
function createPhotoSource(map, features = []) {
if (!map) {
return null;
}
const data = {
type: "FeatureCollection",
features,
};
const existingSource = map.getSource("photos");
if (existingSource) {
existingSource.setData(data);
return existingSource;
}
map.addSource("photos", {
type: "geojson",
data,
cluster: true,
clusterRadius: 80,
});
return map.getSource("photos");
}
function updatePhotoSource(map, features = []) {
if (!map) {
return;
}
if (!map.isStyleLoaded()) {
return;
}
const source = map.getSource("photos");
const data = {
type: "FeatureCollection",
features,
};
if (source) {
source.setData(data);
return;
}
createPhotoSource(map, features);
}
function getPhotoSource(map) {
if (!map) {
return null;
}
return map.getSource("photos") || null;
}
function getPhotoSourceFeatures(map) {
const source = getPhotoSource(map);
if (!source) {
return [];
}
return source._data?.features || [];
}
function getPhotoSourceClusters(map) {
if (!map) {
return [];
}
return map.querySourceFeatures("photos", {
filter: ["has", "point_count"],
});
}
function getPhotoSourcePoints(map) {
if (!map) {
return [];
}
return map.querySourceFeatures("photos", {
filter: ["!", ["has", "point_count"]],
});
}
window.PhotoSource = {
create: createPhotoSource,
update: updatePhotoSource,
get: getPhotoSource,
getFeatures: getPhotoSourceFeatures,
getClusters: getPhotoSourceClusters,
getPoints: getPhotoSourcePoints,
};
})();