{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from branca.element import Figure\n",
"\n",
"lon, lat = -122.1889, 46.1991\n",
"\n",
"location = [lat, lon]\n",
"\n",
"zoom_start = 13\n",
"\n",
"tiles = \"OpenStreetMap\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Using same width and height triggers the scroll bar"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import folium\n",
"\n",
"\n",
"width, height = 480, 350\n",
"\n",
"fig = Figure(width=width, height=height)\n",
"\n",
"m = folium.Map(\n",
" location=location, tiles=tiles, width=width, height=height, zoom_start=zoom_start\n",
")\n",
"\n",
"fig.add_child(m)\n",
"\n",
"fig"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Can figure take relative sizes?"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"width, height = \"100%\", 350\n",
"\n",
"fig = Figure(width=width, height=height)\n",
"\n",
"m = folium.Map(\n",
" location=location, tiles=tiles, width=width, height=height, zoom_start=zoom_start\n",
")\n",
"\n",
"fig.add_child(m)\n",
"\n",
"fig"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# I guess not. (Well, it does make sense for a single HTML page, but not for iframes.)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"width, height = 480, \"100%\"\n",
"\n",
"fig = Figure(width=width, height=height)\n",
"\n",
"m = folium.Map(\n",
" location=location, tiles=tiles, width=width, height=height, zoom_start=zoom_start\n",
")\n",
"\n",
"fig.add_child(m)\n",
"\n",
"fig"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Not that Figure is interpreting this as 50px. We should raise something and be explicit on the docs."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"width, height = \"50%\", \"100%\"\n",
"\n",
"fig = Figure(width=width, height=height)\n",
"\n",
"m = folium.Map(\n",
" location=location, tiles=tiles, width=width, height=height, zoom_start=zoom_start\n",
")\n",
"\n",
"fig.add_child(m)\n",
"\n",
"fig"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Cannot parse value 150.0 as '%'\n"
]
}
],
"source": [
"width, height = \"150%\", \"100%\"\n",
"\n",
"try:\n",
" folium.Map(\n",
" location=location,\n",
" tiles=tiles,\n",
" width=width,\n",
" height=height,\n",
" zoom_start=zoom_start,\n",
" )\n",
"except ValueError as e:\n",
" print(e)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Cannot parse value '80p' as '%'\n"
]
}
],
"source": [
"width, height = \"50%\", \"80p\"\n",
"\n",
"try:\n",
" folium.Map(\n",
" location=location,\n",
" tiles=tiles,\n",
" width=width,\n",
" height=height,\n",
" zoom_start=zoom_start,\n",
" )\n",
"except ValueError as e:\n",
" print(e)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Cannot parse value -350.0 as 'px'\n"
]
}
],
"source": [
"width, height = width, height = 480, -350\n",
"\n",
"try:\n",
" folium.Map(\n",
" location=location,\n",
" tiles=tiles,\n",
" width=width,\n",
" height=height,\n",
" zoom_start=zoom_start,\n",
" )\n",
"except ValueError as e:\n",
" print(e)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Maybe we should recommend"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"width, height = 480, 350\n",
"\n",
"fig = Figure(width=width, height=height)\n",
"\n",
"m = folium.Map(\n",
" location=location, tiles=tiles, width=\"100%\", height=\"100%\", zoom_start=zoom_start\n",
")\n",
"\n",
"fig.add_child(m)\n",
"\n",
"fig"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.0"
}
},
"nbformat": 4,
"nbformat_minor": 1
}