首页 / 浏览问题 / 桌面GIS / 问题详情
面积测量增加按钮控制开和关
3月12
下载的openlayers例子中,面积测量增加了控制按钮,但是如何增加关闭按钮,使得测完面积后能使得界面上测量的范围线和结果都去掉,并且能够重新画线进行测量。感谢各位大哥

1个回答

您好,我写的代码如下,您可以参照一下。

<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);
    })
})
杨杰  (13EXP)  才疏学浅
3月14
...