U
    ˜ARd   ã                   @   s„  U d Z ddlZddlZddlmZmZmZmZmZm	Z	m
Z
 ddlZddlmZmZ ddlm  mZ ddlmZ ddlmZ ddlmZ ddlmZ er°dd	lmZ dd
lmZ e	ej dee eeef df Z!ee"d< e#ej$ƒZ%eee&ef  e"d< ddddgZ'ee"d< dZ(ee"d< ddddddddddddd d!d"d#d$d%d&d'd(gZ)ee"d)< G d*d+„ d+ƒZ*e+e,d,œd-d.„Z-e!ee, e&d/œd0d1„Z.dS )2z+A wrapper for simple PyDeck scatter charts.é    N)ÚTYPE_CHECKINGÚAnyÚDictÚIterableÚOptionalÚUnionÚcast)ÚFinalÚ	TypeAlias)Ú	type_util)ÚStreamlitAPIException)ÚDeckGlJsonChart)Úgather_metrics)ÚStyler)ÚDeltaGeneratorr   ÚDataÚ_DEFAULT_MAPéÈ   é   é    Ú_DEFAULT_COLORé   Ú_DEFAULT_ZOOM_LEVELih  é´   éZ   é-   g     €6@g     €&@g     €@g/Ý$@gåÐ"Ûù~ö?gåÐ"Ûù~æ?gºI+‡Ö?gºI+‡Æ?gºI+‡¶?gºI+‡¦?gºI+‡–?gºI+‡†?g{®Gázt?gú~j¼t“h?gü©ñÒMbP?gü©ñÒMb@?gü©ñÒMb0?Ú_ZOOM_LEVELSc                   @   s@   e Zd Zedƒdeee eddœdd„ƒZe	ddœd	d
„ƒZ
dS )ÚMapMixinÚmapNTr   )ÚdataÚzoomÚuse_container_widthÚreturnc                 C   s&   t ƒ }t||ƒ|_||_| j d|¡S )aÏ  Display a map with points on it.

        This is a wrapper around ``st.pydeck_chart`` to quickly create
        scatterplot charts on top of a map, with auto-centering and auto-zoom.

        When using this command, Mapbox provides the map tiles to render map
        content. Note that Mapbox is a third-party product, the use of which is
        governed by Mapbox's Terms of Use.

        Mapbox requires users to register and provide a token before users can
        request map tiles. Currently, Streamlit provides this token for you, but
        this could change at any time. We strongly recommend all users create and
        use their own personal Mapbox token to avoid any disruptions to their
        experience. You can do this with the ``mapbox.token`` config option.

        To get a token for yourself, create an account at https://mapbox.com.
        For more info on how to set config options, see
        https://docs.streamlit.io/library/advanced-features/configuration

        Parameters
        ----------
        data : pandas.DataFrame, pandas.Styler, pyarrow.Table, numpy.ndarray, pyspark.sql.DataFrame, snowflake.snowpark.dataframe.DataFrame, snowflake.snowpark.table.Table, Iterable, dict, or None
            The data to be plotted. Must have two columns:

            - latitude called 'lat', 'latitude', 'LAT', 'LATITUDE'
            - longitude called 'lon', 'longitude', 'LON', 'LONGITUDE'.

        zoom : int
            Zoom level as specified in
            https://wiki.openstreetmap.org/wiki/Zoom_levels
        use_container_width: bool

        Example
        -------
        >>> import streamlit as st
        >>> import pandas as pd
        >>> import numpy as np
        >>>
        >>> df = pd.DataFrame(
        ...     np.random.randn(1000, 2) / [50, 50] + [37.76, -122.4],
        ...     columns=['lat', 'lon'])
        >>>
        >>> st.map(df)

        .. output::
           https://doc-map.streamlitapp.com/
           height: 650px

        Údeck_gl_json_chart)ÚDeckGlJsonChartProtoÚto_deckgl_jsonÚjsonr!   ÚdgZ_enqueue)Úselfr   r    r!   Z	map_proto© r)   ú:/tmp/pip-unpacked-wheel-b9et7o5g/streamlit/elements/map.pyr   L   s    8zMapMixin.map)r"   c                 C   s
   t d| ƒS )zGet our DeltaGenerator.r   )r   )r(   r)   r)   r*   r'   ‰   s    zMapMixin.dg)NNT)Ú__name__Ú
