From 508f7a717d0d1b71c48e761922ceab7887132a89 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 3 Jul 2019 12:46:51 +0200 Subject: Geo search and sheets: add a point precision for display --- ishtar_common/models.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'ishtar_common/models.py') diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 93a099b74..5e7f6e9b3 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1899,12 +1899,22 @@ class GeoItem(models.Model): self.__class__.objects.filter(pk=self.pk), geometry_field=geom_attr, fields=(cached_label_key,)) geojson_dct = json.loads(geojson) + profile = get_current_profile() + precision = profile.point_precision + features = geojson_dct.pop('features') for idx in range(len(features)): feature = features[idx] lbl = feature['properties'].pop(cached_label_key) feature['properties']['name'] = lbl feature['properties']['id'] = self.pk + if precision is not None: + geom_type = feature["geometry"].get("type", None) + if geom_type == "Point": + feature["geometry"]["coordinates"] = [ + round(coord, precision) + for coord in feature["geometry"]["coordinates"] + ] geojson_dct['features'] = features geojson_dct['link_template'] = simple_link_to_window(self).replace( '999999', '' @@ -2575,6 +2585,13 @@ class IshtarSiteProfile(models.Model, Cached): preservation = models.BooleanField(_("Preservation module"), default=False) mapping = models.BooleanField(_("Mapping module"), default=False) + point_precision = models.IntegerField( + _("Point precision (search and sheets)"), null=True, blank=True, + help_text=_( + "Number of digit to round from the decimal point for coordinates " + "in WGS84 (latitude, longitude). Empty value means no round." + ) + ) locate_warehouses = models.BooleanField( _("Locate warehouse and containers"), default=False, help_text=_( -- cgit v1.2.3