add markers placement methods vertex-first and vertex-last

This commit is contained in:
Jiri Drbalek 2014-07-28 15:36:10 +00:00
parent cbe643c3f5
commit fa0b97fff7
5 changed files with 213 additions and 2 deletions

View file

@ -26,6 +26,8 @@
#include <mapnik/markers_placements/line.hpp>
#include <mapnik/markers_placements/point.hpp>
#include <mapnik/markers_placements/interior.hpp>
#include <mapnik/markers_placements/vertext_first.hpp>
#include <mapnik/markers_placements/vertext_last.hpp>
#include <mapnik/symbolizer_enumerations.hpp>
#include <boost/variant.hpp>
@ -41,7 +43,9 @@ class markers_placement_finder : mapnik::noncopyable
public:
using markers_placement = boost::variant<markers_point_placement<Locator, Detector>,
markers_line_placement<Locator, Detector>,
markers_interior_placement<Locator, Detector>>;
markers_interior_placement<Locator, Detector>,
markers_vertex_first_placement<Locator, Detector>,
markers_vertex_last_placement<Locator, Detector>>;
class get_point_visitor : public boost::static_visitor<bool>
{
@ -110,7 +114,9 @@ private:
{
{ MARKER_POINT_PLACEMENT, boost::value_factory<markers_point_placement<Locator, Detector>>() },
{ MARKER_INTERIOR_PLACEMENT, boost::value_factory<markers_interior_placement<Locator, Detector>>() },
{ MARKER_LINE_PLACEMENT, boost::value_factory<markers_line_placement<Locator, Detector>>() }
{ MARKER_LINE_PLACEMENT, boost::value_factory<markers_line_placement<Locator, Detector>>() },
{ MARKER_VERTEX_FIRST_PLACEMENT, boost::value_factory<markers_vertex_first_placement<Locator, Detector>>() },
{ MARKER_VERTEX_LAST_PLACEMENT, boost::value_factory<markers_vertex_last_placement<Locator, Detector>>() }
};
return factories.at(placement_type)(locator, size, tr, detector, spacing, max_error, allow_overlap);
}

View file

@ -0,0 +1,98 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2014 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
*
*****************************************************************************/
#ifndef MAPNIK_MARKERS_PLACEMENTS_VERTEXT_FIRST_HPP
#define MAPNIK_MARKERS_PLACEMENTS_VERTEXT_FIRST_HPP
#include <mapnik/markers_placements/point.hpp>
namespace mapnik {
template <typename Locator, typename Detector>
class markers_vertex_first_placement : public markers_point_placement<Locator, Detector>
{
public:
markers_vertex_first_placement(
Locator &locator,
box2d<double> const& size,
agg::trans_affine const& tr,
Detector &detector,
double spacing,
double max_error,
bool allow_overlap)
: markers_point_placement<Locator, Detector>(
locator, size, tr, detector,
spacing, max_error, allow_overlap)
{
}
bool get_point(double &x, double &y, double &angle, bool ignore_placement)
{
if (this->done_)
{
return false;
}
if (this->locator_.type() == mapnik::geometry_type::types::Point)
{
return markers_point_placement<Locator, Detector>::get_point(x, y, angle, ignore_placement);
}
double x0, y0;
if (agg::is_stop(this->locator_.vertex(&x0, &y0)))
{
this->done_ = true;
return false;
}
x = x0;
y = y0;
angle = 0;
double x1, y1;
if (agg::is_line_to(this->locator_.vertex(&x1, &y1)))
{
angle = std::atan2(y1 - y0, x1 - x0);
}
box2d<double> box = this->perform_transform(angle, x, y);
if (!this->allow_overlap_ && !this->detector_.has_placement(box))
{
return false;
}
if (!ignore_placement)
{
this->detector_.insert(box);
}
this->done_ = true;
return true;
}
};
}
#endif // MAPNIK_MARKERS_PLACEMENTS_VERTEXT_FIRST_HPP

View file

@ -0,0 +1,103 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2014 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
*
*****************************************************************************/
#ifndef MAPNIK_MARKERS_PLACEMENTS_VERTEXT_LAST_HPP
#define MAPNIK_MARKERS_PLACEMENTS_VERTEXT_LAST_HPP
#include <mapnik/markers_placements/point.hpp>
namespace mapnik {
template <typename Locator, typename Detector>
class markers_vertex_last_placement : public markers_point_placement<Locator, Detector>
{
public:
markers_vertex_last_placement(
Locator &locator,
box2d<double> const& size,
agg::trans_affine const& tr,
Detector &detector,
double spacing,
double max_error,
bool allow_overlap)
: markers_point_placement<Locator, Detector>(
locator, size, tr, detector,
spacing, max_error, allow_overlap)
{
}
bool get_point(double &x, double &y, double &angle, bool ignore_placement)
{
if (this->done_)
{
return false;
}
double next_x, next_y;
double x0, y0;
double x1, y1;
unsigned command0, command1 = agg::path_cmd_stop;
while (!agg::is_stop(command0 = this->locator_.vertex(&next_x, &next_y)))
{
command1 = command0;
x1 = x0;
y1 = y0;
x0 = next_x;
y0 = next_y;
}
// If path stopped on the very firts vertex.
if (agg::is_stop(command1))
{
this->done_ = true;
return false;
}
x = x0;
y = y0;
if (agg::is_line_to(command1))
{
angle = std::atan2(y0 - y1, x0 - x1);
}
box2d<double> box = this->perform_transform(angle, x, y);
if (!this->allow_overlap_ && !this->detector_.has_placement(box))
{
return false;
}
if (!ignore_placement)
{
this->detector_.insert(box);
}
this->done_ = true;
return true;
}
};
}
#endif // MAPNIK_MARKERS_PLACEMENTS_VERTEXT_LAST_HPP

View file

@ -102,6 +102,8 @@ enum marker_placement_enum
MARKER_POINT_PLACEMENT,
MARKER_INTERIOR_PLACEMENT,
MARKER_LINE_PLACEMENT,
MARKER_VERTEX_FIRST_PLACEMENT,
MARKER_VERTEX_LAST_PLACEMENT,
marker_placement_enum_MAX
};

View file

@ -65,6 +65,8 @@ static const char * marker_placement_strings[] = {
"point",
"interior",
"line",
"vertex-first",
"vertex-last",
""
};