Skip to content

Commit 94654b1

Browse files
authored
fix linestring/polygon clip error fix #1405 (#1408)
1 parent da78956 commit 94654b1

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/renderer/geometry/Painter.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const TEMP_POINT0 = new Point(0, 0);
2626
const TEMP_PAINT_EXTENT = new PointExtent();
2727
const TEMP_EXTENT = new PointExtent();
2828
const TEMP_FIXED_EXTENT = new PointExtent();
29-
// const TEMP_CLIP_EXTENT0 = new PointExtent();
29+
const TEMP_CLIP_EXTENT0 = new PointExtent();
3030
const TEMP_CLIP_EXTENT1 = new PointExtent();
3131
// const TEMP_CONTAINER_EXTENT = new PointExtent();
3232

@@ -390,16 +390,25 @@ class Painter extends Class {
390390
};
391391
}
392392
const glExtent2D = glExtent._expand(lineWidth * map._glScale);
393+
const { xmin, ymin, xmax, ymax } = glExtent2D;
394+
const dx = Math.abs(xmax - xmin), dy = Math.abs(ymax - ymin);
395+
const maxEdge = Math.max(dx, dy);
396+
const r = maxEdge / 2;
397+
TEMP_CLIP_EXTENT0.xmin = glExtent2D.xmin - r;
398+
TEMP_CLIP_EXTENT0.xmax = glExtent2D.xmax + r;
399+
TEMP_CLIP_EXTENT0.ymin = glExtent2D.ymin - r;
400+
TEMP_CLIP_EXTENT0.ymax = glExtent2D.ymax + r;
401+
393402
const smoothness = geometry.options['smoothness'];
394403
// if (this.geometry instanceof Polygon) {
395404
if (geometry.getShell && this.geometry.getHoles && !smoothness) {
396405
// clip the polygon to draw less and improve performance
397406
if (!Array.isArray(points[0])) {
398-
clipPoints = clipPolygon(points, glExtent2D);
407+
clipPoints = clipPolygon(points, TEMP_CLIP_EXTENT0);
399408
} else {
400409
clipPoints = [];
401410
for (let i = 0; i < points.length; i++) {
402-
const part = clipPolygon(points[i], glExtent2D);
411+
const part = clipPolygon(points[i], TEMP_CLIP_EXTENT0);
403412
if (part.length) {
404413
clipPoints.push(part);
405414
}
@@ -408,11 +417,11 @@ class Painter extends Class {
408417
} else if (geometry.getJSONType() === 'LineString' && !smoothness) {
409418
// clip the line string to draw less and improve performance
410419
if (!Array.isArray(points[0])) {
411-
clipPoints = clipLine(points, glExtent2D, false, !!smoothness);
420+
clipPoints = clipLine(points, TEMP_CLIP_EXTENT0, false, !!smoothness);
412421
} else {
413422
clipPoints = [];
414423
for (let i = 0; i < points.length; i++) {
415-
pushIn(clipPoints, clipLine(points[i], glExtent2D, false, !!smoothness));
424+
pushIn(clipPoints, clipLine(points[i], TEMP_CLIP_EXTENT0, false, !!smoothness));
416425
}
417426
}
418427
//interpolate line's segment's altitude if altitude is an array

0 commit comments

Comments
 (0)