Skip to content

Commit 98ba471

Browse files
authored
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
1 parent de87051 commit 98ba471

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

lonboard/_map.py

+38
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,44 @@ def __init__(
167167
[`lonboard.basemap.CartoBasemap.PositronNoLabels`][lonboard.basemap.CartoBasemap.PositronNoLabels]
168168
"""
169169

170+
custom_attribution = traitlets.Union(
171+
[
172+
traitlets.Unicode(allow_none=True),
173+
traitlets.List(traitlets.Unicode(allow_none=False)),
174+
]
175+
).tag(sync=True)
176+
"""
177+
Custom attribution to display on the map.
178+
179+
This attribute supports the same format as the `attribution` property in the
180+
Maplibre API.
181+
182+
- Type: `str` or `List[str]`
183+
- Default: `None`
184+
185+
You can provide either a single string or a list of strings for custom attributions.
186+
If an attribution value is set in the map style, it will be displayed in addition to
187+
this custom attribution.
188+
189+
**Example:**
190+
191+
```py
192+
m = Map(
193+
layers,
194+
custom_attribution="Development Seed"
195+
)
196+
```
197+
198+
**Example:**
199+
200+
```py
201+
m = Map(
202+
layers,
203+
custom_attribution=["Development Seed", "OpenStreetMap"]
204+
)
205+
```
206+
"""
207+
170208
# TODO: We'd prefer a "Strict union of bool and float" but that doesn't
171209
# work here because `Union[bool, float]` would coerce `1` to `True`, which we don't
172210
# want, and `Union[float, bool]` would coerce `True` to `1`, which we also don't

src/index.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { v4 as uuidv4 } from "uuid";
1414
import { Message } from "./types.js";
1515
import { flyTo } from "./actions/fly-to.js";
1616
import { useViewStateDebounced } from "./state";
17+
import "maplibre-gl/dist/maplibre-gl.css";
1718

1819
await initParquetWasm();
1920

@@ -71,6 +72,7 @@ function App() {
7172
let [pickingRadius] = useModelState<number>("picking_radius");
7273
let [useDevicePixels] = useModelState<number | boolean>("use_device_pixels");
7374
let [parameters] = useModelState<object>("parameters");
75+
let [customAttribution] = useModelState<string>("custom_attribution");
7476

7577
// initialViewState is the value of view_state on the Python side. This is
7678
// called `initial` here because it gets passed in to deck's
@@ -184,7 +186,10 @@ function App() {
184186
}}
185187
parameters={parameters || {}}
186188
>
187-
<Map mapStyle={mapStyle || DEFAULT_MAP_STYLE} />
189+
<Map
190+
mapStyle={mapStyle || DEFAULT_MAP_STYLE}
191+
customAttribution={customAttribution}
192+
></Map>
188193
</DeckGL>
189194
</div>
190195
);

src/model/base-layer.ts

-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ export abstract class BaseLayerModel extends BaseModel {
6262
}
6363

6464
baseLayerProps(): LayerProps {
65-
// console.log("extensions", this.extensionInstances());
66-
// console.log("extensionprops", this.extensionProps());
6765
return {
6866
extensions: this.extensionInstances(),
6967
...this.extensionProps(),

0 commit comments

Comments
 (0)