diff --git a/src/ol/geom/flat/interiorpoint.js b/src/ol/geom/flat/interiorpoint.js index 3311a6cf5a..f3b263964a 100644 --- a/src/ol/geom/flat/interiorpoint.js +++ b/src/ol/geom/flat/interiorpoint.js @@ -14,7 +14,8 @@ goog.require('ol.geom.flat.contains'); * @param {Array.} flatCenters Flat centers. * @param {number} flatCentersOffset Flat center offset. * @param {Array.=} opt_dest Destination. - * @return {Array.} Destination. + * @return {Array.} Destination point as XYM coordinate, where M is the + * length of the horizontal intersection that the point belongs to. */ ol.geom.flat.interiorpoint.linearRings = function(flatCoordinates, offset, ends, stride, flatCenters, flatCentersOffset, opt_dest) { @@ -61,10 +62,10 @@ ol.geom.flat.interiorpoint.linearRings = function(flatCoordinates, offset, pointX = flatCenters[flatCentersOffset]; } if (opt_dest) { - opt_dest.push(pointX, y); + opt_dest.push(pointX, y, maxSegmentLength); return opt_dest; } else { - return [pointX, y]; + return [pointX, y, maxSegmentLength]; } }; @@ -75,7 +76,8 @@ ol.geom.flat.interiorpoint.linearRings = function(flatCoordinates, offset, * @param {Array.>} endss Endss. * @param {number} stride Stride. * @param {Array.} flatCenters Flat centers. - * @return {Array.} Interior points. + * @return {Array.} Interior points as XYM coordinates, where M is the + * length of the horizontal intersection that the point belongs to. */ ol.geom.flat.interiorpoint.linearRingss = function(flatCoordinates, offset, endss, stride, flatCenters) { var interiorPoints = []; diff --git a/src/ol/geom/multipolygon.js b/src/ol/geom/multipolygon.js index 7f2f9c1589..93e3a9b635 100644 --- a/src/ol/geom/multipolygon.js +++ b/src/ol/geom/multipolygon.js @@ -223,12 +223,13 @@ ol.geom.MultiPolygon.prototype.getFlatInteriorPoints = function() { /** * Return the interior points as {@link ol.geom.MultiPoint multipoint}. - * @return {ol.geom.MultiPoint} Interior points. + * @return {ol.geom.MultiPoint} Interior points as XYM coordinates, where M is + * the length of the horizontal intersection that the point belongs to. * @api */ ol.geom.MultiPolygon.prototype.getInteriorPoints = function() { var interiorPoints = new ol.geom.MultiPoint(null); - interiorPoints.setFlatCoordinates(ol.geom.GeometryLayout.XY, + interiorPoints.setFlatCoordinates(ol.geom.GeometryLayout.XYM, this.getFlatInteriorPoints().slice()); return interiorPoints; }; diff --git a/src/ol/geom/polygon.js b/src/ol/geom/polygon.js index 7884ca53fd..76d2795ab7 100644 --- a/src/ol/geom/polygon.js +++ b/src/ol/geom/polygon.js @@ -210,11 +210,12 @@ ol.geom.Polygon.prototype.getFlatInteriorPoint = function() { /** * Return an interior point of the polygon. - * @return {ol.geom.Point} Interior point. + * @return {ol.geom.Point} Interior point as XYM coordinate, where M is the + * length of the horizontal intersection that the point belongs to. * @api */ ol.geom.Polygon.prototype.getInteriorPoint = function() { - return new ol.geom.Point(this.getFlatInteriorPoint()); + return new ol.geom.Point(this.getFlatInteriorPoint(), ol.geom.GeometryLayout.XYM); }; diff --git a/test/spec/ol/geom/multipolygon.test.js b/test/spec/ol/geom/multipolygon.test.js index c45341be7e..4ec851383b 100644 --- a/test/spec/ol/geom/multipolygon.test.js +++ b/test/spec/ol/geom/multipolygon.test.js @@ -195,4 +195,18 @@ describe('ol.geom.MultiPolygon', function() { }); + describe('#getInteriorPoints', function() { + + it('returns XYM multipoint with intersection width as M', function() { + var geom = new ol.geom.MultiPolygon([ + [[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]], + [[[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]]] + ]); + var interiorPoints = geom.getInteriorPoints(); + expect(interiorPoints.getType()).to.be('MultiPoint'); + expect(interiorPoints.layout).to.be('XYM'); + expect(interiorPoints.getCoordinates()).to.eql([[0.5, 0.5, 1], [1.5, 1.5, 1]]); + }); + }); + }); diff --git a/test/spec/ol/geom/polygon.test.js b/test/spec/ol/geom/polygon.test.js index a600afe1de..0a6345abe4 100644 --- a/test/spec/ol/geom/polygon.test.js +++ b/test/spec/ol/geom/polygon.test.js @@ -541,6 +541,17 @@ describe('ol.geom.Polygon', function() { }); + describe('#getInteriorPoint', function() { + + it('returns XYM point with intersection width as M', function() { + var geom = new ol.geom.Polygon([[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]]); + var interiorPoint = geom.getInteriorPoint(); + expect(interiorPoint.getType()).to.be('Point'); + expect(interiorPoint.layout).to.be('XYM'); + expect(interiorPoint.getCoordinates()).to.eql([0.5, 0.5, 1]); + }); + }); + describe('ol.geom.Polygon.fromExtent', function() { it('creates the correct polygon', function() { var extent = [1, 2, 3, 5];