Skip to content

Commit 40e915b

Browse files
Increased the width of main-panel in notebook viewer (#787)
* Increased main-panel width(#761) * Add a comment Co-authored-by: martinRenou <[email protected]> --------- Co-authored-by: martinRenou <[email protected]>
1 parent 85c7b9e commit 40e915b

File tree

1 file changed

+89
-15
lines changed

1 file changed

+89
-15
lines changed

packages/base/src/mainview/mainView.tsx

Lines changed: 89 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,35 @@ export class MainView extends React.Component<IProps, IStates> {
112112
constructor(props: IProps) {
113113
super(props);
114114

115+
// Enforce the map to take the full available width in the case of Jupyter Notebook viewer
116+
const el = document.getElementById('main-panel');
117+
118+
if (el) {
119+
const setWidthOneHundred = (selector: string) => {
120+
(document.querySelector(selector) as HTMLElement).style.setProperty(
121+
'width',
122+
'100%',
123+
);
124+
};
125+
//We need to observe the size to counteract
126+
//What the default jupyter plugin will try
127+
//To do dynamically with the width
128+
const resizeObserver = new ResizeObserver(_ => {
129+
el.style.setProperty('width', '100%');
130+
el.style.setProperty('max-width', '100%');
131+
el?.style.setProperty('left', '0px');
132+
133+
setWidthOneHundred('#main-panel jp-toolbar');
134+
setWidthOneHundred('#main-panel .lm-SplitPanel ');
135+
136+
setWidthOneHundred(
137+
'#main-panel .lm-SplitPanel .lm-SplitPanel-child ',
138+
);
139+
});
140+
141+
resizeObserver.observe(el);
142+
}
143+
115144
this._mainViewModel = this.props.viewModel;
116145
this._mainViewModel.viewSettingChanged.connect(this._onViewChanged, this);
117146

@@ -173,7 +202,9 @@ export class MainView extends React.Component<IProps, IStates> {
173202
this._sources = [];
174203
this._loadingLayers = new Set();
175204
this._commands = new CommandRegistry();
176-
this._contextMenu = new ContextMenu({ commands: this._commands });
205+
this._contextMenu = new ContextMenu({
206+
commands: this._commands,
207+
});
177208
}
178209

179210
async componentDidMount(): Promise<void> {
@@ -184,6 +215,7 @@ export class MainView extends React.Component<IProps, IStates> {
184215
? fromLonLat([options.longitude!, options.latitude!])
185216
: [0, 0];
186217
const zoom = options.zoom !== undefined ? options.zoom! : 1;
218+
187219
await this.generateMap(center, zoom);
188220
this.addContextMenu();
189221
this._mainViewModel.initSignal();
@@ -285,7 +317,13 @@ export class MainView extends React.Component<IProps, IStates> {
285317
return;
286318
}
287319
this._model.syncViewport(
288-
{ coordinates: { x: center[0], y: center[1] }, zoom },
320+
{
321+
coordinates: {
322+
x: center[0],
323+
y: center[1],
324+
},
325+
zoom,
326+
},
289327
this._mainViewModel.id,
290328
);
291329
}),
@@ -458,7 +496,10 @@ export class MainView extends React.Component<IProps, IStates> {
458496
}
459497

460498
this._mainViewModel.addAnnotation({
461-
position: { x: this._clickCoords[0], y: this._clickCoords[1] },
499+
position: {
500+
x: this._clickCoords[0],
501+
y: this._clickCoords[1],
502+
},
462503
zoom: this._Map.getView().getZoom() ?? 0,
463504
label: 'New annotation',
464505
contents: [],
@@ -538,7 +579,9 @@ export class MainView extends React.Component<IProps, IStates> {
538579
minZoom: sourceParameters.minZoom,
539580
maxZoom: sourceParameters.maxZoom,
540581
url: url,
541-
format: new MVT({ featureClass: RenderFeature }),
582+
format: new MVT({
583+
featureClass: RenderFeature,
584+
}),
542585
});
543586
} else {
544587
newSource = new PMTilesVectorSource({
@@ -916,7 +959,9 @@ export class MainView extends React.Component<IProps, IStates> {
916959
};
917960

918961
if (layerParameters.color) {
919-
layerOptions['style'] = { color: layerParameters.color };
962+
layerOptions['style'] = {
963+
color: layerParameters.color,
964+
};
920965
}
921966

922967
newMapLayer = new WebGlTileLayer(layerOptions);
@@ -1339,8 +1384,13 @@ export class MainView extends React.Component<IProps, IStates> {
13391384
return new Style({
13401385
image: new Circle({
13411386
radius: 6,
1342-
fill: new Fill({ color: 'rgba(255, 255, 0, 0.8)' }),
1343-
stroke: new Stroke({ color: '#ff0', width: 2 }),
1387+
fill: new Fill({
1388+
color: 'rgba(255, 255, 0, 0.8)',
1389+
}),
1390+
stroke: new Stroke({
1391+
color: '#ff0',
1392+
width: 2,
1393+
}),
13441394
}),
13451395
});
13461396
case 'LineString':
@@ -1388,7 +1438,10 @@ export class MainView extends React.Component<IProps, IStates> {
13881438
return new Promise(resolve => {
13891439
const checkReady = () => {
13901440
if (this._loadingLayers.size === 0) {
1391-
this.setState(old => ({ ...old, loadingLayer: false }));
1441+
this.setState(old => ({
1442+
...old,
1443+
loadingLayer: false,
1444+
}));
13921445
resolve();
13931446
} else {
13941447
setTimeout(checkReady, 50);
@@ -1454,7 +1507,10 @@ export class MainView extends React.Component<IProps, IStates> {
14541507
}
14551508

14561509
if (remoteState.user?.username !== this.state.remoteUser?.username) {
1457-
this.setState(old => ({ ...old, remoteUser: remoteState.user }));
1510+
this.setState(old => ({
1511+
...old,
1512+
remoteUser: remoteState.user,
1513+
}));
14581514
}
14591515

14601516
const remoteViewport = remoteState.viewportState;
@@ -1468,7 +1524,10 @@ export class MainView extends React.Component<IProps, IStates> {
14681524
} else {
14691525
// If we are unfollowing a remote user, we reset our center and zoom to their previous values
14701526
if (this.state.remoteUser !== null) {
1471-
this.setState(old => ({ ...old, remoteUser: null }));
1527+
this.setState(old => ({
1528+
...old,
1529+
remoteUser: null,
1530+
}));
14721531
const viewportState = localState.viewportState?.value;
14731532

14741533
if (viewportState) {
@@ -1506,14 +1565,26 @@ export class MainView extends React.Component<IProps, IStates> {
15061565
username: client.user.username,
15071566
displayName: client.user.display_name,
15081567
color: client.user.color,
1509-
coordinates: { x: pixel[0], y: pixel[1] },
1510-
lonLat: { longitude: lonLat[0], latitude: lonLat[1] },
1568+
coordinates: {
1569+
x: pixel[0],
1570+
y: pixel[1],
1571+
},
1572+
lonLat: {
1573+
longitude: lonLat[0],
1574+
latitude: lonLat[1],
1575+
},
15111576
};
15121577
} else {
15131578
currentClientPointer = {
15141579
...currentClientPointer,
1515-
coordinates: { x: pixel[0], y: pixel[1] },
1516-
lonLat: { longitude: lonLat[0], latitude: lonLat[1] },
1580+
coordinates: {
1581+
x: pixel[0],
1582+
y: pixel[1],
1583+
},
1584+
lonLat: {
1585+
longitude: lonLat[0],
1586+
latitude: lonLat[1],
1587+
},
15171588
};
15181589
}
15191590

@@ -1875,7 +1946,10 @@ export class MainView extends React.Component<IProps, IStates> {
18751946
// Zoom needs to be set before changing center
18761947
if (!view.animate === undefined) {
18771948
view.animate({ zoom, duration });
1878-
view.animate({ center: [center.x, center.y], duration });
1949+
view.animate({
1950+
center: [center.x, center.y],
1951+
duration,
1952+
});
18791953
}
18801954
}
18811955

0 commit comments

Comments
 (0)