def __init__(self, html=None, max_width=300): super(Popup, self).__init__() self._name = 'Popup' self.header = Element() self.html = Element() self.script = Element() self.header._parent = self self.html._parent = self self.script._parent = self if isinstance(html, Element): self.html.add_children(html) elif isinstance(html, text_type) or isinstance(html, binary_type): self.html.add_children(Html(text_type(html))) self.max_width = max_width self._template = Template(u""" var {{this.get_name()}} = L.popup({maxWidth: '{{this.max_width}}'}); {% for name, element in this.html._children.items() %} var {{name}} = $('{{element.render(**kwargs).replace('\\n',' ')}}')[0]; {{this.get_name()}}.setContent({{name}}); {% endfor %} {{this._parent.get_name()}}.bindPopup({{this.get_name()}}); {% for name, element in this.script._children.items() %} {{element.render()}} {% endfor %} """) # noqa
def __init__(self, tiles='OpenStreetMap', min_zoom=1, max_zoom=18, attr=None, API_key=None, detect_retina=False, name=None, overlay=False, control=True): self.tile_name = (name if name is not None else ''.join( tiles.lower().strip().split())) super(TileLayer, self).__init__(name=self.tile_name, overlay=overlay, control=control) self._name = 'TileLayer' self._env = ENV self.min_zoom = min_zoom self.max_zoom = max_zoom self.detect_retina = detect_retina self.tiles = ''.join(tiles.lower().strip().split()) if self.tiles in ('cloudmade', 'mapbox') and not API_key: raise ValueError('You must pass an API key if using Cloudmade' ' or non-default Mapbox tiles.') templates = list( self._env.list_templates( filter_func=lambda x: x.startswith('tiles/'))) tile_template = 'tiles/' + self.tiles + '/tiles.txt' attr_template = 'tiles/' + self.tiles + '/attr.txt' if tile_template in templates and attr_template in templates: self.tiles = self._env.get_template(tile_template).render( API_key=API_key) # noqa self.attr = self._env.get_template(attr_template).render() else: self.tiles = tiles if not attr: raise ValueError('Custom tiles must' ' also be passed an attribution.') if isinstance(attr, binary_type): attr = text_type(attr, 'utf8') self.attr = attr self._template = Template(u""" {% macro script(this, kwargs) %} var {{this.get_name()}} = L.tileLayer( '{{this.tiles}}', { maxZoom: {{this.max_zoom}}, minZoom: {{this.min_zoom}}, attribution: '{{this.attr}}', detectRetina: {{this.detect_retina.__str__().lower()}} } ).addTo({{this._parent.get_name()}}); {% endmacro %} """)
def __init__(self, html=None, max_width=300): super(Popup, self).__init__() self._name = 'Popup' self.header = Element() self.html = Element() self.script = Element() self.header._parent = self self.html._parent = self self.script._parent = self if isinstance(html, Element): self.html.add_child(html) elif isinstance(html, text_type) or isinstance(html, binary_type): self.html.add_child(Html(text_type(html))) self.max_width = max_width self._template = Template(u""" var {{this.get_name()}} = L.popup({maxWidth: '{{this.max_width}}'}); {% for name, element in this.html._children.items() %} var {{name}} = $('{{element.render(**kwargs).replace('\\n',' ')}}')[0]; {{this.get_name()}}.setContent({{name}}); {% endfor %} {{this._parent.get_name()}}.bindPopup({{this.get_name()}}); {% for name, element in this.script._children.items() %} {{element.render()}} {% endfor %} """) # noqa
def __init__(self, tiles='OpenStreetMap', min_zoom=1, max_zoom=18, attr=None, API_key=None, detect_retina=False, name=None, overlay=False, control=True): self.tile_name = (name if name is not None else ''.join(tiles.lower().strip().split())) super(TileLayer, self).__init__(name=self.tile_name, overlay=overlay, control=control) self._name = 'TileLayer' self._env = ENV self.min_zoom = min_zoom self.max_zoom = max_zoom self.detect_retina = detect_retina self.tiles = ''.join(tiles.lower().strip().split()) if self.tiles in ('cloudmade', 'mapbox') and not API_key: raise ValueError('You must pass an API key if using Cloudmade' ' or non-default Mapbox tiles.') templates = list(self._env.list_templates( filter_func=lambda x: x.startswith('tiles/'))) tile_template = 'tiles/'+self.tiles+'/tiles.txt' attr_template = 'tiles/'+self.tiles+'/attr.txt' if tile_template in templates and attr_template in templates: self.tiles = self._env.get_template(tile_template).render(API_key=API_key) # noqa self.attr = self._env.get_template(attr_template).render() else: self.tiles = tiles if not attr: raise ValueError('Custom tiles must' ' also be passed an attribution.') if isinstance(attr, binary_type): attr = text_type(attr, 'utf8') self.attr = attr self._template = Template(u""" {% macro script(this, kwargs) %} var {{this.get_name()}} = L.tileLayer( '{{this.tiles}}', { maxZoom: {{this.max_zoom}}, minZoom: {{this.min_zoom}}, attribution: '{{this.attr}}', detectRetina: {{this.detect_retina.__str__().lower()}} } ).addTo({{this._parent.get_name()}}); {% endmacro %} """)
def __init__( self, tiles="OpenStreetMap", min_zoom=1, max_zoom=18, attr=None, API_key=None, detect_retina=False, continuous_world=False, name=None, overlay=False, control=True, no_wrap=False, ): self.tile_name = name if name is not None else "".join(tiles.lower().strip().split()) super(TileLayer, self).__init__(name=self.tile_name, overlay=overlay, control=control) self._name = "TileLayer" self._env = ENV self.min_zoom = min_zoom self.max_zoom = max_zoom self.no_wrap = no_wrap self.continuous_world = continuous_world self.detect_retina = detect_retina self.tiles = "".join(tiles.lower().strip().split()) if self.tiles in ("cloudmade", "mapbox") and not API_key: raise ValueError("You must pass an API key if using Cloudmade" " or non-default Mapbox tiles.") templates = list(self._env.list_templates(filter_func=lambda x: x.startswith("tiles/"))) tile_template = "tiles/" + self.tiles + "/tiles.txt" attr_template = "tiles/" + self.tiles + "/attr.txt" if tile_template in templates and attr_template in templates: self.tiles = self._env.get_template(tile_template).render(API_key=API_key) # noqa self.attr = self._env.get_template(attr_template).render() else: self.tiles = tiles if not attr: raise ValueError("Custom tiles must" " also be passed an attribution.") if isinstance(attr, binary_type): attr = text_type(attr, "utf8") self.attr = attr self._template = Template( """ {% macro script(this, kwargs) %} var {{this.get_name()}} = L.tileLayer( '{{this.tiles}}', { maxZoom: {{this.max_zoom}}, minZoom: {{this.min_zoom}}, continuousWorld: {{this.continuous_world.__str__().lower()}}, noWrap: {{this.no_wrap.__str__().lower()}}, attribution: '{{this.attr}}', detectRetina: {{this.detect_retina.__str__().lower()}} } ).addTo({{this._parent.get_name()}}); {% endmacro %} """ ) # noqa