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

docs(widgets) Custom Widget Developer Guide #9304

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
12 changes: 10 additions & 2 deletions docs/developer-guide/custom-widgets/preact-widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ class LayerListWidget implements Widget<LayerListWidgetProps> {
return element;
}

setProps(props: Partial<LayerListWidgetProps>) {
// Handle when props change here.
this.placement = props.placement ?? this.placement;
this.viewId = props.viewId ?? this.viewId;
this.props = {...props};
this.update();
}

onRedraw({layers}: {layers: Layer[]}) {
this.layers = layers;
this.update();
Expand All @@ -113,15 +121,15 @@ class LayerListWidget implements Widget<LayerListWidgetProps> {
this.viewports[viewport.id] = viewport
}

update() {
private update() {
const element = this.element;
if (!element) {
return;
}
let layers = this.layers
if (this.deck?.props.layerFilter) {
const ui = (
{viewports.values().map(viewport => (
{this.viewports.values().map(viewport => (
<div>
{viewport.id}
<ul>
Expand Down
9 changes: 8 additions & 1 deletion docs/developer-guide/custom-widgets/react-widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class RotateWidget implements Widget<RotateWidgetProps> {

constructor(props: RotateWidgetProps) {
this.id = props.id ?? this.id;
this.placement = props.placement || this.placement;
this.placement = props.placement ?? this.placement;
this.props = { ...props };
}

Expand All @@ -62,6 +62,13 @@ class RotateWidget implements Widget<RotateWidgetProps> {
return this.props.ref.current;
}

setProps(props: Partial<LayerLoadingWidgetProps>) {
// Handle when props change here.
this.placement = props.placement ?? this.placement;
this.viewId = props.viewId ?? this.viewId;
this.props = {...props};
Copy link
Collaborator

Choose a reason for hiding this comment

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

This could wipe out existing props?

Suggested change
this.props = {...props};
this.props = {...this.props, ...props};

}

onViewportChange(viewport) {
this.viewports[viewport.id] = viewport;
}
Expand Down
7 changes: 5 additions & 2 deletions docs/developer-guide/custom-widgets/universal-widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ interface LayerLoadingWidgetProps {
className?: string;
}

class LayerListWidget implements Widget<LayerLoadingWidgetProps> {
class LayerLoadingWidget implements Widget<LayerLoadingWidgetProps> {
id = 'layer-loading-widget';
props: LayerLoadingWidgetProps;
placement: WidgetPlacement = 'top-left';
Expand Down Expand Up @@ -318,16 +318,19 @@ class LayerListWidget implements Widget<LayerLoadingWidgetProps> {
}

setProps(props: Partial<LayerLoadingWidgetProps>) {
// Handle when props change here.
this.placement = props.placement ?? this.placement;
this.viewId = props.viewId ?? this.viewId;
this.props = {...props};
this.update();
}

onRedraw({layers}: {layers: Layer[]}) {
this.layers = layers;
this.update();
}

update() {
private update() {
const element = this.element;
if (!element) {
return;
Expand Down
Loading