o
    PfD                     @   s   d Z ddlZddlZddlmZmZmZmZmZ ddl	m
Z
mZ ddlmZ ddlmZ ddlmZmZmZ ddlmZ dd	lmZmZmZmZmZmZmZ g d
Zg dZG dd de
Z G dd deeZ!dS )z>
Make beautiful, interactive maps with Python and Leaflet.js

    N)AnyListOptionalSequenceUnion)ElementFigure)Template)
JSCSSMixin)Evented	FitBoundsLayer)	TileLayer)
TypeBoundsTypeJsonValue_parse_sizeparse_font_sizeparse_optionstemp_html_filepathvalidate_location))leafletz:https://cdn.jsdelivr.net/npm/leaflet@1.9.3/dist/leaflet.js)jqueryz+https://code.jquery.com/jquery-3.7.1.min.js)	bootstrapzLhttps://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js)awesome_markersz_https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.js))leaflet_cssz;https://cdn.jsdelivr.net/npm/leaflet@1.9.3/dist/leaflet.css)bootstrap_csszGhttps://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css)glyphicons_csszLhttps://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css)awesome_markers_font_csszPhttps://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.2.0/css/all.min.css)awesome_markers_cssz`https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.css)awesome_rotate_csszghttps://cdn.jsdelivr.net/gh/python-visualization/folium/folium/templates/leaflet.awesome.rotate.min.cssc                       s&   e Zd ZedZd fdd	Z  ZS )GlobalSwitchesz
        <script>
            L_NO_TOUCH = {{ this.no_touch |tojson}};
            L_DISABLE_3D = {{ this.disable_3d|tojson }};
        </script>
    Fc                    s    t    d| _|| _|| _d S )Nr    )super__init___nameno_touch
disable_3d)selfr$   r%   	__class__ Y/home/deployuser/azure_apps/autowriter/venv/lib/python3.10/site-packages/folium/folium.pyr"   K   s   

zGlobalSwitches.__init__)FF)__name__
__module____qualname__r	   	_templater"   __classcell__r)   r)   r'   r*   r    A   s
    	r    c                3       s  e Zd ZdZedZeZeZ															
											dCde
