69,7 → 69,12 |
TbPlaces.prototype.launchSearch = function () { |
if (!!this.places.val()) { |
const url = NOMINATIM_OSM_URL+'search', |
params = {'q': this.places.val()}; |
params = { |
'q': this.places.val(), |
'format': 'json', |
'polygon_geojson': 1, |
'zoom': 17 |
}; |
|
this.placeLabel.addClass('loading'); |
$.ajax({ |
117,15 → 122,21 |
} |
} |
}); |
this.placesResultsContainer.removeClass('hidden'); |
if(0 < acceptedSuggestions.length) { |
this.placesResultsContainer.removeClass('hidden'); |
} else { |
this.resetPlacesSearch(); |
} |
}; |
|
TbPlaces.prototype.validateSuggestionData = function(suggestion) { |
const validGeometry = undefined !== suggestion.lat && undefined !== suggestion.lon, |
typeLocalisation = this.places.data('typeLocalisation') || '', |
validGeometryType = 'rue' === typeLocalisation ? 'LineString' === suggestion?.geojson.type : true, |
validAddressData = undefined !== suggestion.address, |
validDisplayName = undefined !== suggestion['display_name']; |
|
return (validGeometry && validAddressData && validDisplayName); |
return (validGeometry && validGeometryType && validAddressData && validDisplayName); |
}; |
|
TbPlaces.prototype.onSuggestionSelected = function() { |
138,6 → 149,8 |
evt.preventDefault(); |
|
lthis.places.val($thisSuggestion.text()); |
|
suggestion.geojson.coordinates = lthis.formatCoordinatesArray(suggestion.geojson); |
lthis.clientCallback(suggestion); |
lthis.placesCloseButton.trigger('click'); |
|
163,6 → 176,22 |
}); |
}; |
|
TbPlaces.prototype.formatCoordinatesArray = function(geojson) { |
const coordinatesArray = geojson.coordinates, |
geojsonType = geojson.type, |
coordinatesArrayLength = coordinatesArray.length; |
|
if ('Point' === geojsonType) { |
coordinatesArray.reverse(); |
} else if (0 > coordinatesArrayLength) { |
for (let i = 0; i <= coordinatesArrayLength; i++) { |
coordinatesArray[i].reverse(); |
} |
} |
|
return coordinatesArray; |
} |
|
TbPlaces.prototype.resetOnClick = function () { |
const lthis = this; |
|
182,12 → 211,12 |
if (0 === $('#tb-places-error').length) { |
this.places.closest('#tb-places-zone').after( |
`<span id="tb-places-error" class="error mb-3 mt-3"> |
Votre recherche n’a rien donné.<br>veuillez modifier votre recherche ou rechercher votre station directement sur la carte. |
Votre recherche n’a pas donné de résultat pour le moment.<br>Vous pouvez soit poursuivre ou modifier votre recherche,<br>soit rechercher votre station directement sur la carte. |
</span>` |
); |
setTimeout(function() { |
$('#tb-places-error').remove(); |
}, 5000); |
}, 10000); |
} |
}; |
|