Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add minimap plugin #968

Merged
merged 14 commits into from
Oct 16, 2018
Next Next commit
Add inital minimap plugin
  • Loading branch information
ColinTalbert committed Sep 21, 2018
commit 3191c20bcdc1b758620c95a336b8ce3a5bc37013
106 changes: 106 additions & 0 deletions examples/MiniMap.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import folium\n",
"from folium.plugins import MiniMap"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9ZmFsc2U7IExfRElTQUJMRV8zRD1mYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS4zLjQvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2FqYXguZ29vZ2xlYXBpcy5jb20vYWpheC9saWJzL2pxdWVyeS8xLjExLjEvanF1ZXJ5Lm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9tYXhjZG4uYm9vdHN0cmFwY2RuLmNvbS9ib290c3R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QtbWluaW1hcC8zLjYuMS9Db250cm9sLk1pbmlNYXAuY3NzIi8+CjwvaGVhZD4KPGJvZHk+ICAgIAogICAgCiAgICA8ZGl2IGNsYXNzPSJmb2xpdW0tbWFwIiBpZD0ibWFwX2I0Y2E3MWJlMDc2OTQ1MjdiMDI0YjI0MWU5NDZiNmVkIiA+PC9kaXY+CjwvYm9keT4KPHNjcmlwdD4gICAgCiAgICAKICAgIAogICAgICAgIHZhciBib3VuZHMgPSBudWxsOwogICAgCgogICAgdmFyIG1hcF9iNGNhNzFiZTA3Njk0NTI3YjAyNGIyNDFlOTQ2YjZlZCA9IEwubWFwKAogICAgICAgICdtYXBfYjRjYTcxYmUwNzY5NDUyN2IwMjRiMjQxZTk0NmI2ZWQnLCB7CiAgICAgICAgY2VudGVyOiBbMzAsIDIwXSwKICAgICAgICB6b29tOiA0LAogICAgICAgIG1heEJvdW5kczogYm91bmRzLAogICAgICAgIGxheWVyczogW10sCiAgICAgICAgd29ybGRDb3B5SnVtcDogZmFsc2UsCiAgICAgICAgY3JzOiBMLkNSUy5FUFNHMzg1NywKICAgICAgICB6b29tQ29udHJvbDogdHJ1ZSwKICAgICAgICB9KTsKCiAgICAKICAgIAogICAgdmFyIHRpbGVfbGF5ZXJfNjNlNzlhOWFjZWM3NDU0MjgyZjkyNjY0ZTUzN2IzZDMgPSBMLnRpbGVMYXllcigKICAgICAgICAnaHR0cHM6Ly97c30udGlsZS5vcGVuc3RyZWV0bWFwLm9yZy97en0ve3h9L3t5fS5wbmcnLAogICAgICAgIHsKICAgICAgICAiYXR0cmlidXRpb24iOiBudWxsLAogICAgICAgICJkZXRlY3RSZXRpbmEiOiBmYWxzZSwKICAgICAgICAibWF4TmF0aXZlWm9vbSI6IDE4LAogICAgICAgICJtYXhab29tIjogMTgsCiAgICAgICAgIm1pblpvb20iOiAwLAogICAgICAgICJub1dyYXAiOiBmYWxzZSwKICAgICAgICAib3BhY2l0eSI6IDEsCiAgICAgICAgInN1YmRvbWFpbnMi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AgICAgICAiZGV0ZWN0UmV0aW5hIjogZmFsc2UsCiAgICAgICAgIm1heE5hdGl2ZVpvb20iOiAxOCwKICAgICAgICAibWF4Wm9vbSI6IDE4LAogICAgICAgICJtaW5ab29tIjogMCwKICAgICAgICAibm9XcmFwIjogZmFsc2UsCiAgICAgICAgIm9wYWNpdHkiOiAxLAogICAgICAgICJzdWJkb21haW5zIjogImFiYyIsCiAgICAgICAgInRtcyI6IGZhbHNlCn0pLmFkZFRvKGZpZ3VyZV8yZmM2MTFkZDAxOTU0ODAxOWZjZjRkYTRkNDQ0MzRhYyk7Cjwvc2NyaXB0Pg==\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
],
"text/plain": [
"<folium.folium.Map at 0x1f75fb9bdd8>"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"m = folium.Map(location=(30, 20), zoom_start=4)\n",
"minimap = MiniMap()\n",
"minimap.add_to(m)\n",
"m.save(r\"c:\\temp\\test.html\")\n",
"m"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"from folium.raster_layers import TileLayer\n",
"t = TileLayer(\"Stamen Toner\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9ZmFsc2U7IExfRElTQ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BMLnRpbGVMYXllcigKICAgICAgICAnaHR0cHM6Ly97c30udGlsZS5vcGVuc3RyZWV0bWFwLm9yZy97en0ve3h9L3t5fS5wbmcnLAogICAgICAgIHsKICAgICAgICAiYXR0cmlidXRpb24iOiBudWxsLAogICAgICAgICJkZXRlY3RSZXRpbmEiOiBmYWxzZSwKICAgICAgICAibWF4TmF0aXZlWm9vbSI6IDE4LAogICAgICAgICJtYXhab29tIjogMTgsCiAgICAgICAgIm1pblpvb20iOiAwLAogICAgICAgICJub1dyYXAiOiBmYWxzZSwKICAgICAgICAib3BhY2l0eSI6IDEsCiAgICAgICAgInN1YmRvbWFpbnMiOiAiYWJjIiwKICAgICAgICAidG1zIjogZmFsc2UKfSkuYWRkVG8obWFwXzRjOWU1M2JmNTdjYjQzZTZhNTkyZmNkYzY5YzVmZDdjKTsKICAgIAoKICAgICAgICB2YXIgdGlsZV9sYXllcl9jODMwNjRmYTk2MDg0ZmY0ODIxMDk4ODQyOWQ5ZjkyOSA9IEwudGlsZUxheWVyKAogICAgICAgICdodHRwczovL3N0YW1lbi10aWxlcy17c30uYS5zc2wuZmFzdGx5Lm5ldC90b25lci97en0ve3h9L3t5fS5wbmcnLAogICAgICAgIHsKICAiZW1wdHlTdHJpbmciOiAiVW5hdmFpbGFibGUiLAogICJsbmdGaXJzdCI6IGZhbHNlLAogICJudW1EaWdpdHMiOiA1LAogICJwb3NpdGlvbiI6ICJib3R0b21yaWdodCIsCiAgInByZWZpeCI6ICIiLAogICJzZXBhcmF0b3IiOiAiIDogIgp9ICk7CgogICAgICAgIHZhciBtaW5pX21hcF9mNGFiMDRiMjk4YWI0NzhiYjM5Njk0MjdhYTY0N2E5NyA9IG5ldyBMLkNvbnRyb2wuTWluaU1hcCggdGlsZV9sYXllcl9jODMwNjRmYTk2MDg0ZmY0ODIxMDk4ODQyOWQ5ZjkyOSApOwogICAgICAgIG1hcF80YzllNTNiZjU3Y2I0M2U2YTU5MmZjZGM2OWM1ZmQ3Yy5hZGRDb250cm9sKG1pbmlfbWFwX2Y0YWIwNGIyOThhYjQ3OGJiMzk2OTQyN2FhNjQ3YTk3KTsKCiAgICAgICAgCiAgICB2YXIgdGlsZV9sYXllcl9jODMwNjRmYTk2MDg0ZmY0ODIxMDk4ODQyOWQ5ZjkyOSA9IEwudGlsZUxheWVyKAogICAgICAgICdodHRwczovL3N0YW1lbi10aWxlcy17c30uYS5zc2wuZmFzdGx5Lm5ldC90b25lci97en0ve3h9L3t5fS5wbmcnLAogICAgICAgIHsKICAgICAgICAiYXR0cmlidXRpb24iOiBudWxsLAogICAgICAgICJkZXRlY3RSZXRpbmEiOiBmYWxzZSwKICAgICAgICAibWF4TmF0aXZlWm9vbSI6IDE4LAogICAgICAgICJtYXhab29tIjogMTgsCiAgICAgICAgIm1pblpvb20iOiAwLAogICAgICAgICJub1dyYXAiOiBmYWxzZSwKICAgICAgICAib3BhY2l0eSI6IDEsCiAgICAgICAgInN1YmRvbWFpbnMiOiAiYWJjIiwKICAgICAgICAidG1zIjogZmFsc2UKfSkuYWRkVG8oZmlndXJlXzk1ZDViZTJhYjQ0ZDRkZjVhODdhNDg0ZjU1OWEzNjZmKTsKPC9zY3JpcHQ+\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
],
"text/plain": [
"<folium.folium.Map at 0x1f75fbef780>"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"m = folium.Map(location=(30, 20), zoom_start=4)\n",
"minimap = MiniMap(tile_layer=t)\n",
"minimap.add_to(m)\n",
"m.save(r\"c:\\temp\\test.html\")\n",
"m"
]
}
],
"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.6.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
2 changes: 2 additions & 0 deletions folium/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from folium.plugins.timestamped_geo_json import TimestampedGeoJson
from folium.plugins.timestamped_wmstilelayer import TimestampedWmsTileLayers
from folium.plugins.search import Search
from folium.plugins.minimap import MiniMap

