a
    V                     @   s`   d dl m Z  d dlmZ d dlmZ d dlZdd Zdd Zd	d
 ZdddZ	G dd dZ
dS )    vincenty)SON)HTMLNc                 C   s
   t | |S )zD
    1 = 1km
    :param source:
    :param target:
    :return:
    r   )sourcetarget r   U/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/umap/get.pydistance	   s    r
   c                 C   s2   |t d|fd|d fgi}| |}| |fS )u  
    MongoDB GeoSpatial Search
    :param database: db.test
    :param name: field name 'gps'
    :param location: [lat, lon]
    "All documents must store location data in the same order.
    If you use latitude and longitude as your coordinate system,
    always store longitude first.
    MongoDB’s 2d spherical index operators only recognize
    [longitude, latitude] ordering."
    :param maxkm: limit of distance
    :return: count, database
    z$nearz$maxDistancegHz[@)r   findcount)ZdatabasenamelocationZmaxkmquerydatar   r   r	   nearest   s
    


r   c                 C   s@   t | tjr4|   | jdd}tdj|d}ntd|S )z
    Embeds the HTML source of the map directly into the IPython notebook.

    This method will not work if the map depends on any files (json data). Also this uses
    the HTML5 srcdoc attribute, which may not be supported in all browsers.
    "&quot;T<iframe srcdoc="{srcdoc}" style="width: 100%; height: 500px; border: none"></iframe>srcdocz"{!r} is not a folium Map instance.)
isinstancefoliumMap
_build_mapr   replaceformat
ValueError)mapr   embedr   r   r	   
inline_mapH   s    
r    map.htmlc                 C   s    |}| j |d tdj|dS )N)pathzU<iframe src="files/{path}" style="width: 100%; height: 510px; border: none"></iframe>)Z
create_mapr   r   )r   r"   r   r   r	   	embed_mapY   s    r#   c                   @   s:   e Zd ZdZdd Zdd Zdd ZdddZdd ZdS )r   z
    Map with folium
    c                 C   s6   d| _ d| _d| _tj| j | jg| jd| _g | _dS )z&
        lat, lon, zoom_start
        g(\B@gq=
ף_@   r   
zoom_startN)latlonr&   r   r   mcirclesselfr   r   r	   __init__   s
    zMap.__init__c                 C   s$   g | _ tj| j| jg| jd| _dS )z5
        reset circles, map
        :return:
        r%   N)r*   r   r   r'   r(   r&   r)   r+   r   r   r	   reset   s    z	Map.resetc              	   C   sx   t | jdkrJ| jD ]4}| jj|d |d |d |d |d |d d q| j  | jjdd	}td
j|d}|S )z9
        Map drawing
        :return: iframe map
        r                  )r   radiusfill_opacitypopup
fill_color
line_colorr   r   r   r   )lenr*   r)   Zcircle_markerr   r   r   r   )r,   cr   r   r   r   r	   drawing   s    

zMap.drawing2   皙? blackNonec                 C   s<   t |tkr|d}| j|ddd |||||g dS )a  
        Add a circle in the map
        :param location: [lat, lon]
        :param radius: circle radius
        :param fill_opacity: transparency
        :param popup: text
        :param fill_color:
        :param line_color: circle line color
        :return:
        utf8N)typeZunicodeencoder*   append)r,   r   r4   r5   r6   r7   r8   r   r   r	   
add_circle   s    
zMap.add_circlec                 C   s   | j S )z=
        Get a list of circles
        :return: list
        )r*   r+   r   r   r	   get_circles   s    zMap.get_circlesN)r<   r=   r>   r?   r@   )	__name__
__module____qualname____doc__r-   r.   r;   rF   rG   r   r   r   r	   r      s   
  
r   )r!   )r   Zbson.sonr   ZIPython.displayr   r   r
   r   r    r#   r   r   r   r   r	   <module>   s   	6
1