o
    gi                     @   s   d Z ddlZddlZddlmZ 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 dd	lmZ G d
d deZdS )a  
A world map is a map of most or all of the surface of Earth. World maps, because of their scale,
must deal with the problem of projection.
Maps rendered in two dimensions by necessity distort the display of the three-dimensional surface of the Earth.
While this is true of any map, these distortions reach extremes in a world map.
Many techniques have been developed to present world maps that address diverse technical and aesthetic goals.
    NDecimal)DisconnectedShape)Color)HexColor)	Alignment)ConnectedShape)Shapesc                5       s  e Zd ZdZddeddededededddeddejedededededededededdejfde	j
ded	eje d
ededededededededededeje dededeje deje deje deje dededededeje d ef4 fd!d"Zd#ed$d fd%d&Z	d-ded#eje d$d fd'd(Z	d-ded#eje d$d fd)d*Z	d-ded#eje d$d fd+d,Z  ZS ).Mapa  
    A world map is a map of most or all of the surface of Earth. World maps, because of their scale,
    must deal with the problem of projection.
    Maps rendered in two dimensions by necessity distort the display of the three-dimensional surface of the Earth.
    While this is true of any map, these distortions reach extremes in a world map.
    Many techniques have been developed to present world maps that address diverse technical and aesthetic goals.
    NF000000r      geojson_filename_keybackground_colorborder_bottomborder_colorborder_leftborder_radius_bottom_leftborder_radius_bottom_rightborder_radius_top_leftborder_radius_top_rightborder_right
border_topborder_width
fill_colorhorizontal_alignment
line_widthmargin_bottommargin_leftmargin_right
margin_toppadding_bottompadding_leftpadding_rightpadding_topstroke_colorvertical_alignmentc           "         s  i | _ t|d[}t| }|d D ]G}|d |d }g | j |< |d d D ]1}t|tjrGt|d tjrGt|d d tjrG|d }| j | 	t
dd |D |||d	 q)qW d    n1 sfw   Y  g } | j  D ]}!| |! qrtt| jd#i d
| d|d|d|d|d|d|d|	d|
d|d|d|d|d|d|d|d|d|d|d|d|d|d |d!|d"| d S )$Nrfeatures
propertiesgeometrycoordinatesr   c                 S   s    g | ]\}}t |t |fqS  r   ).0xyr,   r,   X/home/ubuntu/.local/lib/python3.10/site-packages/borb/pdf/canvas/layout/geography/map.py
<listcomp>V   s     z Map.__init__.<locals>.<listcomp>)r%   r   r   shapesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r,   )_iso3_code_to_shapesopenjsonloadsreadget
isinstancetypingListappendr   valuesextendsuperr
   __init__)"selfr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   json_file_handlegeo_json_datafeature_dictiso3_keypolygon
all_shapescss	__class__r,   r0   r@   $   s    


	
zMap.__init__keyreturnc                    s<   | j |d  dur| j |  fdd| jD | _| S )z
        This function removes a key (associated with one or multiple ConnectedShape or DisconnectedShape objects)
        :param key:     the key to be removed
        :return:        self
        Nc                    s   g | ]}| vr|qS r,   r,   )r-   r.   shapes_to_remover,   r0   r1      s    zMap.pop.<locals>.<listcomp>)r3   r8   pop_shapes)rA   rK   r,   rM   r0   rO      s   zMap.popc                 C   J   |du r| j  D ]\}}|D ]}||_qq	| S | j | D ]}||_q| S )a  
        This function sets the fill Color of all countries, or a specific country (specified by its ISO3 code)
        :param fill_color:          the fill Color
        :param key:                 an ISO3 country code, or None
        :return:                    self
        N)r3   items_fill_color)rA   r   rK   _rH   csr,   r,   r0   set_fill_color   s   zMap.set_fill_colorc                 C   rQ   )a  
        This function sets the line width of all countries, or a specific country (specified by its ISO3 code)
        :param line_width:          the line width
        :param key:                 an ISO3 country code, or None
        :return:                    self
        N)r3   rR   _line_width)rA   r   rK   rT   rH   rU   r,   r,   r0   set_line_width      zMap.set_line_widthc                 C   rQ   )a  
        This function sets the stroke Color of all countries, or a specific country (specified by its ISO3 code)
        :param stroke_color:        the stroke Color
        :param key:                 an ISO3 country code, or None
        :return:                    self
        N)r3   rR   _stroke_color)rA   r%   rK   rT   rH   rU   r,   r,   r0   set_stroke_color   rY   zMap.set_stroke_color)N)__name__
__module____qualname____doc__r   r   r   LEFTTOPpathlibPathstrr:   Optionalr   boolr@   rO   rV   rX   r[   __classcell__r,   r,   rI   r0   r
      s    	
c

r
   )r_   r5   r:   decimalr   rb   /borb.pdf.canvas.layout.shape.disconnected_shaper   borb.pdf.canvas.color.colorr   r   %borb.pdf.canvas.layout.layout_elementr   ,borb.pdf.canvas.layout.shape.connected_shaper   #borb.pdf.canvas.layout.shape.shapesr	   r
   r,   r,   r,   r0   <module>   s   