diff --git a/src/ol/geom/Polygon.js b/src/ol/geom/Polygon.js index 94af9ba32a..eeca8df751 100644 --- a/src/ol/geom/Polygon.js +++ b/src/ol/geom/Polygon.js @@ -404,14 +404,19 @@ export function fromCircle(circle, opt_sides, opt_angle) { const sides = opt_sides ? opt_sides : 32; const stride = circle.getStride(); const layout = circle.getLayout(); + const center = circle.getCenter(); const arrayLength = stride * (sides + 1); const flatCoordinates = new Array(arrayLength); - for (let i = 0; i < arrayLength; i++) { + for (let i = 0; i < arrayLength; i += stride) { flatCoordinates[i] = 0; + flatCoordinates[i + 1] = 0; + for (let j = 2; j < stride; j++) { + flatCoordinates[i + j] = center[j]; + } } const ends = [flatCoordinates.length]; const polygon = new Polygon(flatCoordinates, layout, ends); - makeRegular(polygon, circle.getCenter(), circle.getRadius(), opt_angle); + makeRegular(polygon, center, circle.getRadius(), opt_angle); return polygon; } diff --git a/test/spec/ol/geom/polygon.test.js b/test/spec/ol/geom/polygon.test.js index 1964c0e4e2..2fee739827 100644 --- a/test/spec/ol/geom/polygon.test.js +++ b/test/spec/ol/geom/polygon.test.js @@ -605,6 +605,14 @@ describe('ol/geom/Polygon', function() { expect(coordinates[0][0]).to.roughlyEqual(0, 1e-9); expect(coordinates[0][1]).to.roughlyEqual(1, 1e-9); }); + + it('creates a regular polygon, maintaining ZM values', () => { + const circle = new Circle([0, 0, 1, 1], 1, 'XYZM'); + const polygon = fromCircle(circle); + const coordinates = polygon.getLinearRing(0).getCoordinates(); + expect(coordinates[0][2]).to.eql(1); + expect(coordinates[0][3]).to.eql(1); + }); }); });