ee  deeef deeef deeef deeef dedeeedf de
e de
e de
e dededededed ed!ed"ed#ed$ed%ed&ed'eeef d(ed)ef2 fd*d+Zd,efd-d.ZdDd0ed1ed,efd2d3Zd,e
e fd4d5ZdE fd6d7ZdEd8d9Z				dFd:ed;e
ee  d<e
ee  d=e
ee  de
e d,dfd>d?Zd@ed,dfdAdBZ  ZS )GMapae  Create a Map with Folium and Leaflet.js

    Generate a base map of given width and height with either default
    tilesets or a custom tileset URL. Folium has built-in all tilesets
    available in the ``xyzservices`` package. For example, you can pass
    any of the following to the "tiles" keyword:

        - "OpenStreetMap"
        - "CartoDB Positron"
        - "CartoDB Voyager"

    Explore more provider names available in ``xyzservices`` here:
    https://leaflet-extras.github.io/leaflet-providers/preview/.

    You can also pass a custom tileset by passing a
    :class:`xyzservices.TileProvider` or a Leaflet-style
    URL to the tiles parameter: ``https://{s}.yourtiles.com/{z}/{x}/{y}.png``.

    Parameters
    ----------
    location: tuple or list, default None
        Latitude and Longitude of Map (Northing, Easting).
    width: pixel int or percentage string (default: '100%')
        Width of the map.
    height: pixel int or percentage string (default: '100%')
        Height of the map.
    tiles: str or TileLayer or :class:`xyzservices.TileProvider`, default 'OpenStreetMap'
        Map tileset to use. Can choose from a list of built-in tiles,
        pass a :class:`xyzservices.TileProvider`,
        pass a custom URL, pass a TileLayer object,
        or pass `None` to create a map without tiles.
        For more advanced tile layer options, use the `TileLayer` class.
    min_zoom: int, optional, default 0
        Minimum allowed zoom level for the tile layer that is created.
        Filled by xyzservices by default.
    max_zoom: int, optional, default 18
        Maximum allowed zoom level for the tile layer that is created.
        Filled by xyzservices by default.
    zoom_start: int, default 10
        Initial zoom level for the map.
    attr: string, default None
        Map tile attribution; only required if passing custom tile URL.
    crs : str, default 'EPSG3857'
        Defines coordinate reference systems for projecting geographical points
        into pixel (screen) coordinates and back.
        You can use Leaflet's values :
        * EPSG3857 : The most common CRS for online maps, used by almost all
        free and commercial tile providers. Uses Spherical Mercator projection.
        Set in by default in Map's crs option.
        * EPSG4326 : A common CRS among GIS enthusiasts.
        Uses simple Equirectangular projection.
        * EPSG3395 : Rarely used by some commercial tile providers.
        Uses Elliptical Mercator projection.
        * Simple : A simple CRS that maps longitude and latitude into
        x and y directly. May be used for maps of flat surfaces
        (e.g. game maps). Note that the y axis should still be inverted
        (going from bottom to top).
    control_scale : bool, default False
        Whether to add a control scale on the map.
    prefer_canvas : bool, default False
        Forces Leaflet to use the Canvas back-end (if available) for
        vector layers instead of SVG. This can increase performance
        considerably in some cases (e.g. many thousands of circle
        markers on the map).
    no_touch : bool, default False
        Forces Leaflet to not use touch events even if it detects them.
    disable_3d : bool, default False
        Forces Leaflet to not use hardware-accelerated CSS 3D
        transforms for positioning (which may cause glitches in some
        rare environments) even if they're supported.
    zoom_control : bool or position string, default True
        Display zoom controls on the map. The default `True` places it in the top left corner.
        Other options are 'topleft', 'topright', 'bottomleft' or 'bottomright'.
    font_size : int or float or string (default: '1rem')
        The font size to use for Leaflet, can either be a number or a
        string ending in 'rem', 'em', or 'px'.
    **kwargs
        Additional keyword arguments are passed to Leaflets Map class:
        https://leafletjs.com/reference.html#map

    Returns
    -------
    Folium Map Object

    Examples
    --------
    >>> m = folium.Map(location=[45.523, -122.675], width=750, height=500)
    >>> m = folium.Map(location=[45.523, -122.675], tiles="cartodb positron")
    >>> m = folium.Map(
    ...     location=[45.523, -122.675],
    ...     zoom_start=2,
    ...     tiles="https://api.mapbox.com/v4/mapbox.streets/{z}/{x}/{y}.png?access_token=mytoken",
    ...     attr="Mapbox attribution",
    ... )

    a  
        {% macro header(this, kwargs) %}
            <meta name="viewport" content="width=device-width,
                initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
            <style>
                #{{ this.get_name() }} {
                    position: {{this.position}};
                    width: {{this.width[0]}}{{this.width[1]}};
                    height: {{this.height[0]}}{{this.height[1]}};
                    left: {{this.left[0]}}{{this.left[1]}};
                    top: {{this.top[0]}}{{this.top[1]}};
                }
                .leaflet-container { font-size: {{this.font_size}}; }
            </style>
        {% endmacro %}

        {% macro html(this, kwargs) %}
            <div class="folium-map" id={{ this.get_name()|tojson }} ></div>
        {% endmacro %}

        {% macro script(this, kwargs) %}
            var {{ this.get_name() }} = L.map(
                {{ this.get_name()|tojson }},
                {
                    center: {{ this.location|tojson }},
                    crs: L.CRS.{{ this.crs }},
                    {%- for key, value in this.options.items() %}
                    {{ key }}: {{ value|tojson }},
                    {%- endfor %}
                }
            );

            {%- if this.control_scale %}
            L.control.scale().addTo({{ this.get_name() }});
            {%- endif %}

            {%- if this.zoom_control_position %}
            L.control.zoom( { position: {{ this.zoom_control|tojson }} } ).addTo({{ this.get_name() }});
            {%- endif %}

            {% if this.objects_to_stay_in_front %}
            function objects_in_front() {
                {%- for obj in this.objects_to_stay_in_front %}
                    {{ obj.get_name() }}.bringToFront();
                {%- endfor %}
            };
            {{ this.get_name() }}.on("overlayadd", objects_in_front);
            $(document).ready(objects_in_front);
            {%- endif %}

        {% endmacro %}
        N100%0%relativeOpenStreetMap
   Z   L   FEPSG3857T1remlocationwidthheightlefttoppositiontilesattrmin_zoommax_zoom
zoom_startmin_latmax_latmin_lonmax_lon
max_boundscrscontrol_scaleprefer_canvasr$   r%   png_enabledzoom_control	font_sizekwargsc                    sN  t    d| _d | _|| _|d u rddg| _d}nt|| _t |  t	|| _
t	|| _t	|| _t	|| _|| _t|| _|rK||g||ggnd }|| _|| _t|trgd| _|dvrctd|| _nd| _td||| jrsdn||d|| _t||| _g | _t|tr| | d S |rt|||	|
d	}| j||jd
 d S d S )Nr0   g           T>   toplefttopright
bottomleftbottomrightzeIncorrect value for `zoom_control`, choose from 'topleft', 'topright', 'bottomleft' or 'bottomright'.F)rK   zoomrP   rN   )rB   rC   rD   rE   namer)   )r!   r"   r#   
_png_imagerO   r<   r   r   	add_childr   r=   r>   r?   r@   rA   r   rQ   rL   rM   
isinstancestrzoom_control_position
ValueErrorrP   r   optionsr    global_switchesobjects_to_stay_in_frontr   	tile_name)r&   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   r$   r%   rO   rP   rQ   rR   max_bounds_array
tile_layerr'   r)   r*   r"      sZ   









