美文网首页
openlayers绘制多边形

openlayers绘制多边形

作者: MarvinCHN | 来源:发表于2020-06-12 17:36 被阅读0次

import VectorLayer from 'ol/layer/Vector'

import VectorSource from 'ol/source/Vector'

import Draw from 'ol/interaction/Draw';

const drawSource = new VectorSource();

const drawLayer = new VectorLayer({

    source: drawSource

});

map.addLayer(drawLayer);

var draw;

// 开始绘制多边形

drawPolygon (type) {

    draw = new Draw({

        source: drawSource,

        type: type

    })

    map.addInteraction(draw);

    draw.on('drawend', ()  => {

        console.log('绘制完成');

    });

}

// 结束绘制

endDraw () {

    map.removeInteraction(draw);

}

// Point  LineString  Polygon  Circle

drawPolygon('Polygon');

相关文章

网友评论

      本文标题:openlayers绘制多边形

      本文链接:https://www.haomeiwen.com/subject/vcjntktx.html