def copy_layer(obj): lyr = Layer(obj.name) if hasattr(lyr, 'title'): lyr.title = obj.title if hasattr(lyr, 'abstract'): lyr.abstract = obj.abstract # only if mapnik version supports it # http://trac.mapnik.org/ticket/503 if hasattr(lyr, 'tolerance'): lyr.tolerance = obj.tolerance lyr.toleranceunits = obj.toleranceunits lyr.srs = obj.srs lyr.minzoom = obj.minzoom lyr.maxzoom = obj.maxzoom lyr.active = obj.active lyr.queryable = obj.queryable lyr.clear_label_cache = obj.clear_label_cache lyr.datasource = obj.datasource if hasattr(obj, 'wmsdefaultstyle'): lyr.wmsdefaultstyle = obj.wmsdefaultstyle if hasattr(obj, 'wmsextrastyles'): lyr.wmsextrastyles = obj.wmsextrastyles if hasattr(obj, 'meta_style'): lyr.meta_style = obj.meta_style if hasattr(lyr, 'wms_srs'): lyr.wms_srs = obj.wms_srs return lyr
def copy_layer(obj): lyr = Layer(obj.name) lyr.abstract = obj.abstract lyr.active = obj.active lyr.clear_label_cache = obj.clear_label_cache lyr.datasource = obj.datasource #lyr.maxzoom = obj.maxzoom #lyr.minzoom = obj.minzoom lyr.queryable = obj.queryable lyr.srs = obj.srs lyr.title = obj.title if hasattr(obj,'wmsdefaultstyle'): lyr.wmsdefaultstyle = obj.wmsdefaultstyle if hasattr(obj,'wmsextrastyles'): lyr.wmsextrastyles = obj.wmsextrastyles return lyr
def process_trip(self, request, reqparams): """Process Trip request.""" if not 'trip_id' in reqparams: return trip_id = reqparams['trip_id'] trip = get_object_or_404(Trip, pk=trip_id, offer__id__isnull=False) new_style_name = "trip_style" if new_style_name not in self.mapfactory.styles: new_style = Style() new_rule = Rule() new_rule.symbols.append(PointSymbolizer()) new_rule.symbols.append(LineSymbolizer( Color('#2a4776'), 2) ) new_style.rules.append(new_rule) self.mapfactory.register_style(new_style_name, new_style) styles = {new_style_name: new_style_name} new_layer_name = "trip_%s" % trip_id str_new_layer_name = "%s_aggragatestyle" % new_layer_name if new_layer_name not in self.mapfactory.layers: new_layer = Layer(new_layer_name) new_layer.queryable = True new_layer.datasource = PostGIS( host=settings.DATABASE_HOST, user=settings.DATABASE_USER, password=settings.DATABASE_PASSWORD, port=settings.DATABASE_PORT, dbname=settings.DATABASE_NAME, table="(SELECT route FROM carpool_tripoffer o LEFT JOIN carpool_trip t ON t.offer_id=o.id WHERE t.id=%s) geom" % trip.offer_id ) new_layer.srs = '+init=epsg:4326' new_layer.styles.append(str_new_layer_name) self.mapfactory.register_aggregate_style(str_new_layer_name, styles) self.mapfactory.register_layer(new_layer, str_new_layer_name)