|
| 1 | +/***************************************************************************** |
| 2 | + * |
| 3 | + * This file is part of Mapnik (c++ mapping toolkit) |
| 4 | + * |
| 5 | + * Copyright (C) 2017 Artem Pavlenko |
| 6 | + * |
| 7 | + * This library is free software; you can redistribute it and/or |
| 8 | + * modify it under the terms of the GNU Lesser General Public |
| 9 | + * License as published by the Free Software Foundation; either |
| 10 | + * version 2.1 of the License, or (at your option) any later version. |
| 11 | + * |
| 12 | + * This library is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | + * Lesser General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU Lesser General Public |
| 18 | + * License along with this library; if not, write to the Free Software |
| 19 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | + * |
| 21 | + *****************************************************************************/ |
| 22 | + |
| 23 | +#ifndef MAPNIK_MARKERS_PLACEMENTS_POLYLABEL_HPP |
| 24 | +#define MAPNIK_MARKERS_PLACEMENTS_POLYLABEL_HPP |
| 25 | + |
| 26 | +#include <mapnik/markers_placements/point.hpp> |
| 27 | +#include <mapnik/geom_util.hpp> |
| 28 | +#include <mapnik/geometry/geometry_types.hpp> |
| 29 | +#include <mapnik/geometry/polygon_vertex_processor.hpp> |
| 30 | + |
| 31 | +#include <mapnik/geometry/point.hpp> |
| 32 | +#include <mapnik/geometry/polylabel.hpp> |
| 33 | + |
| 34 | +namespace mapnik { |
| 35 | + |
| 36 | +template <typename Locator, typename Detector> |
| 37 | +class markers_polylabel_placement : public markers_point_placement<Locator, Detector> |
| 38 | +{ |
| 39 | +public: |
| 40 | + using point_placement = markers_point_placement<Locator, Detector>; |
| 41 | + using point_placement::point_placement; |
| 42 | + |
| 43 | + bool get_point(double &x, double &y, double &angle, bool ignore_placement) |
| 44 | + { |
| 45 | + if (this->done_) |
| 46 | + { |
| 47 | + return false; |
| 48 | + } |
| 49 | + |
| 50 | + if (this->locator_.type() != geometry::geometry_types::Polygon) |
| 51 | + { |
| 52 | + return point_placement::get_point(x, y, angle, ignore_placement); |
| 53 | + } |
| 54 | + |
| 55 | + geometry::polygon_vertex_processor<double> vertex_processor; |
| 56 | + vertex_processor.add_path(this->locator_); |
| 57 | + double precision = geometry::polylabel_precision(vertex_processor.polygon_, |
| 58 | + this->params_.scale_factor); |
| 59 | + geometry::point<double> placement = geometry::polylabel(vertex_processor.polygon_, precision); |
| 60 | + |
| 61 | + x = placement.x; |
| 62 | + y = placement.y; |
| 63 | + angle = 0; |
| 64 | + |
| 65 | + if (!this->push_to_detector(x, y, angle, ignore_placement)) |
| 66 | + { |
| 67 | + return false; |
| 68 | + } |
| 69 | + |
| 70 | + this->done_ = true; |
| 71 | + return true; |
| 72 | + } |
| 73 | +}; |
| 74 | + |
| 75 | +} |
| 76 | + |
| 77 | +#endif // MAPNIK_MARKERS_PLACEMENTS_POLYLABEL_HPP |
0 commit comments