diff --git a/src/ol/reproj/Triangulation.js b/src/ol/reproj/Triangulation.js index 9fe7270abd..d5c7580584 100644 --- a/src/ol/reproj/Triangulation.js +++ b/src/ol/reproj/Triangulation.js @@ -247,12 +247,19 @@ class Triangulation { } if (!needsSubdivision && this.maxSourceExtent_) { - if (!intersects(sourceQuadExtent, this.maxSourceExtent_)) { - // whole quad outside source projection extent -> ignore - return; + if (isFinite(sourceQuadExtent[0]) && + isFinite(sourceQuadExtent[1]) && + isFinite(sourceQuadExtent[2]) && + isFinite(sourceQuadExtent[3])) { + if (!intersects(sourceQuadExtent, this.maxSourceExtent_)) { + // whole quad outside source projection extent -> ignore + return; + } } } + let isNotFinite = 0; + if (!needsSubdivision) { if (!isFinite(aSrc[0]) || !isFinite(aSrc[1]) || !isFinite(bSrc[0]) || !isFinite(bSrc[1]) || @@ -261,7 +268,16 @@ class Triangulation { if (maxSubdivision > 0) { needsSubdivision = true; } else { - return; + // It might be the case that only 1 of the points is infinite. In this case + // we can draw a single triangle with the other three points + isNotFinite = + (((!isFinite(aSrc[0]) || !isFinite(aSrc[1])) | 0) << 3) + + (((!isFinite(bSrc[0]) || !isFinite(bSrc[1])) | 0) << 2) + + (((!isFinite(cSrc[0]) || !isFinite(cSrc[1])) | 0) << 1) + + ((!isFinite(dSrc[0]) || !isFinite(dSrc[1])) | 0); + if (isNotFinite != 1 && isNotFinite != 2 && isNotFinite != 4 && isNotFinite != 8) { + return; + } } } } @@ -320,8 +336,22 @@ class Triangulation { this.wrapsXInSource_ = true; } - this.addTriangle_(a, c, d, aSrc, cSrc, dSrc); - this.addTriangle_(a, c, b, aSrc, cSrc, bSrc); + // Exactly zero or one of *Src is not finite + if ((isNotFinite & 0xb) == 0) { + this.addTriangle_(a, c, d, aSrc, cSrc, dSrc); + } + if ((isNotFinite & 0xe) == 0) { + this.addTriangle_(a, c, b, aSrc, cSrc, bSrc); + } + if (isNotFinite) { + // Try the other two triangles + if ((isNotFinite & 0xd) == 0) { + this.addTriangle_(b, d, a, bSrc, dSrc, aSrc); + } + if ((isNotFinite & 0x7) == 0) { + this.addTriangle_(b, d, c, bSrc, dSrc, cSrc); + } + } } /**