
    rbi;                         d dl Z d dlmZ d dlZd dlZd dlmZ d dl	m
Z
 d dlZg dZddddddddddddd	ddd
d
ddddi i i i i i i i fdZd Zd Zdddddd
d
ddi i i i fdZdS )    N)meanis_datetime64_any_dtype
LineString)locationprefer_canvasno_touch
disable_3dpng_enabledzoom_controlcrs
zoom_startlefttoppositionmin_zoommax_zoommin_latmax_latmin_lonmax_lon
max_boundsOpenStreetMapTF   z100%c                 n  OPQR d`Ofd	}	 ddl } ddl}!ddl}"ddlm}# ddlm}$ ddlmO ddlm	}% n$# t          t          f$ r t          d          w xY w	 ddl}&d}'n# t          t          f$ r d	}'Y nw xY w|                                 P| j        d
k    }(|(                                r)Pj        |(                             d           Pj        |(<   t%          Pt&          j                  rP                                PPj        dd<   d}n/Pj                            d          sP                    d          PPj        PfdPj        D                                          Pj        Pj        dk                       })t9          |)          dk    rP                    d |)D                       Pt%          Pj        t>          j                   sCtC          Pj                  sPj        j"        dk    rPj                            d          P_        |Pj#        }*$                    dd          }+|+tK          j&        |*          '                                sZtQ          |*d         |*d         g          },tQ          |*d         |*d         g          }-|-|,f}+d)                                v rd	}.nd}.nd	}.tT          D ]%}/|/|v rtW          d|/ d|/ d||/          d          &i |fd)                                D             }|'rt%          |tX                    r,	 |&j-        .                    |          }n# tV          $ r Y nw xY wt%          ||&j/                  r[|r|n|j0        }d|vr|1                    dd          |d<   d|vr|1                    dd          |d<   |2                    d !          } |"j3        da|+|||||d"|}|.r3|4                    |*d         |*d         g|*d         |*d         gg           Pj5        '                                rtm          j7        d#tp          d$           |S tT          D ]}0$                    |0d           d}1|7t>          j9        j:        ;                    |          r7t9          |          Pj<        d         k    rtW          d%          d&}2|P|2<   |2}nt%          P|         j"        t>          j=                  r|tW          d'          d}
nt>          j9        j:        >                    P|                   sVt>          j9        j:        ?                    P|                   s,t>          j9        j:        @                    P|                   s|rd}
t?          jA        P|                   }1|
rt?          jB        P|         |1          |(          }3t9          |3jC                  }4rnd)|#                                v rbtK          jD        |%jE        d ||4|3jF        *                    tK          jD        |%jE        d ||4t          |4          *                    }5nOt%          |%jH                  r\tK          jD        |%jE        d |3jF                            tK          jD        |%jE        d t          |4                              }5nt>          j9        j:        ;                              ri|4t9                    k    r|4t9                    z  dz   z  tK          jI        |3jF                  tK          jI        t          |4                    }5nQtW          d+          t                    rfd,| |         D             n|P|         K                                n|}|P|         L                                n|}|h|i }d-|vr||d-<    |$tK          jM        P|         |1                    |fi |}6tK          jD        |%jE        d ||6jN        |6jO        *                    nwtK          jP        ||d.          dd         }7 |$tK          jM        P|         |1                    d/|70          }6tK          jD        |%jE        d |d1|6jO        *                    d2vrd3d2<   d4vrdd4<   d5v r<d5         Rt          R          stW          d6          $                    d5           nd7 }8|8Rt%          tX                    r-t%          Pt&          jQ                  rPj        v r
Rfd8}9|9}:nt%          Pt&          j                  rt'          jQ        P9          P|1=|1                                r)|$                    d:d          };|;Pd;<   PjR        |1 d;f<   nPd;<   $                    d:d          QQs	Rfd<}<|<}:nQRfd=}=|=}:nRfd>}>|>}:|	rd2vrd?d2<   fd@}?|?}@nd}@|dA}|}At%          |tX                    r}|dBk    r |"jS        dai |}Ani|dCk    r |"jT        dai |}AnU|dAk    r@|1                    dDd          |dD<   |1                    dEd          |dE<    |"jU        dai |}AntW          dF          t%          Pt&          jQ                  r?PfdGPj        dHk    V                                D             }BPW                    |BI          Pt%          Pt&          jQ                  r?Pj        jX        PY                                Pt          dJ|Pfi |}t          dK|Pfi |}nd}d}PPj        A                                Pj        j5        z            j[        }C|CdL         D ][}D|DdM         D ]P}Et%          |DdM         |E         tX                    r-| \                    dNdO |DdM         |E                   |DdM         |E<   Q\ |"j]        |Cf|||A|:|@dP^                    |           |r1|d&k    s|ndQ}F|$                    dR|F          }F|
r|3jC        _                                }|5`                                }5|1                                r@|;r>|a                    |$                    dSdT                     |5a                    |;           t          ||F||5           nz|w|$                    dUd          }Gi }HdV|v r|$                    dV          |HdV<   |rStK          jD        |%jE        d ||6jN        t          |6jN                  *                    }I|GrP|$                    dWd          r|g|6jc        `                                z   }Jnd}J |!jd        je        |If|||F|JdX|H}Kn[|$                    dYdZ          }Ld[|v r	|d[         }n9|6f                    |L          }|$                    d\d	          }M|Msd] |D             }|1                                r@|;r>|a                    |$                    dSdT                     tK          ja        |I|;          }It          ||F||I           nt%          |!jd        jg                  r}Kn{ |          }NtK          jD        |%jE        d |Nt          |Njh                                      }I|Njh        d^k    r |!jd        ji        |If|||Fd_|H}Kn |!jd        je        |If|||Fd_|H}K|GrS|1                                r*|;r(t          |dQ|$                    dSdT          g|;g           |j                    |K           |S )buh'  Explore data in interactive map based on GeoPandas and folium/leaflet.js.

    Generate an interactive leaflet map based on :class:`~geopandas.GeoDataFrame`

    Parameters
    ----------
    column : str, np.array, pd.Series (default None)
        The name of the dataframe column, :class:`numpy.array`,
        or :class:`pandas.Series` to be plotted. If :class:`numpy.array` or
        :class:`pandas.Series` are used then it must have same length as dataframe.
    cmap : str, matplotlib.Colormap, branca.colormap or function (default None)
        The name of a colormap recognized by ``matplotlib``, a list-like of colors,
        :class:`matplotlib.colors.Colormap`, a :class:`branca.colormap.ColorMap` or
        function that returns a named color or hex based on the column
        value, e.g.::

            def my_colormap(value):  # scalar value defined in 'column'
                if value > 1:
                    return "green"
                return "red"

    color : str, array-like (default None)
        Named color or a list-like of colors (named or hex).
    m : folium.Map (default None)
        Existing map instance on which to draw the plot.
    tiles : str, xyzservices.TileProvider (default 'OpenStreetMap Mapnik')
        Map tileset to use. Can choose from the list supported by folium, query a
        :class:`xyzservices.TileProvider` by a name from ``xyzservices.providers``,
        pass :class:`xyzservices.TileProvider` object or pass custom XYZ URL.
        The current list of built-in providers (when ``xyzservices`` is not available):

        ``["OpenStreetMap", "CartoDB positron", “CartoDB dark_matter"]``

        You can pass a custom tileset to Folium by passing a Leaflet-style URL
        to the tiles parameter: ``http://{s}.yourtiles.com/{z}/{x}/{y}.png``.
        Be sure to check their terms and conditions and to provide attribution with
        the ``attr`` keyword.
    attr : str (default None)
        Map tile attribution; only required if passing custom tile URL.
    tooltip : bool, str, int, list (default True)
        Display GeoDataFrame attributes when hovering over the object.
        ``True`` includes all columns. ``False`` removes tooltip. Pass string or list of
        strings to specify a column(s). Integer specifies first n columns to be
        included. Defaults to ``True``.
    popup : bool, str, int, list (default False)
        Input GeoDataFrame attributes for object displayed when clicking.
        ``True`` includes all columns. ``False`` removes popup. Pass string or list of
        strings to specify a column(s). Integer specifies first n columns to be
        included. Defaults to ``False``.
    highlight : bool (default True)
        Enable highlight functionality when hovering over a geometry.
    categorical : bool (default False)
        If ``False``, ``cmap`` will reflect numerical values of the
        column being plotted. For non-numerical columns, this
        will be set to True.
    legend : bool (default True)
        Plot a legend in choropleth plots.
        Ignored if no ``column`` is given.
    scheme : str (default None)
        Name of a choropleth classification scheme (requires ``mapclassify`` >= 2.4.0).
        A :func:`mapclassify.classify` will be used
        under the hood. Supported are all schemes provided by ``mapclassify`` (e.g.
        ``'BoxPlot'``, ``'EqualInterval'``, ``'FisherJenks'``, ``'FisherJenksSampled'``,
        ``'HeadTailBreaks'``, ``'JenksCaspall'``, ``'JenksCaspallForced'``,
        ``'JenksCaspallSampled'``, ``'MaxP'``, ``'MaximumBreaks'``,
        ``'NaturalBreaks'``, ``'Quantiles'``, ``'Percentiles'``, ``'StdMean'``,
        ``'UserDefined'``). Arguments can be passed in ``classification_kwds``.
    k : int (default 5)
        Number of classes
    vmin : None or float (default None)
        Minimum value of ``cmap``. If ``None``, the minimum data value
        in the column to be plotted is used.
    vmax : None or float (default None)
        Maximum value of ``cmap``. If ``None``, the maximum data value
        in the column to be plotted is used.
    width : pixel int or percentage string (default: '100%')
        Width of the folium :class:`~folium.folium.Map`. If the argument
        m is given explicitly, width is ignored.
    height : pixel int or percentage string (default: '100%')
        Height of the folium :class:`~folium.folium.Map`. If the argument
        m is given explicitly, height is ignored.
    categories : list-like
        Ordered list-like object of categories to be used for categorical plot.
    classification_kwds : dict (default None)
        Keyword arguments to pass to mapclassify
    control_scale : bool, (default True)
        Whether to add a control scale on the map.
    marker_type : str, folium.Circle, folium.CircleMarker, folium.Marker (default None)
        Allowed string options are ('marker', 'circle', 'circle_marker'). Defaults to
        folium.CircleMarker.
    marker_kwds: dict (default {})
        Additional keywords to be passed to the selected ``marker_type``, e.g.:

        radius : float (default 2 for ``circle_marker`` and 50 for ``circle``))
            Radius of the circle, in meters (for ``circle``) or pixels
            (for ``circle_marker``).
        fill : bool (default True)
            Whether to fill the ``circle`` or ``circle_marker`` with color.
        icon : folium.map.Icon
            the :class:`folium.map.Icon` object to use to render the marker.
        draggable : bool (default False)
            Set to True to be able to drag the marker around the map.

    style_kwds : dict (default {})
        Additional style to be passed to folium ``style_function``:

        stroke : bool (default True)
            Whether to draw stroke along the path. Set it to ``False`` to
            disable borders on polygons or circles.
        color : str
            Stroke color
        weight : int
            Stroke width in pixels
        opacity : float (default 1.0)
            Stroke opacity
        fill : boolean (default True)
            Whether to fill the path with color. Set it to ``False`` to
            disable filling on polygons or circles.
        fillColor : str
            Fill color. Defaults to the value of the color option
        fillOpacity : float (default 0.5)
            Fill opacity.
        style_function : callable
            Function mapping a GeoJson Feature to a style ``dict``.

            * Style properties :func:`folium.vector_layers.path_options`
            * GeoJson features :class:`GeoDataFrame.__geo_interface__`

            e.g.::

                lambda x: {"color":"red" if x["properties"]["gdp_md_est"]<10**6
                                             else "blue"}

        Plus all supported by :func:`folium.vector_layers.path_options`. See the
        documentation of :class:`folium.features.GeoJson` for details.

    highlight_kwds : dict (default {})
        Style to be passed to folium highlight_function. Uses the same keywords
        as ``style_kwds``. When empty, defaults to ``{"fillOpacity": 0.75}``.
    missing_kwds : dict (default {})
        Additional style for missing values:

        color : str
            Color of missing values. Defaults to ``None``, which uses Folium's default.
        label : str (default "NaN")
            Legend entry for missing values.
    tooltip_kwds : dict (default {})
        Additional keywords to be passed to :class:`folium.features.GeoJsonTooltip`,
        e.g. ``aliases``, ``labels``, or ``sticky``.
    popup_kwds : dict (default {})
        Additional keywords to be passed to :class:`folium.features.GeoJsonPopup`,
        e.g. ``aliases`` or ``labels``.
    legend_kwds : dict (default {})
        Additional keywords to be passed to the legend.

        Currently supported customisation:

        caption : string
            Custom caption of the legend. Defaults to the column name.

        Additional accepted keywords when ``scheme`` is specified:

        colorbar : bool (default True)
            An option to control the style of the legend. If True, continuous
            colorbar will be used. If False, categorical legend will be used for bins.
        scale : bool (default True)
            Scale bins along the colorbar axis according to the bin edges (True)
            or use the equal length for each bin (False)
        fmt : string (default "{:.2f}")
            A formatting specification for the bin edges of the classes in the
            legend. For example, to have no decimals: ``{"fmt": "{:.0f}"}``. Applies
            if ``colorbar=False``.
        labels : list-like
            A list of legend labels to override the auto-generated labels.
            Needs to have the same number of elements as the number of
            classes (`k`). Applies if ``colorbar=False``.
        interval : boolean (default False)
            An option to control brackets from mapclassify legend.
            If True, open/closed interval brackets are shown in the legend.
            Applies if ``colorbar=False``.
        max_labels : int, default 10
            Maximum number of colorbar tick labels (requires branca>=0.5.0)
    map_kwds : dict (default {})
        Additional keywords to be passed to folium :class:`~folium.folium.Map`,
        e.g. ``dragging``, or ``scrollWheelZoom``.


    **kwargs : dict
        Additional options to be passed on to the folium object.

    Returns
    -------
    m : folium.folium.Map
        folium :class:`~folium.folium.Map` instance

    Examples
    --------
    >>> import geodatasets
    >>> df = geopandas.read_file(
    ...     geodatasets.get_path("geoda.chicago_health")
    ... )
    >>> df.head(2)  # doctest: +SKIP
       ComAreaID  ...                                           geometry
    0         35  ...  POLYGON ((-87.60914 41.84469, -87.60915 41.844...
    1         36  ...  POLYGON ((-87.59215 41.81693, -87.59231 41.816...

    [2 rows x 87 columns]

    >>> df.explore("Pop2012", cmap="Blues")  # doctest: +SKIP
    Nc                     |s                     |           S                       |                               |          |          S )z`Return the color map specified.

        Helper function for MPL deprecation - GH#2596.
        )get_cmap	resampled)_cmap
