openlayers绘制多边形

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绘制多边形)