Skip to content

Commit

Permalink
Move selected_bounds from Layer to Map (#676)
Browse files Browse the repository at this point in the history
`selected_bounds` should be a property of the **Map**. In the future,
when we use deck.gl to perform picking, we'll have `selected_indices` as
a property of each _individual layer_. This is necessary because the
data is a property of each layer, while

Or alternatively if we perform data filtering on the Python side, then
in the future we could also add `selected_bounds` to each layer (though
probably as a private attribute)
  • Loading branch information
kylebarron authored Oct 7, 2024
1 parent 25f7e13 commit f7c8d33
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
11 changes: 0 additions & 11 deletions lonboard/_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,17 +250,6 @@ def _add_extension_traits(self, extensions: Sequence[BaseExtension]):
- Default: `[0, 0, 128, 128]`
"""

selected_bounds = t.Tuple(
t.Float(), t.Float(), t.Float(), t.Float(), allow_none=True, default_value=None
).tag(sync=True)
"""
Bounds selected by the user, represented as a tuple of floats ordered as
```
(minx, miny, maxx, maxy)
```
"""

selected_index = t.Int(None, allow_none=True).tag(sync=True)
"""
The positional index of the most-recently clicked on row of data.
Expand Down
11 changes: 11 additions & 0 deletions lonboard/_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,17 @@ def __init__(
global `parameters` when that layer is rendered.
"""

selected_bounds = t.Tuple(
t.Float(), t.Float(), t.Float(), t.Float(), allow_none=True, default_value=None
).tag(sync=True)
"""
Bounds selected by the user, represented as a tuple of floats ordered as
```
(minx, miny, maxx, maxy)
```
"""

def add_layer(
self,
layers: BaseLayer | Sequence[BaseLayer] | Map,
Expand Down
12 changes: 8 additions & 4 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,14 @@ function App() {
setSubModelState(newSubModelState);

if (!isDrawingBBoxSelection) {
childModels.forEach((layer) => {
layer.set("selected_bounds", bboxSelectBounds);
layer.save_changes();
});
// Note: selected_bounds is a property of the **Map**. In the future,
// when we use deck.gl to perform picking, we'll have
// `selected_indices` as a property of each individual layer.
model.set("selected_bounds", bboxSelectBounds);
// childModels.forEach((layer) => {
// layer.set("selected_bounds", bboxSelectBounds);
// layer.save_changes();
// });
}
} catch (error) {
console.error("Error loading child models or setting bounds:", error);
Expand Down

0 comments on commit f7c8d33

Please sign in to comment.