n_resampleidxcms      a/var/www/html/mdtn/previsions/meteo_cartes/venv/lib/python3.11/site-packages/geopandas/explore.py_colormap_helperz"_explore.<locals>._colormap_helper  sJ    
  	A;;u%%%;2;;u%%//
;;C@@@    r   )classify)	colormaps)colorszThe 'folium>=0.12', 'matplotlib' and 'mapclassify' packages are required for 'explore()'. You can install them using 'conda install -c conda-forge "folium>=0.12" matplotlib mapclassify' or 'pip install "folium>=0.12" matplotlib mapclassify'.TF
LinearRingc                      t          |           S Nr   )gs    r$   <lambda>z_explore.<locals>.<lambda>@  s    jmm r&   Simpler   i  c                 :    g | ]}t          |                   S  r   ).0cgdfs     r$   
<listcomp>z_explore.<locals>.<listcomp>M  s&    >>>Q	 Q	(	(>>>r&   objectc                     i | ]}|d S )stringr1   r2   r3   s     r$   
<dictcomp>z_explore.<locals>.<dictcomp>Q  s    GGG!!XGGGr&   r8   r            r   'z.' cannot be specified in 'map_kwds'. Use the '=z' argument instead.c                 4    i | ]}|t           v ||         S r1   )_MAP_KWARGS)r2   ikwargss     r$   r:   z_explore.<locals>.<dictcomp>q  s)    GGGa;6F6Fq&)6F6F6Fr&   r   r      z{r})scale_factor)r   control_scaletilesattrwidthheightzeThe GeoSeries you are attempting to plot is composed of empty geometries. Nothing has been displayed.)
stacklevelz@The GeoDataFrame and given column have different number of rows.__plottable_columnz=Cannot specify 'categories' when column has categorical dtype)
categoriestab20)r!   r"   zo'cmap' is invalid. For categorical plots, pass either valid named matplotlib colormap or a list-like of colors.c                 &    g | ]} |          S r1   r1   )r2   xcmaps     r$   r5   z_explore.<locals>.<listcomp>  s!    111TT!WW111r&   ki  UserDefined)bins   fillOpacityg      ?weightstyle_functionz%'style_function' has to be a callablec                     i S r,   r1   rP   s    r$   	_no_stylez_explore.<locals>._no_style  s    Ir&   c                 F    d| d                  i}i | |           S )N	fillColor
propertiesr1   )rP   
base_stylecolor
style_kwdsstyle_kwds_functions     r$   _style_colorz_explore.<locals>._style_color  sE    <!7 
 ))!,, r&   )geometryr`   __folium_colorc                 `    | d         d         | d         d         d}i | |           S Nr^   re   )r]   r`   r1   )rP   r_   ra   rb   s     r$   _style_columnz_explore.<locals>._style_column3  sX    %&|_5E%F!"<1A!B" " %"J
$--a00 r&   c                 H    | d         d         d}i | |           S rg   r1   )rP   r_   stroke_colorra   rb   s     r$   _style_strokez_explore.<locals>._style_strokeA  sN    %&|_5E%F!-" " %"J
$--a00 r&   c                 "    i  |           S r,   r1   )rP   ra   rb   s    r$   _style_defaultz _explore.<locals>._style_defaultO  s    ;j;$7$7$:$:;;r&   g      ?c                     i S r,   r1   )rP   highlight_kwdss    r$   _style_highlightz"_explore.<locals>._style_highlightX  s    %n%%r&   circle_markermarkercircleradiusfillzKOnly 'marker', 'circle', and 'circle_marker' are supported as marker valuesc                 >    g | ]\  }}|r|j         j        k    |S r1   )rd   name)r2   rw   valr4   s      r$   r5   z_explore.<locals>.<listcomp>u  sA     
 
 
c
 s|000 000r&   rd   )columnstooltippopupfeaturesr^   z\{{2,}c                 8    d|                      d          z   dz   S )Nz	{% raw %}r   z{% endraw %})grouprZ   s    r$   r.   z_explore.<locals>.<lambda>  s    kAGGAJJ6G r&   )rz   r{   rr   rX   highlight_function captionlabelNaNcolorbar
max_labelsscale)vminvmaxr   indexfmtz{:.2f}labelsintervalc                 "    g | ]}|d d         S )r<   r1   r9   s     r$   r5   z_explore.<locals>.<listcomp>  s     )F)F)Fa!AbD')F)F)Fr&      )r   r   r   )NNr1   )krebrancafoliummatplotlib.pyplotpyplotmapclassifyr'   
matplotlibr(   r)   ImportErrorModuleNotFoundErrorxyzservicescopy	geom_typeanyrd   apply
isinstance	geopandas	GeoSeriesto_framer   equalsto_crsry   uniondtypeslenastyper   pd
MultiIndexr   dtypetotal_boundspopnpisnanallr   keysrA   
ValueErrorstr	providers
query_nameTileProviderhtml_attributionget	build_urlMap
fit_boundsis_emptywarningswarnUserWarningapitypesis_list_likeshapeCategoricalDtypeis_object_dtypeis_bool_dtypeis_string_dtypeisnaCategoricalrM   apply_along_axisto_hexcodesrangeColormaptakecallableminmaxasarrayrR   yblinspaceGeoDataFramelocMarkerCircleCircleMarkeritemsdroprw   reset_index_tooltip_popup__geo_interface__subGeoJsonadd_toto_listtolistappend_categorical_legendrT   colormapStepColormapget_legend_classesColorMapNLinearColormap	add_child)SdfcolumnrQ   r`   mrG   rH   rz   r{   	highlightcategoricallegendschemerR   r   r   rI   rJ   rM   classification_kwdsrF   marker_typemarker_kwdsra   ro   missing_kwdstooltip_kwds
popup_kwdslegend_kwdsmap_kwdsrC   r%   r   bcr   pltr'   r)   r   HAS_XYZSERVICES
rings_maskjson_not_supported_colsboundsr   rP   yfitrB   map_kwdnan_idxcolumn_namecatr   legend_colorsbinningrT   r[   rc   rX   	nan_colorrh   rk   rm   rp   r   rr   non_active_geomsfeature_collectionfeaturepropr   cbarcolormap_kwds	cb_colorsr   r   r   show_intervalmp_cmapr#   r4   rj   rb   sS     ``                   ``     `                                                @@@@r$   _explorer  "   s   hA A A A A A
			''''''((((((......%%%%%%%,- 
 
 
H
 
 	

 ,-        ''))C -J~~ 
#&<
#;#A#A##$
 $
Z  #y*++ llnn
w uW^^D!! jj "k>>>>#+>>>eCK
h./00  "##a''jjGG/FGGGHHci// /	**//2y(/J/JI$$X..	 	y!::j$//BHV$4$4$8$8$:$:fQi+,,AfQi+,,A1vHv{{}},,C  	 	AH}} E E E !E E$,QKE E E   


GGGGV[[]]GGG

  	<%%% '1<<UCCEE!   D %!9:: <#?tt)?X--+099Z+C+CHZ(X--+099Z+D+DHZ(U;;FJ 
'
 
 
 
  	KLL6!9fQi06!9fQi2HIJJJ
| H		
 	
 	
 	
  " "

7D!!!!G6<$$V,, 	6{{cil** V   3#)K $F)2+>?? 	% S   KKFL((V55	v|))#f+66	 v|++CK88	 		 K'#f+&& D	.VgX!6:NNNCCN##A,44WD s}}&&+M$$TaSYGGG 
 !# 3M1&6&6tuUVxx&X&X&X! !
 D&/22 +FM1dd39ooNN " 3FM1dd5QR88nn U U **400 
s4yy==1D		>A#56Dci00 "eAhh 7 7 !J  
 d^^ "	1111bj111EE )-3v;??$$$$D(,3v;??$$$$D !&.*,'111/0',"(Js6{G8455v AT  +M$$TgiWZPPP  {4s33ABB7"(Js6{G8455}4   +M$$TcwzJJJ  J&&$'
=!z!! 
8:%%()9:+,, 	FDEEE'((((	 	 	 ( uc""9	/3	 6779	/ $$       *NN#y233 ;,c:::"w{{}}"(,,Wd;;	(1$%6;"2233(-$%%>>'488L /	 	 	 	 	 	 "/	 	 	 	 	 	 	 "/	< 	< 	< 	< 	< 	< ( 	"..,0N=)	& 	& 	& 	& 	& .! %F+s## ("""V]11[11FFH$$"V]11[11FFO++$/OOHa$@$@K!"-//&$"?"?K(V(77;77FF-   #y-.. 1
 
 
 
!jJ6==??
 
 

 hh/h00 #y-.. 	9>%//##C GSIILIIwsAAjAA
,



 5
56  &j1  L) 	 	D',/5s;; .0ffGGL)$// /%d+	 FN%-    fQiii V& &*> > >&&B//)W55 R	&//11J)0022M{{}} 0 0!!,"2"27E"B"BCCC$$Y///7JFFFF??:t44DM{**.9ool.K.Kl+ =/M$$TgiU79EUEUVVV 	
  K"w55 %!%)<)<)>)> > $7r{7! !! '#    (   HH &//%::C;..%0%:

%,%?%?%D%D
(3
E(J(J, G)F)F:)F)F)FJ{{}} D D")),*:*:7E*J*JKKK$&Ii$C$C	'7J	JJJJ dBK$899 #HH..t44G " 3q''%	2B2B*C*C! !I
 y2~~#=2;#=%$!%!%$+	$ $
 ,$ $ $<2;#;%$!%!%$+	$ $
 ,$ $  &;;== Y '2 0 0% @ @AI;   H%%%Hs-   $6 !AA" "A87A8)M 
MMc                 H   ddl }|du s||dk    rdS |du r7|j                            |j        j                                                  }nlt          |t                    r?|j                            |j        j                                                  d|         }nt          |t                    r|g}dD ]}||v r|	                    |           t          t          t          |                    }| dk    r |j        |fi |S | dk    r |j        |fi |S dS )zGet tooltip or popup.r   NFT)rL   re   rz   r{   )r   ry   r   rd   rw   r   r   intr   removelistmapGeoJsonTooltipGeoJsonPopup)typefieldsr4   kwdsr   fields         r$   r   r     sI   MMM &.FaKKtT>>[%%cl&788@@BBFF$$ 	[%%cl&788@@BB7F7KFF$$ 	XF9 ! !F??MM%    #c6""##Fy$v$V44t444	"v"622T222 
r&   c                    d}ddl }|j                                        }|j                            |          |_        |                                                     |           d| d| d}t          ||          D ]\  }}	|d|	 d| d	z  }|d
z  }|j                            |d          }|                                 j	                            |           dS )a;  Add categorical legend to a map.

    The implementation is using the code originally written by Michel Metran
    (@michelmetran) and released on GitHub
    (https://github.com/michelmetran/package_folium) under MIT license.

    Copyright (c) 2020 Michel Metran

    Parameters
    ----------
    m : folium.Map
        Existing map instance on which to draw the plot
    title : str
        title of the legend (e.g. column name)
    categories : list-like
        list of categories
    colors : list-like
        list of colors (in the same order as categories)
    aI  
    {% macro header(this, kwargs) %}
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <script>$( function() {
        $( ".maplegend" ).draggable({
            start: function (event, ui) {
                $(this).css({
                    right: "auto",
                    top: "auto",
                    bottom: "auto"
                });
            }
        });
    });
    </script>
    <style type='text/css'>
      .maplegend {
        position: absolute;
        z-index:9999;
        background-color: rgba(255, 255, 255, .8);
        border-radius: 5px;
        box-shadow: 0 0 15px rgba(0,0,0,0.2);
        padding: 10px;
        font: 12px/14px Arial, Helvetica, sans-serif;
        right: 10px;
        bottom: 20px;
      }
      .maplegend .legend-title {
        text-align: left;
        margin-bottom: 5px;
        font-weight: bold;
        }
      .maplegend .legend-scale ul {
        margin: 0;
        margin-bottom: 0px;
        padding: 0;
        float: left;
        list-style: none;
        }
      .maplegend .legend-scale ul li {
        list-style: none;
        margin-left: 0;
        line-height: 16px;
        margin-bottom: 2px;
        }
      .maplegend ul.legend-labels li span {
        display: block;
        float: left;
        height: 14px;
        width: 14px;
        margin-right: 5px;
        margin-left: 0;
        border: 0px solid #ccc;
        }
      .maplegend .legend-source {
        color: #777;
        clear: both;
        }
      .maplegend a {
        color: #777;
        }
    </style>
    {% endmacro %}
    r   Nz
    <div id='maplegend z7' class='maplegend'>
        <div class='legend-title'>zP</div>
        <div class='legend-scale'>
            <ul class='legend-labels'>z-
                <li><span style='background:z	'></span>z</li>z1
            </ul>
        </div>
    </div>
    r   )
