mirror of
https://forge.chapril.org/tykayn/libre-charge-map
synced 2025-06-20 01:34:43 +02:00
refacto naming exports js librechargemap with lcm_ prefix
This commit is contained in:
parent
7100bc1d52
commit
c194a858b1
8 changed files with 110 additions and 95 deletions
85
js/lcm_editor.js
Normal file
85
js/lcm_editor.js
Normal file
|
@ -0,0 +1,85 @@
|
|||
/**
|
||||
* Fonctions liées à l'édition des données OSM et à l'interaction avec JOSM
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Envoyer les bornes de recharge de la zone visible à JOSM
|
||||
* @param {*} map
|
||||
*/
|
||||
function sendToJOSM(map, geojson_points) {
|
||||
console.log('geojson_points',geojson_points);
|
||||
|
||||
const center = map.getCenter();
|
||||
const centerLat = center.lat;
|
||||
const centerLng = center.lng;
|
||||
|
||||
// Conversion approximative de 1 mètre en degrés (varie selon la latitude)
|
||||
const meterInDegrees = 0.00001;
|
||||
|
||||
const minLat = centerLat - meterInDegrees;
|
||||
const maxLat = centerLat + meterInDegrees;
|
||||
const minLng = centerLng - meterInDegrees;
|
||||
const maxLng = centerLng + meterInDegrees;
|
||||
|
||||
const bbox = `${minLng},${minLat},${maxLng},${maxLat}`;
|
||||
// Construire la chaîne de sélection pour tous les nodeIds de stations de recharge
|
||||
let selectString = '';
|
||||
if (geojson_points && geojson_points.features) {
|
||||
selectString = geojson_points.features
|
||||
.map(feature => `&select=${feature.properties.id}`)
|
||||
.join('');
|
||||
|
||||
}
|
||||
const josmUrl = `http://127.0.0.1:8111/load_and_zoom?layer_name=bornes%20de%20recharge%20depuis%20OSM&left=${minLng}&right=${maxLng}&top=${maxLat}&bottom=${minLat}&select=node[amenity=charging_station]${selectString}`;
|
||||
// Construire l'URL pour la requête Overpass
|
||||
const overpassQuery = `[out:json][timeout:25];
|
||||
(
|
||||
node[amenity=charging_station](${minLat},${minLng},${maxLat},${maxLng});
|
||||
);
|
||||
out body;`;
|
||||
|
||||
const overpassUrl = `https://overpass-api.de/api/interpreter?data=${encodeURIComponent(overpassQuery)}`;
|
||||
|
||||
// Construire l'URL JOSM avec la requête Overpass
|
||||
const josmUrlWithOverpass = `${josmUrl}&url=${encodeURIComponent(overpassUrl)}`;
|
||||
console.log('josmUrl', josmUrl);
|
||||
|
||||
fetch(josmUrl)
|
||||
.then(response => {
|
||||
if (! response.ok) {
|
||||
alert('Erreur : JOSM doit être ouvert avec l\'option "Contrôle à distance" activée');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Erreur JOSM:', error);
|
||||
alert('Erreur : JOSM doit être ouvert avec l\'option "Contrôle à distance" activée');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
const margin_josm_bbox = 0.00001
|
||||
|
||||
/**
|
||||
* lien pour éditer une station de recharge dans JOSM
|
||||
* @param {*} feature
|
||||
* @returns
|
||||
*/
|
||||
function createJOSMEditLink(feature) {
|
||||
var coordinates = feature.geometry.coordinates
|
||||
var nodeId = feature.properties.id
|
||||
var left = coordinates[0] - margin_josm_bbox
|
||||
var right = coordinates[0] + margin_josm_bbox
|
||||
var bottom = coordinates[1] - margin_josm_bbox
|
||||
var top = coordinates[1] + margin_josm_bbox
|
||||
// Ajouter le filtre pour ne charger que les stations de recharge
|
||||
|
||||
// var josmUrl = `http://127.0.0.1:8111/load_and_zoom?changeset_hashtags=IRVE&layer_name=irve-depuis-OSM&left=${left}&top=${top}&right=${right}&bottom=${bottom}&select=node[amenity=charging_station]`
|
||||
var josmUrl = `http://127.0.0.1:8111/load_and_zoom?changeset_hashtags=IRVE&layer_name=irve-depuis-OSM&left=${left}&top=${top}&right=${right}&bottom=${bottom}&select=${nodeId}`
|
||||
return josmUrl
|
||||
}
|
||||
|
||||
export {
|
||||
sendToJOSM,
|
||||
createJOSMEditLink
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue