o
    PÉf€  ã                   @   sj   d dl mZmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZmZmZ G dd„ deeƒZd	S )
é    )ÚOptionalÚUnion)ÚMacroElement)ÚTemplate)Ú
JSCSSMixin)ÚLayer)ÚJsCodeÚcamelizeÚparse_optionsc                       s|   e Zd ZdZedƒZdgZ						ddeee	e
f d	ed
edee
edf dee
edf dedee f‡ fdd„Z‡  ZS )ÚRealtimeaÉ	  Put realtime data on a Leaflet map: live tracking GPS units,
    sensor data or just about anything.

    Based on: https://github.com/perliedman/leaflet-realtime

    Parameters
    ----------
    source: str, dict, JsCode
        The source can be one of:

        * a string with the URL to get data from
        * a dict that is passed to javascript's `fetch` function
          for fetching the data
        * a `folium.JsCode` object in case you need more freedom.
    start: bool, default True
        Should automatic updates be enabled when layer is added
        on the map and stopped when layer is removed from the map
    interval: int, default 60000
        Automatic update interval, in milliseconds
    get_feature_id: str or JsCode, optional
        A JS function with a geojson `feature` as parameter
        default returns `feature.properties.id`
        Function to get an identifier to uniquely identify a feature over time
    update_feature: str or JsCode, optional
        A JS function with a geojson `feature` as parameter
        Used to update an existing feature's layer;
        by default, points (markers) are updated, other layers are discarded
        and replaced with a new, updated layer.
        Allows to create more complex transitions,
        for example, when a feature is updated
    remove_missing: bool, default False
        Should missing features between updates been automatically
        removed from the layer
    container: Layer, default GeoJson
        The container will typically be a `FeatureGroup`, `MarkerCluster` or
        `GeoJson`, but it can be anything that generates a javascript
        L.LayerGroup object, i.e. something that has the methods
        `addLayer` and `removeLayer`.

    Other keyword arguments are passed to the GeoJson layer, so you can pass
    `style`, `point_to_layer` and/or `on_each_feature`. Make sure to wrap
    Javascript functions in the JsCode class.

    Examples
    --------
    >>> from folium import JsCode
    >>> m = folium.Map(location=[40.73, -73.94], zoom_start=12)
    >>> rt = Realtime(
    ...     "https://raw.githubusercontent.com/python-visualization/folium-example-data/main/subway_stations.geojson",
    ...     get_feature_id=JsCode("(f) => { return f.properties.objectid; }"),
    ...     point_to_layer=JsCode(
    ...         "(f, latlng) => { return L.circleMarker(latlng, {radius: 8, fillOpacity: 0.2})}"
    ...     ),
    ...     interval=10000,
    ... )
    >>> rt.add_to(m)
    ar  
        {% macro script(this, kwargs) %}
            var {{ this.get_name() }}_options = {{ this.options|tojson }};
            {% for key, value in this.functions.items() %}
            {{ this.get_name() }}_options["{{key}}"] = {{ value }};
            {% endfor %}

            {% if this.container -%}
                {{ this.get_name() }}_options["container"]
                    = {{ this.container.get_name() }};
            {% endif -%}

            var {{ this.get_name() }} = L.realtime(
            {% if this.src is string or this.src is mapping -%}
                {{ this.src|tojson }},
            {% else -%}
                {{ this.src.js_code }},
            {% endif -%}
                {{ this.get_name() }}_options
            );
            {{ this._parent.get_name() }}.addLayer(
                {{ this.get_name() }}._container);
        {% endmacro %}
    )ÚLeaflet_Realtime_jszQhttps://cdnjs.cloudflare.com/ajax/libs/leaflet-realtime/2.2.0/leaflet-realtime.jsTé`ê  NFÚsourceÚstartÚintervalÚget_feature_idÚupdate_featureÚremove_missingÚ	containerc                    s°   t ƒ  ¡  d| _|| _|| _||d< ||d< |d ur t|ƒ|d< |d ur*t|ƒ|d< ||d< i | _t| ¡ ƒD ]\}	}
t	|
tƒrM|
j
| jt|	ƒ< | |	¡ q7tdi |¤Ž| _d S )Nr   r   r   r   r   r   © )ÚsuperÚ__init__Ú_nameÚsrcr   r   Ú	functionsÚlistÚitemsÚ
isinstanceÚjs_coder	   Úpopr
   Úoptions)Úselfr   r   r   r   r   r   r   ÚkwargsÚkeyÚvalue©Ú	__class__r   úc/home/deployuser/azure_apps/autowriter/venv/lib/python3.10/site-packages/folium/plugins/realtime.pyr   h   s$   


€zRealtime.__init__)Tr   NNFN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú	_templateÚ
default_jsr   ÚstrÚdictr   ÚboolÚintr   r   r   Ú__classcell__r   r   r%   r'   r      s8    :ÿÿ
øþýüûúùør   N)Útypingr   r   Úbranca.elementr   Újinja2r   Úfolium.elementsr   Ú
folium.mapr   Úfolium.utilitiesr   r	   r
   r   r   r   r   r'   Ú<module>   s    