|
| 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) |
0 commit comments