diff --git a/debug/gradient.html b/debug/line-gradient.html similarity index 100% rename from debug/gradient.html rename to debug/line-gradient.html diff --git a/package.json b/package.json index a15e693de6b..5bbec1cee8a 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,6 @@ "@mapbox/mapbox-gl-supported": "^1.3.0", "@mapbox/point-geometry": "^0.1.0", "@mapbox/shelf-pack": "^3.1.0", - "@mapbox/tilebelt": "^1.0.1", "@mapbox/tiny-sdf": "^1.1.0", "@mapbox/unitbezier": "^0.0.0", "@mapbox/vector-tile": "^1.3.1", diff --git a/src/data/bucket/line_bucket.js b/src/data/bucket/line_bucket.js index 72c101faf6b..00c31a538ca 100644 --- a/src/data/bucket/line_bucket.js +++ b/src/data/bucket/line_bucket.js @@ -459,7 +459,7 @@ class LineBucket implements Bucket { const indexArray = this.indexArray; if (distancesForScaling) { - // Scale line from tile units to [0, 2^15) + // For gradient lines, scale distance from tile units to [0, 2^15) distance = scaleDistance(distance, distancesForScaling); } @@ -500,7 +500,7 @@ class LineBucket implements Bucket { * This adds a pie slice triangle near a join to simulate round joins * * @param currentVertex the line vertex to add buffer vertices for - * @param distance the distance from the beggining of the line to the vertex + * @param distance the distance from the beginning of the line to the vertex * @param extrude the offset of the new vertex from the currentVertex * @param lineTurnsLeft whether the line is turning left or right at this angle * @private @@ -532,10 +532,33 @@ class LineBucket implements Bucket { } } +/** + * 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 + * of this vertex along the full linestring feature and scale it to [0, 2^15) + * + * @param {number} tileDistance the distance from the beginning of the tiled line to this vertex + * @param {Object} stats + * @param {number} stats.start the ratio (0-1) along a full original linestring feature of the start of this tiled line feature + * @param {number} stats.end the ratio (0-1) along a full original linestring feature of the end of this tiled line feature + * @param {number} stats.tileTotal the total distance, in tile units, of this tiled line feature + * + * @private + */ function scaleDistance(tileDistance: number, stats: Object) { return ((tileDistance / stats.tileTotal) * (stats.end - stats.start) + stats.start) * (MAX_LINE_DISTANCE - 1); } +/** + * Calculate the total distance, in tile units, of this tiled line feature + * + * @param {Array} vertices the full geometry of this tiled line feature + * @param {number} first the index in the vertices array representing the first vertex we should consider + * @param {number} len the count of vertices we should consider from `first` + * + * @private + */ function calculateFullDistance(vertices: Array, first: number, len: number) { let currentVertex, nextVertex; let total = 0; diff --git a/src/style/properties.js b/src/style/properties.js index f374690dadc..b02b1a294d6 100644 --- a/src/style/properties.js +++ b/src/style/properties.js @@ -620,7 +620,7 @@ class CrossFadedProperty implements Property> { /** * An implementation of `Property` for `heatmap-color` and `line-gradient`. Interpolation is a no-op, and - * evaluation returns a value in order to indicate its presence, but the real + * evaluation returns a boolean value in order to indicate its presence, but the real * evaluation happens in StyleLayer classes. * * @private @@ -633,7 +633,7 @@ class ColorRampProperty implements Property { } possiblyEvaluate(value: PropertyValue, parameters: EvaluationParameters): boolean { - return !!value.expression.evaluate(parameters); // ? + return !!value.expression.evaluate(parameters); } interpolate(): boolean { return false; } diff --git a/test/integration/tiles/2-1-1-gradient.vector.pbf b/test/integration/tiles/2-1-1-gradient.vector.pbf deleted file mode 100644 index 0fff54e6ce0..00000000000 Binary files a/test/integration/tiles/2-1-1-gradient.vector.pbf and /dev/null differ diff --git a/test/integration/tiles/2-1-2-gradient.vector.pbf b/test/integration/tiles/2-1-2-gradient.vector.pbf deleted file mode 100644 index e49cd782033..00000000000 Binary files a/test/integration/tiles/2-1-2-gradient.vector.pbf and /dev/null differ diff --git a/test/integration/tiles/2-2-1-gradient.vector.pbf b/test/integration/tiles/2-2-1-gradient.vector.pbf deleted file mode 100644 index e1218fe8478..00000000000 Binary files a/test/integration/tiles/2-2-1-gradient.vector.pbf and /dev/null differ diff --git a/test/integration/tiles/2-2-2-gradient.vector.pbf b/test/integration/tiles/2-2-2-gradient.vector.pbf deleted file mode 100644 index fb2e5d43b75..00000000000 Binary files a/test/integration/tiles/2-2-2-gradient.vector.pbf and /dev/null differ diff --git a/test/unit/style-spec/fixture/layers.input.json b/test/unit/style-spec/fixture/layers.input.json index 50521803651..8286a989ac4 100644 --- a/test/unit/style-spec/fixture/layers.input.json +++ b/test/unit/style-spec/fixture/layers.input.json @@ -12,6 +12,11 @@ "geojson": { "type": "geojson", "data": {} + }, + "lineMetrics": { + "type": "geojson", + "data": {}, + "lineMetrics": true } }, "layers": [ @@ -119,7 +124,7 @@ } }, { - "id": "line-gradient-good", + "id": "line-gradient-missing-lineMetrics", "type": "line", "source": "geojson", "source-layer": "source-layer", @@ -131,6 +136,20 @@ 0, "#000000" ] } + }, + { + "id": "line-gradient-good", + "type": "line", + "source": "lineMetrics", + "source-layer": "source-layer", + "paint": { + "line-gradient": [ + "interpolate", + ["linear"], + ["line-progress"], + 0, "#000000" + ] + } } ] } diff --git a/test/unit/style-spec/fixture/layers.output.json b/test/unit/style-spec/fixture/layers.output.json index 210af204e1c..a68f6b0688f 100644 --- a/test/unit/style-spec/fixture/layers.output.json +++ b/test/unit/style-spec/fixture/layers.output.json @@ -1,74 +1,74 @@ [ { "message": "layers[0]: either \"type\" or \"ref\" is required", - "line": 18 + "line": 23 }, { "message": "layers[1]: missing required property \"id\"", - "line": 23 + "line": 28 }, { "message": "layers[3]: \"type\" is prohibited for ref layers", - "line": 37 + "line": 42 }, { "message": "layers[3]: \"source\" is prohibited for ref layers", - "line": 38 + "line": 43 }, { "message": "layers[3]: \"source-layer\" is prohibited for ref layers", - "line": 39 + "line": 44 }, { "message": "layers[3]: \"filter\" is prohibited for ref layers", - "line": 40 + "line": 45 }, { "message": "layers[3]: \"layout\" is prohibited for ref layers", - "line": 41 + "line": 46 }, { "message": "layers[4]: ref layer \"not-found\" not found", - "line": 45 + "line": 50 }, { "message": "layers[5]: ref cannot reference another ref layer", - "line": 49 + "line": 54 }, { "message": "layers[6]: missing required property \"source\"", - "line": 51 + "line": 56 }, { "message": "layers[7]: source \"not-found\" not found", - "line": 58 + "line": 63 }, { "message": "layers[8]: layer \"vector-raster-mismatch\" requires a vector source", - "line": 63 + "line": 68 }, { "message": "layers[9]: layer \"raster-vector-mismatch\" requires a raster source", - "line": 68 + "line": 73 }, { - "message": "layers[11]: duplicate layer id \"duplicate\", previously used at line 72", - "line": 78 + "message": "layers[11]: duplicate layer id \"duplicate\", previously used at line 77", + "line": 83 }, { "message": "layers[12].type: expected one of [fill, line, symbol, circle, heatmap, fill-extrusion, raster, hillshade, background], \"invalid\" found", - "line": 85 + "line": 90 }, { "message": "layers[13]: layer \"missing-source-layer\" must specify a \"source-layer\"", - "line": 95 + "line": 100 }, { "message": "layers[15]: layer \"line-gradient-bad\" specifies a line-gradient, which requires a GeoJSON source with `lineMetrics` enabled.", - "line": 107 + "line": 112 }, { - "message": "layers[16]: layer \"line-gradient-good\" specifies a line-gradient, which requires a GeoJSON source with `lineMetrics` enabled.", - "line": 121 + "message": "layers[16]: layer \"line-gradient-missing-lineMetrics\" specifies a line-gradient, which requires a GeoJSON source with `lineMetrics` enabled.", + "line": 126 } ] \ No newline at end of file