What is CyLeaflet and how does it work?
mainCyLeaflet is a Dash component included with Dash Cytoscape that adds a geospatial mapping layer to Cytoscape graphs. It allows you to render nodes at specific geographic locations by specifying latitude and longitude in the node data.
How it works
CyLeaflet uses the Dash All-in-One Component pattern. It is a composite component that wraps several underlying components to synchronize a Cytoscape canvas with a Leaflet map canvas:
- Dash Cytoscape: Handles the graph rendering.
- Dash Leaflet: Handles the geospatial map layer.
- dcc.Store: Holds the element data used for coordinate transformation.
- html.Divs: Provide styling to align the Cytoscape canvas exactly on top of the Leaflet canvas.
- Clientside Callbacks: Link the components together to ensure synchronization.
Important: Updating Graph Elements
You cannot update Cytoscape nodes directly by modifying the elements property of the component. Doing so skips a critical transformation step where lat and lon coordinates are converted into the (x, y) canvas positions required to align with the map.
To update the graph, you must update the data property of the internal dcc.Store instance. The component uses a callback to transform these coordinates and then update the Cytoscape elements property automatically.