diff --git a/configs/seed_config.json b/configs/seed_config.json index 7c1a99b..78f1334 100644 --- a/configs/seed_config.json +++ b/configs/seed_config.json @@ -25,13 +25,34 @@ "style": { "paint": { "line-color": "hsl(248,7%,66%)" } } }, { - "id": "inventaire", + "id": "seed", "type": "datapackage", + "layerType": "circle", "path": "../catalog/seed/datapackage.json", "resource": "survey", + "columns": { + "geom": "geom", + "id": "OGC_FID", + "orga": "votre_orga", + "responsable": "nom_du_res", + "date_plantation": "date_de_pl", + "type_plant": "type_de_pl", + "prelevement_mangrove": "trace_de_p", + "test": "round(random() * 4 ) + 1" + }, "popup": { "trigger": "click" } + }, + { + "id": "seed_point", + "type": "datapackage", + "path": "../catalog/seed/datapackage.json", + "resource": "survey", + "columns": { + "geom": "centroid(geom)" + }, + "maxzoom": 13 } ], "controls": [ diff --git a/coordo-py/coordo/map/datapackage.py b/coordo-py/coordo/map/datapackage.py index ed2daa8..d9e1b4a 100644 --- a/coordo-py/coordo/map/datapackage.py +++ b/coordo-py/coordo/map/datapackage.py @@ -33,6 +33,7 @@ class DataPackageLayer(BaseLayerModel): filter: str | None = None groupby: list[str] | None = None columns: dict[str, str] | None = None + layerType: str | None = None popup: Popup | None = None def to_maplibre(self, base_path): @@ -40,18 +41,7 @@ def to_maplibre(self, base_path): resource = package.get_resource(name=self.resource) data = self.get_data(base_path=base_path) - # We check the type of the first non-null geometry, it doesn't support yet mixed geometries - geom_type = ( - next(f["geometry"] for f in data["features"] if f["geometry"])["type"] - if data["features"] - else "Point" - ) - if "Polygon" in geom_type: - layer_type = "fill" - elif "LineString" in geom_type: - layer_type = "line" - else: - layer_type = "circle" + layer_type = self.layerType or self.infer_layer_type(data["features"]) source = GeoJSONSource(type="geojson", data=data) metadata = { @@ -97,3 +87,20 @@ def get_data(self, *, base_path, filter=None) -> FeatureCollection: ) assert isinstance(df, GeoDataFrame), "No geometry column found." return df.to_geo_dict(show_bbox=True) # type: ignore + + def infer_layer_type(self, features): + # We check the type of the first non-null geometry, it doesn't support yet mixed geometries + geom_type = ( + next(f["geometry"] for f in features if f["geometry"])["type"] + if features + else "Point" + ) + if "Polygon" in geom_type: + layer_type = "fill" + elif "LineString" in geom_type: + layer_type = "line" + else: + layer_type = "circle" + + return layer_type +