diff --git a/package.json b/package.json index 94c1ed9f..eebf3aac 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "leaflet-contextmenu": "^1.4.0", "leaflet-editable": "^1.2.0", "leaflet-editinosm": "0.2.3", - "leaflet-formbuilder": "0.2.4", + "leaflet-formbuilder": "0.2.6", "leaflet-fullscreen": "1.0.2", "leaflet-hash": "0.2.1", "leaflet-i18n": "0.3.1", diff --git a/umap/static/umap/js/umap.core.js b/umap/static/umap/js/umap.core.js index 76329be8..bb740c02 100644 --- a/umap/static/umap/js/umap.core.js +++ b/umap/static/umap/js/umap.core.js @@ -656,5 +656,10 @@ L.U.Orderable = L.Evented.extend({ }) L.LatLng.prototype.isValid = function () { - return !isNaN(this.lat) && !isNaN(this.lng) + return ( + isFinite(this.lat) && + Math.abs(this.lat) <= 90 && + isFinite(this.lng) && + Math.abs(this.lng) <= 180 + ) } diff --git a/umap/static/umap/js/umap.features.js b/umap/static/umap/js/umap.features.js index 97076cea..73566f41 100644 --- a/umap/static/umap/js/umap.features.js +++ b/umap/static/umap/js/umap.features.js @@ -627,11 +627,14 @@ L.U.Marker = L.Marker.extend({ ] const builder = new L.U.FormBuilder(this, coordinatesOptions, { callback: function () { - if (!this._latlng.isValid()) - return this.map.ui.alert({ + if (!this._latlng.isValid()) { + this.map.ui.alert({ content: L._('Invalid latitude or longitude'), level: 'error', }) + builder.resetField('_latlng.lat') + builder.resetField('_latlng.lng') + } this._redraw() this.zoomTo({ easing: false }) }, diff --git a/umap/static/umap/test/Marker.js b/umap/static/umap/test/Marker.js index ab219bdf..daf3d327 100644 --- a/umap/static/umap/test/Marker.js +++ b/umap/static/umap/test/Marker.js @@ -95,4 +95,28 @@ describe('L.U.Marker', function () { assert.equal(L.Util.formatNum(layer._latlng.lng), other._latlng.lng) }) }) + + describe('#edit()', function (done) { + it('should allow changing coordinates manually', function () { + var layer = new L.U.Marker(this.map, [10, 20], { + datalayer: this.datalayer, + }).addTo(this.datalayer) + enableEdit() + layer.edit() + changeInputValue(qs('form.umap-form input[name="lat"]'), '54.43') + assert.equal(layer._latlng.lat, 54.43) + }) + + it('should not allow invalid latitude nor longitude', function () { + var layer = new L.U.Marker(this.map, [10, 20], { + datalayer: this.datalayer, + }).addTo(this.datalayer) + enableEdit() + layer.edit() + changeInputValue(qs('form.umap-form input[name="lat"]'), '5443') + assert.equal(layer._latlng.lat, 10) + changeInputValue(qs('form.umap-form input[name="lng"]'), '5443') + assert.equal(layer._latlng.lng, 20) + }) + }) })