11"""FlaskGoogleMaps - Google Maps Extension for Flask"""
22
3- __version__ = "0.4.0 "
3+ __version__ = "0.4.1 "
44
55from json import dumps
6- from typing import Optional , Dict , Any , List , Union , Tuple , Text
6+ from typing import Optional , Dict , Any , List , Union , Tuple , Text # noqa: F401
7+
78import requests
89from flask import Blueprint , Markup , g , render_template
910
10- from flask_googlemaps .icons import dots , Icon
11+ from flask_googlemaps .icons import dots , Icon # noqa: F401
1112
1213DEFAULT_ICON = dots .red
1314DEFAULT_CLUSTER_IMAGE_PATH = "static/images/m"
@@ -27,7 +28,8 @@ def __init__(
2728 cls = "map" , # type: str
2829 language = "en" , # type: str
2930 region = "US" , # type: str
30- rectangles = None , # type: Optional[List[Union[List, Tuple, Tuple[Tuple], Dict]]]
31+ rectangles = None ,
32+ # type: Optional[List[Union[List, Tuple, Tuple[Tuple], Dict]]]
3133 circles = None , # type: Optional[List[Union[List, Tuple, Dict]]]
3234 polylines = None , # type: Optional[List[Union[List, Tuple, Dict]]]
3335 polygons = None , # type: Optional[List[Union[List, Tuple, Dict]]]
@@ -256,13 +258,20 @@ def build_rectangle_dict(
256258 "stroke_weight" : stroke_weight ,
257259 "fill_color" : fill_color ,
258260 "fill_opacity" : fill_opacity ,
259- "bounds" : {"north" : north , "west" : west , "south" : south , "east" : east },
261+ "bounds" : {
262+ "north" : north ,
263+ "west" : west ,
264+ "south" : south ,
265+ "east" : east ,
266+ },
260267 }
261268
262269 return rectangle
263270
264- def add_rectangle (self , north = None , west = None , south = None , east = None , ** kwargs ):
265- # type: (Optional[float], Optional[float], Optional[float], Optional[float], **Any) -> None
271+ def add_rectangle (
272+ self , north = None , west = None , south = None , east = None , ** kwargs
273+ ):
274+ # type: (Optional[float], Optional[float], Optional[float], Optional[float], **Any) -> None # noqa: E501
266275 """Adds a rectangle dict to the Map.rectangles attribute
267276
268277 The Google Maps API describes a rectangle using the LatLngBounds
@@ -297,7 +306,9 @@ def add_rectangle(self, north=None, west=None, south=None, east=None, **kwargs):
297306 if east :
298307 kwargs ["bounds" ]["east" ] = east
299308
300- if set (("north" , "east" , "south" , "west" )) != set (kwargs ["bounds" ].keys ()):
309+ if set (("north" , "east" , "south" , "west" )) != set (
310+ kwargs ["bounds" ].keys ()
311+ ):
301312 raise AttributeError ("rectangle bounds required to rectangles" )
302313
303314 kwargs .setdefault ("stroke_color" , "#FF0000" )
@@ -346,7 +357,9 @@ def build_circles(self, circles):
346357 elif isinstance (circle , (tuple , list )):
347358 if len (circle ) != 3 :
348359 raise AttributeError ("circle requires center and radius" )
349- circle_dict = self .build_circle_dict (circle [0 ], circle [1 ], circle [2 ])
360+ circle_dict = self .build_circle_dict (
361+ circle [0 ], circle [1 ], circle [2 ]
362+ )
350363 self .add_circle (** circle_dict )
351364
352365 def build_circle_dict (
@@ -395,7 +408,9 @@ def build_circle_dict(
395408
396409 return circle
397410
398- def add_circle (self , center_lat = None , center_lng = None , radius = None , ** kwargs ):
411+ def add_circle (
412+ self , center_lat = None , center_lng = None , radius = None , ** kwargs
413+ ):
399414 # type: (Optional[float], Optional[float], Optional[float], **Any) -> None
400415 """Adds a circle dict to the Map.circles attribute
401416
@@ -744,14 +759,16 @@ def build_heatmap(self, heatmap_data, heatmap_layer):
744759 raise AttributeError ("heatmap_later requires 'heatmap_data'" )
745760 if not isinstance (heatmap_data , (list )):
746761 raise AttributeError (
747- "heatmap_data only accepts a list of dicts with keys 'lat' 'lng' and their corresponding values"
762+ "heatmap_data only accepts a list of dicts with keys "
763+ "'lat' 'lng' and their corresponding values"
748764 )
749765 for hm in heatmap_data :
750766 if isinstance (hm , dict ):
751767 self .add_heatmap (** hm )
752768 else :
753769 raise AttributeError (
754- "elements of list 'heatmap_data' must be a dict of keys 'lat' and 'lng' with their corresponding values"
770+ "elements of list 'heatmap_data' must be a dict of keys "
771+ "'lat' and 'lng' with their corresponding values"
755772 )
756773
757774 def add_heatmap (self , lat = None , lng = None , ** kwargs ):
@@ -763,7 +780,9 @@ def add_heatmap(self, lat=None, lng=None, **kwargs):
763780 if "lat" not in kwargs or "lng" not in kwargs :
764781 raise AttributeError ("heatmap_data requires 'lat' and 'lng' values" )
765782 if len (kwargs ) > 2 :
766- raise AttributeError ("heatmap_data can only contain 'lat' and 'lng' values" )
783+ raise AttributeError (
784+ "heatmap_data can only contain 'lat' and 'lng' values"
785+ )
767786
768787 self .heatmap_data .append (kwargs )
769788
@@ -820,7 +839,9 @@ def verify_lat_lng_coordinates(self, lat, lng):
820839 def js (self ):
821840 # type: () -> Markup
822841 return Markup (
823- self .render ("googlemaps/gmapjs.html" , gmap = self , DEFAULT_ICON = DEFAULT_ICON )
842+ self .render (
843+ "googlemaps/gmapjs.html" , gmap = self , DEFAULT_ICON = DEFAULT_ICON
844+ )
824845 )
825846
826847 @property
@@ -860,18 +881,30 @@ def set_googlemaps_loaded():
860881def get_address (API_KEY , lat , lon ):
861882 # type: (str, float, float) -> dict
862883 add_dict = dict ()
863- response = rq .get (
884+ response = requests .get (
864885 "https://maps.googleapis.com/maps/api/geocode/json?latlng="
865886 + "," .join (map (str , [lat , lon ]))
866887 + "&key="
867888 + API_KEY
868889 ).json ()
869- add_dict ["zip" ] = response ["results" ][0 ]["address_components" ][- 1 ]["long_name" ]
870- add_dict ["country" ] = response ["results" ][0 ]["address_components" ][- 2 ]["long_name" ]
871- add_dict ["state" ] = response ["results" ][0 ]["address_components" ][- 3 ]["long_name" ]
872- add_dict ["city" ] = response ["results" ][0 ]["address_components" ][- 4 ]["long_name" ]
873- add_dict ["locality" ] = response ["results" ][0 ]["address_components" ][- 5 ]["long_name" ]
874- add_dict ["road" ] = response ["results" ][0 ]["address_components" ][- 6 ]["long_name" ]
890+ add_dict ["zip" ] = response ["results" ][0 ]["address_components" ][- 1 ][
891+ "long_name"
892+ ]
893+ add_dict ["country" ] = response ["results" ][0 ]["address_components" ][- 2 ][
894+ "long_name"
895+ ]
896+ add_dict ["state" ] = response ["results" ][0 ]["address_components" ][- 3 ][
897+ "long_name"
898+ ]
899+ add_dict ["city" ] = response ["results" ][0 ]["address_components" ][- 4 ][
900+ "long_name"
901+ ]
902+ add_dict ["locality" ] = response ["results" ][0 ]["address_components" ][- 5 ][
903+ "long_name"
904+ ]
905+ add_dict ["road" ] = response ["results" ][0 ]["address_components" ][- 6 ][
906+ "long_name"
907+ ]
875908 add_dict ["formatted_address" ] = response ["results" ][0 ]["formatted_address" ]
876909 return add_dict
877910
@@ -909,7 +942,9 @@ def init_app(self, app):
909942 app .add_template_global (googlemap_obj )
910943 app .add_template_filter (googlemap )
911944 app .add_template_global (googlemap )
912- app .add_template_global (app .config .get ("GOOGLEMAPS_KEY" ), name = "GOOGLEMAPS_KEY" )
945+ app .add_template_global (
946+ app .config .get ("GOOGLEMAPS_KEY" ), name = "GOOGLEMAPS_KEY"
947+ )
913948 app .add_template_global (set_googlemaps_loaded )
914949 app .add_template_global (is_googlemaps_loaded )
915950
0 commit comments