Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaoji Chen committed Mar 10, 2020
1 parent 771f436 commit bf040cd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
2 changes: 1 addition & 1 deletion docs/layers/bitmap-layer.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ new deck.BitmapLayer({});

### Data

##### `bitmap` (String|Texture2D|Image|HTMLCanvasElement|HTMLVideoElement)
##### `image` (String|Texture2D|Image|HTMLCanvasElement|HTMLVideoElement)

- Default `null`.

Expand Down
48 changes: 27 additions & 21 deletions docs/layers/terrain-layer.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

# TerrainLayer

This TerrainLayer reconstructs mesh surfaces from height map images, e.g. [Mapzen Terrain Tiles](https://github.com/tilezen/joerd/blob/master/docs/formats.md), which encodes elevation into R,G,B values.
The `TerrainLayer` reconstructs mesh surfaces from height map images, e.g. [Mapzen Terrain Tiles](https://github.com/tilezen/joerd/blob/master/docs/formats.md), which encodes elevation into R,G,B values.

When `terrainImage` is supplied with a templated tile server URL, e.g. URL containing "{x}", it renders terrain tiles globally using the TileLayer and SimpleMeshLayer. Otherwise, supply an absolute URL to `terrainImage` and a `bounds` prop to render a any terrain image (e.g. non-Slippy map tiles) with a SimpleMeshLayer.
When `elevationData` is supplied with a URL template, i.e. a string containing `'{x}'` and `'{y}'`, it loads terrain tiles on demand using a `TileLayer` and renders a mesh for each tile. If `elevationData` is an absolute URL, a single mesh is used, and the `bounds` prop is required to position it into the world space.

```js
import DeckGL from '@deck.gl/react';
Expand All @@ -27,8 +27,8 @@ export const App = ({viewport}) => {
bScaler: 1/256,
offset: -32768
},
terrainImage: 'https://s3.amazonaws.com/elevation-tiles-prod/terrarium/{z}/{x}/{y}.png',
surfaceImage: 'https://wms.chartbundle.com/tms/1.0.0/sec/{z}/{x}/{y}.png?origin=nw'
elevationData: 'https://s3.amazonaws.com/elevation-tiles-prod/terrarium/{z}/{x}/{y}.png',
texture: 'https://wms.chartbundle.com/tms/1.0.0/sec/{z}/{x}/{y}.png?origin=nw'
});
return <DeckGL {...viewport} layers={[layer]} />;
};
Expand Down Expand Up @@ -71,25 +71,21 @@ When in Tiled Mode, inherits from all [TileLayer](/docs/api-reference/tile-layer

### Data Options

##### `terrainImage` (String)
##### `elevationData` (String|Array, required)

Image url that encodes height data.
Image URL that encodes height data.

- Default: `null`

Depending on the `terrainImage` string, this layer renders as a tiled layer composed of a TileLayer of SimpleMeshLayers, or as a single mesh rendered as a SimpleMeshLayer.

* Tiled `terrainImage`: https://s3.amazonaws.com/elevation-tiles-prod/terrarium/{z}/{x}/{y}.png
- If the value is a valid URL, this layer will render a single mesh.
- If the value is a string, and contains substrings `{x}` and `{y}`, it is considered a URL template. This layer will render a `TileLayer` of meshes. `{x}` `{y}` and `{z}` will be replaced with a tile's actual index when it is requested.
- If the value is an array: multiple URL templates. See `TileLayer`'s `data` prop documentation for use cases.

* Non-Tiled `terrainImage`: https://s3.amazonaws.com/elevation-tiles-prod/terrarium/1/1/0.png

##### `surfaceImage` (String|Null, optional)
##### `texture` (String|Null, optional)

Image url to use as surface texture. Same URL parsing as `terrainImage`.
Image URL to use as the surface texture. Same schema as `elevationData`.

- Default: `0`
- Default: `null`

### Mesh Options

##### `meshMaxError` (Number, optional)

Expand Down Expand Up @@ -140,25 +136,25 @@ The default value of `elevationDecoder` decodes a grayscale image:

##### `bounds` (Array, optional)

Bounds of the image to fit x,y coordinates into. In [minX, minY, maxX, maxY] world coordinates. Must be supplied when using as a Non-Tiled terrain, otherwise optional.
Bounds of the image to fit x,y coordinates into. In `[left, top, right, bottom]` world coordinates. Must be supplied when using non-tiled elevation data.

- Default: `null`

The pixel coordinates start from the top left corner.
`left`, `bottom`, `right`, `top` refers to the coordinate of the corresponding side of the image.

##### `workerUrl` (String, optional)

**Advanced** Supply url to local terrain worker bundle. Custom `workerUrl` may be desirable if the application wishes to serve the worker code itself without relying on `unpkg.com`. The worker bundle can be located in `"node_modules/@loaders.gl/terrain/dist/terrain-loader.worker.js"`.
**Advanced** Supply url to local terrain worker bundle. By default, it points to the latest published `@loaders.gl/terrain` NPM module on [unpkg.com](unpkg.com). Custom `workerUrl` may be desirable if the application wishes to serve the worker code itself without relying on the CDN. The worker bundle can be located locally in `"node_modules/@loaders.gl/terrain/dist/terrain-loader.worker.js"`.

Set `workerUrl` to empty string to disable worker (improves error messages).
Set `workerUrl` to an empty string to disable worker during debugging (improves error messages).

- Default: `null`

### Render Options

##### `color` (Color, optional)

Color to use if `surfaceImage` is unavailable. Equivalent to setting SimpleMeshLayer `getColor` prop to `d => prop.color`.
Color to use if `texture` is unavailable. Equivalent to setting SimpleMeshLayer's `getColor` prop.

- Default: `[255, 255, 255]`

Expand All @@ -168,6 +164,16 @@ Forwarded to SimpleMeshLayer `wireframe` prop.

- Default: `false`


## Sub Layers

The `TerrainLayer` renders the following sublayers:

* `tiles` - a [TileLayer](/docs/layers/tile-layer.md). Only rendered if `elevationData` is a URL template.
* `mesh` - a [SimpleMeshLayer](/docs/layers/simple-mesh-layer.md) rendering the terrain mesh.



# Source

[modules/geo-layers/src/terrain-layer](https://github.com/uber/deck.gl/tree/master/modules/geo-layers/src/terrain-layer)
9 changes: 6 additions & 3 deletions modules/geo-layers/src/terrain-layer/terrain-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export default class TerrainLayer extends CompositeLayer {
}

renderSubLayers(props) {
const SubLayerClass = this.getSubLayerClass('mesh', SimpleMeshLayer);
const {data, color} = props;
let mesh = null;
let texture = null;
Expand All @@ -155,7 +156,7 @@ export default class TerrainLayer extends CompositeLayer {
texture = data.then(result => result && result[1]);
}

return new SimpleMeshLayer(props, {
return new SubLayerClass(props, {
data: DUMMY_DATA,
mesh,
texture,
Expand All @@ -178,7 +179,7 @@ export default class TerrainLayer extends CompositeLayer {
wireframe,
color,
getTileData: this.getTiledTerrainData.bind(this),
renderSubLayers: this.renderSubLayers,
renderSubLayers: this.renderSubLayers.bind(this),
updateTriggers: {
getTileData: {
elevationData: urlTemplateToUpdateTrigger(elevationData),
Expand All @@ -190,7 +191,9 @@ export default class TerrainLayer extends CompositeLayer {
}
);
}
return new SimpleMeshLayer(

const SubLayerClass = this.getSubLayerClass('mesh', SimpleMeshLayer);
return new SubLayerClass(
this.getSubLayerProps({
id: 'mesh'
}),
Expand Down

0 comments on commit bf040cd

Please sign in to comment.