-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Changes from 7 commits
52ecb8f
8bc6a6c
1153205
00081d8
bccd13a
83e9e1a
f426da6
f243652
55bc861
7b42227
53d1fed
426cfba
465fa3a
20340a2
57eecb0
8499466
441ae11
5c27d31
2c55f49
26ff0d8
603cfde
65a997f
4660151
a74796b
a71c282
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
# 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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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=""): | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. W293 blank line contains whitespace There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. W293 blank line contains whitespace There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are already using |
||
|
||
figure.header.add_child( | ||
CssLink('https://cdn.rawgit.com/ardhi/Leaflet.MousePosition/c32f1c84/src/L.Control.MousePosition.css')) # noqa |
There was a problem hiding this comment.
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.