Skip to content

Commit

Permalink
Working example to be polished
Browse files Browse the repository at this point in the history
  • Loading branch information
martinRenou committed Jul 15, 2024
1 parent c6f6dbe commit dd282ad
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 62 deletions.
55 changes: 29 additions & 26 deletions examples/buildings.jGIS
Original file line number Diff line number Diff line change
@@ -1,50 +1,53 @@
{
"layers": {
"f99eb7b0-5e38-4078-b310-36a0746472aa": {
"visible": true,
"name": "OpenStreetMap.Mapnik Layer",
"parameters": {
"source": "ed8628b0-3e0a-45d5-9cd0-65e2a7dd61f5"
},
"type": "RasterLayer"
},
"148f2fb3-3077-4dcb-8d70-831570d5021f": {
"type": "VectorLayer",
"name": "Vector Tile Source Layer",
"parameters": {
"type": "line",
"source": "7a7ee6fd-c1e2-4c5d-a4e2-a7974db138a4"
"opacity": 1.0,
"source": "7a7ee6fd-c1e2-4c5d-a4e2-a7974db138a4",
"sourceLayer": "bingmlbuildings",
"color": "green",
"type": "fill"
},
"name": "Vector Tile Source Layer",
"visible": true
},
"f99eb7b0-5e38-4078-b310-36a0746472aa": {
"parameters": {
"source": "ed8628b0-3e0a-45d5-9cd0-65e2a7dd61f5"
},
"visible": true,
"type": "RasterLayer",
"name": "OpenStreetMap.Mapnik Layer"
}
},
"sources": {
"7a7ee6fd-c1e2-4c5d-a4e2-a7974db138a4": {
"name": "Vector Tile Source",
"parameters": {
"minZoom": 13.0,
"url": "https://planetarycomputer.microsoft.com/api/data/v1/vector/collections/ms-buildings/tilesets/global-footprints/tiles/{z}/{x}/{y}",
"maxZoom": 13.0
},
"type": "VectorTileSource"
},
"ed8628b0-3e0a-45d5-9cd0-65e2a7dd61f5": {
"parameters": {
"urlParameters": {},
"provider": "OpenStreetMap",
"minZoom": 0.0,
"url": "https://tile.openstreetmap.org/{z}/{x}/{y}.png",
"maxZoom": 19.0,
"attribution": "(C) OpenStreetMap contributors",
"maxZoom": 19.0
"minZoom": 0.0,
"urlParameters": {}
},
"type": "RasterSource",
"name": "OpenStreetMap.Mapnik"
},
"7a7ee6fd-c1e2-4c5d-a4e2-a7974db138a4": {
"type": "VectorTileSource",
"name": "Vector Tile Source",
"parameters": {
"url": "https://planetarycomputer.microsoft.com/api/data/v1/vector/collections/ms-buildings/tilesets/global-footprints/tiles/{z}/{x}/{y}",
"minZoom": 0.0,
"maxZoom": 24.0
}
}
},
"options": {
"latitude": 41.91867,
"longitude": -88.10602,
"zoom": 15.0
"longitude": -88.1392955068439,
"zoom": 13.915138763623208,
"latitude": 41.932061631424034
},
"layerTree": [
"f99eb7b0-5e38-4078-b310-36a0746472aa",
Expand Down
1 change: 0 additions & 1 deletion packages/base/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ namespace Private {
default: (model: IJupyterGISModel) => {
return {
name: 'Vector Tile Source',
url: 'https://planetarycomputer.microsoft.com/api/data/v1/vector/collections/ms-buildings/tilesets/global-footprints/tiles/{z}/{x}/{y}',
maxZoom: 24,
minZoom: 0
};
Expand Down
63 changes: 32 additions & 31 deletions packages/base/src/mainview/mainview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {
IJupyterGISDoc,
IJupyterGISModel,
IRasterSource,
JupyterGISModel
JupyterGISModel,
IVectorLayer,
IVectorTileSource
} from '@jupytergis/schema';
import { showErrorMessage } from '@jupyterlab/apputils';
import { IObservableMap, ObservableMap } from '@jupyterlab/observables';
Expand Down Expand Up @@ -166,8 +168,12 @@ export class MainView extends React.Component<IProps, IStates> {
case 'VectorTileSource': {
const mapSource = this._Map.getSource(id) as MapLibre.VectorTileSource;
if (!mapSource) {
const parameters = source.parameters as IVectorTileSource;
this._Map.addSource(id, {
type: 'vector',
minzoom: parameters.minZoom,
maxzoom: parameters.maxZoom,
attribution: parameters.attribution || '',
tiles: [this.computeSourceUrl(source)]
});
}
Expand Down Expand Up @@ -367,39 +373,34 @@ export class MainView extends React.Component<IProps, IStates> {
break;
}
case 'VectorLayer': {
const vectorLayerType = layer.parameters?.type;
if (!vectorLayerType) {
showErrorMessage(
'Vector layer error',
'The vector layer type is undefined'
);
}
this._Map.addLayer(
{
id: id,
type: 'line',
"source-layer": 'buildings',
layout: {
visibility: layer.visible ? 'visible' : 'none'
},
source: sourceId,
minzoom: source.parameters?.minZoom || 0,
maxzoom: source.parameters?.maxZoom || 24
const parameters = layer.parameters as IVectorLayer;
const layerSpecification: MapLibre.AddLayerObject = {
id,
type: parameters.type,
layout: {
visibility: layer.visible ? 'visible' : 'none'
},
source: sourceId,
};

parameters.sourceLayer && (layerSpecification['source-layer'] = parameters.sourceLayer);

this._Map.addLayer(
layerSpecification,
beforeId
);
// this._Map.setPaintProperty(
// id,
// `${vectorLayerType}-color`,
// layer.parameters?.color !== undefined
// ? layer.parameters.color
// : '#FF0000'
// );
// this._Map.setPaintProperty(
// id,
// `${vectorLayerType}-opacity`,
// layer.parameters?.opacity !== undefined ? layer.parameters.opacity : 1
// );
this._Map.setPaintProperty(
id,
`${parameters.type}-color`,
parameters.color !== undefined
? parameters.color
: '#FF0000'
);
this._Map.setPaintProperty(
id,
`${parameters.type}-opacity`,
parameters.opacity !== undefined ? parameters.opacity : 1
);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "object",
"description": "VectorLayer",
"title": "IVectorLayer",
"required": ["source"],
"required": ["source", "type"],
"additionalProperties": false,
"properties": {
"source": {
Expand All @@ -15,6 +15,10 @@
"default": "line",
"description": "The type of vector layer"
},
"sourceLayer": {
"type": "string",
"description": "The source layer to use"
},
"color": {
"type": "string",
"description": "The color of the the object",
Expand Down
3 changes: 0 additions & 3 deletions packages/schema/src/schema/vectortilesource.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,16 @@
"type": "number",
"minimum": 0,
"maximum": 24,
"readOnly": true,
"description": "The maximum zoom level for the raster source"
},
"minZoom": {
"type": "number",
"minimum": 0,
"maximum": 24,
"readOnly": true,
"description": "The minimum zoom level for the raster source"
},
"attribution": {
"type": "string",
"readOnly": true,
"description": "The attribution for the raster source"
},
"provider": {
Expand Down
3 changes: 3 additions & 0 deletions packages/schema/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export * from './_interface/jgis';
export * from './_interface/rasterlayer';
export * from './_interface/vectorlayer';
export * from './_interface/rastersource';
export * from './_interface/vectortilesource';
export * from './_interface/geojsonsource';
export * from './interfaces';
export * from './model';
export * from './doc';
Expand Down

0 comments on commit dd282ad

Please sign in to comment.