Beispiel #1
0
bool svg_renderer<OutputIterator>::process(rule::symbolizers const& syms,
                                           Feature const& feature,
                                           proj_transform const& prj_trans)
{
    // svg renderer supports processing of multiple symbolizers.

    typedef coord_transform<CoordTransform, geometry_type> path_type;

    // process each symbolizer to collect its (path) information.
    // path information (attributes from line_ and polygon_ symbolizers)
    // is collected with the path_attributes_ data member.
    BOOST_FOREACH(symbolizer const& sym, syms)
    {
        boost::apply_visitor(symbol_dispatch(*this, feature, prj_trans), sym);
    }
bool svg_renderer<OutputIterator>::process(rule::symbolizers const& syms,
                                           mapnik::feature_impl & feature,
                                           proj_transform const& prj_trans)
{
    // svg renderer supports processing of multiple symbolizers.
    typedef coord_transform<CoordTransform, geometry_type> path_type;

    bool process_path = false;
    // process each symbolizer to collect its (path) information.
    // path information (attributes from line_ and polygon_ symbolizers)
    // is collected with the path_attributes_ data member.
    for (symbolizer const& sym : syms)
    {
        if (is_path_based(sym))
        {
            process_path = true;
        }
        boost::apply_visitor(symbol_dispatch(*this, feature, prj_trans), sym);
    }

    if (process_path)
    {
        // generate path output for each geometry of the current feature.
        for(std::size_t i=0; i<feature.num_geometries(); ++i)
        {
            geometry_type & geom = feature.get_geometry(i);
            if(geom.size() > 0)
            {
                path_type path(t_, geom, prj_trans);
                generator_.generate_path(path, path_attributes_);
            }
        }
        // set the previously collected values back to their defaults
        // for the feature that will be processed next.
        path_attributes_.reset();
    }
    return true;
}
	void apply_to_layer(Layer const& lay,Processor & p)
	{
	    p.start_layer_processing(lay);
	    datasource *ds=lay.datasource().get();
	    if (ds)
	    {
		Envelope<double> const& bbox=m_.getCurrentExtent();
		double scale = m_.scale();
	
		std::vector<std::string> const& style_names = lay.styles();
		std::vector<std::string>::const_iterator stylesIter = style_names.begin();
		while (stylesIter != style_names.end())
		{
		    std::set<std::string> names;
		    attribute_collector<Feature> collector(names);
		    std::vector<rule_type*> if_rules;
		    std::vector<rule_type*> else_rules;
		
		    bool active_rules=false;
		    
		    feature_type_style const& style=m_.find_style(*stylesIter++);
		    
		    const std::vector<rule_type>& rules=style.get_rules();
		    std::vector<rule_type>::const_iterator ruleIter=rules.begin();
		    
		    query q(bbox,m_.getWidth(),m_.getHeight());
		    while (ruleIter!=rules.end())
		    {
			if (ruleIter->active(scale))
			{
			    active_rules=true;
			    ruleIter->accept(collector);

			    if (ruleIter->has_else_filter())
			    {
				else_rules.push_back(const_cast<rule_type*>(&(*ruleIter)));
			    }
			    else
			    {
				if_rules.push_back(const_cast<rule_type*>(&(*ruleIter))); 		    
			    }
			}
			++ruleIter;
		    }
		    std::set<std::string>::const_iterator namesIter=names.begin();
		    // push all property names
		    while (namesIter!=names.end())
		    {
			q.add_property_name(*namesIter);
			++namesIter;
		    }
		    if (active_rules)
		    {
			featureset_ptr fs=ds->features(q);
			if (fs)
			{   	    
			    feature_ptr feature;
			    while ((feature = fs->next()))
			    {		   
				bool do_else=true;		    
				std::vector<rule_type*>::const_iterator itr=if_rules.begin();
				while (itr!=if_rules.end())
				{
				    filter_ptr const& filter=(*itr)->get_filter();    
				    if (filter->pass(*feature))
				    {   
					do_else=false;
					const symbolizers& symbols = (*itr)->get_symbolizers();
					symbolizers::const_iterator symIter=symbols.begin();
					while (symIter!=symbols.end())
					{   
					    boost::apply_visitor(symbol_dispatch(p,*feature),*symIter++);
					}
				    }			    
				    ++itr;
				}
				if (do_else)
				{
				    //else filter
				    std::vector<rule_type*>::const_iterator itr=else_rules.begin();
				    while (itr != else_rules.end())
				    {
					const symbolizers& symbols = (*itr)->get_symbolizers();
					symbolizers::const_iterator symIter=symbols.begin();
					while (symIter!=symbols.end())
					{
					    boost::apply_visitor(symbol_dispatch(p,*feature),*symIter++);
					}
					++itr;
				    }
				}	  
			    }
			}
		    }
		}
	    }
	    p.end_layer_processing(lay);
	}
void feature_style_processor<Processor>::render_style(
    Processor & p,
    feature_type_style const* style,
    rule_cache const& rc,
    featureset_ptr features,
    proj_transform const& prj_trans)
{
    p.start_style_processing(*style);
    if (!features)
    {
        p.end_style_processing(*style);
        return;
    }
    mapnik::attributes vars = p.variables();
    feature_ptr feature;
    bool was_painted = false;
    while ((feature = features->next()))
    {
        bool do_else = true;
        bool do_also = false;
        for (rule const* r : rc.get_if_rules() )
        {
            expression_ptr const& expr = r->get_filter();
            value_type result = boost::apply_visitor(evaluate<feature_impl,value_type,attributes>(*feature,vars),*expr);
            if (result.to_bool())
            {
                was_painted = true;
                do_else=false;
                do_also=true;
                rule::symbolizers const& symbols = r->get_symbolizers();
                if(!p.process(symbols,*feature,prj_trans))
                {
                    for (symbolizer const& sym : symbols)
                    {
                        boost::apply_visitor(symbol_dispatch(p,*feature,prj_trans),sym);
                    }
                }
                if (style->get_filter_mode() == FILTER_FIRST)
                {
                    // Stop iterating over rules and proceed with next feature.
                    do_also=false;
                    break;
                }
            }
        }
        if (do_else)
        {
            for( rule const* r : rc.get_else_rules() )
            {
                was_painted = true;
                rule::symbolizers const& symbols = r->get_symbolizers();
                if(!p.process(symbols,*feature,prj_trans))
                {
                    for (symbolizer const& sym : symbols)
                    {
                        boost::apply_visitor(symbol_dispatch(p,*feature,prj_trans),sym);
                    }
                }
            }
        }
        if (do_also)
        {
            for( rule const* r : rc.get_also_rules() )
            {
                was_painted = true;
                rule::symbolizers const& symbols = r->get_symbolizers();
                if(!p.process(symbols,*feature,prj_trans))
                {
                    for (symbolizer const& sym : symbols)
                    {
                        boost::apply_visitor(symbol_dispatch(p,*feature,prj_trans),sym);
                    }
                }
            }
        }
    }
    p.painted(was_painted);
    p.end_style_processing(*style);
}