kopia lustrzana https://github.com/hholzgra/maposmatic/
Use the reversegeo service to find the country code
The callback that the slippy map calls when an area is selected is modified so that it gets as argument 'bounds', which represents the bounding box of the selected area. Using this, we get the center of the bounding box, and using an Ajax request, ask the reversegeo service to find the corresponding entries. When the reply is received, we extract the country code from the received reply. This will be used in a later commit to pre-filter the list of languages according to the selected geographic area. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@enix.org> Signed-off-by: Maxime Petazzoni <maxime.petazzoni@bulix.org>stable
rodzic
83bcd12db4
commit
13adf4edc5
|
@ -167,6 +167,15 @@ var selectedCountry;
|
|||
* <option> elements. */
|
||||
var savedLanguageList;
|
||||
|
||||
function setSelectedCountryCallback(geoResults)
|
||||
{
|
||||
$.each(geoResults, function(i, item) {
|
||||
if (typeof item.country_code != 'undefined') {
|
||||
selectedCountry = item.country_code;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* Filter the set of available languages according to the country in
|
||||
* which the administrative boundary is. There is no filtering done
|
||||
* when the area is given by bounding box. */
|
||||
|
@ -535,18 +544,26 @@ function getCurrentMode() {
|
|||
return 'admin';
|
||||
}
|
||||
|
||||
var bboxReverseGeoAjaxQuery = null;
|
||||
|
||||
/** Callback that the slippy map calls when a new area is defined. The
|
||||
* boolean tells whether the area is valid (not too big) or not valid
|
||||
* (too large to be rendered) */
|
||||
function mapAreaSelectionNotifier(isvalid) {
|
||||
if (isvalid) {
|
||||
allowNextStep();
|
||||
$("#toobigareaerror").hide();
|
||||
}
|
||||
else {
|
||||
disallowNextStep();
|
||||
$("#toobigareaerror").show();
|
||||
}
|
||||
function mapAreaSelectionNotifier(isvalid, bounds) {
|
||||
if (isvalid) {
|
||||
center = bounds.getCenterLonLat();
|
||||
if (bboxReverseGeoAjaxQuery != null)
|
||||
bboxReverseGeoAjaxQuery.abort();
|
||||
bboxReverseGeoAjaxQuery =
|
||||
$.getJSON("/apis/reversegeo/" + center.lat + "/" + center.lon + "/",
|
||||
{ }, setSelectedCountryCallback);
|
||||
allowNextStep();
|
||||
$("#toobigareaerror").hide();
|
||||
}
|
||||
else {
|
||||
disallowNextStep();
|
||||
$("#toobigareaerror").show();
|
||||
}
|
||||
}
|
||||
|
||||
/** Page initialization. */
|
||||
|
|
|
@ -68,9 +68,9 @@ function updateFormBbox(bounds, areaSelectionNotifier)
|
|||
|
||||
if (bbox_width > BBOX_MAXIMUM_LENGTH_IN_KM ||
|
||||
bbox_height > BBOX_MAXIMUM_LENGTH_IN_KM)
|
||||
areaSelectionNotifier(false);
|
||||
areaSelectionNotifier(false, bounds);
|
||||
else
|
||||
areaSelectionNotifier(true);
|
||||
areaSelectionNotifier(true, bounds);
|
||||
}
|
||||
|
||||
/* Update the map on form field modification. */
|
||||
|
|
Ładowanie…
Reference in New Issue