您好,我写的代码如下,您可以参照一下。
<div>
<input id="v2" type="button" value="清除">
</div>
var drawLayer = new ol.layer.Vector({
source: new ol.source.Vector()
})
map.addLayer(drawLayer);
interaction = new ol.interaction.Draw({
source: drawLayer.getSource(),
type: "Polygon",
});
interaction.on('drawstart', function (evt) {
feature = evt.feature;
});
interaction.on('drawend', function () {
var areaMeasureParam = new SuperMap.MeasureParameters(feature.getGeometry());
new ol.supermap.MeasureService(url).measureArea(areaMeasureParam, function (serviceResult) {
widgets.alert.showAlert(serviceResult.result.area + "平方米", true);
});
});
map.addInteraction(interaction);
$(function() {
$('#v2').click(function () {
widgets.alert.clearAlert();
drawLayer.getSource().removeFeature(feature);
})
})