1- from dataclasses import dataclass
1+ from dataclasses import dataclass , fields
2+ from enum import Enum
23from typing import Optional
34
45from flask_googlemaps .marker_content import MarkerContent
56
7+ pin_property_mapping = {
8+ "glyph_color" : "glyphColor" ,
9+ "background" : "background" ,
10+ "border_color" : "borderColor" ,
11+ "glyph" : "glyph" ,
12+ "scale" : "scale" ,
13+ }
14+
15+
16+ class PinPropertyMapping (Enum ):
17+ glyph_color = "glyphColor"
18+ background = "background"
19+ border_color = "borderColor"
20+ glyph = "glyph"
21+ scale = "scale"
22+
623
724@dataclass
825class Pin (MarkerContent ):
926
1027 def __post_init__ (self ):
1128 MarkerContent .__post_init__ (self )
1229 self .dom = []
13- if self .glyph_color :
14- self .dom .append (f"\t glyphColor: '{ self .glyph_color } '," )
15- if self .background :
16- self .dom .append (f"\t background: '{ self .background } '," )
17- if self .border_color :
18- self .dom .append (f"\t borderColor: '{ self .border_color } '," )
19- if self .glyph :
20- self .dom .append (f"\t glyph: '{ self .glyph } '," )
30+ for field in fields (Pin ):
31+ if self .__getattribute__ (field .name ):
32+ self .dom .append (
33+ f"\t { PinPropertyMapping .__getitem__ (field .name ).value } : "
34+ f"'{ self .__getattribute__ (field .name )} ',"
35+ )
36+
2137 if self .dom :
2238 self .dom .insert (0 , f"const { self .name } = new PinElement({{" )
2339 self .dom .append ("\t \t });\n " )
@@ -32,7 +48,7 @@ def dom_element(self) -> Optional[str]:
3248 glyph_color : str = ""
3349 background : str = ""
3450 glyph : Optional [str ] = ""
35- scale : float = 1.0
51+ scale : Optional [ float ] = None
3652
3753 def content (self ) -> str :
3854 if self .dom :
0 commit comments