Display elevation APi button only if coordinates are valids

This commit is contained in:
Léo Serre 2021-05-19 23:09:01 +02:00
parent 1c90c9ddab
commit 4816d14faa
2 changed files with 10 additions and 5 deletions

View File

@ -37,7 +37,7 @@
<input type="text" value="<?=$poi->lat?>" name="lat" id="lat" placeholder="Latitude">
<input type="text" value="<?=$poi->lon?>" name="lon" id="lon" placeholder="Longitude">
<input type="text" value="<?=$poi->ele?>" name="ele" id="ele" placeholder="Altitude">
<div id="elevation_icon" title="Calculer l'altitude"><i class="fas fa-search-location"></i></div>
<div id="elevation_icon" style="display:none;" title="Calculer l'altitude"><i class="fas fa-search-location"></i></div>
</div>
<input name="submit" id="submit" type="submit" value="Ajouter l'hébergement">

View File

@ -46,16 +46,22 @@ $( document ).ready(function() {
poi_layer.bindTooltip("Glissez moi au bon endroit.", {permanent: true, direction: 'auto'}).openTooltip();
mymap.on('click', function(e){
poi_layer.unbindTooltip();
poi_layer.setLatLng(e.latlng);
$("#lat").val(e.latlng.lat.toFixed(6));
$("#lon").val(e.latlng.lng.toFixed(6));
})
poi_layer.on('move', function(e){
poi_layer.unbindTooltip();
$("#lat").val(e.latlng.lat.toFixed(6));
$("#lon").val(e.latlng.lng.toFixed(6));
$("#elevation_icon").show();
})
$("#lat,#lon").change(function() { // If the user changes the lat/lon input values manualy
if(isNaN($("#lat").val()) || isNaN($("#lon").val()) || $("#lat").val().length==0 || $("#lon").val()==null)
$("#elevation_icon").hide();
else {
$("#elevation_icon").show();
poi_layer.setLatLng([$("#lat").val(),$("#lon").val()]);
}
});
var poiicon = L.icon({
iconSize: [24, 24],
@ -66,7 +72,6 @@ $( document ).ready(function() {
poiicon.options.iconUrl = e.currentTarget.firstChild.currentSrc;
poi_layer.setIcon(poiicon);
})
$("#elevation_icon").click(function(e) {
$(this).find($(".fas")).removeClass('fa-search-location').addClass('fa-spinner').addClass('fa-spin');
$.get("./elevation_proxy", {location:$("#lat").val()+","+$("#lon").val()}, function(result){