up
This commit is contained in:
parent
a17fd9c232
commit
8bce5fe21c
14 changed files with 628 additions and 634 deletions
73
assets/josm.js
Normal file
73
assets/josm.js
Normal file
|
@ -0,0 +1,73 @@
|
|||
|
||||
|
||||
/**
|
||||
* Ouvre les éléments sélectionnés dans JOSM
|
||||
* @param {Object} map - L'instance de la carte MapLibre
|
||||
* @param {boolean} map_is_loaded - État de chargement de la carte
|
||||
* @param {Array|Object} osmElements - Élément(s) OSM à ouvrir (peut être un tableau d'objets ou un objet unique)
|
||||
* @returns {void}
|
||||
*/
|
||||
function openInJOSM(map, map_is_loaded, osmElements) {
|
||||
if (!map_is_loaded) {
|
||||
alert('Veuillez attendre que la carte soit chargée');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!osmElements || (Array.isArray(osmElements) && osmElements.length === 0)) {
|
||||
alert('Aucun élément à ouvrir dans JOSM');
|
||||
return;
|
||||
}
|
||||
|
||||
const bounds = map.getBounds();
|
||||
|
||||
// Convertir en tableau si c'est un seul élément
|
||||
const elements = Array.isArray(osmElements) ? osmElements : [osmElements];
|
||||
|
||||
// Séparer les éléments par type
|
||||
const nodeIds = [];
|
||||
const wayIds = [];
|
||||
const relationIds = [];
|
||||
|
||||
elements.forEach(element => {
|
||||
if (typeof element === 'string') {
|
||||
// Si c'est juste un ID, on le traite comme un node par défaut
|
||||
nodeIds.push(element);
|
||||
} else {
|
||||
// Sinon on utilise le type spécifié
|
||||
switch (element.osm_type) {
|
||||
case 'node':
|
||||
nodeIds.push(element.osm_id);
|
||||
break;
|
||||
case 'way':
|
||||
wayIds.push(element.osm_id);
|
||||
break;
|
||||
case 'relation':
|
||||
relationIds.push(element.osm_id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Construire les paramètres de sélection
|
||||
const selectParams = [];
|
||||
if (nodeIds.length > 0) selectParams.push(`node${nodeIds.join(',')}`);
|
||||
if (wayIds.length > 0) selectParams.push(`way${wayIds.join(',')}`);
|
||||
if (relationIds.length > 0) selectParams.push(`relation${relationIds.join(',')}`);
|
||||
|
||||
// Construire l'URL JOSM avec les paramètres de la boîte englobante
|
||||
const josmUrl = `http://localhost:8111/load_and_zoom?` +
|
||||
`left=${bounds.getWest()}&` +
|
||||
`right=${bounds.getEast()}&` +
|
||||
`top=${bounds.getNorth()}&` +
|
||||
`bottom=${bounds.getSouth()}&` +
|
||||
`select=${selectParams.join(',')}`;
|
||||
|
||||
// Utiliser le bouton caché pour ouvrir JOSM
|
||||
const josmButton = document.getElementById('josmButton');
|
||||
if (!josmButton) {
|
||||
console.error('Le bouton JOSM n\'existe pas dans le DOM');
|
||||
return;
|
||||
}
|
||||
josmButton.href = josmUrl;
|
||||
josmButton.click();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue