From e3fcdc5372209d672f91ef94b78f262b3756b4be Mon Sep 17 00:00:00 2001 From: Yannick Vaucher Date: Fri, 22 Apr 2016 16:34:20 +0200 Subject: [PATCH 1/3] Don't zoom when setting or changing a geometry --- .../static/src/js/views/geoengine_widgets.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/base_geoengine/static/src/js/views/geoengine_widgets.js b/base_geoengine/static/src/js/views/geoengine_widgets.js index 8a7f28ff1a..0badcf2537 100644 --- a/base_geoengine/static/src/js/views/geoengine_widgets.js +++ b/base_geoengine/static/src/js/views/geoengine_widgets.js @@ -109,24 +109,26 @@ var FieldGeoEngineEditMap = common.AbstractField.extend(geoengine_common.Geoengi }); }, - set_value: function(value) { + set_value: function(value, zoom=true) { this._super.apply(this, arguments); this.value = value; if (this.map) { var vl = this.map.getLayersByName(this.name)[0]; vl.destroyFeatures(); + var extent = this.default_extend; if (this.value) { var features = this.format.read(this.value); vl.addFeatures(features, {silent: true}); - this.map.zoomToExtent(vl.getDataExtent()); - } else { - this.map.zoomToExtent(this.default_extend); + extent = vl.getDataExtent(); + } + if (zoom) { + this.map.zoomToExtent(extent); } } }, on_ui_change: function() { - this.set_value(this.format.write(this._geometry)); + this.set_value(this.format.write(this._geometry), zoom=false); }, validate: function() { From af0c406fcd4f8a2c1f39c53f97dce374f1ae522c Mon Sep 17 00:00:00 2001 From: Yannick Vaucher Date: Fri, 22 Apr 2016 16:35:23 +0200 Subject: [PATCH 2/3] Add an option to set a default zoom to avoid showing a map that you always need to zoom out to get useful informations --- base_geoengine/geo_model.py | 2 ++ base_geoengine/geo_view/ir_view.py | 3 +++ base_geoengine/geo_view/ir_view_view.xml | 1 + base_geoengine/static/src/js/views/geoengine_widgets.js | 4 ++++ 4 files changed, 10 insertions(+) diff --git a/base_geoengine/geo_model.py b/base_geoengine/geo_model.py index 86fa9c38a9..3b94a2af68 100644 --- a/base_geoengine/geo_model.py +++ b/base_geoengine/geo_model.py @@ -117,6 +117,7 @@ def set_field_real_name(in_tuple): res['geoengine_layers']['restricted_extent'] = restricted_extent default_extent = view.default_extent or DEFAULT_EXTENT res['geoengine_layers']['default_extent'] = default_extent + res['geoengine_layers']['default_zoom'] = view.default_zoom # TODO find why context in read does not work with webclient for layer in view.raster_layer_ids: layer_dict = raster_obj.read(cursor, uid, layer.id) @@ -167,6 +168,7 @@ def get_edit_info_for_geo_column(self, cursor, uid, column, context=None): res['projection'] = view.projection res['restricted_extent'] = view.restricted_extent res['default_extent'] = view.default_extent + res['default_zoom'] = view.default_zoom return res def geo_search(self, cursor, uid, domain=None, geo_domain=None, offset=0, diff --git a/base_geoengine/geo_view/ir_view.py b/base_geoengine/geo_view/ir_view.py index ac3fff0213..5409739363 100644 --- a/base_geoengine/geo_view/ir_view.py +++ b/base_geoengine/geo_view/ir_view.py @@ -36,6 +36,9 @@ def _setup_fields(self, partial): default='-123164.85222423, 5574694.9538936, 1578017.6490538,' ' 6186191.1800898' ) + default_zoom = fields.Integer( + 'Default map zoom', + ) restricted_extent = fields.Char( 'Restricted map extent', size=128, ) diff --git a/base_geoengine/geo_view/ir_view_view.xml b/base_geoengine/geo_view/ir_view_view.xml index c74b05c439..3e9357e063 100644 --- a/base_geoengine/geo_view/ir_view_view.xml +++ b/base_geoengine/geo_view/ir_view_view.xml @@ -14,6 +14,7 @@ + diff --git a/base_geoengine/static/src/js/views/geoengine_widgets.js b/base_geoengine/static/src/js/views/geoengine_widgets.js index 0badcf2537..0bb7529142 100644 --- a/base_geoengine/static/src/js/views/geoengine_widgets.js +++ b/base_geoengine/static/src/js/views/geoengine_widgets.js @@ -101,6 +101,7 @@ var FieldGeoEngineEditMap = common.AbstractField.extend(geoengine_common.Geoengi self.geo_type = result.geo_type; self.projection = result.projection; self.default_extent = result.default_extent; + self.default_zoom = result.default_zoom; self.restricted_extent = result.restricted_extent; self.srid = result.srid; if (self.$el.is(':visible')){ @@ -123,6 +124,9 @@ var FieldGeoEngineEditMap = common.AbstractField.extend(geoengine_common.Geoengi } if (zoom) { this.map.zoomToExtent(extent); + if (this.value && this.default_zoom) { + this.map.zoomTo(this.default_zoom); + } } } }, From 9255c050dd21602bfee04da81ff25dae59fa6a86 Mon Sep 17 00:00:00 2001 From: Yannick Vaucher Date: Wed, 27 Apr 2016 10:12:51 +0200 Subject: [PATCH 3/3] No key argument in js, set an optional argument instead with default value --- base_geoengine/static/src/js/views/geoengine_widgets.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/base_geoengine/static/src/js/views/geoengine_widgets.js b/base_geoengine/static/src/js/views/geoengine_widgets.js index 0bb7529142..704dccf808 100644 --- a/base_geoengine/static/src/js/views/geoengine_widgets.js +++ b/base_geoengine/static/src/js/views/geoengine_widgets.js @@ -110,7 +110,9 @@ var FieldGeoEngineEditMap = common.AbstractField.extend(geoengine_common.Geoengi }); }, - set_value: function(value, zoom=true) { + set_value: function(value, zoom) { + zoom = (typeof zoom === 'undefined') ? true : zoom + this._super.apply(this, arguments); this.value = value; if (this.map) { @@ -132,7 +134,7 @@ var FieldGeoEngineEditMap = common.AbstractField.extend(geoengine_common.Geoengi }, on_ui_change: function() { - this.set_value(this.format.write(this._geometry), zoom=false); + this.set_value(this.format.write(this._geometry), false); }, validate: function() {