Skip to content

Commit

Permalink
Improve hillshade layers not using raster-dem sources error message (#…
Browse files Browse the repository at this point in the history
…353)

* Improve hillshade error message

* Add changelog entry
  • Loading branch information
ibesora authored Sep 27, 2023
1 parent 58eb347 commit fe9ba79
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## main
* Improve error messages around `hillshade` layers not using `raster-dem` sources [#353](https://github.com/maplibre/maplibre-style-spec/pull/353)

## 19.3.1

Expand Down
2 changes: 2 additions & 0 deletions src/validate/validate_layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export default function validateLayer(options) {
errors.push(new ValidationError(key, layer.source, `source "${layer.source}" not found`));
} else if (sourceType === 'vector' && type === 'raster') {
errors.push(new ValidationError(key, layer.source, `layer "${layer.id}" requires a raster source`));
} else if (sourceType !== 'raster-dem' && type === 'hillshade') {
errors.push(new ValidationError(key, layer.source, `layer "${layer.id}" requires a raster-dem source`));
} else if (sourceType === 'raster' && type !== 'raster') {
errors.push(new ValidationError(key, layer.source, `layer "${layer.id}" requires a vector source`));
} else if (sourceType === 'vector' && !layer['source-layer']) {
Expand Down
22 changes: 22 additions & 0 deletions test/integration/style-spec/tests/layers.input.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"type": "raster",
"url": "https://demotiles.maplibre.org/terrain-tiles/tiles.json"
},
"raster-dem": {
"type": "raster-dem",
"url": "https://demotiles.maplibre.org/terrain-tiles/tiles.json"
},
"geojson": {
"type": "geojson",
"data": {}
Expand Down Expand Up @@ -73,6 +77,24 @@
"source": "vector",
"source-layer": "source-layer"
},
{
"id": "raster-hillshade-mismatch",
"type": "hillshade",
"source": "raster",
"source-layer": "source-layer"
},
{
"id": "vector-hillshade-mismatch",
"type": "hillshade",
"source": "vector",
"source-layer": "source-layer"
},
{
"id": "raster-dem-raster-mismatch",
"type": "raster",
"source": "raster-dem",
"source-layer": "source-layer"
},
{
"id": "duplicate",
"type": "line",
Expand Down
58 changes: 35 additions & 23 deletions test/integration/style-spec/tests/layers.output.json
Original file line number Diff line number Diff line change
@@ -1,78 +1,90 @@
[
{
"message": "layers[0]: either \"type\" or \"ref\" is required",
"line": 23
"line": 27
},
{
"message": "layers[1]: missing required property \"id\"",
"line": 28
"line": 32
},
{
"message": "layers[3]: \"type\" is prohibited for ref layers",
"line": 42
"line": 46
},
{
"message": "layers[3]: \"source\" is prohibited for ref layers",
"line": 43
"line": 47
},
{
"message": "layers[3]: \"source-layer\" is prohibited for ref layers",
"line": 44
"line": 48
},
{
"message": "layers[3]: \"filter\" is prohibited for ref layers",
"line": 45
"line": 49
},
{
"message": "layers[3]: \"layout\" is prohibited for ref layers",
"line": 46
"line": 50
},
{
"message": "layers[4]: ref layer \"not-found\" not found",
"line": 50
"line": 54
},
{
"message": "layers[5]: ref cannot reference another ref layer",
"line": 54
"line": 58
},
{
"message": "layers[6]: missing required property \"source\"",
"line": 56
"line": 60
},
{
"message": "layers[7]: source \"not-found\" not found",
"line": 63
"line": 67
},
{
"message": "layers[8]: layer \"vector-raster-mismatch\" requires a vector source",
"line": 68
"line": 72
},
{
"message": "layers[9]: layer \"raster-vector-mismatch\" requires a raster source",
"line": 73
"line": 77
},
{
"message": "layers[11]: duplicate layer id \"duplicate\", previously used at line 77",
"message": "layers[10]: layer \"raster-hillshade-mismatch\" requires a raster-dem source",
"line": 83
},
{
"message": "layers[12].type: expected one of [fill, line, symbol, circle, heatmap, fill-extrusion, raster, hillshade, background], \"invalid\" found",
"line": 90
"message": "layers[11]: layer \"vector-hillshade-mismatch\" requires a raster-dem source",
"line": 89
},
{
"message": "layers[13]: layer \"missing-source-layer\" must specify a \"source-layer\"",
"line": 100
"message": "layers[12]: raster-dem source can only be used with layer type 'hillshade'.",
"line": 95
},
{
"message": "layers[15]: layer \"line-gradient-bad\" specifies a line-gradient, which requires a GeoJSON source with `lineMetrics` enabled.",
"message": "layers[14]: duplicate layer id \"duplicate\", previously used at line 99",
"line": 105
},
{
"message": "layers[15].type: expected one of [fill, line, symbol, circle, heatmap, fill-extrusion, raster, hillshade, background], \"invalid\" found",
"line": 112
},
{
"message": "layers[16]: layer \"line-gradient-missing-lineMetrics\" specifies a line-gradient, which requires a GeoJSON source with `lineMetrics` enabled.",
"line": 126
"message": "layers[16]: layer \"missing-source-layer\" must specify a \"source-layer\"",
"line": 122
},
{
"message": "layers[18]: layer \"line-gradient-bad\" specifies a line-gradient, which requires a GeoJSON source with `lineMetrics` enabled.",
"line": 134
},
{
"message": "layers[19]: layer \"line-gradient-missing-lineMetrics\" specifies a line-gradient, which requires a GeoJSON source with `lineMetrics` enabled.",
"line": 148
},
{
"message": "layers[18].type: expected one of [fill, line, symbol, circle, heatmap, fill-extrusion, raster, hillshade, background], \"custom\" found",
"line": 156
"message": "layers[21].type: expected one of [fill, line, symbol, circle, heatmap, fill-extrusion, raster, hillshade, background], \"custom\" found",
"line": 178
}
]

0 comments on commit fe9ba79

Please sign in to comment.