Skip to content

Commit

Permalink
Add layers and sources parameter to Map
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Kuethe committed Jul 21, 2024
1 parent f81f8d4 commit 9b4f6cf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
7 changes: 5 additions & 2 deletions _experimental/add_geopandas_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@

data = read_file(path)

m = Map(MapOptions(style=Carto.POSITRON, bounds=data.total_bounds))
m = Map(
MapOptions(style=Carto.POSITRON, bounds=data.total_bounds),
layers=[Layer(type=LayerType.LINE, source=data)],
)
# m.add_source("states", data)
# m.add_layer(Layer(type=LayerType.LINE, source="states"))
m.add_layer(Layer(type=LayerType.LINE, source=data))
# m.add_layer(Layer(type=LayerType.LINE, source=data))
m.save("/tmp/py-maplibre-express.html")
13 changes: 11 additions & 2 deletions maplibre/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,16 @@ class Map(object):

MESSAGE = "not implemented yet"

def __init__(self, map_options: MapOptions = MapOptions(), **kwargs):
def __init__(
self,
map_options: MapOptions = MapOptions(),
sources: dict = None,
layers: list = None,
**kwargs,
):
self.map_options = map_options.to_dict() | kwargs
self._message_queue = []
self.add_layers(layers, sources)

def __iter__(self):
for k, v in self.to_dict().items():
Expand Down Expand Up @@ -170,7 +177,9 @@ def add_layer(self, layer: [Layer | dict], before_id: str = None) -> None:

self.add_call("addLayer", layer, before_id)

def add_layers(self, layers: list, sources: dict = None):
def add_layers(self, layers: list = None, sources: dict = None):
layers = layers or []
sources = sources or dict()
for source_id, source in sources.items():
self.add_source(source_id, source)

Expand Down

0 comments on commit 9b4f6cf

Please sign in to comment.