r   elementMacroElementTemplate	_templateget_rootr   zipElementhtml)
r   titlerM   r)   headr   macrobodyr   r`   s
             r$   r   r     s-   *?D@  J##%%Ej))$//EOJJLL5!!!** *#(* * *D J// L Lu L-2L L=BL L L 	L 	  D :dH--DJJLL%%%%%r&   c                 8    t          | f|||||||||	|
|||d|S )u  Interactive map based on GeoPandas and folium/leaflet.js.

    Generate an interactive leaflet map based on :class:`~geopandas.GeoSeries`

    Parameters
    ----------
    color : str, array-like (default None)
        Named color or a list-like of colors (named or hex).
    m : folium.Map (default None)
        Existing map instance on which to draw the plot.
    tiles : str, xyzservices.TileProvider (default 'OpenStreetMap Mapnik')
        Map tileset to use. Can choose from the list supported by folium, query a
        :class:`xyzservices.TileProvider` by a name from ``xyzservices.providers``,
        pass :class:`xyzservices.TileProvider` object or pass custom XYZ URL.
        The current list of built-in providers (when ``xyzservices`` is not available):

        ``["OpenStreetMap", "CartoDB positron", “CartoDB dark_matter"]``

        You can pass a custom tileset to Folium by passing a Leaflet-style URL
        to the tiles parameter: ``http://{s}.yourtiles.com/{z}/{x}/{y}.png``.
        Be sure to check their terms and conditions and to provide attribution with
        the ``attr`` keyword.
    attr : str (default None)
        Map tile attribution; only required if passing custom tile URL.
    highlight : bool (default True)
        Enable highlight functionality when hovering over a geometry.
    width : pixel int or percentage string (default: '100%')
        Width of the folium :class:`~folium.folium.Map`. If the argument
        m is given explicitly, width is ignored.
    height : pixel int or percentage string (default: '100%')
        Height of the folium :class:`~folium.folium.Map`. If the argument
        m is given explicitly, height is ignored.
    control_scale : bool, (default True)
        Whether to add a control scale on the map.
    marker_type : str, folium.Circle, folium.CircleMarker, folium.Marker (default None)
        Allowed string options are ('marker', 'circle', 'circle_marker'). Defaults to
        folium.Marker.
    marker_kwds: dict (default {})
        Additional keywords to be passed to the selected ``marker_type``, e.g.:

        radius : float
            Radius of the circle, in meters (for ``'circle'``) or pixels
            (for ``circle_marker``).
        icon : folium.map.Icon
            the :class:`folium.map.Icon` object to use to render the marker.
        draggable : bool (default False)
            Set to True to be able to drag the marker around the map.

    style_kwds : dict (default {})
        Additional style to be passed to folium ``style_function``:

        stroke : bool (default True)
            Whether to draw stroke along the path. Set it to ``False`` to
            disable borders on polygons or circles.
        color : str
            Stroke color
        weight : int
            Stroke width in pixels
        opacity : float (default 1.0)
            Stroke opacity
        fill : boolean (default True)
            Whether to fill the path with color. Set it to ``False`` to
            disable filling on polygons or circles.
        fillColor : str
            Fill color. Defaults to the value of the color option
        fillOpacity : float (default 0.5)
            Fill opacity.
        style_function : callable
            Function mapping a GeoJson Feature to a style ``dict``.

            * Style properties :func:`folium.vector_layers.path_options`
            * GeoJson features :class:`GeoSeries.__geo_interface__`

            e.g.::

                lambda x: {"color":"red" if x["properties"]["gdp_md_est"]<10**6
                                             else "blue"}


        Plus all supported by :func:`folium.vector_layers.path_options`. See the
        documentation of :class:`folium.features.GeoJson` for details.

    highlight_kwds : dict (default {})
        Style to be passed to folium highlight_function. Uses the same keywords
        as ``style_kwds``. When empty, defaults to ``{"fillOpacity": 0.75}``.
    map_kwds : dict (default {})
        Additional keywords to be passed to folium :class:`~folium.folium.Map`,
        e.g. ``dragging``, or ``scrollWheelZoom``.

    **kwargs : dict
        Additional options to be passed on to the folium.

    Returns
    -------
    m : folium.folium.Map
        folium :class:`~folium.folium.Map` instance

    )r`   r   rG   rH   r   rI   rJ   rF   r   r   ra   ro   r   )r  )sr`   r   rG   rH   r   rI   rJ   rF   r   r   ra   ro   r   rC   s                  r$   _explore_geoseriesr/    sU    f 	
#%    r&   )r   
statisticsr   numpyr   pandasr   pandas.api.typesr   shapely.geometryr   r   rA   r  r   r   r/  r1   r&   r$   <module>r5     sZ                  4 4 4 4 4 4 ' ' ' ' ' '      0 	


	
		
=V V V Vr3 3 36o& o& o&h 

	
C C C C C Cr&   