|
2 | 2 | "cells": [
|
3 | 3 | {
|
4 | 4 | "cell_type": "code",
|
5 |
| - "execution_count": null, |
| 5 | + "execution_count": 12, |
6 | 6 | "id": "43ef0082-9552-44e9-82d3-c1e27209d2c5",
|
7 | 7 | "metadata": {
|
8 | 8 | "tags": []
|
9 | 9 | },
|
10 |
| - "outputs": [], |
| 10 | + "outputs": [ |
| 11 | + { |
| 12 | + "data": { |
| 13 | + "application/vnd.jupyter.widget-view+json": { |
| 14 | + "model_id": "620b5ab499a04a69bf13d9bbe53f6907", |
| 15 | + "version_major": 2, |
| 16 | + "version_minor": 0 |
| 17 | + }, |
| 18 | + "text/plain": [ |
| 19 | + "Map(center=[47, 2], controls=(AttributionControl(options=['position', 'prefix'], position='bottomright'), Zoom…" |
| 20 | + ] |
| 21 | + }, |
| 22 | + "metadata": {}, |
| 23 | + "output_type": "display_data" |
| 24 | + } |
| 25 | + ], |
11 | 26 | "source": [
|
12 |
| - "from ipyleaflet import Map, TileLayer, FullScreenControl, ScaleControl\n", |
| 27 | + "import json\n", |
| 28 | + "import requests\n", |
| 29 | + "import random\n", |
| 30 | + "from ipyleaflet import Map, TileLayer, FullScreenControl, ScaleControl , ZoomControl, Marker , SearchControl , AwesomeIcon , WidgetControl, GeoJSON, Popup\n", |
| 31 | + "from ipywidgets import IntSlider, ColorPicker, Button, link, HTML, jslink\n", |
| 32 | + "m = Map(center=(47, 2), zoom=5, zoom_control = False )\n", |
| 33 | + "\n", |
| 34 | + "#create Zoom_control\n", |
| 35 | + "m.add_control(ZoomControl(position='topleft'))\n", |
| 36 | + "#create Scale_Control\n", |
| 37 | + "m.add_control(ScaleControl(position='bottomleft'))\n", |
| 38 | + "#Create Full_Screen_Control\n", |
| 39 | + "m.add_control(FullScreenControl())\n", |
| 40 | + "\n", |
13 | 41 | "\n",
|
14 |
| - "m = Map(center=(47, 2), zoom=5)\n", |
| 42 | + "zoom_slider = IntSlider(description='Zoom level:', min=0, max=15, value=7)\n", |
| 43 | + "jslink((zoom_slider, 'value'), (m, 'zoom'))\n", |
| 44 | + "widget_control1 = WidgetControl(widget=zoom_slider, position='topright')\n", |
| 45 | + "m.add_control(widget_control1)\n", |
15 | 46 | "\n",
|
16 |
| - "radon = TileLayer(url='https://cartoradon.irsn.fr/static/r/{z}/{x}/{y}.png',\n", |
17 |
| - " tms=True, opacity=0.5)\n", |
| 47 | + "\n", |
| 48 | + "#Create a local Tile Layer concerning the irsn map\n", |
| 49 | + "radon = TileLayer(url='https://cartoradon.irsn.fr/static/r/{z}/{x}/{y}.png',tms=True, opacity=0.5)\n", |
18 | 50 | "m.add_layer(radon)\n",
|
19 | 51 | "\n",
|
20 |
| - "fullscreen = FullScreenControl()\n", |
21 |
| - "m.add_control(fullscreen)\n", |
22 |
| - "scalecontrol = ScaleControl(position='bottomleft')\n", |
23 |
| - "m.add_control(scalecontrol)\n", |
| 52 | + "#Create a function get_data which fetch the datas from the irsn application\n", |
| 53 | + "def get_data():\n", |
| 54 | + " r = requests.get('https://cartoradon.irsn.fr/commune.py/communes/lonlat/{};{}'.format(lng,lat))\n", |
| 55 | + " return r.json()\n", |
| 56 | + "\n", |
| 57 | + "#take a method on_interation providing Map object to obtain the coordinates\n", |
| 58 | + "def on_interaction(event, type, coordinates):\n", |
| 59 | + " \n", |
| 60 | + " if type == 'click':\n", |
| 61 | + " data = get_data(coordinates[1], coordinates[0])\n", |
| 62 | + "\n", |
| 63 | + " # Display geojson\n", |
| 64 | + " geometry = data['geometry']\n", |
| 65 | + " geojson = GeoJSON(data=geometry,style={'opacity': 1, 'dashArray': '9', 'fillOpacity': 0.1, 'weight': 1},hover_style={'color': 'white', 'dashArray': '0', 'fillOpacity': 0.5})\n", |
| 66 | + " m.add_layer(geojson)\n", |
| 67 | + "\n", |
| 68 | + " # Create Popup\n", |
| 69 | + " message1 = HTML()\n", |
| 70 | + " dict_properties = data['properties']\n", |
| 71 | + " get_name = dict_properties.get('name')\n", |
| 72 | + " get_class = dict_properties.get('classr')\n", |
| 73 | + " message1.value = 'Ville: {}, Classe : {}'.format(get_name,get_class)\n", |
| 74 | + " popup = Popup(location= coordinates ,child=message1,close_button=True,auto_close=True,close_on_escape_key=False)\n", |
| 75 | + " m.add_layer(popup)\n", |
| 76 | + "m.on_interaction(on_interaction) \n", |
| 77 | + "\n", |
24 | 78 | "m\n",
|
25 | 79 | "\n"
|
26 | 80 | ]
|
|
34 | 88 | },
|
35 | 89 | "outputs": [],
|
36 | 90 | "source": []
|
| 91 | + }, |
| 92 | + { |
| 93 | + "cell_type": "code", |
| 94 | + "execution_count": null, |
| 95 | + "id": "3312020d-cbd5-4f27-b9f0-845145da5811", |
| 96 | + "metadata": {}, |
| 97 | + "outputs": [], |
| 98 | + "source": [] |
37 | 99 | }
|
38 | 100 | ],
|
39 | 101 | "metadata": {
|
|
52 | 114 | "name": "python",
|
53 | 115 | "nbconvert_exporter": "python",
|
54 | 116 | "pygments_lexer": "ipython3",
|
55 |
| - "version": "3.9.7" |
| 117 | + "version": "3.10.0" |
56 | 118 | }
|
57 | 119 | },
|
58 | 120 | "nbformat": 4,
|
|
0 commit comments