Skip to content

Commit c174e7b

Browse files
authored
Fix: Draw creation and control added to map
* Bug fix when Draw created and added to Map * Marker emits the same content _onMove and _onMoveend * Update pyqtlet2/leaflet/layer/marker/marker.py
1 parent bf73968 commit c174e7b

File tree

4 files changed

+7
-3
lines changed

4 files changed

+7
-3
lines changed

pyqtlet2/leaflet/control/control.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ def controlName(self, name):
4242

4343
def __init__(self):
4444
super().__init__()
45+
self._map = None
4546
self._controlName = self._getNewControlName()
4647

4748
def addTo(self, map_):
4849
map_.addControl(self)
50+
return self
4951

5052
def removeFrom(self, map_):
5153
map_.removeControl(self)

pyqtlet2/leaflet/control/draw.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ def __init__(self, options={}, handleFeatureGroup=True):
1414
self.handleFeatureGroup = handleFeatureGroup
1515
self.featureGroup = None
1616
self._handleOptions()
17-
self._initJs()
17+
if self._map:
18+
self._initJs()
1819
if handleFeatureGroup:
1920
self.addedToMap.connect(self.addDrawnToFeatureGroup)
2021

@@ -23,7 +24,7 @@ def _initJs(self):
2324
if self.options:
2425
jsObject += '{options}'.format(options=self._stringifyForJs(self.options))
2526
jsObject += ')'
26-
self._createJsObject(jsObject)
27+
self._createJsObject(jsObject, self._map.mapWidgetIndex)
2728

2829
def _handleOptions(self):
2930
# If there are no options, then we want to set the default options

pyqtlet2/leaflet/layer/marker/marker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def _onMove(self, event):
2828
self._logger.debug('marker moved. event: {event}'.format(event=event))
2929
event = self._qJsonValueToDict(event)
3030
self.latLng = [event["latlng"]["lat"], event["latlng"]["lng"]]
31-
self.move.emit(event)
31+
self.move.emit({**self._qJsonValueToDict(event), "sender": self})
3232

3333
@Slot(QJsonValue)
3434
def _onMoveend(self, event):

pyqtlet2/leaflet/map/map.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ def removeLayer(self, layer):
139139
def addControl(self, control):
140140
self._controls.append(control)
141141
control.map = self
142+
control._initJs()
142143
js = 'map.addControl({controlName})'.format(controlName=control.controlName)
143144
self.runJavaScriptForMap(js)
144145
return self

0 commit comments

Comments
 (0)