Skip to content

Commit d3c15f2

Browse files
committed
Add form button to update extent and zoom of landmark
1 parent a1d1357 commit d3c15f2

File tree

3 files changed

+96
-14
lines changed

3 files changed

+96
-14
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { IJupyterGISModel } from '@jupytergis/schema';
2+
import { LabIcon } from '@jupyterlab/ui-components';
3+
import React from 'react';
4+
5+
import { targetWithCenterIcon } from '@/src/icons';
6+
import { Button } from '@/src/shared/components/Button';
7+
8+
interface ILandmarkResetProps {
9+
model?: IJupyterGISModel;
10+
layerId?: string;
11+
}
12+
13+
function LandmarkReset({ model, layerId }: ILandmarkResetProps) {
14+
const handleSetLandmarkToCurrentView = () => {
15+
if (!model || !layerId) {
16+
return;
17+
}
18+
const layer = model.getLayer(layerId);
19+
if (!layer) {
20+
return;
21+
}
22+
const { zoom, extent } = model.getOptions();
23+
const updatedLayer = {
24+
...layer,
25+
parameters: {
26+
...layer.parameters,
27+
zoom,
28+
extent,
29+
},
30+
};
31+
32+
model.sharedModel.updateLayer(layerId, updatedLayer);
33+
};
34+
35+
return (
36+
<div>
37+
<Button
38+
title="Set landmark to current view"
39+
onClick={handleSetLandmarkToCurrentView}
40+
>
41+
<LabIcon.resolveReact
42+
icon={targetWithCenterIcon}
43+
className="jp-gis-layerIcon"
44+
tag="span"
45+
/>
46+
Reset Landmark Extent
47+
</Button>
48+
</div>
49+
);
50+
}
51+
52+
export default LandmarkReset;
Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,45 @@
11
import { IDict } from '@jupytergis/schema';
2+
import { FieldProps } from '@rjsf/core';
3+
import * as React from 'react';
24

35
import { LayerPropertiesForm } from './layerform';
6+
import LandmarkReset from '../components/LandmarkReset';
47

5-
/**
6-
* The form to modify a hillshade layer.
7-
*/
88
export class LandmarkLayerPropertiesForm extends LayerPropertiesForm {
99
protected processSchema(
1010
data: IDict<any> | undefined,
1111
schema: IDict,
1212
uiSchema: IDict,
1313
) {
1414
super.processSchema(data, schema, uiSchema);
15+
16+
if (!this.props.model.selected) {
17+
return;
18+
}
19+
20+
let layerId: string | undefined = undefined;
21+
const selectedKeys = Object.keys(this.props.model.selected);
22+
23+
// Find the first selected landmark
24+
// TODO ! we still need to handle selections better, like there should at least be a getFirstSelected
25+
// ! just do that
26+
for (const key of selectedKeys) {
27+
const layer = this.props.model.getLayer(key);
28+
if (layer && layer.type === 'LandmarkLayer') {
29+
layerId = key;
30+
break;
31+
}
32+
}
33+
34+
uiSchema['extent'] = {
35+
'ui:field': (props: FieldProps) =>
36+
React.createElement(LandmarkReset, {
37+
...props,
38+
model: this.props.model,
39+
layerId,
40+
}),
41+
};
42+
1543
uiSchema['content'] = {
1644
...uiSchema['content'],
1745
markdown: {
@@ -21,5 +49,7 @@ export class LandmarkLayerPropertiesForm extends LayerPropertiesForm {
2149
},
2250
},
2351
};
52+
53+
this.removeFormEntry('zoom', data, schema, uiSchema);
2454
}
2555
}

packages/schema/src/schema/project/layers/landmarkLayer.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55
"additionalProperties": false,
66
"required": ["zoom", "extent", "transition"],
77
"properties": {
8+
"zoom": {
9+
"type": "number",
10+
"default": 0
11+
},
12+
"extent": {
13+
"type": "array",
14+
"default": null,
15+
"items": {
16+
"type": "number"
17+
}
18+
},
819
"content": {
920
"type": "object",
1021
"additionalProperties": false,
@@ -22,17 +33,6 @@
2233
}
2334
}
2435
},
25-
"zoom": {
26-
"type": "number",
27-
"default": 0
28-
},
29-
"extent": {
30-
"type": "array",
31-
"default": null,
32-
"items": {
33-
"type": "number"
34-
}
35-
},
3636
"transition": {
3737
"type": "object",
3838
"description": "Transition configuration between to this landmark",

0 commit comments

Comments
 (0)