|
| 1 | +import marimo |
| 2 | + |
| 3 | +__generated_with = "0.10.17" |
| 4 | +app = marimo.App(width="medium") |
| 5 | + |
| 6 | + |
| 7 | +@app.cell |
| 8 | +def _(): |
| 9 | + import marimo as mo |
| 10 | + from maplibre import Layer, LayerType, MapOptions |
| 11 | + from maplibre.sources import GeoJSONSource, VectorTileSource |
| 12 | + from maplibre.ipywidget import MapWidget as Map |
| 13 | + from maplibre.controls import NavigationControl, ScaleControl, ControlPosition |
| 14 | + from maplibre.expressions import color_match_expr |
| 15 | + Map._use_message_queue = False |
| 16 | + return ( |
| 17 | + ControlPosition, |
| 18 | + GeoJSONSource, |
| 19 | + Layer, |
| 20 | + LayerType, |
| 21 | + Map, |
| 22 | + MapOptions, |
| 23 | + NavigationControl, |
| 24 | + ScaleControl, |
| 25 | + VectorTileSource, |
| 26 | + color_match_expr, |
| 27 | + mo, |
| 28 | + ) |
| 29 | + |
| 30 | + |
| 31 | +@app.cell |
| 32 | +def _(VectorTileSource): |
| 33 | + blm_sma_source= VectorTileSource( |
| 34 | + tiles=["https://tiles.lightfield.ag/blm_national_surface_management_data/{z}/{x}/{y}.mvt"], |
| 35 | + min_zoom=0, |
| 36 | + max_zoom=9 |
| 37 | + ) |
| 38 | + return (blm_sma_source,) |
| 39 | + |
| 40 | + |
| 41 | +@app.cell |
| 42 | +def _(color_match_expr): |
| 43 | + fill_color = color_match_expr("ADMIN_DEPT_CODE", ["PVT", "DOD", "DOE", "DOI", "USDA"], "viridis") |
| 44 | + # fill_color |
| 45 | + return (fill_color,) |
| 46 | + |
| 47 | + |
| 48 | +@app.cell |
| 49 | +def _(Layer, LayerType, blm_sma_source, fill_color): |
| 50 | + blm_sma_layer = Layer( |
| 51 | + id="blm-sma", |
| 52 | + type=LayerType.FILL, |
| 53 | + source=blm_sma_source, |
| 54 | + source_layer="blm_national_surface_management_data" |
| 55 | + ).set_paint_props(fill_color=fill_color, fill_outline_color="steelblue") |
| 56 | + return (blm_sma_layer,) |
| 57 | + |
| 58 | + |
| 59 | +@app.cell |
| 60 | +def _(Map, NavigationControl, blm_sma_layer): |
| 61 | + m = Map(controls=[NavigationControl()], layers=[blm_sma_layer]) |
| 62 | + return (m,) |
| 63 | + |
| 64 | + |
| 65 | +@app.cell |
| 66 | +def _(m, mo): |
| 67 | + widget = mo.ui.anywidget(m) |
| 68 | + return (widget,) |
| 69 | + |
| 70 | + |
| 71 | +@app.cell |
| 72 | +def _(widget): |
| 73 | + widget |
| 74 | + return |
| 75 | + |
| 76 | + |
| 77 | +@app.cell |
| 78 | +def _(color_match_expr, m, mo): |
| 79 | + mo.ui.dropdown( |
| 80 | + ["viridis", "YlOrRd", "Blues"], |
| 81 | + label="cmap", |
| 82 | + on_change=lambda x: m.set_paint_property( |
| 83 | + "blm-sma", |
| 84 | + "fill-color", |
| 85 | + color_match_expr("ADMIN_DEPT_CODE", ["PVT", "DOD", "DOE", "DOI", "USDA"], cmap=x) |
| 86 | + ) |
| 87 | + ) |
| 88 | + return |
| 89 | + |
| 90 | + |
| 91 | +@app.cell |
| 92 | +def _(widget): |
| 93 | + widget.view_state |
| 94 | + return |
| 95 | + |
| 96 | + |
| 97 | +if __name__ == "__main__": |
| 98 | + app.run() |
0 commit comments