Skip to content

Commit

Permalink
Switch to maplibre + some tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
martinRenou committed Jun 19, 2024
1 parent 4752863 commit 9c4ca6e
Show file tree
Hide file tree
Showing 6 changed files with 423 additions and 162 deletions.
2 changes: 1 addition & 1 deletion packages/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@types/d3-color": "^3.1.0",
"@types/three": "^0.134.0",
"d3-color": "^3.1.0",
"ol": "^9.2.4",
"maplibre-gl": "^4.4.1",
"react": "^18.0.1",
"styled-components": "^5.3.6",
"three": "^0.135.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/base/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const LAYERS = {
return {
name: newName('TileLayer', model),
url: "https://tile.openstreetmap.org/{z}/{x}/{y}.png",
maxZoom: 10,
minZoom: 1
maxZoom: 24,
minZoom: 0
};
}
},
Expand Down
39 changes: 17 additions & 22 deletions packages/base/src/mainview/mainview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { User } from '@jupyterlab/services';
import { JSONValue } from '@lumino/coreutils';
import * as React from 'react';

import * as OpenLayer from './ol';
import * as MapLibre from 'maplibre-gl';

import 'ol/ol.css';
// import 'maplibre-gl.css';

import { isLightTheme } from '../tools';
import { MainViewModel } from './mainviewmodel';
Expand Down Expand Up @@ -93,22 +93,11 @@ export class MainView extends React.Component<IProps, IStates> {

generateScene = (): void => {
if (this.divRef.current) {
this._openLayersMap = new OpenLayer.Map({
target: this.divRef.current,
// layers: [
// new OpenLayer.TileLayer({
// source: new OpenLayer.XYZ({
// url: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png'
// })
// })
// ],
view: new OpenLayer.View({
center: [0, 0],
zoom: 2
})
this._Map = new MapLibre.Map({
container: this.divRef.current
});

console.log('created map', this._openLayersMap);
console.log('created map', this._Map);

this.setState(old => ({ ...old, loading: false }));
}
Expand Down Expand Up @@ -148,12 +137,18 @@ export class MainView extends React.Component<IProps, IStates> {
switch(layer.layerType) {
case 'TileLayer':
const tileLayerParameters = layer.parameters as ITileLayer;
const tileLayer = new OpenLayer.TileLayer({
source: new OpenLayer.XYZ({
url: tileLayerParameters.url
})
this._Map.addSource('raster-source', {
'type': 'raster',
'tiles': [tileLayerParameters.url],
'tileSize': 256,
});
this._Map.addLayer({
id: 'simple-tiles',
type: 'raster',
source: 'raster-source',
minzoom: tileLayerParameters.minZoom,
maxzoom: tileLayerParameters.maxZoom,
});
this._openLayersMap.addLayer(tileLayer);
}
}
}
Expand Down Expand Up @@ -195,7 +190,7 @@ export class MainView extends React.Component<IProps, IStates> {

private divRef = React.createRef<HTMLDivElement>(); // Reference of render div

private _openLayersMap: OpenLayer.Map;
private _Map: MapLibre.Map;

private _model: IJupyterGISModel;
private _mainViewModel: MainViewModel;
Expand Down
4 changes: 0 additions & 4 deletions packages/base/src/mainview/ol.ts

This file was deleted.

6 changes: 4 additions & 2 deletions packages/schema/src/schema/tilelayer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
},
"maxZoom": {
"type": "number",
"exclusiveMinimum": 0,
"minimum": 0,
"maximum": 24,
"description": "The maximum zoom level for the tile layer"
},
"minZoom": {
"type": "number",
"exclusiveMinimum": 0,
"minimum": 0,
"maximum": 24,
"description": "The minimum zoom level for the tile layer"
}
}
Expand Down
Loading

0 comments on commit 9c4ca6e

Please sign in to comment.