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: 3 additions & 15 deletions packages/base/src/annotations/components/Annotation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,25 @@ import { showDialog, Dialog } from '@jupyterlab/apputils';
import { Button } from '@jupyterlab/ui-components';
import React, { useMemo, useState } from 'react';

import { IControlPanelModel } from '@/src/types';
import { Message } from './Message';

export interface IAnnotationProps {
itemId: string;
annotationModel: IAnnotationModel;
rightPanelModel?: IControlPanelModel;
jgisModel?: IJupyterGISModel;
children?: JSX.Element[] | JSX.Element;
}

const Annotation: React.FC<IAnnotationProps> = ({
itemId,
annotationModel,
rightPanelModel,
jgisModel,
children,
}) => {
const [messageContent, setMessageContent] = useState('');
const [jgisModel, setJgisModel] = useState<IJupyterGISModel | undefined>(
rightPanelModel?.jGISModel,
);

const annotation = annotationModel.getAnnotation(itemId);
const contents = useMemo(() => annotation?.contents ?? [], [annotation]);

/**
* Update the model when it changes.
*/
rightPanelModel?.documentChanged.connect((_, widget) => {
setJgisModel(widget?.model);
});

const handleSubmit = () => {
annotationModel.addContent(itemId, messageContent);
setMessageContent('');
Expand Down Expand Up @@ -98,7 +86,7 @@ const Annotation: React.FC<IAnnotationProps> = ({
<Button className="jp-mod-styled jp-mod-warn" onClick={handleDelete}>
<FontAwesomeIcon icon={faTrash} />
</Button>
{rightPanelModel && (
{jgisModel && (
<Button
className="jp-mod-styled jp-mod-accept"
onClick={centerOnAnnotation}
Expand Down
2 changes: 1 addition & 1 deletion packages/base/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export * from './icons';
export * from './mainview';
export * from './menus';
export * from './panelview';
export * from './stacBrowser';
export * from './store';
export * from './stacBrowser';
export * from './toolbar';
export * from './tools';
export * from './types';
Expand Down
4 changes: 2 additions & 2 deletions packages/base/src/keybindings.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
{
"command": "jupytergis:renameLayer",
"keys": ["F2"],
"selector": ".data-jgis-keybinding .jp-gis-layerItem"
"selector": ".jp-gis-layerItem"
},
{
"command": "jupytergis:removeGroup",
Expand All @@ -47,7 +47,7 @@
{
"command": "jupytergis:renameGroup",
"keys": ["F2"],
"selector": ".data-jgis-keybinding .jp-gis-layerGroupHeader"
"selector": ".jp-gis-layerGroupHeader"
},
{
"command": "jupytergis:executeConsole",
Expand Down
30 changes: 30 additions & 0 deletions packages/base/src/mainview/mainView.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { MapChange } from '@jupyter/ydoc';
import {
IAnnotation,
IAnnotationModel,
IDict,
IGeoTiffSource,
IHeatmapLayer,
IHillshadeLayer,
IImageLayer,
IImageSource,
IJGISFilterItem,
IJGISFormSchemaRegistry,
IJGISLayer,
IJGISLayerDocChange,
IJGISLayerTreeDocChange,
Expand All @@ -34,6 +36,7 @@ import {
import { showErrorMessage } from '@jupyterlab/apputils';
import { IObservableMap, ObservableMap } from '@jupyterlab/observables';
import { User } from '@jupyterlab/services';
import { IStateDB } from '@jupyterlab/statedb';
import { CommandRegistry } from '@lumino/commands';
import { JSONValue, UUID } from '@lumino/coreutils';
import { ContextMenu } from '@lumino/widgets';
Expand Down Expand Up @@ -90,6 +93,7 @@ import CollaboratorPointers, { ClientPointer } from './CollaboratorPointers';
import { FollowIndicator } from './FollowIndicator';
import TemporalSlider from './TemporalSlider';
import { MainViewModel } from './mainviewmodel';
import { LeftPanel, RightPanel } from '../panelview';

type OlLayerTypes =
| TileLayer
Expand All @@ -102,6 +106,9 @@ type OlLayerTypes =
| ImageLayer<any>;
interface IProps {
viewModel: MainViewModel;
state?: IStateDB;
formSchemaRegistry?: IJGISFormSchemaRegistry;
annotationModel?: IAnnotationModel;
}

interface IStates {
Expand All @@ -123,6 +130,11 @@ interface IStates {
export class MainView extends React.Component<IProps, IStates> {
constructor(props: IProps) {
super(props);
this._state = props.state;

this._formSchemaRegistry = props.formSchemaRegistry;

this._annotationModel = props.annotationModel;

// Enforce the map to take the full available width in the case of Jupyter Notebook viewer
const el = document.getElementById('main-panel');
Expand Down Expand Up @@ -2220,6 +2232,21 @@ export class MainView extends React.Component<IProps, IStates> {
scale={this.state.scale}
/>
</div>

{this._state && (
<LeftPanel
model={this._model}
commands={this._mainViewModel.commands}
state={this._state}
></LeftPanel>
)}
{this._formSchemaRegistry && this._annotationModel && (
<RightPanel
model={this._model}
formSchemaRegistry={this._formSchemaRegistry}
annotationModel={this._annotationModel}
></RightPanel>
)}
</>
);
}
Expand All @@ -2240,4 +2267,7 @@ export class MainView extends React.Component<IProps, IStates> {
private _originalFeatures: IDict<Feature<Geometry>[]> = {};
private _highlightLayer: VectorLayer<VectorSource>;
private _updateCenter: CallableFunction;
private _state?: IStateDB;
private _formSchemaRegistry?: IJGISFormSchemaRegistry;
private _annotationModel?: IAnnotationModel;
}
26 changes: 22 additions & 4 deletions packages/base/src/mainview/mainviewwidget.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
import { IAnnotationModel, IJGISFormSchemaRegistry } from '@jupytergis/schema';
import { ReactWidget } from '@jupyterlab/apputils';
import { IStateDB } from '@jupyterlab/statedb';
import * as React from 'react';

import { MainView } from './mainView';
import { MainViewModel } from './mainviewmodel';

export interface IOptions {
mainViewModel: MainViewModel;
state?: IStateDB;
formSchemaRegistry?: IJGISFormSchemaRegistry;
annotationModel?: IAnnotationModel;
}

export class JupyterGISMainViewPanel extends ReactWidget {
/**
* Construct a `JupyterGISPanel`.
*/
constructor(options: { mainViewModel: MainViewModel }) {
constructor(options: IOptions) {
super();
this._mainViewModel = options.mainViewModel;
this._state = options.state;
this.addClass('jp-jupytergis-panel');
this._options = options;
}

render(): JSX.Element {
return <MainView viewModel={this._mainViewModel} />;
return (
<MainView
state={this._state}
viewModel={this._options.mainViewModel}
formSchemaRegistry={this._options.formSchemaRegistry}
annotationModel={this._options.annotationModel}
/>
);
}

private _mainViewModel: MainViewModel;
private _state?: IStateDB;
private _options: IOptions;
}
58 changes: 7 additions & 51 deletions packages/base/src/panelview/annotationPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { IAnnotationModel } from '@jupytergis/schema';
import { PanelWithToolbar, ReactWidget } from '@jupyterlab/ui-components';
import { IAnnotationModel, IJupyterGISModel } from '@jupytergis/schema';
import React, { Component } from 'react';

import Annotation from '@/src/annotations/components/Annotation';
import { IControlPanelModel } from '@/src/types';

interface IAnnotationPanelProps {
annotationModel: IAnnotationModel;
rightPanelModel: IControlPanelModel;
jgisModel: IJupyterGISModel;
}

export class AnnotationsPanel extends Component<IAnnotationPanelProps> {
Expand All @@ -19,20 +17,10 @@ export class AnnotationsPanel extends Component<IAnnotationPanelProps> {
};

this._annotationModel = props.annotationModel;
this._rightPanelModel = props.rightPanelModel;
this._jgisModel = props.jgisModel;

this._annotationModel.modelChanged.connect(async () => {
// await this._annotationModel?.context?.ready;

this._annotationModel?.model?.sharedMetadataChanged.disconnect(
updateCallback,
);
this._annotationModel = props.annotationModel;
this._annotationModel?.model?.sharedMetadataChanged.connect(
updateCallback,
);
this.forceUpdate();
});
this._annotationModel?.model?.sharedMetadataChanged.connect(updateCallback);
this.forceUpdate();
}

render(): JSX.Element {
Expand All @@ -46,7 +34,7 @@ export class AnnotationsPanel extends Component<IAnnotationPanelProps> {
return (
<div>
<Annotation
rightPanelModel={this._rightPanelModel}
jgisModel={this._jgisModel}
annotationModel={this._annotationModel}
itemId={id}
/>
Expand All @@ -59,37 +47,5 @@ export class AnnotationsPanel extends Component<IAnnotationPanelProps> {
}

private _annotationModel: IAnnotationModel;
private _rightPanelModel: IControlPanelModel;
}

export class Annotations extends PanelWithToolbar {
constructor(options: Annotations.IOptions) {
super({});

this.title.label = 'Annotations';
this.addClass('jgis-scrollable');

this._annotationModel = options.annotationModel;
this._rightPanelModel = options.rightPanelModel;

this._widget = ReactWidget.create(
<AnnotationsPanel
rightPanelModel={this._rightPanelModel}
annotationModel={this._annotationModel}
/>,
);

this.addWidget(this._widget);
}

private _widget: ReactWidget;
private _annotationModel: IAnnotationModel;
private _rightPanelModel: IControlPanelModel;
}

export namespace Annotations {
export interface IOptions {
annotationModel: IAnnotationModel;
rightPanelModel: IControlPanelModel;
}
private _jgisModel: IJupyterGISModel;
}
Loading
Loading