draw = new ol.interaction.Draw({
// 在哪个画布上绘制
source: source,
// 绘制的类型
type: 'LineString',
geometryFunction: function (coordinates, geometry) {
if (!geometry) {
//多边形
geometry = new ol.geom.Polygon(null)
}
var start = coordinates[0]
var end = coordinates[1]
geometry.setCoordinates([
[start, [start[0], end[1]], end, [end[0], start[1]], start],
])
return geometry
},
maxPoints: 2
})
逆时针