-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from eodaGmbH/feature/save-map
Feature/save map
- Loading branch information
Showing
6 changed files
with
223 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from maplibre import Map, MapOptions | ||
from maplibre.basemaps import Carto | ||
from maplibre.utils import save_map | ||
|
||
m = Map(MapOptions(style=Carto.VOYAGER)) | ||
filename = save_map(m, preview=True) | ||
print(filename) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import marimo | ||
|
||
__generated_with = "0.6.23" | ||
app = marimo.App(width="medium") | ||
|
||
|
||
@app.cell | ||
def __(): | ||
import marimo as mo | ||
|
||
return (mo,) | ||
|
||
|
||
@app.cell | ||
def __(): | ||
from maplibre.controls import NavigationControl, ScaleControl | ||
from maplibre.ipywidget import MapOptions, MapWidget | ||
|
||
return MapOptions, MapWidget, NavigationControl, ScaleControl | ||
|
||
|
||
@app.cell | ||
def __(): | ||
deck_grid_layer = { | ||
"@@type": "GridLayer", | ||
"id": "GridLayer", | ||
"data": "https://raw.githubusercontent.com/visgl/deck.gl-data/master/website/sf-bike-parking.json", | ||
"extruded": True, | ||
"getPosition": "@@=COORDINATES", | ||
"getColorWeight": "@@=SPACES", | ||
"getElevationWeight": "@@=SPACES", | ||
"elevationScale": 4, | ||
"cellSize": 200, | ||
"pickable": True, | ||
} | ||
return (deck_grid_layer,) | ||
|
||
|
||
@app.cell | ||
def __(MapOptions): | ||
map_options = MapOptions( | ||
center=(-122.4, 37.74), | ||
zoom=12, | ||
hash=True, | ||
pitch=40, | ||
) | ||
return (map_options,) | ||
|
||
|
||
@app.cell | ||
def __(MapWidget, NavigationControl, deck_grid_layer, map_options): | ||
m = MapWidget(map_options) | ||
m.use_message_queue(False) | ||
m.add_control(NavigationControl()) | ||
m.add_deck_layers([deck_grid_layer]) | ||
m | ||
return (m,) | ||
|
||
|
||
@app.cell | ||
def __(m): | ||
m.clicked | ||
return | ||
|
||
|
||
@app.cell | ||
def __(m): | ||
m.zoom | ||
return | ||
|
||
|
||
@app.cell | ||
def __(m): | ||
m.center | ||
return | ||
|
||
|
||
@app.cell | ||
def __(ScaleControl, m): | ||
m.add_control(ScaleControl()) | ||
return | ||
|
||
|
||
@app.cell | ||
def __(): | ||
return | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import marimo | ||
|
||
__generated_with = "0.6.23" | ||
app = marimo.App(width="medium") | ||
|
||
|
||
@app.cell | ||
def __(): | ||
import anywidget | ||
import marimo as mo | ||
import traitlets | ||
|
||
class CounterWidget(anywidget.AnyWidget): | ||
# Widget front-end JavaScript code | ||
_esm = """ | ||
function render({ model, el }) { | ||
let getCount = () => model.get("count"); | ||
let button = document.createElement("button"); | ||
button.innerHTML = `count is ${getCount()}`; | ||
button.addEventListener("click", () => { | ||
model.set("count", getCount() + 1); | ||
model.save_changes(); | ||
}); | ||
model.on("change:count", () => { | ||
button.innerHTML = `count is ${getCount()}`; | ||
}); | ||
el.appendChild(button); | ||
} | ||
export default { render }; | ||
""" | ||
_css = """ | ||
button { | ||
padding: 5px !important; | ||
border-radius: 5px !important; | ||
background-color: #f0f0f0 !important; | ||
&:hover { | ||
background-color: lightblue !important; | ||
color: white !important; | ||
} | ||
} | ||
""" | ||
|
||
# Stateful property that can be accessed by JavaScript & Python | ||
count = traitlets.Int(0).tag(sync=True) | ||
|
||
cw = CounterWidget() | ||
widget = mo.ui.anywidget(cw) | ||
return CounterWidget, anywidget, cw, mo, traitlets, widget | ||
|
||
|
||
@app.cell | ||
def __(widget): | ||
widget | ||
return | ||
|
||
|
||
@app.cell | ||
def __(widget): | ||
widget.value["count"] = 19 | ||
return | ||
|
||
|
||
@app.cell | ||
def __(widget): | ||
widget.value | ||
return | ||
|
||
|
||
@app.cell | ||
def __(cw): | ||
cw.count = 20 | ||
return | ||
|
||
|
||
@app.cell | ||
def __(cw): | ||
cw.count | ||
return | ||
|
||
|
||
@app.cell | ||
def __(): | ||
return | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from os.path import splitext | ||
|
||
from maplibre._utils import get_temp_filename | ||
|
||
|
||
def test_get_temp_filename(): | ||
filename = get_temp_filename() | ||
|
||
print(filename) | ||
filename, file_extension = splitext(filename) | ||
print(filename, file_extension) | ||
|
||
assert file_extension == ".html" | ||
assert "py-maplibre-gl-" in filename |