__all__ = [
'BeautifyIcon',
Expand All @@ -50,4 +51,5 @@
'TimestampedGeoJson',
'TimestampedWmsTileLayers',
'Search',
'MiniMap'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comma

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

]
129 changes: 129 additions & 0 deletions folium/plugins/minimap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# -*- coding: utf-8 -*-

from __future__ import (absolute_import, division, print_function)

import json

from branca.element import CssLink, Figure, JavascriptLink, MacroElement
from folium.raster_layers import TileLayer

from jinja2 import Template


class MiniMap(MacroElement):
"""Add a minimap (locator) to an existing map.

Uses the Leaflet plugin by Norkart under BSD 2-Clause "Simplified" License.
https://github.com/Norkart/Leaflet-MiniMap

Parameters
----------
tile_layer: folium tilelayer, str (Optional)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could use a line with explanation. e.g.:

tile_layer: folium TileLayer object or str, optional
    Provide a folium TileLayer object or the wanted tiles as string.
    If not provided it will use the default of `TileLayer`.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to have empty lines between the parameters

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still seeing them on the 'files changed' page, am I missing something?

position : str, default 'bottomright'
The standard Control position parameter for the widget.


width: int, default 150
The width of the minimap in pixels.

height: int, default 150
The height of the minimap in pixels.

collapsed_width: int, default 25
The width of the toggle marker and the minimap when collapsed, in pixels.

collapsed_height: int, default 25
The height of the toggle marker and the minimap when collapsed

zoom_level_offset: int, defalut -5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

The offset applied to the zoom in the minimap compared to the zoom of the main map. Can be positive or negative.

zoom_level_fixed: int, default None
Overrides the offset to apply a fixed zoom level to the minimap regardless of the main map zoom.
Set it to any valid zoom level, if unset zoomLevelOffset is used instead.

center_fixed: bool, default False
Applies a fixed position to the minimap regardless of the main map's view / position. P
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Word is broken

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

revents panning the minimap, but does allow zooming (both in the minimap and the main map).
If the minimap is zoomed, it will always zoom around the centerFixed point.
You can pass in a LatLng-equivalent object.

zoom_animation: bool, default False
Sets whether the minimap should have an animated zoom.
(Will cause it to lag a bit after the movement of the main map.)

toggle_display: bool, default
Sets whether the minimap should have a button to minimise it.

auto_toggle_display: bool, default
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're missing some default values here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Sets whether the minimap should hide automatically
if the parent map bounds does not fit within the minimap bounds.
Especially useful when 'zoomLevelFixed' is set.

minimized: bool, default
Sets whether the minimap should start in a minimized position.

Examples
--------
>>> MiniMap(tile_layer='Stamen WaterColor', position='bottomleft')
"""

