Repository navigation
Conversation
| "values": { | ||
| "raster-dem": { | ||
| "doc": "A raster DEM source using Mapbox Terrain RGB" | ||
| "doc": "A raster DEM source" |
There was a problem hiding this comment.
I think we should still leave in the Terrain RGB part as it's still limited to sources of that type. For example it can't handle single band 16bit GeoTIFF tiles which are raster DEMs.
There was a problem hiding this comment.
Corrected it in the new commit.
I also expanded the declaration of the encoding parameter to explicitly tell the supported values
There was a problem hiding this comment.
Thank you @ibesora for the contribution! We definitely want to support other encoding schemes for our raster-dem type. We have not yet discussed as a team how customizable we want our raster-dem encoding to be but this is a step in the right direction!
Due to the recent Mapzen shutdown, I think we should link to the AWS documentation and maybe call the encoding type "terrarium" since that's the only format of theirs we support: https://aws.amazon.com/public-datasets/terrain/
Also, I don't think we need a separate debug page for this – maybe you could add a toggle on the existing hillshade.html page to use the mapzen tiles instead (and remove your mapzen key and probably use the AWS endpoint)
| level.set(x, y, this.scale * ((pixels[j] * 256 * 256 + pixels[j + 1] * 256.0 + pixels[j + 2]) / 10.0 - 10000.0)); | ||
| } | ||
| } | ||
| this.unpackData(level, data, encoding); |
| "doc": "Contains an attribution to be displayed when the map is shown to a user." | ||
| }, | ||
| "encoding": { | ||
| "type": "string", |
There was a problem hiding this comment.
this should be "type": "enum" with a values object listing the possible types.
| this.type = 'raster-dem'; | ||
| this.maxzoom = 22; | ||
| this._options = util.extend({}, options); | ||
| this.encoding = "mapbox"; |
There was a problem hiding this comment.
options.encoding || "mapbox";
| for (let x = 0; x < level.dim; x++) { | ||
| const i = y * level.dim + x; | ||
| const j = i * 4; | ||
| // decoding per https://mapzen.com/documentation/terrain-tiles/formats/#types-of-terrain-tiles |
|
Hi @mollymerp . |
|
|
||
|
|
||
| class RasterDEMTileSource extends RasterTileSource implements Source { | ||
| encoding: string; |
There was a problem hiding this comment.
you can explicitly type this as encoding: "mapbox" | "terrarium";
| this.loaded = true; | ||
| } | ||
|
|
||
| unpackData(level: Level, pixels: Uint8Array | Uint8ClampedArray, encoding: string) { |
There was a problem hiding this comment.
to reduce code duplication, you could refactor to something like
unpackMapbox(x, y, r, g, b) {
level.set(x, y, this.scale * ((r * 256 * 256 +g * 256.0 + b) / 10.0 - 10000.0));
}
unpackTerrarium(x, y, r, g, b) {
level.set(x, y, this.scale * ((r * 256 + g+ b / 256) - 32768.0));
}
const unpackFunctions = {"mapbox": unpackMapbox, "terrarium": unpackTerrarium};
const unpack = unpackFunctions[encoding];
for (let y = 0; y < level.dim; y++) {
for (let x = 0; x < level.dim; x++) {
const i = y * level.dim +
const j = i * 4;
unpack(x, y, pixels[j], pixels[j+1], pixels[j+2]);
}
}| coord: { z: number, x: number, y: number, w: number }, | ||
| rawImageData: RGBAImage | ||
| rawImageData: RGBAImage, | ||
| encoding: string |
There was a problem hiding this comment.
explicitly type for enum values (as above)
| "doc": "Terrarium format PNG tiles. See https://aws.amazon.com/es/public-datasets/terrain/ for more info." | ||
| }, | ||
| "mapbox": { | ||
| "doc": "Mapbox Terrain RGB tiles. See https://www.mapbox.com/blog/terrain-rgb/ for more info." |
There was a problem hiding this comment.
I just found out we have official documentation for this now, so we can link to https://www.mapbox.com/help/access-elevation-data/#mapbox-terrain-rgb
|
Hi again @mollymerp I've just pushed some changes that incorporate your comments. |
mollymerp
left a comment
There was a problem hiding this comment.
Just a couple of small nits that I missed earlier, but I think this is almost ready to merge!
Sorry about the delay in following up.
| } | ||
|
|
||
| loadFromImage(data: RGBAImage) { | ||
| loadFromImage(data: RGBAImage, encoding: ?string) { |
There was a problem hiding this comment.
this typing can also be "mapbox | "terrarium" – sorry I missed it earlier!
| this.loaded = true; | ||
| } | ||
|
|
||
| unpackMapbox(r: number, g: number, b: number) { |
There was a problem hiding this comment.
I think we can use _unpack* for these functions to signify that they're private to the DEMData class
|
closing here in favor of #6110 |
Launch Checklist
Implements Support additional encoding formulas for RasterDEM sources #5824 and adds support for the Mapzen terrarium terrain format by adding a new encoding parameter to the raster-dem source type that selects which unpack function should be used.
Also adds a new debug map that shows this new terrain format.
Adds a new parameter called encoding to the raster-dem source type. Defaults to mapbox to use the mapbox terrain encoding
Works as expected