diff --git a/src/js/elevation-line-control.js b/src/js/elevation-line-control.js index 01ceec07..d99e8aad 100644 --- a/src/js/elevation-line-control.js +++ b/src/js/elevation-line-control.js @@ -125,7 +125,11 @@ class ElevationLineControl { if (lastLngLat != null) { currentDistance += currentLngLat.distanceTo(lastLngLat); } - let currentDataPoint = {x: currentDistance, y: elevation.z} + let elevationValue = elevation.z; + if (elevationValue == -99999) { + elevationValue = 0; + } + let currentDataPoint = {x: currentDistance, y: elevationValue} this.elevationData.push(currentDataPoint); lastLngLat = currentLngLat; }); diff --git a/src/js/my-position.js b/src/js/my-position.js index d97e17d6..26d05830 100644 --- a/src/js/my-position.js +++ b/src/js/my-position.js @@ -80,6 +80,25 @@ class Position { var longitude = this.coordinates.lon; var altitude = this.elevation; + // adresse disponible + var templateAddress = ` + ${address.number} ${address.street}
+ ${address.postcode} ${address.city} + ` + // pas d'adresse + if (!address.street) { + templateAddress = ` + ${address.city} ${address.postcode} + ` + } + // Ni adress ni poi + if (!address.city) { + templateAddress = ` + ${latitude}, ${longitude} + ` + } + + // template litteral this.contentPopup = `
@@ -88,8 +107,7 @@ class Position {
- ${address.number} ${address.street}
- ${address.postcode} ${address.city} + ${templateAddress}
@@ -112,6 +130,13 @@ class Position { // message var message = `${self.address.number} ${self.address.street}, ${self.address.postcode} ${self.address.city} (latitiude: ${self.coordinates.lat} / longitude: ${self.coordinates.lon} / altitude: ${self.elevation} m)`; + if (!address.street) { + message = `${self.address.city} ${self.address.postcode} + (latitiude: ${self.coordinates.lat} / longitude: ${self.coordinates.lon} / altitude: ${self.elevation} m)`; + } + if (!address.city) { + message = `latitiude: ${self.coordinates.lat} / longitude: ${self.coordinates.lon} / altitude: ${self.elevation} m`; + } // redirection vers... if (self.isDesktop()) { window.open(`https://api.whatsapp.com:/send?text= ${message}`); @@ -130,8 +155,7 @@ class Position {
- ${address.number} ${address.street}
- ${address.postcode} ${address.city} + ${templateAddress}
diff --git a/src/js/services/elevation.js b/src/js/services/elevation.js index 92fb8c00..48b7aeda 100644 --- a/src/js/services/elevation.js +++ b/src/js/services/elevation.js @@ -13,8 +13,8 @@ const target = new EventTarget(); /** * service - * @param {*} coordinates - * @returns + * @param {*} coordinates + * @returns * @fire elevation */ const compute = async (coordinates) => { @@ -62,12 +62,15 @@ const compute = async (coordinates) => { return results; }; -/** +/** * obtenir la valeur Z * @example * { lon lat } */ const getElevation = () => { + if (results.elevations[0] == -99999) { + return 0; + } return results.elevations[0]; }; @@ -80,4 +83,4 @@ export default { target, compute, getElevation -}; \ No newline at end of file +}; diff --git a/src/js/services/reverse.js b/src/js/services/reverse.js index 4df279fe..2e63129f 100644 --- a/src/js/services/reverse.js +++ b/src/js/services/reverse.js @@ -25,10 +25,11 @@ const compute = async (coordinates) => { let url = new URL("https://data.geopf.fr/geocodage/reverse"); let params = { - index: "address", + index: "address,poi", searchgeom: `{"type":"Circle","coordinates":[${coordinates.lon},${coordinates.lat}],"radius":100}`, lon: coordinates.lon, - lat: coordinates.lat + lat: coordinates.lat, + limit: 1, }; Object.keys(params).forEach(key => url.searchParams.append(key, params[key])); @@ -39,18 +40,42 @@ const compute = async (coordinates) => { if (response.status !== 200) { throw new Error(response.message); } + let number = ""; + let street = ""; + let postcode = ""; + let city = ""; + let lon = coordinates.lon; + let lat = coordinates.lat; + + if (geojson.features[0]) { + if (geojson.features[0].properties._type === "address") { + if (geojson.features[0].properties.housenumber) { + number = geojson.features[0].properties.housenumber; + } + street = geojson.features[0].properties.street; + postcode = geojson.features[0].properties.postcode; + city = geojson.features[0].properties.city; + } else if (geojson.features[0] && geojson.features[0].properties._type === "poi") { + city = geojson.features[0].properties.toponym; + if (geojson.features[0].properties.postcode) { + postcode = geojson.features[0].properties.postcode[0]; + } + } + lon = geojson.features[0].geometry.coordinates[0]; + lat = geojson.features[0].geometry.coordinates[1]; + } var address = { - number : geojson.features[0].properties.housenumber, - street : geojson.features[0].properties.street, - postcode : geojson.features[0].properties.postcode, - city : geojson.features[0].properties.city + number : number, + street : street, + postcode : postcode, + city : city, }; results = { coordinates : { - lon : geojson.features[0].geometry.coordinates[0], - lat : geojson.features[0].geometry.coordinates[1] + lon : lon, + lat : lat, }, address : address, }; @@ -93,4 +118,4 @@ export default { compute, getCoordinates, getAddress -}; \ No newline at end of file +};