Skip to content

Commit a7007e8

Browse files
Restore type on vector layers.
1 parent 24677db commit a7007e8

File tree

5 files changed

+164
-49
lines changed

5 files changed

+164
-49
lines changed

packages/base/src/formbuilder/creationform.tsx

Lines changed: 148 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import * as React from 'react';
1414

1515
import { deepCopy } from '@/src/tools';
1616
import { getLayerTypeForm, getSourceTypeForm } from './formselectors';
17+
import { loadFile } from '@/src/tools';
1718

1819
export interface ICreationFormProps {
1920
/**
@@ -80,9 +81,15 @@ export class CreationForm extends React.Component<ICreationFormProps, any> {
8081
super(props);
8182

8283
this.filePath = props.model.filePath;
84+
console.log('filePath:', this.filePath);
8385
this.jGISModel = props.model;
8486
}
8587

88+
async loadData(path: string) {
89+
const data = await loadFile({ filepath: path, type: this.props.sourceType, model: this.jGISModel });
90+
return data
91+
}
92+
8693
render() {
8794
const sourceId = UUID.uuid4();
8895
let layerSchema: IDict | undefined = undefined;
@@ -186,56 +193,152 @@ export class CreationForm extends React.Component<ICreationFormProps, any> {
186193
visible: true,
187194
name: actualName,
188195
};
189-
190-
this.jGISModel.addLayer(UUID.uuid4(), layerModel);
196+
console.log('layerModel:', layerModel);
197+
198+
199+
if (this.props.layerType === 'VectorLayer' && this.props.sourceType === 'GeoJSONSource') {
200+
const data = await this.loadData(this.props?.sourceData?.path)
201+
const features = data.features;
202+
203+
let points: any = [];
204+
let lineStrings: any = [];
205+
let polygons: any = [];
206+
207+
features.forEach((feature: any) => {
208+
if (feature.geometry.type === 'Point') {
209+
points.push(feature);
210+
} else if (feature.geometry.type === 'LineString') {
211+
lineStrings.push(feature);
212+
} else if (feature.geometry.type === 'Polygon') {
213+
polygons.push(feature);
214+
}
215+
})
216+
const pointsData = {
217+
type: 'FeatureCollection',
218+
features: points,
219+
};
220+
221+
const lineStringsData = {
222+
type: 'FeatureCollection',
223+
features: lineStrings,
224+
};
225+
226+
const polygonData = {
227+
type: 'FeatureCollection',
228+
features: polygons,
229+
};
230+
231+
232+
const pointSource: IJGISSource = {
233+
name: "Point Source",
234+
type: "GeoJSONSource",
235+
parameters: {
236+
data: pointsData,
237+
},
238+
};
239+
240+
const lineStringSource: IJGISSource = {
241+
name: "LineString Source",
242+
type: "GeoJSONSource",
243+
parameters: {
244+
data: lineStringsData,
245+
},
246+
};
247+
248+
const polygonSource: IJGISSource = {
249+
name: "",
250+
type: "GeoJSONSource",
251+
parameters: {
252+
data: polygonData,
253+
},
254+
};
255+
256+
const pointLayer: IJGISLayer = {
257+
type: 'VectorLayer',
258+
visible: true,
259+
name: 'Point Vector Layer',
260+
parameters: {
261+
type: 'point',
262+
source: pointSource,
263+
},
264+
};
265+
266+
const lineStringLayer: IJGISLayer = {
267+
type: 'VectorLayer',
268+
visible: true,
269+
name: 'LineString Vector Layer',
270+
parameters: {
271+
type: 'lineString',
272+
source: lineStringSource,
273+
},
274+
};
275+
276+
const polygonLayer: IJGISLayer = {
277+
type: 'VectorLayer',
278+
visible: true,
279+
name: 'Polygon Vector Layer',
280+
parameters: {
281+
type: 'polygon',
282+
source: polygonSource,
283+
},
284+
};
285+
//this.jGISModel.addLayer(UUID.uuid4(), layerModel);
286+
this.jGISModel.addLayer(UUID.uuid4(), pointLayer);
287+
this.jGISModel.addLayer(UUID.uuid4(), lineStringLayer);
288+
this.jGISModel.addLayer(UUID.uuid4(), polygonLayer);
289+
}
191290
}
192291
});
193292

194293
return (
195294
<div>
196-
{this.props.createSource && (
197-
<div>
198-
<h3>Source Properties</h3>
199-
<SourceForm
200-
formContext="create"
201-
model={this.jGISModel}
202-
filePath={this.filePath}
203-
schema={sourceSchema}
204-
sourceData={this.props.sourceData}
205-
syncData={(properties: { [key: string]: any }) => {
206-
sourceCreationPromise?.resolve(properties);
207-
}}
208-
ok={this.props.ok}
209-
cancel={this.props.cancel}
210-
formChangedSignal={this.sourceFormChangedSignal}
211-
formErrorSignal={this.props.formErrorSignal}
212-
dialogOptions={this.props.dialogOptions}
213-
sourceType={this.props.sourceType}
214-
/>
215-
</div>
216-
)}
217-
{this.props.createLayer && (
218-
<div>
219-
<h3>Layer Properties</h3>
220-
<LayerForm
221-
formContext="create"
222-
sourceType={this.props.sourceType}
223-
model={this.jGISModel}
224-
filePath={this.filePath}
225-
schema={layerSchema}
226-
sourceData={layerData}
227-
syncData={(properties: { [key: string]: any }) => {
228-
layerCreationPromise?.resolve(properties);
229-
}}
230-
ok={this.props.ok}
231-
cancel={this.props.cancel}
232-
sourceFormChangedSignal={this.sourceFormChangedSignal}
233-
formErrorSignal={this.props.formErrorSignal}
234-
dialogOptions={this.props.dialogOptions}
235-
/>
236-
</div>
237-
)}
238-
</div>
295+
{
296+
this.props.createSource && (
297+
<div>
298+
<h3>Source Properties</h3>
299+
<SourceForm
300+
formContext="create"
301+
model={this.jGISModel}
302+
filePath={this.filePath}
303+
schema={sourceSchema}
304+
sourceData={this.props.sourceData}
305+
syncData={(properties: { [key: string]: any }) => {
306+
sourceCreationPromise?.resolve(properties);
307+
}}
308+
ok={this.props.ok}
309+
cancel={this.props.cancel}
310+
formChangedSignal={this.sourceFormChangedSignal}
311+
formErrorSignal={this.props.formErrorSignal}
312+
dialogOptions={this.props.dialogOptions}
313+
sourceType={this.props.sourceType}
314+
/>
315+
</div>
316+
)
317+
}
318+
{
319+
this.props.createLayer && (
320+
<div>
321+
<h3>Layer Properties</h3>
322+
<LayerForm
323+
formContext="create"
324+
sourceType={this.props.sourceType}
325+
model={this.jGISModel}
326+
filePath={this.filePath}
327+
schema={layerSchema}
328+
sourceData={layerData}
329+
syncData={(properties: { [key: string]: any }) => {
330+
layerCreationPromise?.resolve(properties);
331+
}}
332+
ok={this.props.ok}
333+
cancel={this.props.cancel}
334+
sourceFormChangedSignal={this.sourceFormChangedSignal}
335+
formErrorSignal={this.props.formErrorSignal}
336+
dialogOptions={this.props.dialogOptions}
337+
/>
338+
</div>
339+
)
340+
}
341+
</div >
239342
);
240343
}
241344

packages/base/src/tools.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,9 @@ export const loadFile = async (fileInfo: {
504504
model: IJupyterGISModel;
505505
}) => {
506506
const { filepath, type, model } = fileInfo;
507+
if (!filepath) {
508+
return;
509+
}
507510

508511
if (filepath.startsWith('http://') || filepath.startsWith('https://')) {
509512
switch (type) {

packages/schema/src/schema/project/layers/vectorLayer.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22
"type": "object",
33
"description": "VectorLayer",
44
"title": "IVectorLayer",
5-
"required": ["source"],
5+
"required": ["source", "type"],
66
"additionalProperties": false,
77
"properties": {
88
"source": {
99
"type": "string",
1010
"description": "The id of the source"
1111
},
12+
"type": {
13+
"type": "string",
14+
"enum": ["points", "polygons", "lines"],
15+
"default": "points",
16+
"description": "The type of vector layer"
17+
},
1218
"color": {
1319
"type": "object",
1420
"description": "The color of the the object"

python/jupytergis_lab/jupytergis_lab/notebook/gis_document.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ def add_geojson_layer(
245245
path: str | Path | None = None,
246246
data: Dict | None = None,
247247
name: str = "GeoJSON Layer",
248+
type: "points" | "polygons" | "lines" = "points",
248249
opacity: float = 1,
249250
logical_op: str | None = None,
250251
feature: str | None = None,
@@ -258,6 +259,7 @@ def add_geojson_layer(
258259
:param name: The name that will be used for the object in the document.
259260
:param path: The path to the JSON file or URL to embed into the jGIS file.
260261
:param data: The raw GeoJSON data to embed into the jGIS file.
262+
:param type: The type of the vector layer to create.
261263
:param opacity: The opacity, between 0 and 1.
262264
:param color_expr: The style expression used to style the layer, defaults to None
263265
"""
@@ -301,6 +303,7 @@ def add_geojson_layer(
301303
"visible": True,
302304
"parameters": {
303305
"source": source_id,
306+
"type": type,
304307
"color": color_expr,
305308
"opacity": opacity,
306309
},

python/jupytergis_qgis/jupytergis_qgis/qgis_loader.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ def build_uri(parameters: dict[str, str], source_type: str) -> str | None:
783783
geometry_type = layer.get("parameters", {}).get("type")
784784
layer_params = layer.get("parameters", {})
785785

786-
if geometry_type == "circle":
786+
if geometry_type == "points":
787787
symbol = QgsMarkerSymbol()
788788
color_params = layer_params.get("color", {})
789789
opacity = layer_params.get("opacity", 1.0)
@@ -811,7 +811,7 @@ def build_uri(parameters: dict[str, str], source_type: str) -> str | None:
811811
symbology_state, geometry_type, color_params, symbol
812812
)
813813

814-
elif geometry_type == "line":
814+
elif geometry_type == "lines":
815815
symbol = QgsLineSymbol()
816816
symbol.setOutputUnit(Qgis.RenderUnit.Pixels)
817817
color_params = layer_params.get("color", {})
@@ -840,7 +840,7 @@ def build_uri(parameters: dict[str, str], source_type: str) -> str | None:
840840
symbology_state, geometry_type, color_params, symbol
841841
)
842842

843-
elif geometry_type == "fill":
843+
elif geometry_type == "polygons":
844844
symbol = QgsFillSymbol()
845845
symbol.setOutputUnit(Qgis.RenderUnit.Pixels)
846846
color_params = layer_params.get("color", {})

0 commit comments

Comments
 (0)