From 98ba471b2959bbd29130a67600c30975d72c3cfc Mon Sep 17 00:00:00 2001 From: Vitor George Date: Thu, 4 Jul 2024 17:33:32 +0100 Subject: [PATCH] Fix attribution (#561) This adds a `custom_attribution` property to the `Map` class and fix Maplibre CSS by adding an import. Contributes to: - #436 - #545 --- lonboard/_map.py | 38 ++++++++++++++++++++++++++++++++++++++ src/index.tsx | 7 ++++++- src/model/base-layer.ts | 2 -- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/lonboard/_map.py b/lonboard/_map.py index bf207e0a..a18318cd 100644 --- a/lonboard/_map.py +++ b/lonboard/_map.py @@ -167,6 +167,44 @@ def __init__( [`lonboard.basemap.CartoBasemap.PositronNoLabels`][lonboard.basemap.CartoBasemap.PositronNoLabels] """ + custom_attribution = traitlets.Union( + [ + traitlets.Unicode(allow_none=True), + traitlets.List(traitlets.Unicode(allow_none=False)), + ] + ).tag(sync=True) + """ + Custom attribution to display on the map. + + This attribute supports the same format as the `attribution` property in the + Maplibre API. + + - Type: `str` or `List[str]` + - Default: `None` + + You can provide either a single string or a list of strings for custom attributions. + If an attribution value is set in the map style, it will be displayed in addition to + this custom attribution. + + **Example:** + + ```py + m = Map( + layers, + custom_attribution="Development Seed" + ) + ``` + + **Example:** + + ```py + m = Map( + layers, + custom_attribution=["Development Seed", "OpenStreetMap"] + ) + ``` + """ + # TODO: We'd prefer a "Strict union of bool and float" but that doesn't # work here because `Union[bool, float]` would coerce `1` to `True`, which we don't # want, and `Union[float, bool]` would coerce `True` to `1`, which we also don't diff --git a/src/index.tsx b/src/index.tsx index 3bb13703..a821a1c5 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -14,6 +14,7 @@ import { v4 as uuidv4 } from "uuid"; import { Message } from "./types.js"; import { flyTo } from "./actions/fly-to.js"; import { useViewStateDebounced } from "./state"; +import "maplibre-gl/dist/maplibre-gl.css"; await initParquetWasm(); @@ -71,6 +72,7 @@ function App() { let [pickingRadius] = useModelState("picking_radius"); let [useDevicePixels] = useModelState("use_device_pixels"); let [parameters] = useModelState("parameters"); + let [customAttribution] = useModelState("custom_attribution"); // initialViewState is the value of view_state on the Python side. This is // called `initial` here because it gets passed in to deck's @@ -184,7 +186,10 @@ function App() { }} parameters={parameters || {}} > - + ); diff --git a/src/model/base-layer.ts b/src/model/base-layer.ts index b707c31e..42ef8de9 100644 --- a/src/model/base-layer.ts +++ b/src/model/base-layer.ts @@ -62,8 +62,6 @@ export abstract class BaseLayerModel extends BaseModel { } baseLayerProps(): LayerProps { - // console.log("extensions", this.extensionInstances()); - // console.log("extensionprops", this.extensionProps()); return { extensions: this.extensionInstances(), ...this.extensionProps(),