50def response(resp):
51 results = []
52 json = loads(resp.text)
53
54
55 for r in json.get('features', {}):
56
57 properties = r.get('properties')
58
59 if not properties:
60 continue
61
62
63 title = properties.get('name')
64
65
66 if properties.get('osm_type') == 'N':
67 osm_type = 'node'
68 elif properties.get('osm_type') == 'W':
69 osm_type = 'way'
70 elif properties.get('osm_type') == 'R':
71 osm_type = 'relation'
72 else:
73
74 continue
75
76 url = result_base_url.format(osm_type=osm_type, osm_id=properties.get('osm_id'))
77
78 osm = {'type': osm_type, 'id': properties.get('osm_id')}
79
80 geojson = r.get('geometry')
81
82 if properties.get('extent'):
83 boundingbox = [
84 properties.get('extent')[3],
85 properties.get('extent')[1],
86 properties.get('extent')[0],
87 properties.get('extent')[2],
88 ]
89 else:
90
91 boundingbox = [
92 geojson['coordinates'][1],
93 geojson['coordinates'][1],
94 geojson['coordinates'][0],
95 geojson['coordinates'][0],
96 ]
97
98
99 address = {}
100
101
102 if (
103 properties.get('osm_key') == 'amenity'
104 or properties.get('osm_key') == 'shop'
105 or properties.get('osm_key') == 'tourism'
106 or properties.get('osm_key') == 'leisure'
107 ):
108 address = {'name': properties.get('name')}
109
110
111 if address.get('name'):
112 address.update(
113 {
114 'house_number': properties.get('housenumber'),
115 'road': properties.get('street'),
116 'locality': properties.get(
117 'city', properties.get('town', properties.get('village'))
118 ),
119 'postcode': properties.get('postcode'),
120 'country': properties.get('country'),
121 }
122 )
123 else:
124 address = None
125
126
127 results.append(
128 {
129 'template': 'map.html',
130 'title': title,
131 'content': '',
132 'longitude': geojson['coordinates'][0],
133 'latitude': geojson['coordinates'][1],
134 'boundingbox': boundingbox,
135 'geojson': geojson,
136 'address': address,
137 'osm': osm,
138 'url': url,
139 }
140 )
141
142
143 return results