Merge pull request #7543 from ahocevar/interiorpoint-donut
Donut polygon labels do not get a chance to get rendered
This commit is contained in:
@@ -24,18 +24,20 @@ ol.geom.flat.interiorpoint.linearRings = function(flatCoordinates, offset,
|
|||||||
/** @type {Array.<number>} */
|
/** @type {Array.<number>} */
|
||||||
var intersections = [];
|
var intersections = [];
|
||||||
// Calculate intersections with the horizontal line
|
// Calculate intersections with the horizontal line
|
||||||
var end = ends[0];
|
for (var r = 0, rr = ends.length; r < rr; ++r) {
|
||||||
x1 = flatCoordinates[end - stride];
|
var end = ends[r];
|
||||||
y1 = flatCoordinates[end - stride + 1];
|
x1 = flatCoordinates[end - stride];
|
||||||
for (i = offset; i < end; i += stride) {
|
y1 = flatCoordinates[end - stride + 1];
|
||||||
x2 = flatCoordinates[i];
|
for (i = offset; i < end; i += stride) {
|
||||||
y2 = flatCoordinates[i + 1];
|
x2 = flatCoordinates[i];
|
||||||
if ((y <= y1 && y2 <= y) || (y1 <= y && y <= y2)) {
|
y2 = flatCoordinates[i + 1];
|
||||||
x = (y - y1) / (y2 - y1) * (x2 - x1) + x1;
|
if ((y <= y1 && y2 <= y) || (y1 <= y && y <= y2)) {
|
||||||
intersections.push(x);
|
x = (y - y1) / (y2 - y1) * (x2 - x1) + x1;
|
||||||
|
intersections.push(x);
|
||||||
|
}
|
||||||
|
x1 = x2;
|
||||||
|
y1 = y2;
|
||||||
}
|
}
|
||||||
x1 = x2;
|
|
||||||
y1 = y2;
|
|
||||||
}
|
}
|
||||||
// Find the longest segment of the horizontal line that has its center point
|
// Find the longest segment of the horizontal line that has its center point
|
||||||
// inside the linear ring.
|
// inside the linear ring.
|
||||||
|
|||||||
@@ -550,6 +550,17 @@ describe('ol.geom.Polygon', function() {
|
|||||||
expect(interiorPoint.layout).to.be('XYM');
|
expect(interiorPoint.layout).to.be('XYM');
|
||||||
expect(interiorPoint.getCoordinates()).to.eql([0.5, 0.5, 1]);
|
expect(interiorPoint.getCoordinates()).to.eql([0.5, 0.5, 1]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('returns XYM point for donut polygons', function() {
|
||||||
|
var geom = new ol.geom.Polygon([
|
||||||
|
[[0.5, 0.5], [0.5, 2.5], [2.5, 2.5], [2.5, 0.5], [0.5, 0.5]],
|
||||||
|
[[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]]
|
||||||
|
]);
|
||||||
|
var interiorPoint = geom.getInteriorPoint();
|
||||||
|
expect(interiorPoint.getType()).to.be('Point');
|
||||||
|
expect(interiorPoint.layout).to.be('XYM');
|
||||||
|
expect(interiorPoint.getCoordinates()).to.eql([0.75, 1.5, 0.5]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('ol.geom.Polygon.fromExtent', function() {
|
describe('ol.geom.Polygon.fromExtent', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user