Skip to content

Commit cfab231

Browse files
MackyDIARRAmartinRenou
authored andcommitted
radiation notebook updated with SearchControl object adding
1 parent 5d2ec29 commit cfab231

File tree

1 file changed

+49
-61
lines changed

1 file changed

+49
-61
lines changed

examples/Radiation.ipynb

Lines changed: 49 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,21 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 12,
5+
"execution_count": null,
66
"id": "43ef0082-9552-44e9-82d3-c1e27209d2c5",
77
"metadata": {
88
"lines_to_next_cell": 2,
99
"tags": []
1010
},
11-
"outputs": [
12-
{
13-
"data": {
14-
"application/vnd.jupyter.widget-view+json": {
15-
"model_id": "620b5ab499a04a69bf13d9bbe53f6907",
16-
"version_major": 2,
17-
"version_minor": 0
18-
},
19-
"text/plain": [
20-
"Map(center=[47, 2], controls=(AttributionControl(options=['position', 'prefix'], position='bottomright'), Zoom…"
21-
]
22-
},
23-
"metadata": {},
24-
"output_type": "display_data"
25-
}
26-
],
11+
"outputs": [],
2712
"source": [
2813
"import json\n",
2914
"import requests\n",
3015
"import random\n",
3116
"from ipyleaflet import (\n",
3217
" Map,\n",
18+
" LayerGroup,\n",
19+
" SearchControl,\n",
3320
" TileLayer,\n",
3421
" FullScreenControl,\n",
3522
" ScaleControl,\n",
@@ -66,66 +53,67 @@
6653
"m.add_layer(radon)\n",
6754
"\n",
6855
"# Create a function get_data which fetch the datas from the irsn application\n",
69-
"def get_data():\n",
56+
"def get_data(lng, lat):\n",
7057
" r = requests.get(\n",
7158
" \"https://cartoradon.irsn.fr/commune.py/communes/lonlat/{};{}\".format(lng, lat)\n",
7259
" )\n",
7360
" return r.json()\n",
7461
"\n",
7562
"\n",
63+
"def generate_popup(coordinates):\n",
64+
" data = get_data(coordinates[1], coordinates[0])\n",
65+
" # Display geojson\n",
66+
" geometry = data[\"geometry\"]\n",
67+
" geojson = GeoJSON(\n",
68+
" data=geometry,\n",
69+
" style={\"opacity\": 1, \"dashArray\": \"9\", \"fillOpacity\": 0.1, \"weight\": 1},\n",
70+
" hover_style={\"color\": \"white\", \"dashArray\": \"0\", \"fillOpacity\": 0.5},\n",
71+
" )\n",
72+
" m.add_layer(geojson)\n",
73+
"\n",
74+
" # Create Popup\n",
75+
" message1 = HTML()\n",
76+
" dict_properties = data[\"properties\"]\n",
77+
" get_name = dict_properties.get(\"name\")\n",
78+
" get_class = dict_properties.get(\"classr\")\n",
79+
" message1.value = \"Ville: {}, Classe : {}\".format(get_name, get_class)\n",
80+
" popup = Popup(\n",
81+
" location=coordinates,\n",
82+
" child=message1,\n",
83+
" close_button=True,\n",
84+
" auto_close=True,\n",
85+
" close_on_escape_key=False,\n",
86+
" )\n",
87+
" m.add_layer(popup)\n",
88+
"\n",
89+
"\n",
7690
"# take a method on_interation providing Map object to obtain the coordinates\n",
7791
"def on_interaction(event, type, coordinates):\n",
7892
"\n",
7993
" if type == \"click\":\n",
80-
" data = get_data(coordinates[1], coordinates[0])\n",
81-
"\n",
82-
" # Display geojson\n",
83-
" geometry = data[\"geometry\"]\n",
84-
" geojson = GeoJSON(\n",
85-
" data=geometry,\n",
86-
" style={\"opacity\": 1, \"dashArray\": \"9\", \"fillOpacity\": 0.1, \"weight\": 1},\n",
87-
" hover_style={\"color\": \"white\", \"dashArray\": \"0\", \"fillOpacity\": 0.5},\n",
88-
" )\n",
89-
" m.add_layer(geojson)\n",
90-
"\n",
91-
" # Create Popup\n",
92-
" message1 = HTML()\n",
93-
" dict_properties = data[\"properties\"]\n",
94-
" get_name = dict_properties.get(\"name\")\n",
95-
" get_class = dict_properties.get(\"classr\")\n",
96-
" message1.value = \"Ville: {}, Classe : {}\".format(get_name, get_class)\n",
97-
" popup = Popup(\n",
98-
" location=coordinates,\n",
99-
" child=message1,\n",
100-
" close_button=True,\n",
101-
" auto_close=True,\n",
102-
" close_on_escape_key=False,\n",
103-
" )\n",
104-
" m.add_layer(popup)\n",
94+
" generate_popup(coordinates)\n",
10595
"\n",
10696
"\n",
10797
"m.on_interaction(on_interaction)\n",
10898
"\n",
99+
"\n",
100+
"def on_found(text, location, **kwargs):\n",
101+
" generate_popup(location)\n",
102+
"\n",
103+
"\n",
104+
"search = SearchControl(\n",
105+
" position=\"topleft\",\n",
106+
" url=\"https://cartoradon.irsn.fr/commune.py/communes/search/FR/{s}?\",\n",
107+
" zoom=8,\n",
108+
" property_name=\"display_name\",\n",
109+
")\n",
110+
"search.on_location_found(on_found)\n",
111+
"\n",
112+
"m.add_control(search)\n",
113+
"\n",
114+
"\n",
109115
"m"
110116
]
111-
},
112-
{
113-
"cell_type": "code",
114-
"execution_count": null,
115-
"id": "b6e75898-89cf-44e1-826a-11e7b4e9b427",
116-
"metadata": {
117-
"tags": []
118-
},
119-
"outputs": [],
120-
"source": []
121-
},
122-
{
123-
"cell_type": "code",
124-
"execution_count": null,
125-
"id": "3312020d-cbd5-4f27-b9f0-845145da5811",
126-
"metadata": {},
127-
"outputs": [],
128-
"source": []
129117
}
130118
],
131119
"metadata": {

0 commit comments

Comments
 (0)