diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-12-15 17:57:50 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-12-21 13:42:30 -0800 |
commit | bcf2c3ff9e02b1ab11c41824ac8c13aafeae9ffa (patch) | |
tree | 776c1e5ecbe5e595d10d162f9870bc9845708bfe /src | |
parent | 8d52806cbb1893f68e49604d6065f4ca5820232e (diff) | |
download | qtlocation-mapboxgl-bcf2c3ff9e02b1ab11c41824ac8c13aafeae9ffa.tar.gz |
[core] Polylabel-based "pole of inaccessibility" symbol placement
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/layout/symbol_layout.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp index 7be2c13ada..387bb7fb00 100644 --- a/src/mbgl/layout/symbol_layout.cpp +++ b/src/mbgl/layout/symbol_layout.cpp @@ -20,6 +20,8 @@ #include <mbgl/util/platform.hpp> #include <mbgl/util/logging.hpp> +#include <mapbox/polylabel.hpp> + namespace mbgl { using namespace style; @@ -301,12 +303,20 @@ void SymbolLayout::addFeature(const SymbolFeature& feature, } } } else if (feature.type == FeatureType::Polygon) { - // TODO: pole of inaccessibility - for (const auto& ring : feature.geometry) { - for (const auto& point : ring) { - Anchor anchor(point.x, point.y, 0, minScale); - addSymbolInstance(ring, anchor); + for (const auto& polygon : classifyRings(feature.geometry)) { + Polygon<double> poly; + for (const auto& ring : polygon) { + LinearRing<double> r; + for (const auto& p : ring) { + r.push_back(convertPoint<double>(p)); + } + poly.push_back(r); } + + // 16 here represents 2 pixels + auto poi = mapbox::polylabel(poly, 16.0); + Anchor anchor(poi.x, poi.y, 0, minScale); + addSymbolInstance(polygon[0], anchor); } } else if (feature.type == FeatureType::LineString) { for (const auto& line : feature.geometry) { |