From b73833cc93ae30e298aa2c06f430a9fc8b49c50b Mon Sep 17 00:00:00 2001 From: Isaac Besora Date: Tue, 27 Jun 2017 15:40:03 +0200 Subject: [PATCH 01/12] Small correction on the Marker documentation --- src/ui/marker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/marker.js b/src/ui/marker.js index 363ed981a3b..4962be1fdaf 100644 --- a/src/ui/marker.js +++ b/src/ui/marker.js @@ -9,7 +9,7 @@ const smartWrap = require('../util/smart_wrap'); * Creates a marker component * @param {HTMLElement=} element DOM element to use as a marker (creates a div element by default) * @param {Object=} options - * @param {PointLike=} options.offset The offset in pixels as a {@link PointLink} object to apply relative to the element's top left corner. Negatives indicate left and up. + * @param {PointLike=} options.offset The offset in pixels as a {@link PointLike} object to apply relative to the element's top left corner. Negatives indicate left and up. * @example * var marker = new mapboxgl.Marker() * .setLngLat([30.5, 50.5]) From 5c6189a1b039a81c5dbcdeee76339a7c792814bd Mon Sep 17 00:00:00 2001 From: Isaac Besora Vilardaga Date: Fri, 19 Jan 2018 15:59:58 +0100 Subject: [PATCH 02/12] Added the encoding parameter to the raster-dem source type --- debug/hillshade-mapzen.html | 45 ++++++++++++++++++++ flow-typed/style-spec.js | 3 +- src/data/dem_data.js | 46 ++++++++++++++++----- src/source/raster_dem_tile_source.js | 7 +++- src/source/raster_dem_tile_worker_source.js | 2 +- src/source/worker_source.js | 3 +- src/style-spec/reference/v8.json | 6 ++- 7 files changed, 97 insertions(+), 15 deletions(-) create mode 100644 debug/hillshade-mapzen.html diff --git a/debug/hillshade-mapzen.html b/debug/hillshade-mapzen.html new file mode 100644 index 00000000000..bbcfd1d92e7 --- /dev/null +++ b/debug/hillshade-mapzen.html @@ -0,0 +1,45 @@ + + + + Mapbox GL JS debug page + + + + + + + +
+ + + + + + diff --git a/flow-typed/style-spec.js b/flow-typed/style-spec.js index 7ece7672149..caa4000a015 100644 --- a/flow-typed/style-spec.js +++ b/flow-typed/style-spec.js @@ -102,7 +102,8 @@ declare type RasterDEMSourceSpecification = { "minzoom"?: number, "maxzoom"?: number, "tileSize"?: number, - "attribution"?: string + "attribution"?: string, + "encoding"?: string } declare type GeojsonSourceSpecification = {| diff --git a/src/data/dem_data.js b/src/data/dem_data.js index ae2d1f7fa3f..ccd5ef6fb46 100644 --- a/src/data/dem_data.js +++ b/src/data/dem_data.js @@ -57,22 +57,14 @@ class DEMData { this.loaded = !!data; } - loadFromImage(data: RGBAImage) { + loadFromImage(data: RGBAImage, encoding: string) { if (data.height !== data.width) throw new RangeError('DEM tiles must be square'); // Build level 0 const level = this.level = new Level(data.width, data.width / 2); const pixels = data.data; - // unpack - for (let y = 0; y < level.dim; y++) { - for (let x = 0; x < level.dim; x++) { - const i = y * level.dim + x; - const j = i * 4; - // decoding per https://blog.mapbox.com/global-elevation-data-6689f1d0ba65 - 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); // in order to avoid flashing seams between tiles, here we are initially populating a 1px border of pixels around the image // with the data of the nearest pixel from the image. this data is eventually replaced when the tile's neighboring @@ -95,6 +87,40 @@ class DEMData { this.loaded = true; } + unpackData(level: Level, pixels: Uint8Array, encoding: string) { + + switch(encoding) { + case 'mapzen': + this.unpackMapzenData(level, pixels); + break; + default: + this.unpackMapboxData(level, pixels); + } + + } + + unpackMapboxData(level: Level, pixels: Uint8Array) { + for (let y = 0; y < level.dim; y++) { + for (let x = 0; x < level.dim; x++) { + const i = y * level.dim + x; + const j = i * 4; + // decoding per https://blog.mapbox.com/global-elevation-data-6689f1d0ba65 + level.set(x, y, this.scale * ((pixels[j] * 256 * 256 + pixels[j + 1] * 256.0 + pixels[j + 2]) / 10.0 - 10000.0)); + } + } + } + + unpackMapzenData(level: Level, pixels: Uint8Array) { + for (let y = 0; y < level.dim; y++) { + 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 + level.set(x, y, this.scale * ((pixels[j] * 256 + pixels[j + 1] + pixels[j + 2] / 256) - 32768.0)); + } + } + } + getPixels() { return new RGBAImage({width: this.level.dim + 2 * this.level.border, height: this.level.dim + 2 * this.level.border}, new Uint8Array(this.level.data.buffer)); } diff --git a/src/source/raster_dem_tile_source.js b/src/source/raster_dem_tile_source.js index d8ed8ba8121..2c17a043b2c 100644 --- a/src/source/raster_dem_tile_source.js +++ b/src/source/raster_dem_tile_source.js @@ -15,11 +15,14 @@ import type {Callback} from '../types/callback'; class RasterDEMTileSource extends RasterTileSource implements Source { + encoding: string; + 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"; } serialize() { @@ -29,6 +32,7 @@ class RasterDEMTileSource extends RasterTileSource implements Source { tileSize: this.tileSize, tiles: this.tiles, bounds: this.bounds, + encoding: this.encoding }; } @@ -55,7 +59,8 @@ class RasterDEMTileSource extends RasterTileSource implements Source { uid: tile.uid, coord: tile.tileID, source: this.id, - rawImageData: rawImageData + rawImageData: rawImageData, + encoding: this.encoding }; if (!tile.workerID || tile.state === 'expired') { diff --git a/src/source/raster_dem_tile_worker_source.js b/src/source/raster_dem_tile_worker_source.js index 6211921fc1a..80acc443a6a 100644 --- a/src/source/raster_dem_tile_worker_source.js +++ b/src/source/raster_dem_tile_worker_source.js @@ -29,7 +29,7 @@ class RasterDEMTileWorkerSource { const dem = new DEMData(uid); this.loading[source][uid] = dem; - dem.loadFromImage(params.rawImageData); + dem.loadFromImage(params.rawImageData, params.encoding); delete this.loading[source][uid]; this.loaded[source] = this.loaded[source] || {}; diff --git a/src/source/worker_source.js b/src/source/worker_source.js index fb68dfcd970..9b4dd3ea301 100644 --- a/src/source/worker_source.js +++ b/src/source/worker_source.js @@ -26,7 +26,8 @@ export type WorkerTileParameters = TileParameters & { export type WorkerDEMTileParameters = TileParameters & { coord: { z: number, x: number, y: number, w: number }, - rawImageData: RGBAImage + rawImageData: RGBAImage, + encoding: string }; export type WorkerTileResult = { diff --git a/src/style-spec/reference/v8.json b/src/style-spec/reference/v8.json index 957e2133f10..fb37fc96031 100644 --- a/src/style-spec/reference/v8.json +++ b/src/style-spec/reference/v8.json @@ -231,7 +231,7 @@ "type": "enum", "values": { "raster-dem": { - "doc": "A raster DEM source using Mapbox Terrain RGB" + "doc": "A raster DEM source" } }, "doc": "The type of the source." @@ -272,6 +272,10 @@ "type": "string", "doc": "Contains an attribution to be displayed when the map is shown to a user." }, + "encoding": { + "type": "string", + "doc": "The encoding used by this source. Mapbox Terrain RGB is used by default" + }, "*": { "type": "*", "doc": "Other keys to configure the data source." From 1a398f276b3e42148e3b409e4f6e22b8e95ccf4a Mon Sep 17 00:00:00 2001 From: Isaac Besora Vilardaga Date: Sun, 21 Jan 2018 10:33:30 +0100 Subject: [PATCH 03/12] Changed the raster-dem description and expanded the encoding parameter one --- src/style-spec/reference/v8.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/style-spec/reference/v8.json b/src/style-spec/reference/v8.json index fb37fc96031..3a3474b8002 100644 --- a/src/style-spec/reference/v8.json +++ b/src/style-spec/reference/v8.json @@ -231,7 +231,7 @@ "type": "enum", "values": { "raster-dem": { - "doc": "A raster DEM source" + "doc": "A RGB-encoded raster DEM source" } }, "doc": "The type of the source." @@ -274,7 +274,7 @@ }, "encoding": { "type": "string", - "doc": "The encoding used by this source. Mapbox Terrain RGB is used by default" + "doc": "The encoding used by this source. Mapbox Terrain RGB is used by default. Supported encodings are `mapbox` and `mapzen`." }, "*": { "type": "*", From 4d4a4c3f8d66ca0517fb3ca2994c52f6858057db Mon Sep 17 00:00:00 2001 From: Isaac Besora Vilardaga Date: Sun, 21 Jan 2018 10:42:44 +0100 Subject: [PATCH 04/12] Changed the description in the style spec reference --- src/style-spec/reference/v8.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/style-spec/reference/v8.json b/src/style-spec/reference/v8.json index 3a3474b8002..23075daea4b 100644 --- a/src/style-spec/reference/v8.json +++ b/src/style-spec/reference/v8.json @@ -506,7 +506,7 @@ } }, "hillshade": { - "doc": "Client-side hillshading visualization based on DEM data. Currently, the implementation only supports Mapbox Terrain RGB tiles", + "doc": "Client-side hillshading visualization based on DEM data. Currently, the implementation only supports Mapbox Terrain RGB and Mapzen Terrarium tiles.", "sdk-support": { "basic functionality": { "js": "0.43.0" From d427624644d8f678093853bc78989f4cc6e2a0bb Mon Sep 17 00:00:00 2001 From: Isaac Besora Vilardaga Date: Tue, 23 Jan 2018 11:07:03 +0100 Subject: [PATCH 05/12] Changes proposed by @mollymerp --- debug/hillshade-mapzen.html | 45 ------------ debug/hillshade.html | 104 +++++++++++++++++++++++++-- src/data/dem_data.js | 6 +- src/source/raster_dem_tile_source.js | 2 +- src/style-spec/reference/v8.json | 11 ++- 5 files changed, 114 insertions(+), 54 deletions(-) delete mode 100644 debug/hillshade-mapzen.html diff --git a/debug/hillshade-mapzen.html b/debug/hillshade-mapzen.html deleted file mode 100644 index bbcfd1d92e7..00000000000 --- a/debug/hillshade-mapzen.html +++ /dev/null @@ -1,45 +0,0 @@ - - - - Mapbox GL JS debug page - - - - - - - -
- - - - - - diff --git a/debug/hillshade.html b/debug/hillshade.html index 68965655cca..3dd96bd6748 100644 --- a/debug/hillshade.html +++ b/debug/hillshade.html @@ -12,6 +12,52 @@ + + + +
@@ -26,19 +72,69 @@ }); map.on('load', function () { - map.addSource('dem', { + + map.addSource('mapbox-dem', { "type": "raster-dem", - "url": "mapbox://mapbox.terrain-rgb" + "url": "mapbox://mapbox.terrain-rgb", + "tileSize": 256 }); map.addLayer({ - "id": "hillshading", - "source": "dem", + "id": "Mapbox data", + "source": "mapbox-dem", "type": "hillshade" // insert below waterway-river-canal-shadow; // where hillshading sits in the Mapbox Outdoors style }, 'waterway-river-canal-shadow'); + + map.addSource('terrarium-dem', { + "type": "raster-dem", + "encoding": "terrarium", + "tiles": [ + "https://s3.amazonaws.com/elevation-tiles-prod/terrarium/{z}/{x}/{y}.png" + ], + "tileSize": 256 + }); + map.addLayer({ + "id": "Terrarium data", + "source": "terrarium-dem", + "type": "hillshade", + "layout": { + "visibility": "none" + } + // insert below waterway-river-canal-shadow; + // where hillshading sits in the Mapbox Outdoors style + }, 'waterway-river-canal-shadow'); + }); +var toggleableLayerIds = ['Mapbox data', 'Terrarium data']; + +for (var i = 0; i < toggleableLayerIds.length; i++) { + var id = toggleableLayerIds[i]; + + var link = document.createElement('a'); + link.href = '#'; + link.className = (0 === i) ? 'active' : ''; + link.textContent = id; + + link.onclick = function (e) { + var clickedLayer = this.textContent; + e.preventDefault(); + e.stopPropagation(); + + if (this.className === '') { + var activeLayer = document.getElementsByClassName('active')[0]; + activeLayer.className = ''; + map.setLayoutProperty(activeLayer.textContent, 'visibility', 'none'); + this.className = 'active'; + map.setLayoutProperty(clickedLayer, 'visibility', 'visible'); + } + }; + + var layers = document.getElementById('menu'); + layers.appendChild(link); +} + diff --git a/src/data/dem_data.js b/src/data/dem_data.js index ccd5ef6fb46..9d617cba0fd 100644 --- a/src/data/dem_data.js +++ b/src/data/dem_data.js @@ -64,7 +64,7 @@ class DEMData { const level = this.level = new Level(data.width, data.width / 2); const pixels = data.data; - this.unpackData(level, data, encoding); + this.unpackData(level, pixels, encoding); // in order to avoid flashing seams between tiles, here we are initially populating a 1px border of pixels around the image // with the data of the nearest pixel from the image. this data is eventually replaced when the tile's neighboring @@ -90,7 +90,7 @@ class DEMData { unpackData(level: Level, pixels: Uint8Array, encoding: string) { switch(encoding) { - case 'mapzen': + case 'terrarium': this.unpackMapzenData(level, pixels); break; default: @@ -115,7 +115,7 @@ class DEMData { 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 + // decoding per https://aws.amazon.com/es/public-datasets/terrain/ level.set(x, y, this.scale * ((pixels[j] * 256 + pixels[j + 1] + pixels[j + 2] / 256) - 32768.0)); } } diff --git a/src/source/raster_dem_tile_source.js b/src/source/raster_dem_tile_source.js index 2c17a043b2c..4b4174cca96 100644 --- a/src/source/raster_dem_tile_source.js +++ b/src/source/raster_dem_tile_source.js @@ -22,7 +22,7 @@ class RasterDEMTileSource extends RasterTileSource implements Source { this.type = 'raster-dem'; this.maxzoom = 22; this._options = util.extend({}, options); - this.encoding = "mapbox"; + this.encoding = options.encoding || "mapbox"; } serialize() { diff --git a/src/style-spec/reference/v8.json b/src/style-spec/reference/v8.json index fb37fc96031..3a36d3260d4 100644 --- a/src/style-spec/reference/v8.json +++ b/src/style-spec/reference/v8.json @@ -273,7 +273,16 @@ "doc": "Contains an attribution to be displayed when the map is shown to a user." }, "encoding": { - "type": "string", + "type": "enum", + "values": { + "terrarium": { + "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." + } + }, + "default": "mapbox", "doc": "The encoding used by this source. Mapbox Terrain RGB is used by default" }, "*": { From 92f0c74a99bc487ea57cc0482df55db939edbb78 Mon Sep 17 00:00:00 2001 From: Isaac Besora Vilardaga Date: Thu, 25 Jan 2018 16:11:34 +0100 Subject: [PATCH 06/12] Fixes linter errors --- debug/hillshade.html | 2 +- src/data/dem_data.js | 12 ++++++------ src/source/raster_dem_tile_source.js | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/debug/hillshade.html b/debug/hillshade.html index 3dd96bd6748..6285c11b7e3 100644 --- a/debug/hillshade.html +++ b/debug/hillshade.html @@ -114,7 +114,7 @@ var link = document.createElement('a'); link.href = '#'; - link.className = (0 === i) ? 'active' : ''; + link.className = (i === 0) ? 'active' : ''; link.textContent = id; link.onclick = function (e) { diff --git a/src/data/dem_data.js b/src/data/dem_data.js index 9d617cba0fd..a81d3b557ca 100644 --- a/src/data/dem_data.js +++ b/src/data/dem_data.js @@ -89,12 +89,12 @@ class DEMData { unpackData(level: Level, pixels: Uint8Array, encoding: string) { - switch(encoding) { - case 'terrarium': - this.unpackMapzenData(level, pixels); - break; - default: - this.unpackMapboxData(level, pixels); + switch (encoding) { + case 'terrarium': + this.unpackMapzenData(level, pixels); + break; + default: + this.unpackMapboxData(level, pixels); } } diff --git a/src/source/raster_dem_tile_source.js b/src/source/raster_dem_tile_source.js index 4b4174cca96..b9474670bff 100644 --- a/src/source/raster_dem_tile_source.js +++ b/src/source/raster_dem_tile_source.js @@ -59,7 +59,7 @@ class RasterDEMTileSource extends RasterTileSource implements Source { uid: tile.uid, coord: tile.tileID, source: this.id, - rawImageData: rawImageData, + rawImageData: rawImageData, encoding: this.encoding }; From 2b5b4ce5c14367ab0a7b6ebef94ba5eac224f9a5 Mon Sep 17 00:00:00 2001 From: Isaac Besora Vilardaga Date: Thu, 25 Jan 2018 16:53:13 +0100 Subject: [PATCH 07/12] Changed ts type --- flow-typed/style-spec.js | 2 +- src/data/dem_data.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/flow-typed/style-spec.js b/flow-typed/style-spec.js index caa4000a015..b00732c7959 100644 --- a/flow-typed/style-spec.js +++ b/flow-typed/style-spec.js @@ -103,7 +103,7 @@ declare type RasterDEMSourceSpecification = { "maxzoom"?: number, "tileSize"?: number, "attribution"?: string, - "encoding"?: string + "encoding"?: "terrarium" | "mapbox" } declare type GeojsonSourceSpecification = {| diff --git a/src/data/dem_data.js b/src/data/dem_data.js index a81d3b557ca..15215434bed 100644 --- a/src/data/dem_data.js +++ b/src/data/dem_data.js @@ -87,7 +87,7 @@ class DEMData { this.loaded = true; } - unpackData(level: Level, pixels: Uint8Array, encoding: string) { + unpackData(level: Level, pixels: Uint8Array | Uint8ClampedArray, encoding: string) { switch (encoding) { case 'terrarium': @@ -99,7 +99,7 @@ class DEMData { } - unpackMapboxData(level: Level, pixels: Uint8Array) { + unpackMapboxData(level: Level, pixels: Uint8Array | Uint8ClampedArray) { for (let y = 0; y < level.dim; y++) { for (let x = 0; x < level.dim; x++) { const i = y * level.dim + x; @@ -110,7 +110,7 @@ class DEMData { } } - unpackMapzenData(level: Level, pixels: Uint8Array) { + unpackMapzenData(level: Level, pixels: Uint8Array | Uint8ClampedArray) { for (let y = 0; y < level.dim; y++) { for (let x = 0; x < level.dim; x++) { const i = y * level.dim + x; From aa01a650fe5e8ec5ab8295bf0dd2aa79404403c0 Mon Sep 17 00:00:00 2001 From: Isaac Besora Vilardaga Date: Sat, 27 Jan 2018 14:35:53 +0100 Subject: [PATCH 08/12] Proposed changes --- src/data/dem_data.js | 30 ++++++++-------------------- src/source/raster_dem_tile_source.js | 2 +- src/source/worker_source.js | 2 +- src/style-spec/reference/v8.json | 2 +- 4 files changed, 11 insertions(+), 25 deletions(-) diff --git a/src/data/dem_data.js b/src/data/dem_data.js index 15215434bed..8ab3f91e776 100644 --- a/src/data/dem_data.js +++ b/src/data/dem_data.js @@ -87,36 +87,22 @@ class DEMData { this.loaded = true; } - unpackData(level: Level, pixels: Uint8Array | Uint8ClampedArray, encoding: string) { - - switch (encoding) { - case 'terrarium': - this.unpackMapzenData(level, pixels); - break; - default: - this.unpackMapboxData(level, pixels); - } - + unpackMapbox(r: number, g: number, b: number) { + return ((r * 256 * 256 + g * 256.0 + b) / 10.0 - 10000.0); } - unpackMapboxData(level: Level, pixels: Uint8Array | Uint8ClampedArray) { - for (let y = 0; y < level.dim; y++) { - for (let x = 0; x < level.dim; x++) { - const i = y * level.dim + x; - const j = i * 4; - // decoding per https://blog.mapbox.com/global-elevation-data-6689f1d0ba65 - level.set(x, y, this.scale * ((pixels[j] * 256 * 256 + pixels[j + 1] * 256.0 + pixels[j + 2]) / 10.0 - 10000.0)); - } - } + unpackMapzen(r: number, g: number, b: number) { + return ((r * 256 + g + b / 256) - 32768.0); } - unpackMapzenData(level: Level, pixels: Uint8Array | Uint8ClampedArray) { + unpackData(level: Level, pixels: Uint8Array | Uint8ClampedArray, encoding: string) { + const unpackFunctions = {"mapbox": this.unpackMapbox, "terrarium": this.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 + x; const j = i * 4; - // decoding per https://aws.amazon.com/es/public-datasets/terrain/ - level.set(x, y, this.scale * ((pixels[j] * 256 + pixels[j + 1] + pixels[j + 2] / 256) - 32768.0)); + level.set(x, y, this.scale * unpack(pixels[j], pixels[j + 1], pixels[j + 2])); } } } diff --git a/src/source/raster_dem_tile_source.js b/src/source/raster_dem_tile_source.js index b9474670bff..666802dac69 100644 --- a/src/source/raster_dem_tile_source.js +++ b/src/source/raster_dem_tile_source.js @@ -15,7 +15,7 @@ import type {Callback} from '../types/callback'; class RasterDEMTileSource extends RasterTileSource implements Source { - encoding: string; + encoding: "mapbox" | "terrarium"; constructor(id: string, options: RasterDEMSourceSpecification, dispatcher: Dispatcher, eventedParent: Evented) { super(id, options, dispatcher, eventedParent); diff --git a/src/source/worker_source.js b/src/source/worker_source.js index b552d3eb994..ace3c4e1992 100644 --- a/src/source/worker_source.js +++ b/src/source/worker_source.js @@ -29,7 +29,7 @@ export type WorkerTileParameters = TileParameters & { export type WorkerDEMTileParameters = TileParameters & { coord: { z: number, x: number, y: number, w: number }, rawImageData: RGBAImage, - encoding: string + encoding: "mapbox" | "terrarium" }; export type WorkerTileResult = { diff --git a/src/style-spec/reference/v8.json b/src/style-spec/reference/v8.json index ccf0496cc53..142850e260c 100644 --- a/src/style-spec/reference/v8.json +++ b/src/style-spec/reference/v8.json @@ -279,7 +279,7 @@ "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." + "doc": "Mapbox Terrain RGB tiles. See https://www.mapbox.com/help/access-elevation-data/#mapbox-terrain-rgb for more info." } }, "default": "mapbox", From 381fcff531cb6e847e3b200954871f9ada034eb6 Mon Sep 17 00:00:00 2001 From: Isaac Besora Vilardaga Date: Sat, 27 Jan 2018 14:49:59 +0100 Subject: [PATCH 09/12] Bug --- src/data/dem_data.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/data/dem_data.js b/src/data/dem_data.js index 8ab3f91e776..a637086beac 100644 --- a/src/data/dem_data.js +++ b/src/data/dem_data.js @@ -91,7 +91,7 @@ class DEMData { return ((r * 256 * 256 + g * 256.0 + b) / 10.0 - 10000.0); } - unpackMapzen(r: number, g: number, b: number) { + unpackTerrarium(r: number, g: number, b: number) { return ((r * 256 + g + b / 256) - 32768.0); } From fdfe9b3c5b07eaf2b68fce46e64483ed9ff58795 Mon Sep 17 00:00:00 2001 From: Isaac Besora Vilardaga Date: Mon, 29 Jan 2018 11:31:14 +0100 Subject: [PATCH 10/12] Added a default value when the RasterDEMTileWorkerSource is called without params --- src/source/raster_dem_tile_worker_source.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/source/raster_dem_tile_worker_source.js b/src/source/raster_dem_tile_worker_source.js index 80acc443a6a..cb7b2e84a07 100644 --- a/src/source/raster_dem_tile_worker_source.js +++ b/src/source/raster_dem_tile_worker_source.js @@ -22,14 +22,15 @@ class RasterDEMTileWorkerSource { loadTile(params: WorkerDEMTileParameters, callback: WorkerDEMTileCallback) { const source = params.source, - uid = params.uid; + uid = params.uid, + encoding = params.encoding || "mapbox"; if (!this.loading[source]) this.loading[source] = {}; const dem = new DEMData(uid); this.loading[source][uid] = dem; - dem.loadFromImage(params.rawImageData, params.encoding); + dem.loadFromImage(params.rawImageData, encoding); delete this.loading[source][uid]; this.loaded[source] = this.loaded[source] || {}; From 2a16718f62d09591c473c1eb3cf062f7a3b4923f Mon Sep 17 00:00:00 2001 From: Isaac Besora Vilardaga Date: Mon, 29 Jan 2018 12:01:50 +0100 Subject: [PATCH 11/12] Adds default value to pass unit tests --- src/data/dem_data.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/data/dem_data.js b/src/data/dem_data.js index a637086beac..2e93ddb5ecd 100644 --- a/src/data/dem_data.js +++ b/src/data/dem_data.js @@ -57,14 +57,14 @@ class DEMData { this.loaded = !!data; } - loadFromImage(data: RGBAImage, encoding: string) { + loadFromImage(data: RGBAImage, encoding: ?string) { if (data.height !== data.width) throw new RangeError('DEM tiles must be square'); // Build level 0 const level = this.level = new Level(data.width, data.width / 2); const pixels = data.data; - this.unpackData(level, pixels, encoding); + this.unpackData(level, pixels, encoding || "mapbox"); // in order to avoid flashing seams between tiles, here we are initially populating a 1px border of pixels around the image // with the data of the nearest pixel from the image. this data is eventually replaced when the tile's neighboring From ec6562f80924f353acf4aea24b19404841a0cbfe Mon Sep 17 00:00:00 2001 From: Isaac Besora Vilardaga Date: Wed, 7 Feb 2018 09:01:22 +0100 Subject: [PATCH 12/12] Explicit encoding type and _ to private functions --- src/data/dem_data.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/data/dem_data.js b/src/data/dem_data.js index 2e93ddb5ecd..f420aeab813 100644 --- a/src/data/dem_data.js +++ b/src/data/dem_data.js @@ -57,7 +57,7 @@ class DEMData { this.loaded = !!data; } - loadFromImage(data: RGBAImage, encoding: ?string) { + loadFromImage(data: RGBAImage, encoding?: "mapbox" | "terrarium") { if (data.height !== data.width) throw new RangeError('DEM tiles must be square'); // Build level 0 @@ -87,16 +87,16 @@ class DEMData { this.loaded = true; } - unpackMapbox(r: number, g: number, b: number) { + _unpackMapbox(r: number, g: number, b: number) { return ((r * 256 * 256 + g * 256.0 + b) / 10.0 - 10000.0); } - unpackTerrarium(r: number, g: number, b: number) { + _unpackTerrarium(r: number, g: number, b: number) { return ((r * 256 + g + b / 256) - 32768.0); } unpackData(level: Level, pixels: Uint8Array | Uint8ClampedArray, encoding: string) { - const unpackFunctions = {"mapbox": this.unpackMapbox, "terrarium": this.unpackTerrarium}; + const unpackFunctions = {"mapbox": this._unpackMapbox, "terrarium": this._unpackTerrarium}; const unpack = unpackFunctions[encoding]; for (let y = 0; y < level.dim; y++) { for (let x = 0; x < level.dim; x++) {