django-leaflet icon indicating copy to clipboard operation
django-leaflet copied to clipboard

Geom field value should not be modified when deserializing its content

Open gutard opened this issue 4 years ago • 2 comments

@Zhigal you change the value of the input field when deserializing:

        this.formfield.value = JSON.stringify(JSON.parse(value));

This is a problem for me. My code does not work anymore with this change. Could you explain the rationale behind your fix ? Why de-re-serialize, why modify de DOM ?

Are you OK with this PR ?

gutard avatar Oct 08 '20 08:10 gutard

Relevant PRs:

https://github.com/makinacorpus/django-leaflet/pull/291 https://github.com/makinacorpus/django-leaflet/pull/294

Gagaro avatar Oct 12 '20 07:10 Gagaro

@gutard, I'm really sorry for breaking your code. But the rationale behind those changes is that this allows to keep input field syncronized with the geometry on a map with the set number of decimal places. I need this because varying precision was adding unpredictable error in my app. Your changes do not make any sence to me since input field will have varying presicion and unpredictable number of decimal places.

We may do something like this:

if (value === 0) {
     var _value = JSON.stringify(JSON.parse(value));
     return L.GeoJSON.geometryToLayer(JSON.parse(_value));
} else {
     this.formfield.value = JSON.stringify(JSON.parse(value));
     return L.GeoJSON.geometryToLayer(JSON.parse(value));
}

Zhigal avatar Sep 13 '21 03:09 Zhigal