_template = Template("""
{% macro script(this, kwargs) %}

var {{ this.tile_layer.get_name() }} = L.tileLayer(
'{{ this.tile_layer.tiles }}',
{{ this.tile_layer.options }} );

var {{ this.get_name() }} = new L.Control.MiniMap( {{this.tile_layer.get_name()}},
{{ this.options }});
{{ this._parent.get_name() }}.addControl({{ this.get_name() }});

{% endmacro %}
""") # noqa

def __init__(self, tile_layer=None, position='bottomright', width=150,
height=150, collapsed_width=25, collapsed_height=25,

Copy link
Member

@Conengmo Conengmo Oct 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty line in between the function arguments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the optional requirement above, It defaults to to whatever TileLayer defaults to (OSM I think) but I'm not sure I should hard code this in. So I put this in which might have been missing when you looked:
https://github.com/talbertc-usgs/folium/blob/minimap/folium/plugins/minimap.py#L23

zoom_level_offset=-5, zoom_level_fixed=None,
center_fixed=False, zoom_animation=False,
toggle_display=False, auto_toggle_display=False,
minimized=False):

super(MiniMap, self).__init__()
self._name = 'MiniMap'

if tile_layer is None:
self.tile_layer = TileLayer()
elif isinstance(tile_layer, TileLayer):
self.tile_layer = tile_layer
else:
self.tile_layer = TileLayer(tile_layer)

