a
    ~b                     @   sh   d dl mZmZmZ d dlZd dlmZmZm	Z	 ddl
mZ ddlmZ ddlmZ G d	d
 d
eZdS )    )absolute_importdivisionunicode_literalsN)WMTSTileSourceBBoxTileSourceQUADKEYTileSource   )SkipRendering)_ATTRIBUTIONS   )ElementPlotc                       sD   e Zd Zg dZdZd fdd	Zdd Zddd	Zd
d Z  Z	S )TilePlot)alphaZrender_parentslevelZ	smoothingmin_zoommax_zoomNcombinedc           
         sX   t t| |||}| jsTtdd |D rT|dv rTd\}}d\}}||||f}	|	S |S )Nc                 s   s"   | ]}|d u pt | V  qd S N)npZisfinite).0e r   =lib/python3.9/site-packages/holoviews/plotting/bokeh/tiles.py	<genexpr>       z'TilePlot.get_extents.<locals>.<genexpr>)r   data)g|Es|EsA)g|Esr   )superr   get_extentsZoverlaidall)
selfelementrangesZ
range_typeZextentsZx0Zx1Zy0Zy1Zglobal_extent	__class__r   r   r      s    zTilePlot.get_extentsc           	         sF  t  jttfstd j   jd u r2tdnbt  jtrDt}nPd jv rTt}n@t fdddD rpt	}n$t fdddD rt}ntd	t  jtr҈ jj
d
d jdd jdd jjd}n\d ji}dD ]}||v r|| ||< qt D ]*\}}t fdd|D r||d< qi d|f i |i|fS )NzZWMTS element data must be a URL string or xyzservices.TileProvider, bokeh cannot render %rz6Tile source URL may not be None with the bokeh backendz{Q}c                 3   s   | ]}| j v V  qd S r   r   r   kwr!   r   r   r   '   r   z$TilePlot.get_data.<locals>.<genexpr>)z{XMIN}z{XMAX}z{YMIN}z{YMAX}c                 3   s   | ]}| j v V  qd S r   r%   r&   r(   r   r   r   )   r   )z{X}z{Y}z{Z}zuTile source URL format not recognized. Must contain {X}/{Y}/{Z}, {XMIN}/{XMAX}/{YMIN}/{YMAX} or {Q} template strings.z@2x)Zscale_factorr   r   r      )urlr   r   attributionr*   )r   r   c                 3   s   | ]}| j v V  qd S r   r%   )r   kr(   r   r   r   ;   r   r+   tile_source)
isinstancer   strdictr	   
ValueErrorr   r   r   r   Z	build_urlgetZhtml_attributionr
   items)	r    r!   r"   Zstyler-   paramsZzoomkeyr+   r   r(   r   get_data   s:    



zTilePlot.get_datac                    sT   |d j  _  jf i  fdd| D  jf i fdd| D  d S )Nr-   c                    s"   i | ]\}}|   v r||qS r   
propertiesr   r,   v)glyphr   r   
<dictcomp>A   s   z*TilePlot._update_glyph.<locals>.<dictcomp>c                    s"   i | ]\}}|   v r||qS r   r7   r9   )rendererr   r   r<   C   s   )r*   updater3   )r    r=   r8   mappingr;   sourcer   r   )r;   r=   r   _update_glyph?   s    "zTilePlot._update_glyphc                 C   s8   |d }| dd}|j||d}|dd|_||fS )z/
        Returns a Bokeh glyph object.
        r-   r   r;   )r   r   r   )popZadd_tiler2   r   )r    Zplotr?   r8   r-   r   r=   r   r   r   _init_glyphF   s
    zTilePlot._init_glyph)r   )NN)
__name__
__module____qualname__Z
style_optsZselection_displayr   r6   rA   rC   __classcell__r   r   r#   r   r      s   
#
r   )Z
__future__r   r   r   Znumpyr   Zbokeh.modelsr   r   r   Zcore.optionsr	   Zelement.tilesr
   r!   r   r   r   r   r   r   <module>   s   