11"""FlaskGoogleMaps - Google Maps Extension for Flask"""
22
3- __version__ = "0.4.2 "
3+ __version__ = "0.5.0 "
44
55from json import dumps
66from typing import Optional , Dict , Any , List , Union , Tuple , Text
7+
78import requests
89from flask import Blueprint , g , render_template
910from markupsafe import Markup
1011
11- from flask_googlemaps .pin import Pin
12+ from flask_googlemaps .marker import Marker
1213
13- DEFAULT_PIN = Pin (border_color = "" , glyph_color = "" , background = "" )
1414DEFAULT_CLUSTER_IMAGE_PATH = "static/images/m"
1515
1616
@@ -28,7 +28,8 @@ def __init__(
2828 cls = "map" , # type: str
2929 language = "en" , # type: str
3030 region = "US" , # type: str
31- rectangles = None , # type: Optional[List[Union[List, Tuple, Tuple[Tuple], Dict]]]
31+ rectangles = None ,
32+ # type: Optional[List[Union[List, Tuple, Tuple[Tuple], Dict]]]
3233 circles = None , # type: Optional[List[Union[List, Tuple, Dict]]]
3334 polylines = None , # type: Optional[List[Union[List, Tuple, Dict]]]
3435 polygons = None , # type: Optional[List[Union[List, Tuple, Dict]]]
@@ -65,12 +66,11 @@ def __init__(
6566 self .language = language
6667 self .region = region
6768 self .varname = varname
68- self .center = self . verify_lat_lng_coordinates (lat , lng )
69+ self .center = Marker . verify_latitude (lat ), Marker . verify_longitude ( lng )
6970 self .zoom = zoom
7071 self .maptype = maptype
71- self .markers = [] # type: List[Any ]
72+ self .markers = Marker . from_list ( markers ) # type: List[Marker ]
7273 self .map_ids = map_ids
73- self .build_markers (markers )
7474 self .rectangles = [] # type: List[Any]
7575 self .build_rectangles (rectangles )
7676 self .circles = [] # type: List[Any]
@@ -107,50 +107,6 @@ def __init__(
107107 self .heatmap_data = []
108108 self .build_heatmap (heatmap_data , heatmap_layer )
109109
110- def build_markers (self , markers ):
111- # type: (Optional[Union[Dict, List, Tuple]]) -> None
112- if not markers :
113- return
114- if not isinstance (markers , (dict , list , tuple )):
115- raise AttributeError ("markers accepts only dict, list and tuple" )
116-
117- if isinstance (markers , dict ):
118- for pin , marker_list in markers .items ():
119- for marker in marker_list :
120- marker_dict = self .build_marker_dict (marker , pin = pin )
121- self .add_marker (** marker_dict )
122- else :
123- for marker in markers :
124- if isinstance (marker , dict ):
125- self .add_marker (** marker )
126- elif isinstance (marker , (tuple , list )):
127- marker_dict = self .build_marker_dict (marker )
128- self .add_marker (** marker_dict )
129-
130- def build_marker_dict (self , marker , pin = None ):
131- # type: (Union[List, Tuple], Optional[Pin]) -> Dict
132- marker_dict = {
133- "lat" : marker [0 ],
134- "lng" : marker [1 ],
135- "pin" : pin or DEFAULT_PIN ,
136- }
137- if len (marker ) > 2 :
138- marker_dict ["infobox" ] = marker [2 ]
139- if len (marker ) > 3 :
140- marker_dict ["pin" ] = marker [3 ]
141- return marker_dict
142-
143- def add_marker (self , lat = None , lng = None , ** kwargs ):
144- # type: (Optional[float], Optional[float], **Any) -> None
145- if lat is not None :
146- kwargs ["lat" ] = lat
147- if lng is not None :
148- kwargs ["lng" ] = lng
149- if "lat" not in kwargs or "lng" not in kwargs :
150- raise AttributeError ("lat and lng required" )
151-
152- self .markers .append (kwargs )
153-
154110 def build_rectangles (self , rectangles ):
155111 # type: (Optional[List[Union[List, Tuple, Tuple[Tuple], Dict]]]) -> None
156112 """Process data to construct rectangles
@@ -805,24 +761,10 @@ def as_json(self):
805761
806762 return json_dict
807763
808- def verify_lat_lng_coordinates (self , lat , lng ):
809- if not (90 >= lat >= - 90 ):
810- raise AttributeError (
811- "Latitude must be between -90 and 90 degrees inclusive."
812- )
813- if not (180 >= lng >= - 180 ):
814- raise AttributeError (
815- "Longitude must be between -180 and 180 degrees inclusive."
816- )
817-
818- return (lat , lng )
819-
820764 @property
821765 def js (self ):
822766 # type: () -> Markup
823- return Markup (
824- self .render ("googlemaps/gmapjs.html" , gmap = self , DEFAULT_PIN = DEFAULT_PIN )
825- )
767+ return Markup (self .render ("googlemaps/gmapjs.html" , gmap = self , DEFAULT_PIN = "" ))
826768
827769 @property
828770 def html (self ):
0 commit comments