Skip to content

Commit

Permalink
Merge pull request #89 from yvaucher/avoid-zoom-on-set-value
Browse files Browse the repository at this point in the history
[9.0] Avoid zoom on set_value + define default zoom
  • Loading branch information
yvaucher authored Sep 1, 2016
2 parents 742cabe + 9255c05 commit c9255e0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
2 changes: 2 additions & 0 deletions base_geoengine/geo_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions base_geoengine/geo_view/ir_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
1 change: 1 addition & 0 deletions base_geoengine/geo_view/ir_view_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<field name="projection"/>
<field name="restricted_extent" colspan="4"/>
<field name="default_extent" colspan="4"/>
<field name="default_zoom"/>
</group>
<separator string="Vector (Active layers)" colspan="4"/>
<field name="vector_layer_ids" colspan="4" nolabel="1"/>
Expand Down
18 changes: 13 additions & 5 deletions base_geoengine/static/src/js/views/geoengine_widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,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')){
Expand All @@ -121,24 +122,31 @@ var FieldGeoEngineEditMap = common.AbstractField.extend(geoengine_common.Geoengi
});
},

set_value: function(value) {
set_value: function(value, zoom) {
zoom = (typeof zoom === 'undefined') ? true : zoom

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);
if (this.value && this.default_zoom) {
this.map.zoomTo(this.default_zoom);
}
}
}
},

on_ui_change: function() {
this.set_value(this.format.write(this._geometry));
this.set_value(this.format.write(this._geometry), false);
},

validate: function() {
Expand Down

0 comments on commit c9255e0

Please sign in to comment.