options = {
'position': position,
'width': width,
'height': height,
'collapsedWidth': collapsed_width,
'collapsedHeight': collapsed_height,
'zoomLevelOffset': zoom_level_offset,
'zoomLevelFixed': zoom_level_fixed,
'centerFixed': center_fixed,
'zoomAnimation': zoom_animation,
'toggleDisplay': toggle_display,
'autoToggleDisplay': auto_toggle_display,
'minimized': minimized,
}
self.options = json.dumps(options, sort_keys=True, indent=2)

def render(self, **kwargs):
figure = self.get_root()
assert isinstance(figure, Figure), ('You cannot render this Element '
'if it is not in a Figure.')
super(MiniMap, self).render()

figure.header.add_child(JavascriptLink('https://cdnjs.cloudflare.com/ajax/libs/leaflet-minimap/3.6.1/Control.MiniMap.js')) # noqa

figure.header.add_child(CssLink('https://cdnjs.cloudflare.com/ajax/libs/leaflet-minimap/3.6.1/Control.MiniMap.css')) # noqa
figure.add_child(self.tile_layer)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

W292 no newline at end of file

32 changes: 32 additions & 0 deletions tests/plugins/test_minimap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-

"""
Test FloatImage
Copy link
Member

@Conengmo Conengmo Sep 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong title.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

---------------
"""

from __future__ import (absolute_import, division, print_function)

import folium

from folium import plugins


def test_minimap():
m = folium.Map(location=(30, 20), zoom_start=4)

minimap = plugins.MiniMap()
m.add_child(minimap)

out = m._parent.render()

# Verify that a new minimap is getting created.
assert 'new L.Control.MiniMap' in out

m = folium.Map(location=(30, 20), zoom_start=4)
minimap = plugins.MiniMap(tile_layer="Stamen Toner")
minimap.add_to(m)

out = m._parent.render()
# verify that Stamen Toner tiles are being used
assert 'https://stamen-tiles' in out