Skip to content

Commit

Permalink
Reimplement clear geometry button
Browse files Browse the repository at this point in the history
  • Loading branch information
yvaucher committed Oct 9, 2016
1 parent 1aa1303 commit 0c6ecc0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 34 deletions.
28 changes: 3 additions & 25 deletions base_geoengine/static/src/css/style.css
Expand Up @@ -39,31 +39,9 @@ div.olControlPanel {
margin: 80px 10px;
}

div.olClearMapItemInactive {
border-radius: 4px;
float: right;
display: block;
margin: 1px;
padding: 0;
color: white;
text-align: center;
font-size: 18px;
font-family: FontAwesome, Verdana;
content: "\f1f8";
height: 22px;
width:22px;
background: #130085; /* fallback for IE - IE6 requires background shorthand*/
background: rgba(0, 60, 136, 0.5);
filter: alpha(opacity=80);
}
div.olClearMapItemInactive:before {
font-family: FontAwesome, Verdana;
content: "\f1f8";
}
div.olClearMapItemInactive:hover {
background: #130085; /* fallback for IE */
background: rgba(0, 60, 136, 0.7);
filter: alpha(opacity=100);
div.ol-clear {
top: 65px;
left: .5em;
}
.olmap:fullscreen {
height: 100%;
Expand Down
35 changes: 27 additions & 8 deletions base_geoengine/static/src/js/views/geoengine_widgets.js
Expand Up @@ -154,8 +154,11 @@ var FieldGeoEngineEditMap = common.AbstractField.extend(geoengine_common.Geoengi
},

on_ui_change: function() {
this.source.clear()
this.set_value(this.format.writeGeometry(this._geometry), false);
value = null;
if (this._geometry) {
value = this.format.writeGeometry(this._geometry);
}
this.set_value(value, false);
},

validate: function() {
Expand Down Expand Up @@ -224,13 +227,28 @@ var FieldGeoEngineEditMap = common.AbstractField.extend(geoengine_common.Geoengi
this.map.addInteraction(this.modify_control);
this.modify_control.on('modifyend', onchange_geom);

//TODO
function clearMap() {
var vl = this.map.getLayersByName(this.widget.name)[0];
vl.destroyFeatures();
this.widget.set_value(null);
}
ClearMapControl = function(opt_options) {
var options = opt_options || {};
var button = document.createElement('button');
button.innerHTML = '<i class="fa fa-trash"/>';
button.addEventListener('click', function() {
self.source.clear();
self._geometry = null;
self.on_ui_change();
});
var element = document.createElement('div');
element.className = 'ol-clear ol-unselectable ol-control';
element.appendChild(button);

ol.control.Control.call(this, {
element: element,
target: options.target,
});
};
ol.inherits(ClearMapControl, ol.control.Control);
this.clearmap_control = new ClearMapControl();

this.map.addControl(this.clearmap_control);
},

render_map: function() {
Expand Down Expand Up @@ -265,6 +283,7 @@ var FieldGeoEngineEditMap = common.AbstractField.extend(geoengine_common.Geoengi
var edit_active = (!this.get("effective_readonly") && !this.force_readonly);
this.draw_control.setActive(edit_active);
this.modify_control.setActive(edit_active);
this.clearmap_control.element.children[0].disabled = !edit_active;
},
});

Expand Down
1 change: 0 additions & 1 deletion base_geoengine/static/src/xml/geoengine.xml
Expand Up @@ -12,7 +12,6 @@
<div id="map_info"/>
</div>
<div id="map_legend" class="ol-control"/>
<div id="map_measurementbox" class="map_overlay"/>
</div>
</div>

Expand Down

0 comments on commit 0c6ecc0

Please sign in to comment.