From 4952b372565b4a7aa2c73d38cba6a10ce1784319 Mon Sep 17 00:00:00 2001 From: Will Franklin Date: Fri, 12 Jun 2015 11:51:20 +0100 Subject: [PATCH] Check bounds before clipping --- src/layer/vector/Polygon.js | 13 ++++++++----- src/layer/vector/Polyline.js | 10 +++++++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/layer/vector/Polygon.js b/src/layer/vector/Polygon.js index f0fe5681..b9a50d7f 100644 --- a/src/layer/vector/Polygon.js +++ b/src/layer/vector/Polygon.js @@ -65,11 +65,6 @@ L.Polygon = L.Polyline.extend({ }, _clipPoints: function () { - if (this.options.noClip) { - this._parts = this._rings; - return; - } - // polygons need a different clipping algorithm so we redefine that var bounds = this._renderer._bounds, @@ -80,6 +75,14 @@ L.Polygon = L.Polyline.extend({ bounds = new L.Bounds(bounds.min.subtract(p), bounds.max.add(p)); this._parts = []; + if (!this._pxBounds || !this._pxBounds.intersects(bounds)) { + return; + } + + if (this.options.noClip) { + this._parts = this._rings; + return; + } for (var i = 0, len = this._rings.length, clipped; i < len; i++) { clipped = L.PolyUtil.clipPolygon(this._rings[i], bounds, true); diff --git a/src/layer/vector/Polyline.js b/src/layer/vector/Polyline.js index 2af13209..7a0e387a 100644 --- a/src/layer/vector/Polyline.js +++ b/src/layer/vector/Polyline.js @@ -165,15 +165,19 @@ L.Polyline = L.Path.extend({ // clip polyline by renderer bounds so that we have less to render for performance _clipPoints: function () { + var bounds = this._renderer._bounds; + + this._parts = []; + if (!this._pxBounds || !this._pxBounds.intersects(bounds)) { + return; + } + if (this.options.noClip) { this._parts = this._rings; return; } - this._parts = []; - var parts = this._parts, - bounds = this._renderer._bounds, i, j, k, len, len2, segment, points; for (i = 0, k = 0, len = this._rings.length; i < len; i++) {