2010-06-01 15:31:08 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
2011-10-23 15:04:25 +02:00
|
|
|
* Copyright (C) 2011 Artem Pavlenko
|
2010-06-01 15:31:08 +02:00
|
|
|
*
|
|
|
|
* 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/agg_renderer.hpp>
|
2010-06-13 14:03:42 +02:00
|
|
|
#include <mapnik/agg_rasterizer.hpp>
|
2010-06-01 15:31:08 +02:00
|
|
|
#include <mapnik/image_util.hpp>
|
2012-08-02 20:13:44 +02:00
|
|
|
|
|
|
|
#include <mapnik/geom_util.hpp>
|
|
|
|
#include <mapnik/point_symbolizer.hpp>
|
|
|
|
#include <mapnik/expression_evaluator.hpp>
|
2012-03-08 17:37:58 +01:00
|
|
|
#include <mapnik/marker.hpp>
|
2011-01-26 02:18:40 +01:00
|
|
|
#include <mapnik/marker_cache.hpp>
|
2010-06-01 15:31:08 +02:00
|
|
|
|
2012-04-08 02:45:01 +02:00
|
|
|
// agg
|
2012-08-02 20:13:44 +02:00
|
|
|
#include "agg_trans_affine.h"
|
2010-06-01 15:31:08 +02:00
|
|
|
|
|
|
|
// stl
|
|
|
|
#include <string>
|
|
|
|
|
2011-05-10 23:09:54 +02:00
|
|
|
// boost
|
|
|
|
#include <boost/make_shared.hpp>
|
|
|
|
|
2010-06-01 15:31:08 +02:00
|
|
|
namespace mapnik {
|
|
|
|
|
2011-01-26 02:18:40 +01:00
|
|
|
template <typename T>
|
|
|
|
void agg_renderer<T>::process(point_symbolizer const& sym,
|
2012-06-16 04:17:26 +02:00
|
|
|
mapnik::feature_impl & feature,
|
2011-01-26 02:18:40 +01:00
|
|
|
proj_transform const& prj_trans)
|
|
|
|
{
|
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-01-26 02:18:40 +01:00
|
|
|
boost::optional<mapnik::marker_ptr> marker;
|
|
|
|
if ( !filename.empty() )
|
|
|
|
{
|
2010-06-03 14:35:43 +02:00
|
|
|
marker = marker_cache::instance()->find(filename, true);
|
2011-01-26 02:18:40 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-05-10 23:09:54 +02:00
|
|
|
marker.reset(boost::make_shared<mapnik::marker>());
|
2011-01-26 02:18:40 +01:00
|
|
|
}
|
2010-06-08 12:16:22 +02:00
|
|
|
|
2011-01-26 02:18:40 +01:00
|
|
|
if (marker)
|
|
|
|
{
|
2012-05-27 23:50:09 +02:00
|
|
|
box2d<double> const& bbox = (*marker)->bounding_box();
|
2012-07-24 10:44:14 +02:00
|
|
|
coord2d center = bbox.center();
|
2012-05-27 23:50:09 +02:00
|
|
|
|
2011-09-23 17:52:32 +02:00
|
|
|
agg::trans_affine tr;
|
2012-06-16 04:17:26 +02:00
|
|
|
evaluate_transform(tr, feature, sym.get_image_transform());
|
2012-07-24 10:44:14 +02:00
|
|
|
agg::trans_affine_translation recenter(-center.x, -center.y);
|
|
|
|
agg::trans_affine recenter_tr = recenter * tr;
|
2012-05-27 23:50:09 +02:00
|
|
|
box2d<double> label_ext = bbox * recenter_tr;
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2012-06-16 04:17:26 +02:00
|
|
|
for (unsigned i=0; i<feature.num_geometries(); ++i)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2012-06-16 04:17:26 +02:00
|
|
|
geometry_type const& geom = feature.get_geometry(i);
|
2011-01-26 02:18:40 +01:00
|
|
|
double x;
|
|
|
|
double y;
|
|
|
|
double z=0;
|
2011-02-24 19:05:07 +01:00
|
|
|
if (sym.get_point_placement() == CENTROID_POINT_PLACEMENT)
|
2012-07-20 18:32:38 +02:00
|
|
|
label::centroid(geom, x, y);
|
2011-02-01 09:16:32 +01:00
|
|
|
else
|
2012-07-20 20:18:33 +02:00
|
|
|
label::interior_position(geom ,x, y);
|
2011-01-26 02:18:40 +01:00
|
|
|
|
|
|
|
prj_trans.backward(x,y,z);
|
|
|
|
t_.forward(&x,&y);
|
2011-09-23 17:52:32 +02:00
|
|
|
label_ext.re_center(x,y);
|
2011-01-26 02:18:40 +01:00
|
|
|
if (sym.get_allow_overlap() ||
|
2011-10-12 02:05:35 +02:00
|
|
|
detector_->has_placement(label_ext))
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2012-07-16 20:51:14 +02:00
|
|
|
render_marker(pixel_position(x, y),
|
|
|
|
**marker,
|
|
|
|
tr,
|
|
|
|
sym.get_opacity(),
|
|
|
|
sym.comp_op());
|
2012-05-27 23:50:09 +02:00
|
|
|
|
2011-01-26 02:18:40 +01:00
|
|
|
if (!sym.get_ignore_placement())
|
2011-10-12 02:05:35 +02:00
|
|
|
detector_->insert(label_ext);
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
|
|
|
}
|
2010-06-01 15:31:08 +02:00
|
|
|
}
|
2011-01-26 02:18:40 +01:00
|
|
|
|
2010-06-01 15:31:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template void agg_renderer<image_32>::process(point_symbolizer const&,
|
2012-06-16 04:17:26 +02:00
|
|
|
mapnik::feature_impl &,
|
2010-06-02 13:03:30 +02:00
|
|
|
proj_transform const&);
|
2010-06-01 15:31:08 +02:00
|
|
|
|
|
|
|
}
|