__module__Ú__qualname__r   r   r   ÚintÚboolr   Úpropertyr'   r)   r)   r)   r*   r   K   s      üû<r   )Údistancer"   c                 C   sF   t ttƒd ƒD ]0}t|d  |   k r4t| krn q|  S qtS )a9  Get the zoom level for a given distance in degrees.

    See https://wiki.openstreetmap.org/wiki/Zoom_levels for reference.

    Parameters
    ----------
    distance : float
        How many degrees of longitude should fit in the map.

    Returns
    -------
    int
        The zoom level, from 0 to 20.

    é   )ÚrangeÚlenr   r   )r1   Úir)   r)   r*   Ú_get_zoom_level   s    $
r6   )r   r    r"   c                    sH  ˆ d krt  t¡S tˆ dƒr,ˆ jr,t  t¡S t ˆ ¡‰ d tt	t
ˆ jƒƒ¡}ddddh}t‡ fdd„|D ƒd ƒ}|sœd tt	t|ƒƒ¡}td	|› d
|› ƒ‚ddddh}t‡ fdd„|D ƒd ƒ}|sìd tt	t|ƒƒ¡}td|› d
|› ƒ‚ˆ |  ¡ j ¡ sˆ |  ¡ j ¡ rtdƒ‚ˆ |  ¡ }ˆ |  ¡ }	ˆ |  ¡ }
ˆ |  ¡ }|	| d }||
 d }t||
 ƒ}t|	| ƒ}|d kr¢||kr–|}n|}t|ƒ}ˆ j |¡d }ˆ j |¡d }g }ˆ  ¡ D ]&}| t|| ƒt|| ƒdœ¡ qÎt t¡}||d d< ||d d< ||d d< dddddt|dœg|d< t  |¡S )NÚemptyz, ÚlatZlatitudeZLATZLATITUDEc                 3   s   | ]}|ˆ kr|V  qd S ©Nr)   ©Ú.0Úd©r   r)   r*   Ú	<genexpr>µ   s      z!to_deckgl_json.<locals>.<genexpr>z/Map data must contain a latitude column named: z. Existing columns: ÚlonZ	longitudeZLONZ	LONGITUDEc                 3   s   | ]}|ˆ kr|V  qd S r9   r)   r:   r=   r)   r*   r>   Á   s      z0Map data must contain a longitude column named: z,Latitude and longitude data must be numeric.g       @r2   )r?   r8   ZinitialViewStater    ZScatterplotLayerz@@=[lon, lat]é
   é   )z@@typeÚgetPositionZ	getRadiusZradiusScaleZradiusMinPixelsZgetFillColorr   Zlayers)r&   Údumpsr   Úhasattrr7   r   Zconvert_anything_to_dfÚjoinr   ÚreprÚlistÚcolumnsÚnextÚsortedr   ZisnullÚvaluesÚanyÚminÚmaxÚabsr6   Zget_locZ
itertuplesÚappendÚfloatÚcopyÚdeepcopyr   )r   r    Zformmated_column_namesZallowed_lat_columnsr8   Zformatted_allowed_column_nameZallowed_lon_columnsr?   Zmin_latZmax_latZmin_lonZmax_lonZ
center_latZ
center_lonZ	range_lonZ	range_latZlongitude_distanceZlon_col_indexZlat_col_indexZ
final_dataÚrowÚdefaultr)   r=   r*   r%   §   sx    


ÿÿÿÿ(

ÿ
ùÿr%   )/Ú__doc__rR   r&   Útypingr   r   r   r   r   r   r   ZpandasÚpdZtyping_extensionsr	   r
   Z%streamlit.elements.deck_gl_json_chartÚelementsr#   Z	streamlitr   Zstreamlit.errorsr   Z#streamlit.proto.DeckGlJsonChart_pb2r   r$   Zstreamlit.runtime.metrics_utilr   Zpandas.io.formats.styler   Zstreamlit.delta_generatorr   Z	DataFramer   Ú__annotations__ÚdictZ	EMPTY_MAPr   Ústrr   r   r   r   rQ   r.   r6   r%   r)   r)   r)   r*   Ú<module>   sb   $
üÿ	ëD