Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 18 additions & 0 deletions docs/api-reference/core/view.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,24 @@ Returns:
Note: For speed, deck.gl uses shallow equality. This means that a value of `false` does not guarantee that the views are not equivalent.


#### `clone` {#clone}

<img src="https://img.shields.io/badge/from-v9.2-green.svg?style=flat-square" alt="from v9.2" />

```js
view.clone(newProps)
```

Creates a new `View` instance by merging the existing view's props with the provided `newProps`.

Parameters:

* `newProps` (Object) - Partial view props to override on the cloned view.

Returns:

* `View` - A new view instance with merged props.

#### `makeViewport` {#makeviewport}

```js
Expand Down
8 changes: 8 additions & 0 deletions docs/whats-new.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

This page contains highlights of each deck.gl release. Also check our [vis.gl blog](https://medium.com/vis-gl) for news about new releases and features in deck.gl.

## deck.gl v9.2

Target release date: Q2, 2025

### Widgets

- React: Pre-wrapped React components for the new deck.gl widgets are available via the [`@deck.gl/react`](./api-reference/react/overview.md) package, including: `ResetViewWidget`, `ScaleWidget`, `GeolocateWidget`, `ScreenshotWidget`, `LoadingWidget`, `ThemeWidget`, `InfoWidget`, and `SplitterWidget` (in addition to the `ZoomWidget`, `CompassWidget`, `FullscreenWidget` from v9.1)

## Core

- [`View.clone()`](./api-reference/core/view.md) - New method that simplifies creating new Views with modified props, similar to `Layer.clone()`.

## deck.gl v9.1

Release date: Jan 21, 2025
Expand Down
6 changes: 6 additions & 0 deletions modules/core/src/views/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ export default abstract class View<
return this.constructor === view.constructor && deepEqual(this.props, view.props, 2);
}

/** Clone this view with modified props */
clone(newProps: Partial<ViewProps>): this {
const ViewConstructor = this.constructor as new (props: ViewProps) => this;
return new ViewConstructor({...this.props, ...newProps});
}

/** Make viewport from canvas dimensions and view state */
makeViewport({width, height, viewState}: {width: number; height: number; viewState: ViewState}) {
viewState = this.filterViewState(viewState);
Expand Down
23 changes: 23 additions & 0 deletions test/modules/core/views/view.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,29 @@ test('View#imports', t => {
t.end();
});

test('View#clone', t => {
const view = new MapView({
id: 'test-view',
latitude: 0,
longitude: 0,
zoom: 1
});
const identicalClone = view.clone({});
t.ok(identicalClone instanceof MapView, 'identical clone is an instance of MapView');
t.ok(identicalClone !== view, 'identical clone is a new instance');
t.ok(identicalClone.equals(view), 'identical clone.equals() is true');

const clone = view.clone({
id: 'cloned-view',
zoom: 5
});
t.is(clone.id, 'cloned-view', 'modified clone id is overridden');
t.is(clone.props.zoom, 5, 'modified clone prop zoom is overridden');
t.is(clone.props.latitude, view.props.latitude, 'other props are preserved');
t.is(clone.props.longitude, view.props.longitude, 'other props are preserved');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also test that cloning a view should produce an identical view with matching matrices?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also test that cloning a view should produce an identical view with matching matrices?

I considered it, but seemed to require a bit more work than I would like, I feel that adding the equal test should be pretty solid.

t.end();
});

test('View#equals', t => {
const mapView1 = new MapView({
id: 'default-view',
Expand Down
Loading