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
|
* Envoyer les bornes de recharge de la zone visible à JOSM
|
||||||
* @param {*} map
|
* @param {*} map
|
||||||
*/
|
*/
|
||||||
function sendToJOSM(map) {
|
function sendToJOSM(map, geojson_points) {
|
||||||
const bounds = map.getBounds();
|
console.log('geojson_points',geojson_points);
|
||||||
const bbox = `${bounds.getWest()},${bounds.getSouth()},${bounds.getEast()},${bounds.getNorth()}`;
|
|
||||||
|
|
||||||
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)
|
fetch(josmUrl)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.ok) {
|
if (! response.ok) {
|
||||||
alert('Données envoyées à JOSM avec succès !');
|
|
||||||
} else {
|
|
||||||
alert('Erreur : JOSM doit être ouvert avec l\'option "Contrôle à distance" activée');
|
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 right = coordinates[0] + margin_josm_bbox
|
||||||
var bottom = coordinates[1] - margin_josm_bbox
|
var bottom = coordinates[1] - margin_josm_bbox
|
||||||
var top = 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}`
|
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
|
return josmUrl
|
||||||
}
|
}
|
||||||
|
26
js/main.js
26
js/main.js
@ -509,12 +509,19 @@ function onMapMoveEnd() {
|
|||||||
let center = map.getCenter()
|
let center = map.getCenter()
|
||||||
let zoom = map.getZoom()
|
let zoom = map.getZoom()
|
||||||
let infos = `Lat: ${center.lat}, Lon: ${center.lng}, Zoom : ${zoom}`
|
let infos = `Lat: ${center.lat}, Lon: ${center.lng}, Zoom : ${zoom}`
|
||||||
|
|
||||||
if (zoom < 10) {
|
if (zoom < 10) {
|
||||||
$('#zoomMessage').show()
|
$('#zoomMessage').show()
|
||||||
} else {
|
} else {
|
||||||
$('#zoomMessage').hide()
|
$('#zoomMessage').hide()
|
||||||
loadOverpassQuery()
|
loadOverpassQuery()
|
||||||
}
|
}
|
||||||
|
if (map.getZoom() > 14) {
|
||||||
|
searchFoodPlaces(map);
|
||||||
|
} else {
|
||||||
|
food_places_markers.clearLayers();
|
||||||
|
}
|
||||||
|
|
||||||
$('#infos_carte').html(infos)
|
$('#infos_carte').html(infos)
|
||||||
// Stocker les dernières coordonnées connues
|
// Stocker les dernières coordonnées connues
|
||||||
if (!window.lastKnownPosition) {
|
if (!window.lastKnownPosition) {
|
||||||
@ -673,17 +680,16 @@ function init() {
|
|||||||
|
|
||||||
L.control.layers(null, overlayMaps).addTo(map);
|
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').on('click', () => {
|
||||||
sendToJOSM(map);
|
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);
|
$('#searchButton').on('click', searchLocation);
|
||||||
|
Loading…
Reference in New Issue
Block a user