-
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 branch 'main' of github.com:eodaGmbH/py-maplibregl into main
- Loading branch information
Showing
24 changed files
with
576 additions
and
127 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,67 @@ | ||
# Shiny Express App | ||
|
||
import json | ||
import webbrowser | ||
|
||
from maplibre import Map, MapOptions, render_maplibregl | ||
from maplibre.basemaps import Carto | ||
from maplibre.controls import ( | ||
ControlPosition, | ||
InfoBoxControl, | ||
LayerSwitcherControl, | ||
NavigationControl, | ||
ScaleControl, | ||
) | ||
from shiny.express import input, render, ui | ||
|
||
m = Map( | ||
MapOptions( | ||
style=Carto.POSITRON, | ||
center=(-122.4, 37.74), | ||
zoom=12, | ||
hash=True, | ||
pitch=40, | ||
) | ||
) | ||
m.add_control(NavigationControl()) | ||
m.add_control(ScaleControl(), ControlPosition.BOTTOM_LEFT) | ||
|
||
# m.add_call( | ||
# "addControl", | ||
# "InfoBoxControl", | ||
# { | ||
# "cssText": "padding: 20px; font-size: 20px;font-family: monospace;", | ||
# "content": "<h1>Awesome control.</h1><p>And some text.</p>", | ||
# }, | ||
# ControlPosition.TOP_LEFT.value, | ||
# ) | ||
|
||
m.add_control(InfoBoxControl(content="Toggle layers"), ControlPosition.TOP_LEFT) | ||
m.add_control( | ||
LayerSwitcherControl( | ||
layer_ids=["water", "landcover"], | ||
theme="default", | ||
# css_text="padding: 10px; border: 1px solid black; border-radius: 3x;font-size: 15px;", | ||
), | ||
ControlPosition.TOP_LEFT, | ||
) | ||
|
||
|
||
@render_maplibregl | ||
def maplibre(): | ||
return m | ||
|
||
|
||
@render.code | ||
def selected_features(): | ||
obj = input.maplibre_draw_features_selected() | ||
print(obj) | ||
return json.dumps(obj["features"], indent=2) if obj else "Pick some features!" | ||
|
||
|
||
if __name__ == "__main__": | ||
filename = "docs/examples/mapbox_draw_plugin/app.html" | ||
with open(filename, "w") as f: | ||
f.write(m.to_html()) | ||
|
||
webbrowser.open(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
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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,94 @@ | ||
# Example taken from here: https://maplibre.org/maplibre-gl-js/docs/examples/pmtiles/ | ||
|
||
import webbrowser | ||
|
||
from maplibre import Layer, LayerType, Map, MapOptions, render_maplibregl | ||
from maplibre.basemaps import construct_basemap_style | ||
from maplibre.controls import ( | ||
ControlPosition, | ||
InfoBoxControl, | ||
LayerSwitcherControl, | ||
NavigationControl, | ||
) | ||
from shiny.express import input, render, ui | ||
|
||
PMTILES_URL = "https://pmtiles.io/protomaps(vector)ODbL_firenze.pmtiles" | ||
|
||
pmtiles_source = { | ||
"type": "vector", | ||
"url": f"pmtiles://{PMTILES_URL}", | ||
"attribution": '© <a href="https://openstreetmap.org">OpenStreetMap</a>', | ||
} | ||
|
||
custom_basemap = construct_basemap_style( | ||
sources={"pmtiles": pmtiles_source}, | ||
layers=[ | ||
Layer( | ||
id="buildings", | ||
source="pmtiles", | ||
source_layer="landuse", | ||
type=LayerType.FILL, | ||
paint={"fill-color": "red"}, | ||
layout={"visibility": "none"}, | ||
), | ||
Layer( | ||
id="roads", | ||
source="pmtiles", | ||
source_layer="roads", | ||
type=LayerType.LINE, | ||
paint={"line-color": "black"}, | ||
), | ||
Layer( | ||
id="mask", | ||
source="pmtiles", | ||
source_layer="mask", | ||
type=LayerType.FILL, | ||
paint={"fill-color": "yellow"}, | ||
layout={"visibility": "none"}, | ||
), | ||
], | ||
) | ||
|
||
|
||
map_options = MapOptions( | ||
style=custom_basemap, | ||
# hash=True, | ||
# bounds=(11.154026, 43.7270125, 11.3289395, 43.8325455), | ||
center=(11.2415, 43.7798), | ||
zoom=12.5, | ||
) | ||
|
||
|
||
def create_map(): | ||
m = Map(map_options) | ||
m.add_control(NavigationControl()) | ||
m.add_control( | ||
InfoBoxControl( | ||
content="Toggle layers of PMTiles source", | ||
css_text="padding: 10px; background-color: yellow; color: steelblue; font-weight: bold;", | ||
), | ||
ControlPosition.TOP_LEFT, | ||
) | ||
m.add_control( | ||
LayerSwitcherControl( | ||
layer_ids=["buildings", "roads", "mask"], | ||
css_text="padding: 5px; border: 1px solid darkgrey; border-radius: 4px;", | ||
), | ||
position=ControlPosition.TOP_LEFT, | ||
) | ||
return m | ||
|
||
|
||
@render_maplibregl | ||
def render_map(): | ||
return create_map() | ||
|
||
|
||
if __name__ == "__main__": | ||
file_name = "docs/examples/layer_switcher/app.html" | ||
|
||
m = create_map() | ||
with open(file_name, "w") as f: | ||
f.write(m.to_html()) | ||
|
||
webbrowser.open(file_name) |
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,13 @@ | ||
<!-- <a href="app.html" target="_blank">See example in action</a> --> | ||
|
||
<iframe src="app.html" height="620px", width="100%" style="border:none;"></iframe> | ||
|
||
```python | ||
-8<-- "layer_switcher/app.py" | ||
``` | ||
|
||
Run example: | ||
|
||
``` bash | ||
shiny run docs/examples/layer_switcher/app.py | ||
``` |
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
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "maplibre" | ||
version = "0.2.4" | ||
version = "0.2.5" | ||
description = "Python bindings for MapLibre GL JS" | ||
authors = ["Stefan Kuethe <[email protected]>"] | ||
readme = "README.md" | ||
|
Oops, something went wrong.