def __init__(self, icon_image, icon_size=None, icon_anchor=None, shadow_image=None, shadow_size=None, shadow_anchor=None, popup_anchor=None): super(Icon, self).__init__() self._name = 'CustomIcon' self.icon_url = image_to_url(icon_image) self.icon_size = icon_size self.icon_anchor = icon_anchor self.shadow_url = (image_to_url(shadow_image) if shadow_image is not None else None) self.shadow_size = shadow_size self.shadow_anchor = shadow_anchor self.popup_anchor = popup_anchor self._template = Template(u""" {% macro script(this, kwargs) %} var {{this.get_name()}} = L.icon({ iconUrl: '{{this.icon_url}}', {% if this.icon_size %}iconSize: [{{this.icon_size[0]}},{{this.icon_size[1]}}],{% endif %} {% if this.icon_anchor %}iconAnchor: [{{this.icon_anchor[0]}},{{this.icon_anchor[1]}}],{% endif %} {% if this.shadow_url %}shadowUrl: '{{this.shadow_url}}',{% endif %} {% if this.shadow_size %}shadowSize: [{{this.shadow_size[0]}},{{this.shadow_size[1]}}],{% endif %} {% if this.shadow_anchor %}shadowAnchor: [{{this.shadow_anchor[0]}},{{this.shadow_anchor[1]}}],{% endif %} {% if this.popup_anchor %}popupAnchor: [{{this.popup_anchor[0]}},{{this.popup_anchor[1]}}],{% endif %} }); {{this._parent.get_name()}}.setIcon({{this.get_name()}}); {% endmacro %} """) # noqa
def __init__(self, icon_image, icon_size=None, icon_anchor=None, shadow_image=None, shadow_size=None, shadow_anchor=None, popup_anchor=None): super(Icon, self).__init__() self._name = 'CustomIcon' self.icon_url = image_to_url(icon_image) self.icon_size = icon_size self.icon_anchor = icon_anchor self.shadow_url = (image_to_url(shadow_image) if shadow_image is not None else None) self.shadow_size = shadow_size self.shadow_anchor = shadow_anchor self.popup_anchor = popup_anchor
def __init__(self, image, bounds, opacity=1., attr=None, origin='upper', colormap=None, mercator_project=False, overlay=True, control=True): """ Used to load and display a single image over specific bounds of the map, implements ILayer interface. Parameters ---------- image: string, file or array-like object The data you want to draw on the map. * If string, it will be written directly in the output file. * If file, it's content will be converted as embedded in the output file. * If array-like, it will be converted to PNG base64 string and embedded in the output. bounds: list Image bounds on the map in the form [[lat_min, lon_min], [lat_max, lon_max]] opacity: float, default Leaflet's default (1.0) attr: string, default Leaflet's default ("") origin : ['upper' | 'lower'], optional, default 'upper' Place the [0,0] index of the array in the upper left or lower left corner of the axes. colormap : callable, used only for `mono` image. Function of the form [x -> (r,g,b)] or [x -> (r,g,b,a)] for transforming a mono image into RGB. It must output iterables of length 3 or 4, with values between 0 and 1. Hint : you can use colormaps from `matplotlib.cm`. mercator_project : bool, default False. Used only for array-like image. Transforms the data to project (longitude, latitude) coordinates to the Mercator projection. Beware that this will only work if `image` is an array-like object. """ super(ImageOverlay, self).__init__(overlay=overlay, control=control) self._name = 'ImageOverlay' self.overlay = overlay if mercator_project: image = mercator_transform(image, [bounds[0][0], bounds[1][0]], origin=origin) self.url = image_to_url(image, origin=origin, colormap=colormap) self.bounds = json.loads(json.dumps(bounds)) options = { 'opacity': opacity, 'attribution': attr, } self.options = json.dumps({key: val for key, val in options.items() if val}, sort_keys=True) self._template = Template(u""" {% macro script(this, kwargs) %} var {{this.get_name()}} = L.imageOverlay( '{{ this.url }}', {{ this.bounds }}, {{ this.options }} ).addTo({{this._parent.get_name()}}); {% endmacro %} """)