diff --git a/src/data/bucket/line_bucket.js b/src/data/bucket/line_bucket.js index 7e11a4fdae4..e15e45ff2a6 100644 --- a/src/data/bucket/line_bucket.js +++ b/src/data/bucket/line_bucket.js @@ -231,6 +231,7 @@ class LineBucket implements Bucket { for (let i = 0; i < vertices.length - 1; i++) { this.totalDistance += vertices[i].dist(vertices[i + 1]); } + this.updateScaledDistance(); } const isPolygon = vectorTileFeatureTypes[feature.type] === 'Polygon'; @@ -526,9 +527,7 @@ class LineBucket implements Bucket { } } - updateDistance(prev: Point, next: Point) { - this.distance += prev.dist(next); - + updateScaledDistance() { // Knowing the ratio of the full linestring covered by this tiled feature, as well // as the total distance (in tile units) of this tiled feature, and the distance // (in tile units) of the current vertex, we can determine the relative distance @@ -537,6 +536,11 @@ class LineBucket implements Bucket { (this.clipStart + (this.clipEnd - this.clipStart) * this.distance / this.totalDistance) * (MAX_LINE_DISTANCE - 1) : this.distance; } + + updateDistance(prev: Point, next: Point) { + this.distance += prev.dist(next); + this.updateScaledDistance(); + } } register('LineBucket', LineBucket, {omit: ['layers', 'patternFeatures']}); diff --git a/test/integration/render-tests/line-gradient/gradient-tile-boundaries/expected.png b/test/integration/render-tests/line-gradient/gradient-tile-boundaries/expected.png new file mode 100644 index 00000000000..e85d8986b31 Binary files /dev/null and b/test/integration/render-tests/line-gradient/gradient-tile-boundaries/expected.png differ diff --git a/test/integration/render-tests/line-gradient/gradient-tile-boundaries/style.json b/test/integration/render-tests/line-gradient/gradient-tile-boundaries/style.json new file mode 100644 index 00000000000..106da0da967 --- /dev/null +++ b/test/integration/render-tests/line-gradient/gradient-tile-boundaries/style.json @@ -0,0 +1,56 @@ +{ + "version": 8, + "metadata": { + "test": { + "width": 64, + "height": 128 + } + }, + "center": [ + -77.02803308586635, + 38.891047607560125 + ], + "zoom": 18, + "sources": { + "gradient": { + "type": "geojson", + "data": { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [ + [-77.028035, 38.890600 ], + [-77.028035, 38.891088 ] + ] + } + }, + "lineMetrics": true + } + }, + "layers": [ + { + "id": "line", + "type": "line", + "source": "gradient", + "layout": { + "line-cap": "round", + "line-join": "round" + }, + "paint": { + "line-width": 15, + "line-gradient": [ + "interpolate", + ["linear"], + ["line-progress"], + 0, "rgba(0, 0, 255, 0)", + 0.1, "royalblue", + 0.3, "cyan", + 0.5, "lime", + 0.7, "yellow", + 1, "red" + ] + } + } + ] +}