Skip to content

Commit

Permalink
Update Map.js and update example notebook Subitems.ipynb.
Browse files Browse the repository at this point in the history
  • Loading branch information
HaudinFlorence committed Sep 6, 2022
1 parent 2be7918 commit 36d6e74
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 80 deletions.
87 changes: 26 additions & 61 deletions examples/Subitems.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,25 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Set up for JupyterLite\n",
"try:\n",
" import piplite\n",
" await piplite.install('ipyleaflet')\n",
"except ImportError:\n",
" pass"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from ipyleaflet import Map, Marker, Choropleth, MagnifyingGlass, ColormapControl\n",
"from ipyleaflet import Map, Marker, Choropleth, MagnifyingGlass, ColormapControl, AwesomeIcon, basemaps, basemap_to_tiles\n",
"import json\n",
"import pandas as pd\n",
"from ipywidgets import link, FloatSlider\n",
Expand All @@ -17,7 +31,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -42,7 +56,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -59,31 +73,9 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"layer1.subitems : 3\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "49a96e262fc543e09343d5e557f50b16",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Map(center=[43, -100], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', 'zoom_out_t…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"layer1.subitems = layer1.subitems+(colormap_control1, magnifying_glass1)\n",
"print('layer1.subitems :', len(layer1.subitems))\n",
Expand All @@ -92,15 +84,11 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Example2 with a basemap\n",
"from ipyleaflet import Map, Marker, AwesomeIcon, basemaps, basemap_to_tiles\n",
"#center = (40.730610, -73.935242)\n",
"#zoom =10\n",
"#m2 = Map(center=center, zoom=zoom)\n",
"icon1 = AwesomeIcon(\n",
" name='gear',\n",
" marker_color='blue',\n",
Expand All @@ -113,7 +101,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -129,42 +117,19 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "49a96e262fc543e09343d5e557f50b16",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Map(bottom=1705.0, center=[43, -100], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_titl…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"layer2 = basemap_to_tiles(basemaps.Strava.Water, subitems= (marker1, marker2))\n",
"m1.add(layer2)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"len(layer2.subitems): 2\n"
]
}
],
"outputs": [],
"source": [
"print('len(layer2.subitems):', len(layer2.subitems))"
]
Expand Down
34 changes: 15 additions & 19 deletions js/src/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,20 +229,20 @@ export class LeafletMapView extends utils.LeafletDOMWidgetView {
add_subitem_model(child_model) {
return this.create_child_view(child_model, {
map_view: this
}).then(view => {
if(child_model['name'].includes('Control')){
this.obj.addControl(view.obj);
} else {
this.obj.addLayer(view.obj);
}
}).then(view => {
if(child_model['name'].includes('Control')){
this.obj.addControl(view.obj);
} else {
this.obj.addLayer(view.obj);
}

// Trigger the displayed event of the child view.
this.displayed.then(() => {
view.trigger('displayed', this);
});
this.displayed.then(() => {
view.trigger('displayed', this);
});
return view;
});
}
}

render() {
super.render();
Expand Down Expand Up @@ -277,19 +277,15 @@ export class LeafletMapView extends utils.LeafletDOMWidgetView {
this.create_panes();
this.layer_views.update(this.model.get('layers'));
this.control_views.update(this.model.get('controls'));

var layer_list = this.model.get('layers');
var all_subitems = [];
layer_list.forEach((layer) => {
var all_subitems = []
var subitem_list = layer.attributes.subitems
var subitem_list = layer.attributes.subitems;
subitem_list.forEach((subitem) => {
console.log('subitem is:', subitem)
all_subitems.push(subitem)
}
)
all_subitems.push(subitem);
});
this.subitem_views.update(all_subitems);
}
)
});

this.leaflet_events();
this.model_events();
Expand Down

0 comments on commit 36d6e74

Please sign in to comment.