<s> from __future__ import unicode_literals <EOL> from django . conf import settings <EOL> from django . contrib . gis . maps . google . overlays import ( <EOL> GMarker , GPolygon , GPolyline , <EOL> ) <EOL> from django . template . loader import render_to_string <EOL> from django . utils . html import format_html <EOL> from django . utils . safestring import mark_safe <EOL> from django . utils . six . moves import range <EOL> class GoogleMapException ( Exception ) : <EOL> pass <EOL> GOOGLE_MAPS_URL = '<STR_LIT>' <EOL> class GoogleMap ( object ) : <EOL> "<STR_LIT>" <EOL> onunload = mark_safe ( '<STR_LIT>' ) <EOL> vml_css = mark_safe ( '<STR_LIT>' ) <EOL> xmlns = mark_safe ( '<STR_LIT>' ) <EOL> def __init__ ( self , key = None , api_url = None , version = None , <EOL> center = None , zoom = None , dom_id = '<STR_LIT>' , <EOL> kml_urls = [ ] , polylines = None , polygons = None , markers = None , <EOL> template = '<STR_LIT>' , <EOL> js_module = '<STR_LIT>' , <EOL> extra_context = { } ) : <EOL> if not key : <EOL> try : <EOL> self . key = settings . GOOGLE_MAPS_API_KEY <EOL> except AttributeError : <EOL> raise GoogleMapException ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> else : <EOL> self . key = key <EOL> if not version : <EOL> self . version = getattr ( settings , '<STR_LIT>' , '<STR_LIT>' ) <EOL> else : <EOL> self . version = version <EOL> if not api_url : <EOL> self . api_url = getattr ( settings , '<STR_LIT>' , GOOGLE_MAPS_URL ) % self . version <EOL> else : <EOL> self . api_url = api_url <EOL> self . dom_id = dom_id <EOL> self . extra_context = extra_context <EOL> self . js_module = js_module <EOL> self . template = template <EOL> self . kml_urls = kml_urls <EOL> overlay_info = [ [ GMarker , markers , '<STR_LIT>' ] , <EOL> [ GPolygon , polygons , '<STR_LIT>' ] , <EOL> [ GPolyline , polylines , '<STR_LIT>' ] ] <EOL> for overlay_class , overlay_list , varname in overlay_info : <EOL> setattr ( self , varname , [ ] ) <EOL> if overlay_list : <EOL> for overlay in overlay_list : <EOL> if isinstance ( overlay , overlay_class ) : <EOL> getattr ( self , varname ) . append ( overlay ) <EOL> else : <EOL> getattr ( self , varname ) . append ( overlay_class ( overlay ) ) <EOL> self . calc_zoom = False <EOL> if self . polygons or self . polylines or self . markers : <EOL> if center is None or zoom is None : <EOL> self . calc_zoom = True <EOL> if zoom is None : <EOL> zoom = <NUM_LIT:4> <EOL> self . zoom = zoom <EOL> if center is None : <EOL> center = ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . center = center <EOL> def render ( self ) : <EOL> """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : self . calc_zoom , <EOL> '<STR_LIT>' : self . center , <EOL> '<STR_LIT>' : self . dom_id , <EOL> '<STR_LIT>' : self . js_module , <EOL> '<STR_LIT>' : self . kml_urls , <EOL> '<STR_LIT>' : self . zoom , <EOL> '<STR_LIT>' : self . polygons , <EOL> '<STR_LIT>' : self . polylines , <EOL> '<STR_LIT>' : self . icons , <EOL> '<STR_LIT>' : self . markers , <EOL> } <EOL> params . update ( self . extra_context ) <EOL> return render_to_string ( self . template , params ) <EOL> @ property <EOL> def body ( self ) : <EOL> "<STR_LIT>" <EOL> return format_html ( '<STR_LIT>' , self . onload , self . onunload ) <EOL> @ property <EOL> def onload ( self ) : <EOL> "<STR_LIT>" <EOL> return format_html ( '<STR_LIT>' , self . js_module , self . dom_id ) <EOL> @ property <EOL> def api_script ( self ) : <EOL> "<STR_LIT>" <EOL> return format_html ( '<STR_LIT>' , <EOL> self . api_url , self . key ) <EOL> @ property <EOL> def js ( self ) : <EOL> "<STR_LIT>" <EOL> return self . render ( ) <EOL> @ property <EOL> def scripts ( self ) : <EOL> "<STR_LIT>" <EOL> return format_html ( '<STR_LIT>' , <EOL> self . api_script , mark_safe ( self . js ) ) <EOL> @ property <EOL> def style ( self ) : <EOL> "<STR_LIT>" <EOL> return format_html ( '<STR_LIT>' , self . vml_css ) <EOL> @ property <EOL> def xhtml ( self ) : <EOL> "<STR_LIT>" <EOL> return format_html ( '<STR_LIT>' , self . xmlns ) <EOL> @ property <EOL> def icons ( self ) : <EOL> "<STR_LIT>" <EOL> return set ( marker . icon for marker in self . markers if marker . icon ) <EOL> class GoogleMapSet ( GoogleMap ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> template = kwargs . pop ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . map_template = kwargs . pop ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> super ( GoogleMapSet , self ) . __init__ ( ** kwargs ) <EOL> self . template = template <EOL> if isinstance ( args [ <NUM_LIT:0> ] , ( tuple , list ) ) : <EOL> self . maps = args [ <NUM_LIT:0> ] <EOL> else : <EOL> self . maps = args <EOL> self . dom_ids = [ '<STR_LIT>' % i for i in range ( len ( self . maps ) ) ] <EOL> def load_map_js ( self ) : <EOL> """<STR_LIT>""" <EOL> result = [ ] <EOL> for dom_id , gmap in zip ( self . dom_ids , self . maps ) : <EOL> tmp = ( gmap . template , gmap . dom_id ) <EOL> gmap . template = self . map_template <EOL> gmap . dom_id = dom_id <EOL> result . append ( gmap . js ) <EOL> gmap . template , gmap . dom_id = tmp <EOL> return mark_safe ( '<STR_LIT>' . join ( result ) ) <EOL> def render ( self ) : <EOL> """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : self . js_module , <EOL> '<STR_LIT>' : self . dom_ids , <EOL> '<STR_LIT>' : self . load_map_js ( ) , <EOL> '<STR_LIT>' : self . icons , <EOL> } <EOL> params . update ( self . extra_context ) <EOL> return render_to_string ( self . template , params ) <EOL> @ property <EOL> def onload ( self ) : <EOL> "<STR_LIT>" <EOL> return mark_safe ( '<STR_LIT>' % self . js_module ) <EOL> @ property <EOL> def icons ( self ) : <EOL> "<STR_LIT>" <EOL> icons = set ( ) <EOL> for map in self . maps : <EOL> icons |= map . icons <EOL> return icons </s>
