@jupytergis/base 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/mainview/mainView.d.ts +8 -7
- package/lib/mainview/mainView.js +44 -80
- package/package.json +2 -2
|
@@ -47,6 +47,14 @@ export declare class MainView extends React.Component<IProps, IStates> {
|
|
|
47
47
|
*/
|
|
48
48
|
updateLayers(layerIds: string[]): void;
|
|
49
49
|
private _updateLayersImpl;
|
|
50
|
+
/**
|
|
51
|
+
* Build the map layer.
|
|
52
|
+
*
|
|
53
|
+
* @param id - id of the layer.
|
|
54
|
+
* @param layer - the layer object.
|
|
55
|
+
* @returns - the map layer.
|
|
56
|
+
*/
|
|
57
|
+
private _buildMapLayer;
|
|
50
58
|
/**
|
|
51
59
|
* Add a layer to the map.
|
|
52
60
|
*
|
|
@@ -65,13 +73,6 @@ export declare class MainView extends React.Component<IProps, IStates> {
|
|
|
65
73
|
* @returns
|
|
66
74
|
*/
|
|
67
75
|
private hillshadeMath;
|
|
68
|
-
/**
|
|
69
|
-
* Move a layer in the stack.
|
|
70
|
-
*
|
|
71
|
-
* @param id - id of the layer.
|
|
72
|
-
* @param index - expected index of the layer.
|
|
73
|
-
*/
|
|
74
|
-
moveLayer(id: string, index: number | undefined): void;
|
|
75
76
|
/**
|
|
76
77
|
* Update a layer of the map.
|
|
77
78
|
*
|
package/lib/mainview/mainView.js
CHANGED
|
@@ -215,10 +215,7 @@ export class MainView extends React.Component {
|
|
|
215
215
|
projection: projection.getCode(),
|
|
216
216
|
zoom
|
|
217
217
|
};
|
|
218
|
-
|
|
219
|
-
if (currentOptions.extent) {
|
|
220
|
-
updatedOptions.extent = view.calculateExtent();
|
|
221
|
-
}
|
|
218
|
+
updatedOptions.extent = view.calculateExtent();
|
|
222
219
|
this._model.setOptions(Object.assign(Object.assign({}, currentOptions), updatedOptions));
|
|
223
220
|
});
|
|
224
221
|
if (JupyterGISModel.getOrderedLayerIds(this._model).length !== 0) {
|
|
@@ -426,59 +423,30 @@ export class MainView extends React.Component {
|
|
|
426
423
|
this._updateLayersImpl(layerIds);
|
|
427
424
|
}
|
|
428
425
|
async _updateLayersImpl(layerIds) {
|
|
429
|
-
const
|
|
430
|
-
|
|
431
|
-
// bottom.
|
|
432
|
-
// This is to ensure that the beforeId (layer on top of the one we add/move)
|
|
433
|
-
// is already added/moved in the map.
|
|
434
|
-
const reversedLayerIds = layerIds.slice().reverse();
|
|
435
|
-
for (const layerId of reversedLayerIds) {
|
|
426
|
+
const mapLayers = [];
|
|
427
|
+
for (const layerId of layerIds) {
|
|
436
428
|
const layer = this._model.sharedModel.getLayer(layerId);
|
|
437
429
|
if (!layer) {
|
|
438
430
|
console.log(`Layer id ${layerId} does not exist`);
|
|
439
|
-
|
|
440
|
-
}
|
|
441
|
-
// Get the expected index in the map.
|
|
442
|
-
const currentLayerIds = [...previousLayerIds];
|
|
443
|
-
let indexInMap = currentLayerIds.length;
|
|
444
|
-
const nextLayer = layerIds[layerIds.indexOf(layerId) + 1];
|
|
445
|
-
if (nextLayer !== undefined) {
|
|
446
|
-
indexInMap = currentLayerIds.indexOf(nextLayer);
|
|
447
|
-
if (indexInMap === -1) {
|
|
448
|
-
indexInMap = currentLayerIds.length;
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
if (this.getLayer(layerId)) {
|
|
452
|
-
this.moveLayer(layerId, indexInMap);
|
|
453
|
-
}
|
|
454
|
-
else {
|
|
455
|
-
await this.addLayer(layerId, layer, indexInMap);
|
|
431
|
+
continue;
|
|
456
432
|
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
previousLayerIds.splice(index, 1);
|
|
433
|
+
const newMapLayer = await this._buildMapLayer(layerId, layer);
|
|
434
|
+
if (newMapLayer !== undefined) {
|
|
435
|
+
mapLayers.push(newMapLayer);
|
|
461
436
|
}
|
|
462
437
|
}
|
|
463
|
-
|
|
464
|
-
previousLayerIds.forEach(layerId => {
|
|
465
|
-
this._Map.removeLayer(layerId);
|
|
466
|
-
});
|
|
438
|
+
this._Map.setLayers(mapLayers);
|
|
467
439
|
this._ready = true;
|
|
468
440
|
}
|
|
469
441
|
/**
|
|
470
|
-
*
|
|
442
|
+
* Build the map layer.
|
|
471
443
|
*
|
|
472
444
|
* @param id - id of the layer.
|
|
473
445
|
* @param layer - the layer object.
|
|
474
|
-
* @
|
|
446
|
+
* @returns - the map layer.
|
|
475
447
|
*/
|
|
476
|
-
async
|
|
448
|
+
async _buildMapLayer(id, layer) {
|
|
477
449
|
var _a;
|
|
478
|
-
if (this.getLayer(id)) {
|
|
479
|
-
// Layer already exists
|
|
480
|
-
return;
|
|
481
|
-
}
|
|
482
450
|
const sourceId = (_a = layer.parameters) === null || _a === void 0 ? void 0 : _a.source;
|
|
483
451
|
const source = this._model.sharedModel.getSource(sourceId);
|
|
484
452
|
if (!source) {
|
|
@@ -487,14 +455,14 @@ export class MainView extends React.Component {
|
|
|
487
455
|
if (!this._sources[sourceId]) {
|
|
488
456
|
await this.addSource(sourceId, source);
|
|
489
457
|
}
|
|
490
|
-
let
|
|
458
|
+
let newMapLayer;
|
|
491
459
|
let layerParameters;
|
|
492
460
|
// TODO: OpenLayers provides a bunch of sources for specific tile
|
|
493
461
|
// providers, so maybe set up some way to use those
|
|
494
462
|
switch (layer.type) {
|
|
495
463
|
case 'RasterLayer': {
|
|
496
464
|
layerParameters = layer.parameters;
|
|
497
|
-
|
|
465
|
+
newMapLayer = new TileLayer({
|
|
498
466
|
opacity: layerParameters.opacity,
|
|
499
467
|
visible: layer.visible,
|
|
500
468
|
source: this._sources[layerParameters.source]
|
|
@@ -503,7 +471,7 @@ export class MainView extends React.Component {
|
|
|
503
471
|
}
|
|
504
472
|
case 'VectorLayer': {
|
|
505
473
|
layerParameters = layer.parameters;
|
|
506
|
-
|
|
474
|
+
newMapLayer = new VectorLayer({
|
|
507
475
|
opacity: layerParameters.opacity,
|
|
508
476
|
visible: layer.visible,
|
|
509
477
|
source: this._sources[layerParameters.source],
|
|
@@ -516,16 +484,16 @@ export class MainView extends React.Component {
|
|
|
516
484
|
if (!layerParameters.color) {
|
|
517
485
|
return;
|
|
518
486
|
}
|
|
519
|
-
|
|
487
|
+
newMapLayer = new VectorTileLayer({
|
|
520
488
|
opacity: layerParameters.opacity,
|
|
521
489
|
source: this._sources[layerParameters.source]
|
|
522
490
|
});
|
|
523
|
-
this.updateLayer(id, layer,
|
|
491
|
+
this.updateLayer(id, layer, newMapLayer);
|
|
524
492
|
break;
|
|
525
493
|
}
|
|
526
494
|
case 'HillshadeLayer': {
|
|
527
495
|
layerParameters = layer.parameters;
|
|
528
|
-
|
|
496
|
+
newMapLayer = new WebGlTileLayer({
|
|
529
497
|
opacity: 0.3,
|
|
530
498
|
source: this._sources[layerParameters.source],
|
|
531
499
|
style: {
|
|
@@ -536,7 +504,7 @@ export class MainView extends React.Component {
|
|
|
536
504
|
}
|
|
537
505
|
case 'ImageLayer': {
|
|
538
506
|
layerParameters = layer.parameters;
|
|
539
|
-
|
|
507
|
+
newMapLayer = new ImageLayer({
|
|
540
508
|
opacity: layerParameters.opacity,
|
|
541
509
|
source: this._sources[layerParameters.source]
|
|
542
510
|
});
|
|
@@ -552,43 +520,32 @@ export class MainView extends React.Component {
|
|
|
552
520
|
if (layerParameters.color) {
|
|
553
521
|
layerOptions['style'] = { color: layerParameters.color };
|
|
554
522
|
}
|
|
555
|
-
|
|
523
|
+
newMapLayer = new WebGlTileLayer(layerOptions);
|
|
556
524
|
break;
|
|
557
525
|
}
|
|
558
526
|
}
|
|
559
527
|
// OpenLayers doesn't have name/id field so add it
|
|
560
|
-
|
|
528
|
+
newMapLayer.set('id', id);
|
|
561
529
|
// we need to keep track of which source has which layers
|
|
562
530
|
this._sourceToLayerMap.set(layerParameters.source, id);
|
|
563
|
-
|
|
531
|
+
return newMapLayer;
|
|
564
532
|
}
|
|
565
533
|
/**
|
|
566
|
-
*
|
|
534
|
+
* Add a layer to the map.
|
|
567
535
|
*
|
|
568
536
|
* @param id - id of the layer.
|
|
537
|
+
* @param layer - the layer object.
|
|
569
538
|
* @param index - expected index of the layer.
|
|
570
539
|
*/
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
let beforeId = undefined;
|
|
575
|
-
if (!(index === undefined) && index < currentLayerIds.length) {
|
|
576
|
-
beforeId = currentLayerIds[index];
|
|
577
|
-
}
|
|
578
|
-
const layerArray = this._Map.getLayers().getArray();
|
|
579
|
-
const movingLayer = this.getLayer(id);
|
|
580
|
-
if (!movingLayer || !index || !beforeId) {
|
|
540
|
+
async addLayer(id, layer, index) {
|
|
541
|
+
if (this.getLayer(id)) {
|
|
542
|
+
// Layer already exists
|
|
581
543
|
return;
|
|
582
544
|
}
|
|
583
|
-
const
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
if (!beforeLayer) {
|
|
587
|
-
return;
|
|
545
|
+
const newMapLayer = await this._buildMapLayer(id, layer);
|
|
546
|
+
if (newMapLayer !== undefined) {
|
|
547
|
+
this._Map.getLayers().insertAt(index, newMapLayer);
|
|
588
548
|
}
|
|
589
|
-
const indexOfBeforeLayer = layerArray.indexOf(beforeLayer);
|
|
590
|
-
layerArray.splice(indexOfBeforeLayer, 0, movingLayer);
|
|
591
|
-
this._Map.setLayers(layerArray);
|
|
592
549
|
}
|
|
593
550
|
/**
|
|
594
551
|
* Update a layer of the map.
|
|
@@ -662,14 +619,19 @@ export class MainView extends React.Component {
|
|
|
662
619
|
}
|
|
663
620
|
updateOptions(options) {
|
|
664
621
|
const view = this._Map.getView();
|
|
665
|
-
//
|
|
666
|
-
if (options.extent) {
|
|
622
|
+
// Use the extent only if explicitly requested (QGIS files).
|
|
623
|
+
if (options.extent && options.useExtent) {
|
|
667
624
|
view.fit(options.extent);
|
|
668
625
|
}
|
|
669
626
|
else {
|
|
670
627
|
const centerCoord = fromLonLat([options.longitude || 0, options.latitude || 0], this._Map.getView().getProjection());
|
|
671
628
|
this._Map.getView().setZoom(options.zoom || 0);
|
|
672
629
|
this._Map.getView().setCenter(centerCoord);
|
|
630
|
+
// Save the extent if it does not exists, to allow proper export to qgis.
|
|
631
|
+
if (options.extent === undefined) {
|
|
632
|
+
options.extent = view.calculateExtent();
|
|
633
|
+
this._model.setOptions(options);
|
|
634
|
+
}
|
|
673
635
|
}
|
|
674
636
|
view.setRotation(options.bearing || 0);
|
|
675
637
|
}
|
|
@@ -709,12 +671,14 @@ export class MainView extends React.Component {
|
|
|
709
671
|
}
|
|
710
672
|
else {
|
|
711
673
|
const mapLayer = this.getLayer(change.id);
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
674
|
+
const layerTree = JupyterGISModel.getOrderedLayerIds(this._model);
|
|
675
|
+
if (mapLayer) {
|
|
676
|
+
if (layerTree.includes(change.id)) {
|
|
677
|
+
this.updateLayer(change.id, layer, mapLayer);
|
|
678
|
+
}
|
|
679
|
+
else {
|
|
680
|
+
this.updateLayers(layerTree);
|
|
681
|
+
}
|
|
718
682
|
}
|
|
719
683
|
}
|
|
720
684
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupytergis/base",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "A JupyterLab extension for 3D modelling.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jupyter",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@deathbeds/jupyterlab-rjsf": "^1.1.0",
|
|
42
42
|
"@jupyter/docprovider": "^2.0.0",
|
|
43
43
|
"@jupyter/ydoc": "^1.0.0",
|
|
44
|
-
"@jupytergis/schema": "^0.1.
|
|
44
|
+
"@jupytergis/schema": "^0.1.4",
|
|
45
45
|
"@jupyterlab/application": "^4.0.0",
|
|
46
46
|
"@jupyterlab/apputils": "^4.0.0",
|
|
47
47
|
"@jupyterlab/completer": "^4.2.4",
|