2011-04-26 23:44:52 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Artem Pavlenko
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
// mapnik
|
|
|
|
#include <mapnik/grid/grid_rasterizer.hpp>
|
|
|
|
#include <mapnik/grid/grid_renderer.hpp>
|
|
|
|
#include <mapnik/grid/grid_pixfmt.hpp>
|
|
|
|
#include <mapnik/grid/grid_pixel.hpp>
|
|
|
|
#include <mapnik/grid/grid.hpp>
|
2012-01-20 22:43:05 +01:00
|
|
|
#include <mapnik/point_symbolizer.hpp>
|
2011-09-01 02:43:46 +02:00
|
|
|
#include <mapnik/expression_evaluator.hpp>
|
2012-03-08 17:37:58 +01:00
|
|
|
#include <mapnik/marker.hpp>
|
2011-04-26 23:44:52 +02:00
|
|
|
#include <mapnik/marker_cache.hpp>
|
|
|
|
|
|
|
|
// stl
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace mapnik {
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void grid_renderer<T>::process(point_symbolizer const& sym,
|
2012-06-16 04:17:26 +02:00
|
|
|
mapnik::feature_impl & feature,
|
2012-02-02 02:53:35 +01:00
|
|
|
proj_transform const& prj_trans)
|
2011-04-26 23:44:52 +02:00
|
|
|
{
|
2012-06-16 04:17:26 +02:00
|
|
|
std::string filename = path_processor_type::evaluate(*sym.get_filename(), feature);
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2011-04-26 23:44:52 +02:00
|
|
|
boost::optional<mapnik::marker_ptr> marker;
|
|
|
|
if ( !filename.empty() )
|
|
|
|
{
|
|
|
|
marker = marker_cache::instance()->find(filename, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-10-18 01:41:12 +02:00
|
|
|
marker.reset(boost::make_shared<mapnik::marker>());
|
2011-04-26 23:44:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (marker)
|
|
|
|
{
|
2012-07-16 20:51:14 +02:00
|
|
|
box2d<double> const& bbox = (*marker)->bounding_box();
|
|
|
|
coord2d const center = bbox.center();
|
|
|
|
|
2012-05-27 23:50:09 +02:00
|
|
|
agg::trans_affine tr;
|
2012-06-16 04:17:26 +02:00
|
|
|
evaluate_transform(tr, feature, sym.get_image_transform());
|
2012-07-16 20:51:14 +02:00
|
|
|
tr = agg::trans_affine_scaling(scale_factor_) * tr;
|
|
|
|
|
|
|
|
agg::trans_affine_translation const recenter(-center.x, -center.y);
|
|
|
|
agg::trans_affine const recenter_tr = recenter * tr;
|
|
|
|
box2d<double> label_ext = bbox * recenter_tr;
|
2012-05-27 23:50:09 +02:00
|
|
|
|
2012-06-16 04:17:26 +02:00
|
|
|
for (unsigned i=0; i<feature.num_geometries(); ++i)
|
2011-04-26 23:44:52 +02:00
|
|
|
{
|
2012-07-16 20:51:14 +02:00
|
|
|
geometry_type const& geom = feature.get_geometry(i);
|
2011-04-26 23:44:52 +02:00
|
|
|
double x;
|
|
|
|
double y;
|
|
|
|
double z=0;
|
|
|
|
if (sym.get_point_placement() == CENTROID_POINT_PLACEMENT)
|
|
|
|
geom.label_position(&x, &y);
|
|
|
|
else
|
|
|
|
geom.label_interior_position(&x, &y);
|
|
|
|
|
|
|
|
prj_trans.backward(x,y,z);
|
|
|
|
t_.forward(&x,&y);
|
2012-07-16 20:51:14 +02:00
|
|
|
label_ext.re_center(x,y);
|
2011-04-26 23:44:52 +02:00
|
|
|
if (sym.get_allow_overlap() ||
|
|
|
|
detector_.has_placement(label_ext))
|
|
|
|
{
|
2012-07-16 20:51:14 +02:00
|
|
|
|
|
|
|
render_marker(feature,
|
|
|
|
pixmap_.get_resolution(),
|
|
|
|
pixel_position(x, y),
|
|
|
|
**marker,
|
|
|
|
tr,
|
|
|
|
sym.get_opacity(),
|
|
|
|
sym.comp_op());
|
2011-04-26 23:44:52 +02:00
|
|
|
|
|
|
|
if (!sym.get_ignore_placement())
|
|
|
|
detector_.insert(label_ext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template void grid_renderer<grid>::process(point_symbolizer const&,
|
2012-06-16 04:17:26 +02:00
|
|
|
mapnik::feature_impl &,
|
2012-02-02 02:53:35 +01:00
|
|
|
proj_transform const&);
|
2011-04-26 23:44:52 +02:00
|
|
|
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|