Skip to content

Commit 38bea9e

Browse files
Merge pull request #136 from eoda-dev/feature/sky-and-fog
terrain, sky and fog
2 parents 87f8bb3 + 8c15ffd commit 38bea9e

File tree

22 files changed

+468
-54
lines changed

22 files changed

+468
-54
lines changed

.github/workflows/pytest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ jobs:
2727
pip install -e ".[anywidget,shiny,pmtiles]"
2828
- name: Test package
2929
run: |
30-
poetry run pytest
30+
poetry run pytest --ignore tests/test_pmtiles.py
3131
poetry run pytest --doctest-modules maplibre --ignore maplibre/ipywidget.py

docs/changelog.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog for MapLibre for Python
22

3+
## maplibre v0.3.2
4+
5+
* Add `Sky` (#135), `Light` (#137) and `Terrain` (#134) style specifications
6+
* Add `TerrainControl`
7+
* Add `RasterDEMSource`
8+
* Add `RasterSource` as alias for `RasterTileSource`
9+
* Add `VectorSource` as alias for `VectorTileSource`
10+
* Add `BasemapStyle` as successor to `construct_basemap_style`
11+
* Add `BasemapStyle.symbol_layers` to get symbol layers from style
12+
* Add `BasemapStyle.carto_url` etc as successors to `construct_carto_basemap_url` etc
13+
314
## maplibre v0.3.1
415

516
* Switch to [MapLibre GL JS v5.3.0](https://github.com/maplibre/maplibre-gl-js/releases/tag/v5.3.0)

examples/basemaps/raster-tiles.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Example taken from https://maplibre.org/maplibre-gl-js/docs/examples/map-tiles/
2+
3+
from maplibre import Map, MapOptions, Layer, LayerType
4+
from maplibre.sources import RasterSource
5+
from maplibre.basemaps import BasemapStyle
6+
7+
style = BasemapStyle(
8+
sources={
9+
"raster-tiles": RasterSource(
10+
tiles=["https://a.tile.openstreetmap.org/{z}/{x}/{y}.png"],
11+
tile_size=256,
12+
attribution="© OpenStreetMap Contributors",
13+
)
14+
},
15+
layers=[
16+
Layer(
17+
id="simple-tiles",
18+
type=LayerType.RASTER,
19+
source="raster-tiles",
20+
min_zoom=0,
21+
max_zoom=20,
22+
)
23+
],
24+
)
25+
26+
map_options = MapOptions(style=style, center=(-74.5, 40), zoom=2)
27+
28+
m = Map(map_options)
29+
m.save(preview=True)

examples/globe/atmosphere.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from maplibre import Map, MapOptions, Layer, LayerType
2+
from maplibre.basemaps import OpenFreeMap
3+
from maplibre.sky import Sky
4+
from maplibre.light import Light
5+
from maplibre.controls import NavigationControl, GlobeControl
6+
7+
map_options = MapOptions(
8+
style=OpenFreeMap.POSITRON,
9+
zoom=0,
10+
center=(137.9150899566626, 36.25956997955441),
11+
)
12+
13+
sky = Sky(
14+
atmosphere_blend=["interpolate", ["linear"], ["zoom"], 0, 1, 5, 1, 7, 0]
15+
)
16+
17+
light = Light(anchor="map", position=[1.5, 90, 80], intensity=0.5)
18+
19+
m = Map(map_options, controls=[NavigationControl(), GlobeControl()])
20+
m.set_projection("globe")
21+
m.set_sky(sky)
22+
m.set_light(light)
23+
m.save(preview=True, style="background-color: black; height: 600px;")

examples/layers/circle.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
from maplibre import Layer, LayerType, Map, MapOptions
22
from maplibre.basemaps import Carto
3-
from maplibre.controls import NavigationControl, ScaleControl, ControlPosition, GlobeControl
3+
from maplibre.controls import (
4+
NavigationControl,
5+
ScaleControl,
6+
ControlPosition,
7+
GlobeControl,
8+
)
49
from maplibre.sources import GeoJSONSource
510

611
data = "https://docs.mapbox.com/mapbox-gl-js/assets/earthquakes.geojson"
712
layer_id = "earthquakes"
813

9-
layer = Layer(
10-
id=layer_id, type=LayerType.CIRCLE, source=GeoJSONSource(data=data)
11-
).set_paint_props(circle_color="yellow")
14+
layer = Layer(id=layer_id, type=LayerType.CIRCLE, source=GeoJSONSource(data=data)).set_paint_props(
15+
circle_color="yellow"
16+
)
1217

1318
m = Map(MapOptions(style=Carto.POSITRON))
1419
m.add_control(NavigationControl())

examples/layers/shiny_circle.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
data = "https://docs.mapbox.com/mapbox-gl-js/assets/earthquakes.geojson"
1010
layer_id = "earthquakes"
1111

12-
earthquakes = Layer(
13-
id=layer_id, type=LayerType.CIRCLE, source=GeoJSONSource(data=data)
14-
).set_paint_props(circle_color="yellow")
12+
earthquakes = Layer(id=layer_id, type=LayerType.CIRCLE, source=GeoJSONSource(data=data)).set_paint_props(
13+
circle_color="yellow"
14+
)
1515

1616

1717
@MapLibreRenderer
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# See
2+
# - https://maplibre.org/maplibre-gl-js/docs/examples/3d-terrain/
3+
# - https://maplibre.org/maplibre-gl-js/docs/examples/sky-with-fog-and-terrain/
4+
#
5+
from maplibre import Map, MapOptions, Layer, LayerType
6+
from maplibre.sources import RasterTileSource, RasterDEMSource
7+
from maplibre.basemaps import BasemapStyle
8+
from maplibre.controls import NavigationControl, TerrainControl
9+
from maplibre.sky import Sky
10+
from maplibre.terrain import Terrain
11+
12+
13+
style = BasemapStyle(
14+
sources=dict(
15+
osm=RasterTileSource(
16+
tiles=["https://a.tile.openstreetmap.org/{z}/{x}/{y}.png"],
17+
tile_size=256,
18+
attribution="© OpenStreetMap Contributors",
19+
max_zoom=19,
20+
),
21+
# Use a different source for terrain and hillshade layers, to improve render quality
22+
terrain=RasterDEMSource(url="https://demotiles.maplibre.org/terrain-tiles/tiles.json", tile_size=256),
23+
hillshade=RasterDEMSource(url="https://demotiles.maplibre.org/terrain-tiles/tiles.json", tile_size=256),
24+
),
25+
layers=[
26+
Layer(type=LayerType.RASTER, source="osm"),
27+
Layer(type=LayerType.HILLSHADE, source="hillshade").set_paint_props(hillshade_shadow_color="#473B24"),
28+
],
29+
sky=Sky(sky_color="steelblue", horizon_color="orange", fog_color="grey"),
30+
terrain=Terrain(source="terrain")
31+
)
32+
33+
map_options = MapOptions(
34+
style=style,
35+
zoom=12,
36+
# center=(11.39085, 47.27574),
37+
center=(11.2953, 47.5479),
38+
pitch=77,
39+
hash=True,
40+
max_zoom=18,
41+
max_pitch=85
42+
)
43+
44+
m = Map(map_options, controls=[NavigationControl(), TerrainControl(source="terrain")])
45+
# m.set_terrain("terrain")
46+
# m.set_sky(Sky(sky_color="steelblue", horizon_color="orange", fog_color="grey"))
47+
m.save(preview=True)

examples/layers/terrain.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# See
2+
# - https://maplibre.org/maplibre-gl-js/docs/examples/3d-terrain/
3+
# - https://maplibre.org/maplibre-gl-js/docs/examples/sky-with-fog-and-terrain/
4+
#
5+
from maplibre import Map, MapOptions, Layer, LayerType
6+
from maplibre.sources import RasterTileSource, RasterDEMSource
7+
from maplibre.basemaps import construct_basemap_style
8+
from maplibre.controls import NavigationControl, TerrainControl, GlobeControl
9+
from maplibre.sky import Sky
10+
11+
style = construct_basemap_style(
12+
sources=dict(
13+
osm=RasterTileSource(
14+
tiles=["https://a.tile.openstreetmap.org/{z}/{x}/{y}.png"],
15+
tile_size=256,
16+
attribution="© OpenStreetMap Contributors",
17+
max_zoom=19,
18+
),
19+
# Use a different source for terrain and hillshade layers, to improve render quality
20+
terrain=RasterDEMSource(url="https://demotiles.maplibre.org/terrain-tiles/tiles.json", tile_size=256),
21+
hillshade=RasterDEMSource(url="https://demotiles.maplibre.org/terrain-tiles/tiles.json", tile_size=256),
22+
),
23+
layers=[
24+
Layer(type=LayerType.RASTER, source="osm"),
25+
Layer(type=LayerType.HILLSHADE, source="hillshade").set_paint_props(hillshade_shadow_color="#473B24"),
26+
],
27+
)
28+
29+
map_options = MapOptions(
30+
style=style,
31+
zoom=12,
32+
# center=(11.39085, 47.27574),
33+
center=(11.2953, 47.5479),
34+
pitch=77,
35+
hash=True,
36+
max_zoom=18,
37+
max_pitch=85
38+
)
39+
40+
m = Map(map_options, controls=[NavigationControl(), TerrainControl(source="terrain"), GlobeControl()])
41+
m.set_terrain("terrain")
42+
m.set_sky(Sky(sky_color="steelblue", horizon_color="orange", fog_color="grey"))
43+
m.save(preview=True)

maplibre/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import logging
2+
import importlib.metadata
3+
4+
__version__ = importlib.metadata.version(__package__)
25

36
logging.basicConfig()
47
logger = logging.getLogger(__name__)

maplibre/_utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@ def get_temp_filename(file_extension: str = ".html") -> str:
2323
return get_output_dir() + os.sep + str(uuid4()).replace("-", "") + file_extension
2424

2525

26-
def get_internal_file_path(*args):
27-
# print(os.path.dirname(__file__))
26+
def get_internal_file_path(*args) -> str:
2827
return os.path.join(os.path.dirname(__file__), *args)
2928

3029

31-
def read_internal_file(*args):
30+
def read_internal_file(*args) -> str:
3231
with open(get_internal_file_path(*args)) as f:
3332
content = f.read()
3433

0 commit comments

Comments
 (0)