Coverage for crunch/django/app/mapping.py: 100.00%
17 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-10-01 13:43 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2023-10-01 13:43 +0000
1import pydeck
2import pandas as pd
5def item_map(item):
6 geo_attributes = item.descendant_latlongattributes()
8 plot_data = [
9 dict(
10 latitude=float(attribute.latitude),
11 longitude=float(attribute.longitude),
12 item=str(attribute.item),
13 url=str(attribute.item.get_absolute_url()),
14 )
15 for attribute in geo_attributes
16 ]
17 df = pd.DataFrame(plot_data)
19 # ICON_URL = "https://upload.wikimedia.org/wikipedia/commons/9/92/Ic_location_on_48px.svg"
20 # ICON_WIDTH = 48
21 # ICON_HEIGHT = 48
23 ICON_URL = "https://upload.wikimedia.org/wikipedia/commons/6/65/OOjs_UI_icon_mapPin-progressive.svg"
24 ICON_WIDTH = 20
25 ICON_HEIGHT = 20
27 icon_data = {
28 "url": ICON_URL,
29 "width": ICON_WIDTH,
30 "height": ICON_HEIGHT,
31 "anchorY": ICON_HEIGHT,
32 }
34 df["icon_data"] = None
35 for i in df.index:
36 df.at[i, "icon_data"] = icon_data
38 layer = pydeck.Layer(
39 "IconLayer",
40 df,
41 pickable=True,
42 get_icon="icon_data",
43 get_size=20,
44 get_position=["longitude", "latitude"],
45 )
47 view_state = pydeck.ViewState(
48 latitude=df["latitude"].mean(),
49 longitude=df["longitude"].mean(),
50 zoom=2,
51 min_zoom=1,
52 max_zoom=16,
53 pitch=0,
54 bearing=0,
55 )
57 map = pydeck.Deck(layers=[layer], initial_view_state=view_state, map_style="road")
59 return map