zMap.__init__returnc                 K   sL   | j du r| t  |  | j jdi |}d| _ |S | j jdi |}|S )z,Displays the HTML Map in a Jupyter notebook.Nr)   )_parentadd_tor   _repr_html_)r&   rR   outr)   r)   r*   rj   H  s   
zMap._repr_html_   delaydriverc           	      C   s   | j du r[|du r ddlm} |jj }|d |j|d}|  	 }t
|&}|d|  |  t| |dd}|j}|  W d   n1 sSw   Y  || _ | j S )	a  Export the HTML to byte representation of a PNG image.

        Uses selenium to render the HTML and record a PNG. You may need to
        adjust the `delay` time keyword argument if maps render without data or tiles.

        Uses a headless Firefox webdriver by default, though you can provide your own.

        Examples
        --------
        >>> m._to_png()
        >>> m._to_png(time=10)  # Wait 10 seconds between render and snapshot.

        Nr   )	webdriverz
--headless)ra   zfile:///z
class namez
folium-map)r[   seleniumro   firefoxra   Optionsadd_argumentFirefoxget_rootrenderr   getfullscreen_windowtimesleepfind_elementscreenshot_as_pngquit)	r&   rm   rn   ro   ra   htmlfnamedivpngr)   r)   r*   _to_pngS  s"   




zMap._to_pngc                 C   s   | j sdS |  S )z+Displays the PNG Map in a Jupyter notebook.N)rO   r   )r&   r)   r)   r*   
_repr_png_u  s   zMap._repr_png_c                    sj   |   }t|tsJ d|jj| jdd |jjtddd |jjtddd t jd	i | dS )
z/Renders the HTML representation of the element.z8You cannot render this Element if it is not in a Figure.rb   rY   zJ<style>html, body {width: 100%;height: 100%;margin: 0;padding: 0;}</style>	css_stylezF<style>#map {position:absolute;top:0;bottom:0;right:0;left:0;}</style>	map_styleNr)   )	ru   r]   r   headerr\   rb   r   r!   rv   )r&   rR   figurer'   r)   r*   rv   }  s(   	
z
Map.renderc              	   C   sn   t |   %}td|  td z	 td q ty$   Y nw W d   dS 1 s0w   Y  dS )z+Display the Map in the default web browser.zfile://zWYour map should have been opened in your browser automatically.
Press ctrl+c to return.Td   N)	r   ru   rv   
webbrowseropenprintry   rz   KeyboardInterrupt)r&   r   r)   r)   r*   show_in_browser  s   
"zMap.show_in_browserboundspadding_top_leftpadding_bottom_rightpaddingc              	   C   s   |  t|||||d dS )a  Fit the map to contain a bounding box with the
        maximum zoom level possible.

        Parameters
        ----------
        bounds: list of (latitude, longitude) points
            Bounding box specified as two points [southwest, northeast]
        padding_top_left: (x, y) point, default None
            Padding in the top left corner. Useful if some elements in
            the corner, such as controls, might obscure objects you're zooming
            to.
        padding_bottom_right: (x, y) point, default None
            Padding in the bottom right corner.
        padding: (x, y) point, default None
            Equivalent to setting both top left and bottom right padding to
            the same value.
        max_zoom: int, default None
            Maximum zoom to be used.

        Examples
        --------
        >>> m.fit_bounds([[52.193636, -2.221575], [52.636878, -1.139759]])

        )r   r   r   rE   N)r\   r   )r&   r   r   r   r   rE   r)   r)   r*   
fit_bounds  s    zMap.fit_boundsargsc                 G   s   |D ]}| j | qdS )a  Pass one or multiple layers that must stay in front.

        The ordering matters, the last one is put on top.

        Parameters
        ----------
        *args :
            Variable length argument list. Any folium object that counts as an
            overlay. For example FeatureGroup or TileLayer.
            Does not work with markers, for those use z_index_offset.
        N)rc   append)r&   r   objr)   r)   r*   keep_in_front  s   zMap.keep_in_front)Nr1   r1   r2   r2   r3   r4   NNNr5   r6   r7   r8   r9   Fr:   FFFFFTr;   )rl   N)rg   N)NNNN) r+   r,   r-   __doc__r	   r.   _default_js
default_js_default_cssdefault_cssr   r   floatr   r^   r   intboolr   r"   rj   r   bytesr   r   rv   r   r   r   r   r   r/   r)   r)   r'   r*   r0   R   s    a8




	

Y"
'



*r0   )"r   ry   r   typingr   r   r   r   r   branca.elementr   r   jinja2r	   folium.elementsr
   
folium.mapr   r   r   folium.raster_layersr   folium.utilitiesr   r   r   r   r   r   r   r   r   r    r0   r)   r)   r)   r*   <module>   s    $
