2011-03-16 17:50:02 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
2011-10-23 15:04:25 +02:00
|
|
|
* Copyright (C) 2011 Artem Pavlenko
|
2011-03-16 17:50:02 +01: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
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2011-03-16 17:50:02 +01:00
|
|
|
// Mapnik
|
|
|
|
#include <mapnik/metawriter.hpp>
|
|
|
|
#include <mapnik/metawriter_inmem.hpp>
|
|
|
|
#include <mapnik/placement_finder.hpp>
|
2012-02-12 03:55:13 +01:00
|
|
|
#include <mapnik/text_placements/base.hpp>
|
2011-03-16 17:50:02 +01:00
|
|
|
|
|
|
|
// Boost
|
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
|
|
|
|
using std::map;
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
using mapnik::value;
|
|
|
|
using mapnik::Feature;
|
|
|
|
using mapnik::metawriter_properties;
|
|
|
|
|
|
|
|
// intersect a set of properties with those in the feature descriptor
|
2012-01-17 19:41:37 +01:00
|
|
|
map<string,value> intersect_properties(Feature const& feature, metawriter_properties const& properties) {
|
2011-03-16 17:50:02 +01:00
|
|
|
|
2012-01-12 11:04:49 +01:00
|
|
|
map<string,value> nprops;
|
2012-02-02 02:53:35 +01:00
|
|
|
BOOST_FOREACH(string p, properties)
|
2012-01-17 19:41:37 +01:00
|
|
|
{
|
2012-02-02 02:53:35 +01:00
|
|
|
if (feature.has_key(p))
|
2012-01-17 19:41:37 +01:00
|
|
|
nprops.insert(std::make_pair(p,feature.get(p)));
|
2011-03-16 17:50:02 +01:00
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2012-01-17 19:41:37 +01:00
|
|
|
return nprops;
|
|
|
|
}} // end anonymous namespace
|
2011-03-16 17:50:02 +01:00
|
|
|
|
|
|
|
namespace mapnik {
|
|
|
|
|
2012-02-02 02:53:35 +01:00
|
|
|
metawriter_inmem::metawriter_inmem(metawriter_properties dflt_properties)
|
2012-01-17 19:41:37 +01:00
|
|
|
: metawriter(dflt_properties) {
|
2011-03-16 17:50:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
metawriter_inmem::~metawriter_inmem() {
|
|
|
|
}
|
|
|
|
|
2012-02-02 02:53:35 +01:00
|
|
|
void
|
2011-03-16 17:50:02 +01:00
|
|
|
metawriter_inmem::add_box(box2d<double> const& box, Feature const& feature,
|
2011-04-04 06:35:28 +02:00
|
|
|
CoordTransform const& /*t*/,
|
2011-03-16 17:50:02 +01:00
|
|
|
metawriter_properties const& properties) {
|
2012-01-17 19:41:37 +01:00
|
|
|
meta_instance inst;
|
|
|
|
inst.box = box;
|
|
|
|
inst.properties = intersect_properties(feature, properties);
|
|
|
|
instances_.push_back(inst);
|
2011-03-16 17:50:02 +01:00
|
|
|
}
|
|
|
|
|
2012-01-26 14:04:08 +01:00
|
|
|
void
|
|
|
|
metawriter_inmem::add_text(text_placement_info const& p,
|
|
|
|
face_manager_freetype & /*face*/,
|
2011-03-16 17:50:02 +01:00
|
|
|
Feature const& feature,
|
2011-04-04 06:35:28 +02:00
|
|
|
CoordTransform const& /*t*/,
|
2011-03-16 17:50:02 +01:00
|
|
|
metawriter_properties const& properties) {
|
2012-01-17 19:41:37 +01:00
|
|
|
if (p.extents.valid()) {
|
|
|
|
meta_instance inst;
|
|
|
|
inst.properties = intersect_properties(feature, properties);
|
|
|
|
inst.box = p.extents;
|
|
|
|
instances_.push_back(inst);
|
|
|
|
}
|
2011-03-16 17:50:02 +01:00
|
|
|
}
|
|
|
|
|
2012-02-02 02:53:35 +01:00
|
|
|
void
|
2011-03-16 17:50:02 +01:00
|
|
|
metawriter_inmem::add_polygon(path_type & path,
|
|
|
|
Feature const& feature,
|
|
|
|
CoordTransform const& t,
|
|
|
|
metawriter_properties const& properties) {
|
2012-01-17 19:41:37 +01:00
|
|
|
add_vertices(path, feature, t, properties);
|
2011-03-16 17:50:02 +01:00
|
|
|
}
|
|
|
|
|
2012-02-02 02:53:35 +01:00
|
|
|
void
|
2011-03-16 17:50:02 +01:00
|
|
|
metawriter_inmem::add_line(path_type & path,
|
|
|
|
Feature const& feature,
|
|
|
|
CoordTransform const& t,
|
|
|
|
metawriter_properties const& properties) {
|
2012-01-17 19:41:37 +01:00
|
|
|
add_vertices(path, feature, t, properties);
|
2011-03-16 17:50:02 +01:00
|
|
|
}
|
|
|
|
|
2012-02-02 02:53:35 +01:00
|
|
|
void
|
2011-03-16 17:50:02 +01:00
|
|
|
metawriter_inmem::add_vertices(path_type & path,
|
|
|
|
Feature const& feature,
|
2011-04-04 06:35:28 +02:00
|
|
|
CoordTransform const& /*t*/,
|
2011-03-16 17:50:02 +01:00
|
|
|
metawriter_properties const& properties) {
|
2012-01-17 19:41:37 +01:00
|
|
|
box2d<double> box;
|
|
|
|
unsigned cmd;
|
|
|
|
double x = 0.0, y = 0.0;
|
|
|
|
|
|
|
|
path.rewind(0);
|
|
|
|
while ((cmd = path.vertex(&x, &y)) != SEG_END) {
|
|
|
|
box.expand_to_include(x, y);
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2012-01-17 19:41:37 +01:00
|
|
|
if ((box.width() >= 0.0) && (box.height() >= 0.0)) {
|
|
|
|
meta_instance inst;
|
|
|
|
inst.properties = intersect_properties(feature, properties);
|
|
|
|
inst.box = box;
|
|
|
|
instances_.push_back(inst);
|
2012-02-02 02:53:35 +01:00
|
|
|
}
|
2011-03-16 17:50:02 +01:00
|
|
|
}
|
|
|
|
|
2012-02-02 02:53:35 +01:00
|
|
|
void
|
2011-04-04 06:35:28 +02:00
|
|
|
metawriter_inmem::start(metawriter_property_map const& /*properties*/) {
|
2012-01-17 19:41:37 +01:00
|
|
|
instances_.clear();
|
2011-03-16 17:50:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const std::list<metawriter_inmem::meta_instance> &
|
|
|
|
metawriter_inmem::instances() const {
|
2012-01-17 19:41:37 +01:00
|
|
|
return instances_;
|
2011-03-16 17:50:02 +01:00
|
|
|
}
|
|
|
|
|
2012-02-02 02:53:35 +01:00
|
|
|
metawriter_inmem::meta_instance_list::const_iterator
|
2011-03-16 17:50:02 +01:00
|
|
|
metawriter_inmem::inst_begin() const {
|
2012-01-17 19:41:37 +01:00
|
|
|
return instances_.begin();
|
2011-03-16 17:50:02 +01:00
|
|
|
}
|
|
|
|
|
2012-02-02 02:53:35 +01:00
|
|
|
metawriter_inmem::meta_instance_list::const_iterator
|
2011-03-16 17:50:02 +01:00
|
|
|
metawriter_inmem::inst_end() const {
|
2012-01-17 19:41:37 +01:00
|
|
|
return instances_.end();
|
2011-03-16 17:50:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|