up josm remote link
This commit is contained in:
parent
df001ab7ff
commit
725c6eff2f
47
js/editor.js
47
js/editor.js
@ -7,17 +7,47 @@
|
||||
* Envoyer les bornes de recharge de la zone visible à JOSM
|
||||
* @param {*} map
|
||||
*/
|
||||
function sendToJOSM(map) {
|
||||
const bounds = map.getBounds();
|
||||
const bbox = `${bounds.getWest()},${bounds.getSouth()},${bounds.getEast()},${bounds.getNorth()}`;
|
||||
function sendToJOSM(map, geojson_points) {
|
||||
console.log('geojson_points',geojson_points);
|
||||
|
||||
const josmUrl = `http://127.0.0.1:8111/load_and_zoom?left=${bounds.getWest()}&right=${bounds.getEast()}&top=${bounds.getNorth()}&bottom=${bounds.getSouth()}&select=node[amenity=charging_station]`;
|
||||
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('Données envoyées à JOSM avec succès !');
|
||||
} else {
|
||||
if (! response.ok) {
|
||||
alert('Erreur : JOSM doit être ouvert avec l\'option "Contrôle à distance" activée');
|
||||
}
|
||||
})
|
||||
@ -42,6 +72,9 @@ function createJOSMEditLink(feature) {
|
||||
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
|
||||
}
|
||||
|
26
js/main.js
26
js/main.js
@ -509,12 +509,19 @@ function onMapMoveEnd() {
|
||||
let center = map.getCenter()
|
||||
let zoom = map.getZoom()
|
||||
let infos = `Lat: ${center.lat}, Lon: ${center.lng}, Zoom : ${zoom}`
|
||||
|
||||
if (zoom < 10) {
|
||||
$('#zoomMessage').show()
|
||||
} else {
|
||||
$('#zoomMessage').hide()
|
||||
loadOverpassQuery()
|
||||
}
|
||||
if (map.getZoom() > 14) {
|
||||
searchFoodPlaces(map);
|
||||
} else {
|
||||
food_places_markers.clearLayers();
|
||||
}
|
||||
|
||||
$('#infos_carte').html(infos)
|
||||
// Stocker les dernières coordonnées connues
|
||||
if (!window.lastKnownPosition) {
|
||||
@ -673,17 +680,16 @@ function init() {
|
||||
|
||||
L.control.layers(null, overlayMaps).addTo(map);
|
||||
|
||||
// Ajouter l'événement de recherche sur le déplacement de la carte
|
||||
map.on('moveend', function() {
|
||||
if (map.getZoom() > 13) { // Ajuster le niveau de zoom selon vos besoins
|
||||
searchFoodPlaces(map);
|
||||
} else {
|
||||
food_places_markers.clearLayers();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
document.getElementById('sendToJOSM').addEventListener('click', () => {
|
||||
sendToJOSM(map);
|
||||
$('#sendToJOSM').on('click', () => {
|
||||
sendToJOSM(map, geojsondata)
|
||||
.then(() => {
|
||||
console.log('Données envoyées à JOSM avec succès !');
|
||||
})
|
||||
.catch(() => {
|
||||
alert('Erreur : JOSM doit être ouvert avec l\'option "Contrôle à distance" activée');
|
||||
});
|
||||
});
|
||||
|
||||
$('#searchButton').on('click', searchLocation);
|
||||
|
Loading…
Reference in New Issue
Block a user