Skip to content

Mouse Position plugin #916

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

Merged
merged 25 commits into from
Sep 3, 2018
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions folium/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from folium.plugins.heat_map_withtime import HeatMapWithTime
from folium.plugins.marker_cluster import MarkerCluster
from folium.plugins.measure_control import MeasureControl
from folium.plugins.mouse_position import MousePosition
from folium.plugins.polyline_text_path import PolyLineTextPath
from folium.plugins.scroll_zoom_toggler import ScrollZoomToggler
from folium.plugins.terminator import Terminator
Expand All @@ -41,6 +42,7 @@
'HeatMapWithTime',
'MarkerCluster',
'MeasureControl',
'MousePosition',
'PolyLineTextPath',
'ScrollZoomToggler',
'Terminator',
Expand Down
107 changes: 107 additions & 0 deletions folium/plugins/mouse_position.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# -*- coding: utf-8 -*-

# CONVERTED TO PYTHON FROM: https://github.com/ardhi/Leaflet.MousePosition
Copy link
Member

Choose a reason for hiding this comment

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

You are using the plugin and not really converting it to Python.
I'm not a lawyer but I don't think this is necessary.

# With the MIT License as below.

# Copyright 2012 Ardhi Lukianto

# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:

# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

from __future__ import (absolute_import, division, print_function)

import json

from branca.element import CssLink, Figure, JavascriptLink, MacroElement

from jinja2 import Template


class MousePosition(MacroElement):

Choose a reason for hiding this comment

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

E302 expected 2 blank lines, found 1

"""

Parameters
----------
position : str, default 'bottomright'
Location of the widget.

separator : str, default ' : '
Character used to separate latitude and longitude values.

empty_string : str, default 'Unavailable'
String to display when a value cannot be returned.

lng_first : bool, default 'False'
Set as True to display longitude before latitude.

num_digits : int, default '5'
Number of decimal places included in the displayed
longitude and latitude decimal degree values.

lng_formatter : str, default 'None'
Set the format for the longitude values.

lat_formatter : str, default 'None'
Set the format for the latitude values.

prefix : str, default ''
String to display before the latitude and longitude values.

"""
_template = Template("""
{% macro script(this, kwargs) %}
var {{this.get_name()}} = new L.Control.MousePosition(
{{ this.options }});
{{this._parent.get_name()}}.addControl({{this.get_name()}});

{% endmacro %}
""") # noqa

def __init__(self, position='bottomright', separator=' : ',
empty_string='Unavailable', lng_first=False,
num_digits=5, lng_formatter=None, lat_formatter=None,
prefix=""):

Choose a reason for hiding this comment

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

W293 blank line contains whitespace

Choose a reason for hiding this comment

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

W293 blank line contains whitespace

Choose a reason for hiding this comment

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

W293 blank line contains whitespace

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

options = {
'position': position,
'separator': separator,
'empty_string': empty_string,
'lng_first': lng_first,
'num_digits': num_digits,
'lng_formatter': lng_formatter,
'lat_formatter': lat_formatter,
'prefix': prefix,
}
self.options = json.dumps(options)

def render(self, **kwargs):
super(MousePosition, self).render()

figure = self.get_root()
assert isinstance(figure, Figure), ('You cannot render this Element '
'if it is not in a Figure.')

figure.header.add_child(
JavascriptLink('https://cdn.rawgit.com/ardhi/Leaflet.MousePosition/c32f1c84/src/L.Control.MousePosition.js')) # noqa
Copy link
Member

Choose a reason for hiding this comment

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

We are already using noqa so no need for the extra line here.


figure.header.add_child(
CssLink('https://cdn.rawgit.com/ardhi/Leaflet.MousePosition/c32f1c84/src/L.Control.MousePosition.css')) # noqa