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 fb41984 commit e373e53
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 60 deletions.
53 changes: 28 additions & 25 deletions examples/buildings.jGIS
Original file line number Diff line number Diff line change
@@ -1,50 +1,53 @@
{
"layers": {
"f99eb7b0-5e38-4078-b310-36a0746472aa": {
"148f2fb3-3077-4dcb-8d70-831570d5021f": {
"visible": true,
"name": "OpenStreetMap.Mapnik Layer",
"name": "Vector Tile Source Layer",
"parameters": {
"source": "ed8628b0-3e0a-45d5-9cd0-65e2a7dd61f5"
"source": "7a7ee6fd-c1e2-4c5d-a4e2-a7974db138a4",
"color": "green",
"type": "line",
"opacity": 1.0,
"sourceLayer": "bingmlbuildings"
},
"type": "RasterLayer"
"type": "VectorLayer"
},
"148f2fb3-3077-4dcb-8d70-831570d5021f": {
"type": "VectorLayer",
"f99eb7b0-5e38-4078-b310-36a0746472aa": {
"parameters": {
"type": "line",
"source": "7a7ee6fd-c1e2-4c5d-a4e2-a7974db138a4"
"source": "ed8628b0-3e0a-45d5-9cd0-65e2a7dd61f5"
},
"name": "Vector Tile Source Layer",
"visible": true
"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.13435505719718,
"zoom": 14.558550718914468,
"latitude": 41.924770461743464
},
"layerTree": [
"f99eb7b0-5e38-4078-b310-36a0746472aa",
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 @@ -9,7 +9,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 @@ -169,8 +171,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 @@ -370,39 +376,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 e373e53

Please sign in to comment.