<s> from urllib import urlencode <EOL> from django . contrib . gis . geos import Point <EOL> from molly . maps . osm import fit_to_map <EOL> from molly . maps . models import GeneratedMap <EOL> class Map ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , centre_point , points , min_points , zoom , width , height , <EOL> extra_points = [ ] , paths = [ ] ) : <EOL> """<STR_LIT>""" <EOL> self . centre_point = centre_point <EOL> self . extra_points = extra_points <EOL> self . min_points = min_points <EOL> self . paths = paths <EOL> self . width = width <EOL> self . height = height <EOL> try : <EOL> self . static_map_hash , ( self . points , self . zoom , lon_center , lat_center ) = fit_to_map ( <EOL> centre_point = centre_point , <EOL> extra_points = extra_points , <EOL> points = points , <EOL> paths = paths , <EOL> min_points = min_points , <EOL> zoom = zoom , <EOL> width = width , <EOL> height = height , <EOL> ) <EOL> if len ( self . points ) > <NUM_LIT:0> : <EOL> ( lon , lat , colour , title ) , indices = self . points [ <NUM_LIT:0> ] <EOL> except ValueError : <EOL> static_map_hash , metadata = fit_to_map ( <EOL> centre_point = centre_point , <EOL> extra_points = extra_points , <EOL> points = points , <EOL> paths = paths , <EOL> min_points = min_points , <EOL> zoom = zoom , <EOL> width = width , <EOL> height = height , <EOL> ) <EOL> GeneratedMap . objects . get ( hash = static_map_hash ) . delete ( ) <EOL> self . static_map_hash , ( self . points , self . zoom , lon_center , lat_center ) = fit_to_map ( <EOL> centre_point = centre_point , <EOL> extra_points = extra_points , <EOL> points = points , <EOL> paths = paths , <EOL> min_points = min_points , <EOL> zoom = zoom , <EOL> width = width , <EOL> height = height , <EOL> ) <EOL> markers = [ <EOL> ( str ( centre_point [ <NUM_LIT:1> ] ) , <EOL> str ( centre_point [ <NUM_LIT:0> ] ) , <EOL> centre_point [ <NUM_LIT:2> ] + '<STR_LIT>' , <EOL> centre_point [ <NUM_LIT:3> ] . encode ( '<STR_LIT:ascii>' , '<STR_LIT>' ) ) <EOL> ] if centre_point != None else [ ] <EOL> for point in self . extra_points : <EOL> markers . append ( ( str ( point [ <NUM_LIT:1> ] ) , <EOL> str ( point [ <NUM_LIT:0> ] ) , <EOL> point [ <NUM_LIT:2> ] + '<STR_LIT>' , <EOL> point [ <NUM_LIT:3> ] . encode ( '<STR_LIT:ascii>' , '<STR_LIT>' ) ) ) <EOL> for point in self . points : <EOL> markers . append ( <EOL> ( str ( point [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] ) , <EOL> str ( point [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) , <EOL> point [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] + '<STR_LIT:_>' + str ( point [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] + <NUM_LIT:1> ) , <EOL> point [ <NUM_LIT:0> ] [ <NUM_LIT:3> ] . encode ( '<STR_LIT:ascii>' , '<STR_LIT>' ) ) <EOL> ) <EOL> self . lon_centre , self . lat_centre = lon_center , lat_center <EOL> self . markers = markers <EOL> def simplify_for_render ( self , simplify_value , simplify_model ) : <EOL> return { <EOL> '<STR_LIT>' : simplify_value ( self . static_map_hash ) , <EOL> '<STR_LIT>' : simplify_value ( self . centre_point ) , <EOL> '<STR_LIT>' : simplify_value ( self . extra_points ) , <EOL> '<STR_LIT>' : simplify_value ( self . points ) , <EOL> '<STR_LIT>' : simplify_value ( self . paths ) , <EOL> '<STR_LIT:width>' : simplify_value ( self . width ) , <EOL> '<STR_LIT>' : simplify_value ( self . height ) , <EOL> '<STR_LIT>' : simplify_value ( Point ( self . lon_centre , self . lat_centre ) ) , <EOL> '<STR_LIT>' : simplify_value ( self . zoom ) , <EOL> '<STR_LIT>' : simplify_value ( self . markers ) , <EOL> } <EOL> def map_from_point ( point , width , height , colour = '<STR_LIT>' , title = '<STR_LIT>' , zoom = <NUM_LIT:16> ) : <EOL> """<STR_LIT>""" <EOL> return Map ( ( point [ <NUM_LIT:0> ] , point [ <NUM_LIT:1> ] , colour , title ) , [ ] , <NUM_LIT:1> , zoom , width , height ) </s>
