plotly / dash-cytoscape

Interactive network visualization in Python and Dash, powered by Cytoscape.js
https://dash.plot.ly/cytoscape
MIT License
587 stars 120 forks source link

Bugfix/cyleaflet tiles not found #219

Closed Farkites closed 2 weeks ago

Farkites commented 2 weeks ago

About

This PR fixes two bugs in the CyLeaflet all-in-one component:

Description of changes

Pre-Merge checklist

Reference Issues

Closes #218 Closes #206

Other comments

New demo files can be used to test these fixes.

emilykl commented 2 weeks ago

@Farkites This all looks great except for the case where the dev doesn't specify any tiles or leaflet children -- in that case there is no limit put on the zoom and the viewer can zoom in infinitely until they see gray tiles. Could you handle that case?

https://github.com/plotly/dash-cytoscape/assets/4672118/0ca82943-b419-4fa6-a8c8-3877df7d4182

import dash
from dash import html
import dash_cytoscape as cyto

app = dash.Dash(__name__)
server = app.server

cy_stylesheet = [
    {"selector": "node", "style": {"width": "20px", "height": "20px"}},
    {"selector": "edge", "style": {"width": "10px"}},
    {"selector": "node", "style": {"label": "data(label)"}},
]

default_div_style = {
    "height": "400x",
    "width": "600px",
    "border": "2px solid gray",
    "padding": "10px",
    "margin": "5px",
}

city_lat_lon = {
    "Montreal": (45.52028867870132, -73.5757529436986),
}

cyto_elements = [
    {
        "data": {"id": city, "label": city, "lat": lat, "lon": lon }
    }
    for city, (lat, lon) in city_lat_lon.items()
]

# App
app.layout = html.Div(
    [
        html.Div(
            cyto.CyLeaflet(
                id="my-cy-leaflet",
                cytoscape_props={
                    "elements": cyto_elements,
                    "stylesheet": cy_stylesheet,
                },
            ),
            id="cy-leaflet-div",
            style=default_div_style,
        ),
    ],
)

if __name__ == "__main__":
    app.run_server(debug=True)
Farkites commented 2 weeks ago

@Farkites This all looks great except for the case where the dev doesn't specify any tiles or leaflet children -- in that case there is no limit put on the zoom and the viewer can zoom in infinitely until they see gray tiles. Could you handle that case?

Screen.Recording.2024-07-09.at.11.05.59.AM.mov

Good catch, @emilykl ! This should be fixed now!