From 86b81b1fed2cd46d04adf652422adedb59b5e747 Mon Sep 17 00:00:00 2001 From: nboisteault Date: Fri, 20 Oct 2023 17:59:41 +0200 Subject: [PATCH] Add points to vertices when editing a geometry --- assets/src/modules/Digitizing.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/assets/src/modules/Digitizing.js b/assets/src/modules/Digitizing.js index 44ac73759b..39539c9659 100644 --- a/assets/src/modules/Digitizing.js +++ b/assets/src/modules/Digitizing.js @@ -14,7 +14,7 @@ import { Vector as VectorSource } from 'ol/source.js'; import { Vector as VectorLayer } from 'ol/layer.js'; import { Feature } from 'ol'; -import { Point, LineString, Polygon, Circle as CircleGeom } from 'ol/geom.js'; +import { Point, LineString, Polygon, Circle as CircleGeom, MultiPoint } from 'ol/geom.js'; import { circular } from 'ol/geom/Polygon.js'; import { getArea, getLength } from 'ol/sphere.js'; @@ -108,6 +108,24 @@ export default class Digitizing { width: this._strokeWidth }), }), + new Style({ + image: new Circle({ + radius: 5, + fill: new Fill({ + color: color, + }), + }), + geometry: feature => { + const geometryType = feature.getGeometry().getType(); + if (geometryType === "LineString") { + return new MultiPoint(feature.getGeometry().getCoordinates()); + } + if (geometryType === "Polygon") { + // return the coordinates of the first ring of the polygon + return new MultiPoint(feature.getGeometry().getCoordinates()[0]); + } + }, + }), ]; } });