I18n nogo areas errors (#413)
This commit is contained in:
parent
2aa840acda
commit
5e14484302
3 changed files with 45 additions and 19 deletions
|
|
@ -711,7 +711,6 @@
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<p id="nogoError" class="invalid-feedback" style="display: none"></p>
|
|
||||||
<form name="loadNogosForm" id="loadNogosForm">
|
<form name="loadNogosForm" id="loadNogosForm">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend data-i18n="loadNogos.source">Source</legend>
|
<legend data-i18n="loadNogos.source">Source</legend>
|
||||||
|
|
@ -795,6 +794,8 @@
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
|
<p id="nogoError" class="invalid-feedback" style="display: none"></p>
|
||||||
|
|
||||||
<button type="button" class="btn btn-secondary" data-i18n="modal.close" data-dismiss="modal">
|
<button type="button" class="btn btn-secondary" data-i18n="modal.close" data-dismiss="modal">
|
||||||
Close
|
Close
|
||||||
</button>
|
</button>
|
||||||
|
|
|
||||||
|
|
@ -197,7 +197,9 @@ BR.NogoAreas = L.Control.extend({
|
||||||
resolve(reader.result);
|
resolve(reader.result);
|
||||||
};
|
};
|
||||||
reader.onerror = function () {
|
reader.onerror = function () {
|
||||||
self.displayUploadError('Could not load file: ' + reader.error.message);
|
self.displayUploadError(
|
||||||
|
i18next.t('loadNogos.error.loading-file-error', { err: reader.error.message })
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
reader.readAsText(nogoFile);
|
reader.readAsText(nogoFile);
|
||||||
|
|
@ -206,25 +208,25 @@ BR.NogoAreas = L.Control.extend({
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// FIXME: use form validator instead
|
// FIXME: use form validator instead
|
||||||
self.displayUploadError('Missing file or URL.');
|
self.displayUploadError(i18next.t('loadNogos.error.missing-file-url'));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var nogoWeight = parseFloat($('#nogoWeight').val());
|
var nogoWeight = parseFloat($('#nogoWeight').val());
|
||||||
if (isNaN(nogoWeight)) {
|
if (isNaN(nogoWeight)) {
|
||||||
// FIXME: use form validator instead
|
// FIXME: use form validator instead
|
||||||
self.displayUploadError('Missing default nogo weight.');
|
self.displayUploadError(i18next.t('loadNogos.error.missing-default-nogo-weight'));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var nogoRadius = parseFloat($('#nogoRadius').val());
|
var nogoRadius = parseFloat($('#nogoRadius').val());
|
||||||
if (isNaN(nogoRadius) || nogoRadius < 0) {
|
if (isNaN(nogoRadius) || nogoRadius < 0) {
|
||||||
// FIXME: use form validator instead
|
// FIXME: use form validator instead
|
||||||
self.displayUploadError('Invalid default nogo radius.');
|
self.displayUploadError(i18next.t('loadNogos.error.invalid-default-nogo-radius'));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var nogoBuffer = parseFloat($('#nogoBuffer').val());
|
var nogoBuffer = parseFloat($('#nogoBuffer').val());
|
||||||
if (isNaN(nogoBuffer)) {
|
if (isNaN(nogoBuffer)) {
|
||||||
// FIXME: use form validator instead
|
// FIXME: use form validator instead
|
||||||
self.displayUploadError('Invalid nogo buffering radius.');
|
self.displayUploadError(i18next.t('loadNogos.error.invalid-nogo-buffering-radius'));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -243,7 +245,7 @@ BR.NogoAreas = L.Control.extend({
|
||||||
});
|
});
|
||||||
|
|
||||||
if (cleanedGeoJSONFeatures.length === 0) {
|
if (cleanedGeoJSONFeatures.length === 0) {
|
||||||
self.displayUploadError('No valid area found in provided input.');
|
self.displayUploadError(i18next.t('loadNogos.error.no-valid-area'));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -268,18 +270,31 @@ BR.NogoAreas = L.Control.extend({
|
||||||
nogosPoints = nogosPoints.filter(function (e) {
|
nogosPoints = nogosPoints.filter(function (e) {
|
||||||
return e;
|
return e;
|
||||||
});
|
});
|
||||||
self.setOptions({
|
try {
|
||||||
nogos: nogosPoints,
|
self.setOptions({
|
||||||
polygons: geoJSON.getLayers().filter(function (e) {
|
nogos: nogosPoints,
|
||||||
return e.feature.geometry.type === 'Polygon';
|
polygons: geoJSON.getLayers().filter(function (e) {
|
||||||
}),
|
return e.feature.geometry.type === 'Polygon';
|
||||||
polylines: geoJSON.getLayers().filter(function (e) {
|
}),
|
||||||
return e.feature.geometry.type === 'LineString';
|
polylines: geoJSON.getLayers().filter(function (e) {
|
||||||
}),
|
return e.feature.geometry.type === 'LineString';
|
||||||
});
|
}),
|
||||||
self._fireUpdate();
|
});
|
||||||
self.displayUploadError(undefined);
|
self._fireUpdate();
|
||||||
$('#loadNogos').modal('hide');
|
self.displayUploadError(undefined);
|
||||||
|
$('#loadNogos').modal('hide');
|
||||||
|
} catch (err) {
|
||||||
|
if (err.name === 'NS_ERROR_MALFORMED_URI') {
|
||||||
|
self.displayUploadError(i18next.t('loadNogos.error.loading-file-too-big'));
|
||||||
|
} else {
|
||||||
|
self.displayUploadError(i18next.t('loadNogos.error.loading-file-unexpected'));
|
||||||
|
}
|
||||||
|
// fire a fake empty nogos before removing layers from map
|
||||||
|
// because it will automatically refresh the URL, and that will
|
||||||
|
// fail if we do not empty nogos first
|
||||||
|
self.fire('update', { options: { nogos: [], polygons: [], polylines: [] } });
|
||||||
|
self._clear();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,16 @@
|
||||||
},
|
},
|
||||||
"loadNogos": {
|
"loadNogos": {
|
||||||
"defaultProperties": "Default properties",
|
"defaultProperties": "Default properties",
|
||||||
|
"error": {
|
||||||
|
"invalid-default-nogo-radius": "Invalid default nogo radius.",
|
||||||
|
"invalid-nogo-buffering-radius": "Invalid nogo buffering radius.",
|
||||||
|
"loading-file-error": "Could not load file: {{err}}.",
|
||||||
|
"loading-file-too-big": "Too many nogo areas in this file! Please simplify the geometry and/or reduce the number of zones.",
|
||||||
|
"loading-file-unexpected": "Unexpected error when loading this file.",
|
||||||
|
"missing-default-nogo-weight": "Missing default nogo weight.",
|
||||||
|
"missing-file-url": "Missing file or URL.",
|
||||||
|
"no-valid-area": "No valid area found in provided input."
|
||||||
|
},
|
||||||
"file": "File (.geojson)",
|
"file": "File (.geojson)",
|
||||||
"load": "Load",
|
"load": "Load",
|
||||||
"nogoBuffer": "Buffer no-go areas (in meters)",
|
"nogoBuffer": "Buffer no-go areas (in meters)",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue