/trunk/widget/modules/saisie/squelettes/js/tb-geoloc/js/modules/Locality.js |
---|
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 |
} |
} |
}); |
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); |
} |
}; |
/trunk/widget/modules/saisie/squelettes/js/tb-geoloc/js/Geoloc.js |
---|
408,7 → 408,9 |
url: url, |
data: params, |
success: function(locationData) { |
lthis.loadGeolocation(coordinates,locationData,polyline); |
locationData.centroid = lthis.formatPointTypeCoordinates(coordinates); |
locationData.geojson = 'rue' === lthis.geometryFilter ? {type: 'LineString', coordinates: polyline} : locationData.centroid; |
lthis.loadGeolocation(coordinates,locationData); |
}, |
error: (err) => { |
console.warn(err); |
417,7 → 419,11 |
}); |
}; |
Geoloc.prototype.loadGeolocation = function(coordinates,locationData,polyline) { |
Geoloc.prototype.formatPointTypeCoordinates = function(coordinates) { |
return {type : 'Point', coordinates: Object.values(coordinates)}; |
}; |
Geoloc.prototype.loadGeolocation = function(coordinates,locationData) { |
const lthis = this, |
query = { |
'lat': coordinates.lat, |
430,7 → 436,7 |
data: query, |
success: function (geoLocationData) { |
lthis.triggerLocationEvent( |
lthis.formatLocationEventObject(coordinates,geoLocationData,locationData,polyline) |
lthis.formatLocationEventObject(locationData,geoLocationData) |
); |
lthis.geolocLabel.classList.remove('loading'); |
}, |
442,17 → 448,15 |
}; |
Geoloc.prototype.triggerLocationEvent = function (locationDataObject) { |
const location = new CustomEvent('location', {detail: locationDataObject}); |
const locationEvent = new CustomEvent('location', {detail: locationDataObject}); |
this.mapEl.dispatchEvent(location); |
this.mapEl.dispatchEvent(locationEvent); |
}; |
Geoloc.prototype.formatLocationEventObject = function(coordinates,geoLocationData,locationData,polyline) { |
Geoloc.prototype.formatLocationEventObject = function(locationData,geoLocationData) { |
const detail = { |
centroid: { |
type: 'Point', |
coordinates: Object.values(coordinates) |
}, |
centroid: locationData.centroid, |
geometry: locationData.geojson, |
elevation: geoLocationData.altitude, |
inseeData: { |
code: geoLocationData.code_zone, |
470,18 → 474,9 |
osmPlaceId: locationData.place_id |
}; |
if (0 < polyline.length) { |
detail.geometry = { |
type: 'LineString', |
coordinates: polyline |
return detail; |
}; |
} else { |
detail.geometry = detail.centroid; |
} |
return detail; |
} |
Geoloc.prototype.handleCoordinates = function() { |
if (!!this.latitudeEl.value && !!this.longitudeEl.value) { |
this.handleNewLocation({ |
513,17 → 508,28 |
const locality = this.getLocalityFromData(localityData); |
if(!!locality) { |
const coordinates = { |
const coordinates = this.formatCoordinates({ |
'lat' : localityData.lat, |
'lng' : localityData.lon |
}; |
}); |
if(!!coordinates && !!coordinates.lat && !!coordinates.lng) { |
this.zoom = 20; |
this.setMapCoordinates(coordinates); |
if ('point' === this.geometryFilter) { |
this.map.removeControl(this.drawControl); |
this.createDraggableMarker(); |
this.handleMarkerEvents(); |
} |
this.zoom = 18; |
this.handleNewLocation(coordinates); |
localityData.centroid = this.formatPointTypeCoordinates(coordinates); |
if('rue' !== this.geometryFilter && 'Polygon' === localityData.geojson.type ) { |
localityData.geojson = localityData.centroid; |
} |
this.loadGeolocation(coordinates,localityData); |
} |
} |
}; |
Geoloc.prototype.getLocalityFromData = function(localityData) { |
/trunk/widget/modules/saisie/squelettes/saisie.tpl.html |
---|
224,7 → 224,7 |
<div class="form-col search-container"> |
<label for="tb-places" >Trouver un lieu</label> |
<div class="input-search-container"> |
<input id="tb-places" class="tb-places" type="search" name="tb-places" placeholder="Recherchez une adresse ou une ville" autocomplete="off"> |
<input id="tb-places" class="tb-places" type="search" name="tb-places" placeholder="Recherchez une <?php echo 'rue' === $widget['type_localisation'] ? 'rue' : 'adresse ou une ville';?>" autocomplete="off" data-type-localisation="<?php echo $widget['type_localisation'] ?? '';?>"> |
<div class="tb-places-search-icon"></div> |
<button class="tb-places-close hidden"></button> |
</div> |