1. draw = new ol.interaction.Draw({
    2. // 在哪个画布上绘制
    3. source: source,
    4. // 绘制的类型
    5. type: 'LineString',
    6. geometryFunction: function (coordinates, geometry) {
    7. if (!geometry) {
    8. //多边形
    9. geometry = new ol.geom.Polygon(null)
    10. }
    11. var start = coordinates[0]
    12. var end = coordinates[1]
    13. geometry.setCoordinates([
    14. [start, [start[0], end[1]], end, [end[0], start[1]], start],
    15. ])
    16. return geometry
    17. },
    18. maxPoints: 2
    19. })

    image.png

    逆时针