Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions ipyleaflet/leaflet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2676,13 +2676,15 @@ def __isub__(self, item):
def __add__(self, item):
return self.add(item)

def add(self, item):
def add(self, item, position=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def add(self, item, position=None):
def add(self, item, index=None):

"""Add an item on the map: either a layer or a control.

Parameters
----------
item: Layer or Control instance
The layer or control to add.
position: int
The position to insert a Layer. If not specified, the layer is added to the end (on top).
"""
if hasattr(item, 'as_leaflet_layer'):
item = item.as_leaflet_layer()
Expand All @@ -2692,7 +2694,13 @@ def add(self, item):
item = basemap_to_tiles(item)
if item.model_id in self._layer_ids:
raise LayerException('layer already on map: %r' % item)
self.layers = tuple([layer for layer in self.layers] + [item])

if position is not None:
if not isinstance(position, int) or position < 0 or position > len(self.layers):
raise ValueError("Invalid position value")
self.layers = tuple(list(self.layers)[:position] + [item] + list(self.layers)[position:])
else:
self.layers = tuple([layer for layer in self.layers] + [item])

elif isinstance(item, Control):
if item.model_id in self._control_ids:
Expand Down