Skip to content

Commit

Permalink
Fix attribution (#561)
Browse files Browse the repository at this point in the history
This adds a `custom_attribution` property to the `Map` class and fix
Maplibre CSS by adding an import. Contributes to:

- #436
- #545
  • Loading branch information
vgeorge authored Jul 4, 2024
1 parent de87051 commit 98ba471
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
38 changes: 38 additions & 0 deletions lonboard/_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -71,6 +72,7 @@ function App() {
let [pickingRadius] = useModelState<number>("picking_radius");
let [useDevicePixels] = useModelState<number | boolean>("use_device_pixels");
let [parameters] = useModelState<object>("parameters");
let [customAttribution] = useModelState<string>("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
Expand Down Expand Up @@ -184,7 +186,10 @@ function App() {
}}
parameters={parameters || {}}
>
<Map mapStyle={mapStyle || DEFAULT_MAP_STYLE} />
<Map
mapStyle={mapStyle || DEFAULT_MAP_STYLE}
customAttribution={customAttribution}
></Map>
</DeckGL>
</div>
);
Expand Down
2 changes: 0 additions & 2 deletions src/model/base-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 98ba471

Please sign in to comment.