Фолиевая проблема с srdoc - PullRequest
0 голосов
/ 18 марта 2020

Я пытаюсь построить карту с помощью Folium, основываясь на данных. Здесь вы можете проверить всю Jupyter Notebook . Я вставляю ниже код проблемы: c:

map_borough = folium.Map(location = [borough_lat, borough_lng], zoom_start = 10.7)

for lat, lng, neighborhood in zip(borough['Latitude'], borough['Longitude'], borough['Neighborhood']):
    label = folium.Popup(label, parse_html=True)
    folium.CircleMarker(
        [lat, lng],
        radius=5,
        popup=label,
        color='blue',
        fill=True,
        fill_color='#3186cc',
        fill_opacity=0.7).add_to(map_borough)  
map_borough

Как видно на ноутбуке, этот код выдает странную ошибку:

---------------------------------------------------------------------------
UndefinedError                            Traceback (most recent call last)
~/miniconda3/lib/python3.7/site-packages/IPython/core/formatters.py in __call__(self, obj)
    343             method = get_real_method(obj, self.print_method)
    344             if method is not None:
--> 345                 return method()
    346             return None
    347         else:

~/miniconda3/lib/python3.7/site-packages/folium/folium.py in _repr_html_(self, **kwargs)
    291             self._parent = None
    292         else:
--> 293             out = self._parent._repr_html_(**kwargs)
    294         return out
    295 

~/miniconda3/lib/python3.7/site-packages/branca/element.py in _repr_html_(self, **kwargs)
    328         # the HTML in the src attribute with a data URI. The alternative of using a srcdoc
    329         # attribute is not supported in Microsoft Internet Explorer and Edge.
--> 330         html = base64.b64encode(self.render(**kwargs).encode('utf8')).decode('utf8')
    331         onload = (
    332             'this.contentDocument.open();'

~/miniconda3/lib/python3.7/site-packages/branca/element.py in render(self, **kwargs)
    319         """Renders the HTML representation of the element."""
    320         for name, child in self._children.items():
--> 321             child.render(**kwargs)
    322         return self._template.render(this=self, kwargs=kwargs)
    323 

~/miniconda3/lib/python3.7/site-packages/folium/folium.py in render(self, **kwargs)
    368             '</style>'), name='map_style')
    369 
--> 370         super(Map, self).render(**kwargs)
    371 
    372     def fit_bounds(self, bounds, padding_top_left=None,

~/miniconda3/lib/python3.7/site-packages/branca/element.py in render(self, **kwargs)
    637 
    638         for name, element in self._children.items():
--> 639             element.render(**kwargs)

~/miniconda3/lib/python3.7/site-packages/branca/element.py in render(self, **kwargs)
    637 
    638         for name, element in self._children.items():
--> 639             element.render(**kwargs)

~/miniconda3/lib/python3.7/site-packages/folium/map.py in render(self, **kwargs)
    367 
    368         figure.script.add_child(Element(
--> 369             self._template.render(this=self, kwargs=kwargs)),
    370             name=self.get_name())
    371 

~/miniconda3/lib/python3.7/site-packages/jinja2/environment.py in render(self, *args, **kwargs)
   1088             return concat(self.root_render_func(self.new_context(vars)))
   1089         except Exception:
-> 1090             self.environment.handle_exception()
   1091 
   1092     def render_async(self, *args, **kwargs):

~/miniconda3/lib/python3.7/site-packages/jinja2/environment.py in handle_exception(self, source)
    830         from .debug import rewrite_traceback_stack
    831 
--> 832         reraise(*rewrite_traceback_stack(source=source))
    833 
    834     def join_path(self, template, parent):

~/miniconda3/lib/python3.7/site-packages/jinja2/_compat.py in reraise(tp, value, tb)
     26     def reraise(tp, value, tb=None):
     27         if value.__traceback__ is not tb:
---> 28             raise value.with_traceback(tb)
     29         raise value
     30 

<template> in top-level template code()

~/miniconda3/lib/python3.7/site-packages/folium/map.py in render(self, **kwargs)
    367 
    368         figure.script.add_child(Element(
--> 369             self._template.render(this=self, kwargs=kwargs)),
    370             name=self.get_name())
    371 

~/miniconda3/lib/python3.7/site-packages/jinja2/environment.py in render(self, *args, **kwargs)
   1088             return concat(self.root_render_func(self.new_context(vars)))
   1089         except Exception:
-> 1090             self.environment.handle_exception()
   1091 
   1092     def render_async(self, *args, **kwargs):

~/miniconda3/lib/python3.7/site-packages/jinja2/environment.py in handle_exception(self, source)
    830         from .debug import rewrite_traceback_stack
    831 
--> 832         reraise(*rewrite_traceback_stack(source=source))
    833 
    834     def join_path(self, template, parent):

~/miniconda3/lib/python3.7/site-packages/jinja2/_compat.py in reraise(tp, value, tb)
     26     def reraise(tp, value, tb=None):
     27         if value.__traceback__ is not tb:
---> 28             raise value.with_traceback(tb)
     29         raise value
     30 

<template> in top-level template code()

UndefinedError: 'None' has no attribute 'replace'

Я искал и здесь, и в Google, но не могу понять, что происходит. Что не так?

1 Ответ

0 голосов
/ 18 марта 2020

Только что нашел ошибку! Мой for ожидал, что переменная label будет отображаться во всплывающих окнах.

map_borough = folium.Map(location = [borough_lat, borough_lng], zoom_start = 10)

for lat, lng, label in zip(borough['Latitude'], borough['Longitude'], borough['Neighborhood']):
    label = folium.Popup(label, parse_html=True)
    folium.CircleMarker(
        [lat, lng],
        radius=5,
        popup=label,
        color='blue',
        fill=True,
        fill_color='#3186cc',
        fill_opacity=0.7).add_to(map_borough)  
map_borough

Теперь это работает!

...