Tout marche !

This commit is contained in:
Fred Tempez 2024-08-07 21:52:59 +02:00
parent 31b31ce99e
commit 95fb2d6fab
3 changed files with 28 additions and 58 deletions

View File

@ -353,8 +353,8 @@ class geogallery extends common
// Données géographiques // Données géographiques
foreach ((array) $this->getInput('legend', null) as $file => $data) { foreach ((array) $this->getInput('legend', null) as $file => $data) {
$geo[str_replace('.', '', $file)] = [ $geo[str_replace('.', '', $file)] = [
'long' => $this->getInput('gpslong[' . $file . ']'), 'long' => $this->getInput('gpslong[' . $file . ']', helper::FILTER_FLOAT),
'lat' => $this->getInput('gpslat[' . $file . ']') 'lat' => $this->getInput('gpslat[' . $file . ']', helper::FILTER_FLOAT)
]; ];
} }
// Sauvegarder // Sauvegarder
@ -493,7 +493,7 @@ class geogallery extends common
$iterator = new DirectoryIterator($directory); $iterator = new DirectoryIterator($directory);
foreach ($iterator as $fileInfos) { foreach ($iterator as $fileInfos) {
if ($fileInfos->isDot() === false and $fileInfos->isFile() and @getimagesize($fileInfos->getPathname())) { if ($fileInfos->isDot() === false and $fileInfos->isFile() and @getimagesize($fileInfos->getPathname())) {
self::$galleries[$directory . '/' . $fileInfos->getFilename()] = $this->getData(['module', $this->getUrl(0), 'content', $gallery, 'legend', str_replace('.', '', $fileInfos->getFilename())]);
// Créer la miniature si manquante // Créer la miniature si manquante
if (!file_exists(str_replace('source', 'thumb', $fileInfos->getPath()) . '/' . self::THUMBS_SEPARATOR . strtolower($fileInfos->getFilename()))) { if (!file_exists(str_replace('source', 'thumb', $fileInfos->getPath()) . '/' . self::THUMBS_SEPARATOR . strtolower($fileInfos->getFilename()))) {
$this->makeThumb( $this->makeThumb(
@ -504,11 +504,18 @@ class geogallery extends common
} }
$exif = exif_read_data($fileInfos->getPath() . '/' . $fileInfos->getFilename()); $exif = exif_read_data($fileInfos->getPath() . '/' . $fileInfos->getFilename());
// Vérifier si les données EXIF contiennent des informations de géolocalisation // Vérifier si les données EXIF contiennent des informations de géolocalisation
if (!empty($exif['GPSLatitude']) && !empty($exif['GPSLongitude'])) { if (!empty($exif['GPSLatitude']) || !empty($exif['GPSLongitude'])) {
// Coordonnées // Coordonnées
self::$galleries[$directory . '/' . $fileInfos->getFilename()] = [ self::$galleries[] = [
'lat' => $this->gps_decimal($exif['GPSLatitude'], $exif['GPSLatitudeRef']), 'lat' => $this->gps_decimal($exif['GPSLatitude'], $exif['GPSLatitudeRef']),
'long' => $this->gps_decimal($exif['GPSLongitude'], $exif['GPSLatitudeRef']) 'long' => $this->gps_decimal($exif['GPSLongitude'], $exif['GPSLatitudeRef']),
'thumb' => str_replace('source', 'thumb', $fileInfos->getPath()) . '/' . self::THUMBS_SEPARATOR . strtolower($fileInfos->getFilename())
];
} else {
self::$galleries[] = [
'lat' => $this->getData(['module', $this->getUrl(0), 'content', $gallery, 'positions', 'directory', str_replace('.', '', $fileInfos->getFilename())]) ,
'long' => $this->getData(['module', $this->getUrl(0), 'content', $gallery, 'positions', 'directory', str_replace('.', '', $fileInfos->getFilename())]),
'thumb' => str_replace('source', 'thumb', $fileInfos->getPath()) . '/' . self::THUMBS_SEPARATOR . strtolower($fileInfos->getFilename())
]; ];
} }

View File

@ -12,54 +12,21 @@
* @link http://zwiicms.fr/ * @link http://zwiicms.fr/
*/ */
// Récupérer les données JSON des positions des images // Initialisation de la carte
var jsonData = "<?php echo json_encode($module::$galleries); ?>"; var map = L.map('map').setView([51.505, -0.09], 2);
jsonData = JSON.parse(jsonData);
// Initialize the map // Ajouter une couche de tuiles OpenStreetMap
var map = L.map('map').setView([51.505, -0.09], 5); L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
// Add OpenStreetMap tile layer // Les données PHP converties en JSON pour JavaScript
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { const json = '<?php echo json_encode($module::$galleries); ?>';
maxZoom: 19, const obj = JSON.parse(json);
}).addTo(map);
// Helper function to create a popup content
function createPopupContent(image, legend, directory) { // Ajouter les marqueurs à la carte
var imageUrl = directory + '/' + image; obj.forEach(function(location) {
var legendText = legend[image.replace('.jpg', 'jpg')]; var marker = L.marker([location.lat, location.long]).addTo(map);
return ` marker.bindPopup('<img src="' + location.thumb + '" alt="Thumbnail" style="width:100px;height:auto;"><br>Latitude: ' + location.lat + '<br>Longitude: ' + location.long);
<div> });
<img src="${imageUrl}" alt="${legendText}" style="width: 100px; height: auto;" />
<p>${legendText}</p>
</div>
`;
}
// Loop through each geotag dataset
for (var key in jsonData) {
if (jsonData.hasOwnProperty(key)) {
var gallery = jsonData[key];
var directory = gallery.config.directory;
var legend = gallery.legend;
var positions = gallery.positions;
// Loop through each image position
for (var image in positions) {
if (positions.hasOwnProperty(image)) {
var position = positions[image];
var lat = parseFloat(position.lat);
var long = parseFloat(position.long);
// Create a marker
var marker = L.marker([lat, long]).addTo(map);
// Create popup content
var popupContent = createPopupContent(image, legend, directory);
// Bind the popup to the marker
marker.bindPopup(popupContent);
}
}
}
}

View File

@ -1,8 +1,4 @@
<?php if ($module::$galleries): ?> <?php if ($module::$galleries): ?>
<pre>
<?php ;
var_dump($module::$galleries); ?>
</pre>
<div id="map"></div> <div id="map"></div>
<?php else: ?> <?php else: ?>
<?php echo template::speech('Aucune galerie'); ?> <?php echo template::speech('Aucune galerie'); ?>