-
Notifications
You must be signed in to change notification settings - Fork 2.3k
popups allow unicode #95
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 all commits
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 |
|---|---|---|
|
|
@@ -22,6 +22,8 @@ | |
| from folium import utilities | ||
| from folium.six import text_type, binary_type, iteritems | ||
|
|
||
| import sys | ||
|
|
||
|
|
||
| ENV = Environment(loader=PackageLoader('folium', 'templates')) | ||
|
|
||
|
|
@@ -616,10 +618,21 @@ def _popup_render(self, popup=None, mk_name=None, count=None, | |
| if not popup_on: | ||
| return 'var no_pop = null;' | ||
| else: | ||
| if isinstance(popup, str): | ||
| if sys.version_info >= (3,0): | ||
| utype, stype = str, bytes | ||
| else: | ||
| utype, stype = unicode, str | ||
|
|
||
| if isinstance(popup, (utype, stype)): | ||
| popup_temp = self.env.get_template('simple_popup.js') | ||
| if isinstance(popup, utype): | ||
| popup_txt = popup.encode('ascii', 'xmlcharrefreplace') | ||
|
Member
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. Loved it! |
||
| else: | ||
| popup_txt = popup | ||
| if sys.version_info >= (3,0): | ||
| popup_txt = popup_txt.decode() | ||
| return popup_temp.render({'pop_name': mk_name + str(count), | ||
| 'pop_txt': json.dumps(popup), | ||
| 'pop_txt': json.dumps(str(popup_txt)), | ||
|
Member
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. @apatil I am on the fence here. I am not sure if the call to
Contributor
Author
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. I was getting type errors in python3 without it. The encode('ascii', ...) produces a bytes object, which json.dumps doesn't like.
Member
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.
|
||
| 'width': width}) | ||
| elif isinstance(popup, tuple): | ||
| #Update template with JS libs | ||
|
|
@@ -653,6 +666,8 @@ def _popup_render(self, popup=None, mk_name=None, count=None, | |
| 'max_width': max_width, | ||
| 'json_out': json_out, | ||
| 'vega_id': vega_id}) | ||
| else: | ||
| raise TypeError("Unrecognized popup type: {!r}".format(popup)) | ||
|
|
||
| @iter_obj('geojson') | ||
| def geo_json(self, geo_path=None, geo_str=None, data_out='data.json', | ||
|
|
||
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.
Use
instead.