Skip to content
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

Move ClipExtension to @deck.gl/extensions #5726

Merged
merged 3 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions docs/api-reference/extensions/clip-extension.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

# ClipExtension

The `ClipExtension` adds support for clipping rendered layers by rectangular bounds.

```js
import {GeoJsonLayer} from '@deck.gl/layers';
import {ClipExtension} from '@deck.gl/extensions';

const layer = new GeoJsonLayer({
// Natural Earth countries dataset includes Antarctica, which renders stretched further to south in MapView with viewState normalization disabled
data: 'https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_50m_admin_0_countries.geojson',
// clip rendered layer by Mercator bounds
extensions: [new ClipExtension()],
clipBounds: [-180, -85.051129, 180, 85.051129],
});
```

## Installation

To install the dependencies from NPM:

```bash
npm install deck.gl
# or
npm install @deck.gl/core @deck.gl/extensions
```

```js
import {ClipExtension} from '@deck.gl/extensions';
new ClipExtension();
```

To use pre-bundled scripts:

```html
<script src="https://unpkg.com/deck.gl@^8.0.0/dist.min.js"></script>
<!-- or -->
<script src="https://unpkg.com/@deck.gl/core@^8.0.0/dist.min.js"></script>
<script src="https://unpkg.com/@deck.gl/extensions@^8.0.0/dist.min.js"></script>
```

```js
new deck.ClipExtension();
```

## Constructor

```js
new ClipExtension();
```

## Layer Properties

When added to a layer via the `extensions` prop, the `ClipExtension` adds the following properties to the layer:
##### `clipBounds` (Array)

Rectangular bounds to be used for clipping the rendered region.

Supported format: `[left, bottom, right, top]`

##### `clipByInstance` (Boolean, optional)

`clipByInstance` controls whether an object is clipped by its anchor (e.g. icon, point) or by its geometry (e.g. path, polygon). If not specified, it is deduced from whether there is an attribute called `instancePositions`. This behavior can be overridden if:

- the anchor attribute goes by some other name
- to clip an anchored layer by geometry, like the text layer

## Source

[modules/extensions/src/clip](https://github.com/visgl/deck.gl/tree/master/modules/extensions/src/clip)
1 change: 1 addition & 0 deletions docs/api-reference/extensions/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This module contains the following extensions:
- [DataFilterExtension](/docs/api-reference/extensions/data-filter-extension.md)
- [Fp64Extension](/docs/api-reference/extensions/fp64-extension.md)
- [PathStyleExtension](/docs/api-reference/extensions/path-style-extension.md)
- [ClipExtension](/docs/api-reference/extensions/clip-extension.md)

For instructions on authoring your own layer extensions, visit [developer guide](/docs/developer-guide/custom-layers/layer-extensions.md).

Expand Down
2 changes: 1 addition & 1 deletion docs/api-reference/geo-layers/mvt-layer.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ To install the dependencies from NPM:
```bash
npm install deck.gl
# or
npm install @deck.gl/core @deck.gl/layers @deck.gl/geo-layers
npm install @deck.gl/core @deck.gl/layers @deck.gl/extensions @deck.gl/geo-layers
```

```js
Expand Down
1 change: 1 addition & 0 deletions docs/upgrade-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The module entry point is now only lightly transpiled for the most commonly used
- `PathLayer`'s `rounded` prop is deprecated, replaced by two separate flags `jointRounded` and `capRounded`.
- `GeoJsonLayer`'s `lineJointRounded` prop now only controls line joints. To use rounded line caps, set `lineCapRounded` to `true`.
- Dashed lines via `PathStyleExtension` now draw rounded dash caps if `capRounded` is `true`.
- `@deck.gl/geo-layers` now requires `@deck.gl/extensions`, due to `ClipExtension` dependency.

### onError Callback

Expand Down
1 change: 1 addition & 0 deletions modules/extensions/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export {default as DataFilterExtension} from './data-filter/data-filter';
export {default as Fp64Extension} from './fp64/fp64';
export {default as PathStyleExtension} from './path-style/path-style';
export {default as FillStyleExtension} from './fill-style/fill-style';
export {default as ClipExtension} from './clip/clip';

// Shader module
export {default as project64} from './fp64/project64';
1 change: 1 addition & 0 deletions modules/geo-layers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
},
"peerDependencies": {
"@deck.gl/core": "^8.0.0",
"@deck.gl/extensions": "^8.0.0",
"@deck.gl/layers": "^8.0.0",
"@deck.gl/mesh-layers": "^8.0.0",
"@loaders.gl/core": "^3.0.0-alpha"
Expand Down
2 changes: 1 addition & 1 deletion modules/geo-layers/src/mvt-layer/mvt-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import {binaryToGeoJson} from '@loaders.gl/gis';
import {load} from '@loaders.gl/core';
import {COORDINATE_SYSTEM} from '@deck.gl/core';
import {_binaryToFeature, _findIndexBinary} from '@deck.gl/layers';
import {ClipExtension} from '@deck.gl/extensions';

import TileLayer from '../tile-layer/tile-layer';
import {getURLFromTemplate, isURLTemplate} from '../tile-layer/utils';
import ClipExtension from './clip-extension';
import {transform} from './coordinate-transform';

const WORLD_SIZE = 512;
Expand Down
2 changes: 1 addition & 1 deletion test/modules/geo-layers/mvt-layer.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import test from 'tape-catch';
import {testLayer} from '@deck.gl/test-utils';
import {MVTLayer} from '@deck.gl/geo-layers';
import ClipExtension from '@deck.gl/geo-layers/mvt-layer/clip-extension';
import {ClipExtension} from '@deck.gl/extensions';
import {transform} from '@deck.gl/geo-layers/mvt-layer/coordinate-transform';
import {GeoJsonLayer} from '@deck.gl/layers';
import {geojsonToBinary} from '@loaders.gl/gis';
Expand Down