o
    Pf#                     @   s^   d dl 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 G dd deeZdS )	    N)MacroElement)Template)
JSCSSMixin)Map)
get_boundsparse_optionsc                       sf   e Zd ZdZedZg dZddgZ								
					d fdd	Z fddZ	dd Z
  ZS )TimestampedGeoJsonaD
  
    Creates a TimestampedGeoJson plugin from timestamped GeoJSONs to append
    into a map with Map.add_child.

    A geo-json is timestamped if:

    * it contains only features of types LineString, MultiPoint, MultiLineString,
      Polygon and MultiPolygon.
    * each feature has a 'times' property with the same length as the
      coordinates array.
    * each element of each 'times' property is a timestamp in ms since epoch,
      or in ISO string.

    Eventually, you may have Point features with a 'times' property being an
    array of length 1.

    Parameters
    ----------
    data: file, dict or str.
        The timestamped geo-json data you want to plot.

        * If file, then data will be read in the file and fully embedded in
          Leaflet's javascript.
        * If dict, then data will be converted to json and embedded in the
          javascript.
        * If str, then data will be passed to the javascript as-is.
    transition_time: int, default 200.
        The duration in ms of a transition from between timestamps.
    loop: bool, default True
        Whether the animation shall loop.
    auto_play: bool, default True
        Whether the animation shall start automatically at startup.
    add_last_point: bool, default True
        Whether a point is added at the last valid coordinate of a LineString.
    period: str, default "P1D"
        Used to construct the array of available times starting
        from the first available time. Format: ISO8601 Duration
        ex: 'P1M' 1/month, 'P1D' 1/day, 'PT1H' 1/hour, and 'PT1M' 1/minute
    duration: str, default None
        Period of time which the features will be shown on the map after their
        time has passed. If None, all previous times will be shown.
        Format: ISO8601 Duration
        ex: 'P1M' 1/month, 'P1D' 1/day, 'PT1H' 1/hour, and 'PT1M' 1/minute

    Examples
    --------
    >>> TimestampedGeoJson(
    ...     {
    ...         "type": "FeatureCollection",
    ...         "features": [
    ...             {
    ...                 "type": "Feature",
    ...                 "geometry": {
    ...                     "type": "LineString",
    ...                     "coordinates": [[-70, -25], [-70, 35], [70, 35]],
    ...                 },
    ...                 "properties": {
    ...                     "times": [1435708800000, 1435795200000, 1435881600000],
    ...                     "tooltip": "my tooltip text",
    ...                 },
    ...             }
    ...         ],
    ...     }
    ... )

    See https://github.com/socib/Leaflet.TimeDimension for more information.

    a
  
        {% macro script(this, kwargs) %}
            L.Control.TimeDimensionCustom = L.Control.TimeDimension.extend({
                _getDisplayDateFormat: function(date){
                    var newdate = new moment(date);
                    console.log(newdate)
                    return newdate.format("{{this.date_options}}");
                }
            });
            {{this._parent.get_name()}}.timeDimension = L.timeDimension(
                {
                    period: {{ this.period|tojson }},
                }
            );
            var timeDimensionControl = new L.Control.TimeDimensionCustom(
                {{ this.options|tojson }}
            );
            {{this._parent.get_name()}}.addControl(this.timeDimensionControl);

            var geoJsonLayer = L.geoJson({{this.data}}, {
                    pointToLayer: function (feature, latLng) {
                        if (feature.properties.icon == 'marker') {
                            if(feature.properties.iconstyle){
                                return new L.Marker(latLng, {
                                    icon: L.icon(feature.properties.iconstyle)});
                            }
                            //else
                            return new L.Marker(latLng);
                        }
                        if (feature.properties.icon == 'circle') {
                            if (feature.properties.iconstyle) {
                                return new L.circleMarker(latLng, feature.properties.iconstyle)
                                };
                            //else
                            return new L.circleMarker(latLng);
                        }
                        //else

                        return new L.Marker(latLng);
                    },
                    style: function (feature) {
                        return feature.properties.style;
                    },
                    onEachFeature: function(feature, layer) {
                        if (feature.properties.popup) {
                        layer.bindPopup(feature.properties.popup);
                        }
                        if (feature.properties.tooltip) {
                        layer.bindTooltip(feature.properties.tooltip);
                        }
                    }
                })

            var {{this.get_name()}} = L.timeDimension.layer.geoJson(
                geoJsonLayer,
                {
                    updateTimeDimension: true,
                    addlastPoint: {{ this.add_last_point|tojson }},
                    duration: {{ this.duration }},
                }
            ).addTo({{this._parent.get_name()}});
        {% endmacro %}
        ))zjquery3.7.1zAhttps://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js)zjqueryui1.10.2zGhttps://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js)iso8601zChttps://cdn.jsdelivr.net/npm/iso8601-js-period@0.2.1/iso8601.min.js)zleaflet.timedimensionzZhttps://cdn.jsdelivr.net/npm/leaflet-timedimension@1.1.1/dist/leaflet.timedimension.min.js)momentzEhttps://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js)zhighlight.js_csszNhttps://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/default.min.css)zleaflet.timedimension_cssz_https://cdn.jsdelivr.net/npm/leaflet-timedimension@1.1.1/dist/leaflet.timedimension.control.css   TP1D皙?
   FYYYY-MM-DD HH:mm:ssNc                    s   t    d| _dt|v rd| _| | _nt|tu r'd| _t	
|| _nd| _|| _t|| _|| _|
| _|d u r>dnd| d | _td||||	||t||ddd	| _d S )
Nr   readTF	undefined"
bottomleft)transitionTimeloop	startOver)position	min_speed	max_speed	auto_playloop_buttontime_slider_drag_updatespeed_sliderplayer_options)super__init___namedirembedr   datatypedictjsondumpsbooladd_last_pointperioddate_optionsdurationr   intoptions)selfr$   transition_timer   r   r*   r+   r   r   r   r,   r   r-   r   	__class__ o/home/deployuser/azure_apps/autowriter/venv/lib/python3.10/site-packages/folium/plugins/timestamped_geo_json.pyr       s6   

zTimestampedGeoJson.__init__c                    s*   t | jts
J dt jdi | d S )Nz5TimestampedGeoJson can only be added to a Map object.r4   )
isinstance_parentr   r   render)r0   kwargsr2   r4   r5   r8      s   zTimestampedGeoJson.renderc                 C   s^   | j stdt| j}d| vr)t|trd| v s#d|d}d|gd}t|dd	S )
z
        Computes the bounds of the object itself (not including it's children)
        in the form [[lat_min, lon_min], [lat_max, lon_max]].

        z.Cannot compute bounds of non-embedded GeoJSON.featuresgeometryFeature)r%   r;   FeatureCollection)r%   r:   T)lonlat)	r#   
ValueErrorr'   loadsr$   keysr6   r&   r   )r0   r$   r4   r4   r5   _get_self_bounds   s   
z#TimestampedGeoJson._get_self_bounds)r   TTTr   r   r   Fr   FNT)__name__
__module____qualname____doc__r   	_template
default_jsdefault_cssr    r8   rB   __classcell__r4   r4   r2   r5   r      s0    EB0r   )r'   branca.elementr   jinja2r   folium.elementsr   folium.foliumr   folium.utilitiesr   r   r   r4   r4   r4   r5   <module>   s    