-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds support for Mapzen terrain #6024
Conversation
src/style-spec/reference/v8.json
Outdated
@@ -231,7 +231,7 @@ | |||
"type": "enum", | |||
"values": { | |||
"raster-dem": { | |||
"doc": "A raster DEM source using Mapbox Terrain RGB" | |||
"doc": "A raster DEM source" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
src/data/dem_data.js
Outdated
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs to be data.data
src/style-spec/reference/v8.json
Outdated
@@ -272,6 +272,10 @@ | |||
"type": "string", | |||
"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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be "type": "enum"
with a values
object listing the possible types.
src/source/raster_dem_tile_source.js
Outdated
constructor(id: string, options: RasterDEMSourceSpecification, dispatcher: Dispatcher, eventedParent: Evented) { | ||
super(id, options, dispatcher, eventedParent); | ||
this.type = 'raster-dem'; | ||
this.maxzoom = 22; | ||
this._options = util.extend({}, options); | ||
this.encoding = "mapbox"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
options.encoding || "mapbox";
src/data/dem_data.js
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
link to AWS docs
Hi @mollymerp . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the updates @ibesora – made a couple more small comments!
src/source/raster_dem_tile_source.js
Outdated
@@ -15,11 +15,14 @@ import type {Callback} from '../types/callback'; | |||
|
|||
|
|||
class RasterDEMTileSource extends RasterTileSource implements Source { | |||
encoding: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can explicitly type this as encoding: "mapbox" | "terrarium";
src/data/dem_data.js
Outdated
@@ -95,6 +87,40 @@ class DEMData { | |||
this.loaded = true; | |||
} | |||
|
|||
unpackData(level: Level, pixels: Uint8Array | Uint8ClampedArray, encoding: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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]);
}
}
src/source/worker_source.js
Outdated
@@ -28,7 +28,8 @@ export type WorkerTileParameters = TileParameters & { | |||
|
|||
export type WorkerDEMTileParameters = TileParameters & { | |||
coord: { z: number, x: number, y: number, w: number }, | |||
rawImageData: RGBAImage | |||
rawImageData: RGBAImage, | |||
encoding: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explicitly type for enum values (as above)
src/style-spec/reference/v8.json
Outdated
"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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
src/data/dem_data.js
Outdated
@@ -57,22 +57,14 @@ class DEMData { | |||
this.loaded = !!data; | |||
} | |||
|
|||
loadFromImage(data: RGBAImage) { | |||
loadFromImage(data: RGBAImage, encoding: ?string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this typing can also be "mapbox | "terrarium"
– sorry I missed it earlier!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/data/dem_data.js
Outdated
@@ -95,6 +87,26 @@ class DEMData { | |||
this.loaded = true; | |||
} | |||
|
|||
unpackMapbox(r: number, g: number, b: number) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can use _unpack*
for these functions to signify that they're private to the DEMData
class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
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