You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I was trying to remove a layer that already exist so that i can create another, however when i use remove_layer(), the existing layer is removed but the drawing is not.
To Reproduce
class DesenhaLinha(Screen):
def __init__(self, **kwargs):
super(DesenhaLinha, self).__init__(**kwargs)
def desenha(self, valor):
line = LineMapLayer()
if not (line.coordinates == []):
self.ids.mapview.remove_layer(line)
line.coordinates.clear()
print(line.coordinates)
layer = GeoJsonMapLayer(geojson=linha.aggregate([{'$limit': int(valor)}]))
for l in layer.geojson:
x, y = l['geometry']['coordinates']
line.coordinates.append(x)
line.coordinates.append(y)
self.ids.mapview.add_layer(line, mode="scatter")
class LineMapLayer(MapLayer):
def __init__(self, **kwargs):
super(LineMapLayer, self).__init__(**kwargs)
self.zoom = 0
# NOTE: Points must be valid as they're no longer clamped
self.coordinates = []
def reposition(self):
mapview = self.parent
#: Must redraw when the zoom changes
#: as the scatter transform resets for the new tiles
if (self.zoom != mapview.zoom):
self.draw_line()
def get_x(self, lon):
"""Get the x position on the map using this map source's projection
(0, 0) is located at the top left.
"""
return clamp(lon, MIN_LONGITUDE, MAX_LONGITUDE)
def get_y(self, lat):
"""Get the y position on the map using this map source's projection
(0, 0) is located at the top left.
"""
lat = clamp(-lat, MIN_LATITUDE, MAX_LATITUDE)
lat = lat * pi / 180.
return ((1.0 - log(tan(lat) + 1.0 / cos(lat)) / pi))
def draw_line(self, *args):
mapview = self.parent
self.zoom = mapview.zoom
# When zooming we must undo the current scatter transform
# or the animation distorts it
scatter = mapview._scatter
map_source = mapview.map_source
sx, sy, ss = scatter.x, scatter.y, scatter.scale
vx, vy, vs = mapview.viewport_pos[0], mapview.viewport_pos[1], mapview.scale
# Account for map source tile size and mapview zoom
ms = pow(2.0, mapview.zoom) * map_source.dp_tile_size
#: Since lat is not a linear transform we must compute manually
line_points = []
for lon, lat in self.coordinates:
line_points.extend((self.get_x(lon), self.get_y(lat)))
# line_points.extend(mapview.get_window_xy_from(lat,lon,mapview.zoom))
with self.canvas:
# Clear old line
self.canvas.clear()
# Undo the scatter animation transform
Scale(1 / ss, 1 / ss, 1)
Translate(-sx, -sy)
# Apply the get window xy from transforms
Scale(vs, vs, 1)
Translate(-vx, -vy)
# Apply the what we can factor out
# of the mapsource long,lat to x,y conversion
Scale(ms / 360.0, ms / 2.0, 1)
Translate(180, 0)
# Draw new
Color(0, 0, 0, .6)
Line(points=line_points, width=1) # 4/ms)#, joint="round",joint_precision=100)
Expected behavior
i was expcting to remove both the layer and the drawing
Platform:
OS: windows 10
Python 3.7.7
1.0.5
if you want or need to see screenshots please tell me and i will put on the next comment
The text was updated successfully, but these errors were encountered:
asm201
changed the title
Problem with remove_layout
Problem with remove_layer
Jul 7, 2020
Describe the bug
I was trying to remove a layer that already exist so that i can create another, however when i use remove_layer(), the existing layer is removed but the drawing is not.
To Reproduce
Expected behavior
i was expcting to remove both the layer and the drawing
Platform:
if you want or need to see screenshots please tell me and i will put on the next comment
The text was updated successfully, but these errors were encountered: