<s> from django . contrib . gis . geos import fromstr , Point , LineString , LinearRing , Polygon <EOL> from django . utils . functional import total_ordering <EOL> from django . utils . safestring import mark_safe <EOL> from django . utils import six <EOL> from django . utils . encoding import python_2_unicode_compatible <EOL> @ python_2_unicode_compatible <EOL> class GEvent ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , event , action ) : <EOL> """<STR_LIT>""" <EOL> self . event = event <EOL> self . action = action <EOL> def __str__ ( self ) : <EOL> "<STR_LIT>" <EOL> return mark_safe ( '<STR_LIT>' % ( self . event , self . action ) ) <EOL> @ python_2_unicode_compatible <EOL> class GOverlayBase ( object ) : <EOL> def __init__ ( self ) : <EOL> self . events = [ ] <EOL> def latlng_from_coords ( self , coords ) : <EOL> "<STR_LIT>" <EOL> return '<STR_LIT>' % '<STR_LIT:U+002C>' . join ( [ '<STR_LIT>' % ( y , x ) for x , y in coords ] ) <EOL> def add_event ( self , event ) : <EOL> "<STR_LIT>" <EOL> self . events . append ( event ) <EOL> def __str__ ( self ) : <EOL> "<STR_LIT>" <EOL> return mark_safe ( '<STR_LIT>' % ( self . __class__ . __name__ , self . js_params ) ) <EOL> class GPolygon ( GOverlayBase ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , poly , <EOL> stroke_color = '<STR_LIT>' , stroke_weight = <NUM_LIT:2> , stroke_opacity = <NUM_LIT:1> , <EOL> fill_color = '<STR_LIT>' , fill_opacity = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( poly , six . string_types ) : poly = fromstr ( poly ) <EOL> if isinstance ( poly , ( tuple , list ) ) : poly = Polygon ( poly ) <EOL> if not isinstance ( poly , Polygon ) : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> self . envelope = poly . envelope <EOL> self . points = self . latlng_from_coords ( poly . shell . coords ) <EOL> self . stroke_color , self . stroke_opacity , self . stroke_weight = stroke_color , stroke_opacity , stroke_weight <EOL> self . fill_color , self . fill_opacity = fill_color , fill_opacity <EOL> super ( GPolygon , self ) . __init__ ( ) <EOL> @ property <EOL> def js_params ( self ) : <EOL> return '<STR_LIT>' % ( self . points , self . stroke_color , self . stroke_weight , self . stroke_opacity , <EOL> self . fill_color , self . fill_opacity ) <EOL> class GPolyline ( GOverlayBase ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , geom , color = '<STR_LIT>' , weight = <NUM_LIT:2> , opacity = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( geom , six . string_types ) : geom = fromstr ( geom ) <EOL> if isinstance ( geom , ( tuple , list ) ) : geom = Polygon ( geom ) <EOL> if isinstance ( geom , ( LineString , LinearRing ) ) : <EOL> self . latlngs = self . latlng_from_coords ( geom . coords ) <EOL> elif isinstance ( geom , Polygon ) : <EOL> self . latlngs = self . latlng_from_coords ( geom . shell . coords ) <EOL> else : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> self . envelope = geom . envelope <EOL> self . color , self . weight , self . opacity = color , weight , opacity <EOL> super ( GPolyline , self ) . __init__ ( ) <EOL> @ property <EOL> def js_params ( self ) : <EOL> return '<STR_LIT>' % ( self . latlngs , self . color , self . weight , self . opacity ) <EOL> @ total_ordering <EOL> class GIcon ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , varname , image = None , iconsize = None , <EOL> shadow = None , shadowsize = None , iconanchor = None , <EOL> infowindowanchor = None ) : <EOL> self . varname = varname <EOL> self . image = image <EOL> self . iconsize = iconsize <EOL> self . shadow = shadow <EOL> self . shadowsize = shadowsize <EOL> self . iconanchor = iconanchor <EOL> self . infowindowanchor = infowindowanchor <EOL> def __eq__ ( self , other ) : <EOL> return self . varname == other . varname <EOL> def __lt__ ( self , other ) : <EOL> return self . varname < other . varname <EOL> def __hash__ ( self ) : <EOL> return hash ( self . __class__ ) ^ hash ( self . varname ) <EOL> class GMarker ( GOverlayBase ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , geom , title = None , draggable = False , icon = None ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( geom , six . string_types ) : geom = fromstr ( geom ) <EOL> if isinstance ( geom , ( tuple , list ) ) : geom = Point ( geom ) <EOL> if isinstance ( geom , Point ) : <EOL> self . latlng = self . latlng_from_coords ( geom . coords ) <EOL> else : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> self . envelope = geom . envelope <EOL> self . title = title <EOL> self . draggable = draggable <EOL> self . icon = icon <EOL> super ( GMarker , self ) . __init__ ( ) <EOL> def latlng_from_coords ( self , coords ) : <EOL> return '<STR_LIT>' % ( coords [ <NUM_LIT:1> ] , coords [ <NUM_LIT:0> ] ) <EOL> def options ( self ) : <EOL> result = [ ] <EOL> if self . title : result . append ( '<STR_LIT>' % self . title ) <EOL> if self . icon : result . append ( '<STR_LIT>' % self . icon . varname ) <EOL> if self . draggable : result . append ( '<STR_LIT>' ) <EOL> return '<STR_LIT>' % '<STR_LIT:U+002C>' . join ( result ) <EOL> @ property <EOL> def js_params ( self ) : <EOL> return '<STR_LIT>' % ( self . latlng , self . options ( ) ) </s>
