-
Notifications
You must be signed in to change notification settings - Fork 40
refactor: Refactor model initialization logic #923
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors model initialization logic to be fully generic instead of being hardcoded for layer initialization, preparing for future support of additional reactive widget models like views and basemap styles.
- Moved generic model loading logic from
util.tsto a new dedicatedmodel/initialize.tsfile - Created a generic
initializeChildModelsfunction that can handle any type of child model with proper lifecycle management - Updated layer initialization to use the new generic infrastructure while maintaining existing functionality
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/util.ts | Removed layer-specific loadChildModels function to consolidate model loading logic |
| src/model/initialize.ts | Added new generic model initialization utilities with proper lifecycle management |
| src/model/index.ts | Exported the new initializeChildModels function for external use |
| src/model/base-layer.ts | Updated to use generic model initialization and changed extensions from array to Record |
| src/index.tsx | Refactored to use the new generic model initialization infrastructure |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
Open to comments still, but this is a pretty straightforward refactor I think, so I'll merge so that I can use it in #935 |
### Change list
- Adds definitions for map "controls" (which deck.gl calls "widgets",
but the name "widget" is too overloaded in the context of Jupyter, so
I'd like to call them "controls")
- Support for `ScaleControl`, `NavigationControl`, `FullscreenControl`
- These controls are supported by both deck.gl and maplibre, and so
implementations are defined for creating both the deck.gl and maplibre
counterparts
### Example
```py
from lonboard import Map
from lonboard.controls import ScaleControl, FullscreenControl, NavigationControl
from lonboard.basemap import MaplibreBasemap
m = Map([],
basemap=MaplibreBasemap(mode="overlaid"),
controls=[ScaleControl(), FullscreenControl(), NavigationControl()]
)
m
```
<img width="734" height="506" alt="image"
src="https://github.com/user-attachments/assets/42fb5e55-57d8-4b2a-8fe2-f70b804dabce"
/>
We should probably change the default positioning of controls, move the
bbox selector, or make the bbox selector a control itself.
----
However, for deck.gl-driven rendering, I can only see the scale control:
<img width="756" height="611" alt="image"
src="https://github.com/user-attachments/assets/f8e6be57-55ec-45be-9c14-cf76b4ea64d0"
/>
Logged in #990
### Todo list
- Figure out how to pass these react components as children of the
`OverlayRenderer` or `DeckFirstRenderer` (depends on
#921)
- Use the refactored model initialization from
#923 to create the list
of control instances on the deck side
- Integrate more cleanly into the Python API (an extension of
#908)
Closes #842, relevant
to #681
In ipywidgets, a "model" is the core of reactivity. In particular, a Lonboard
Mapis reactive, but every underlying layer is also reactive, so that when a user changes any property on a layer, it automatically gets updated on the map.By extension, our
Extensionclasses are also themselves models. These are separate Python classes that get serialized as their own reactive models on the JS side.Soon we'll have more types of widget models that we want to be reactive, including views and basemap styles (#908).
Right now, model initialization is slightly hard-coded to handle layer initialization. This PR refactors the model initialization to be fully generic.