48 lines
1.6 KiB
PHP
48 lines
1.6 KiB
PHP
/**
|
|
* This file is part of Zwii.
|
|
*
|
|
* For full copyright and license information, please see the LICENSE
|
|
* file that was distributed with this source code.
|
|
*
|
|
* @author Rémi Jean <remi.jean@outlook.com>
|
|
* @copyright Copyright (C) 2008-2018, Rémi Jean
|
|
* @author Frédéric Tempez <frederic.tempez@outlook.com>
|
|
* @copyright Copyright (C) 2018-2024, Frédéric Tempez
|
|
* @license CC Attribution-NonCommercial-NoDerivatives 4.0 International
|
|
* @link http://zwiicms.fr/
|
|
*/
|
|
|
|
// Créer une carte Leaflet centrée sur une position par défaut
|
|
var map = L.map('map').setView([0, 0], 2);
|
|
|
|
// Ajouter une couche de tuiles OpenStreetMap à la carte
|
|
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
|
}).addTo(map);
|
|
|
|
// Récupérer les données JSON des positions des images
|
|
var jsonData = "<?php echo json_encode($imageData); ?>";
|
|
jsonData = JSON.parse(jsonData);
|
|
|
|
// Créer un tableau pour stocker les marqueurs des images
|
|
var markers = [];
|
|
|
|
// Parcourir les données JSON et ajouter des marqueurs pour chaque image
|
|
jsonData.images.forEach(function(image) {
|
|
var marker = L.marker([image.lat, image.lng]).addTo(map);
|
|
markers.push(marker);
|
|
});
|
|
|
|
// Calculer la moyenne des positions des images
|
|
var sumLat = 0;
|
|
var sumLng = 0;
|
|
jsonData.images.forEach(function(image) {
|
|
sumLat += image.lat;
|
|
sumLng += image.lng;
|
|
});
|
|
var avgLat = sumLat / jsonData.images.length;
|
|
var avgLng = sumLng / jsonData.images.length;
|
|
|
|
// Centrer la carte sur la moyenne des positions des images
|
|
map.setView([avgLat, avgLng]);
|