summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-12-15 17:57:50 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-12-21 13:42:30 -0800
commitbcf2c3ff9e02b1ab11c41824ac8c13aafeae9ffa (patch)
tree776c1e5ecbe5e595d10d162f9870bc9845708bfe
parent8d52806cbb1893f68e49604d6065f4ca5820232e (diff)
downloadqtlocation-mapboxgl-bcf2c3ff9e02b1ab11c41824ac8c13aafeae9ffa.tar.gz
[core] Polylabel-based "pole of inaccessibility" symbol placement
-rw-r--r--CMakeLists.txt1
-rw-r--r--cmake/core.cmake1
-rw-r--r--package.json2
-rw-r--r--src/mbgl/layout/symbol_layout.cpp20
4 files changed, 18 insertions, 6 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f0f3d80cb6..28778ed58a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -52,6 +52,7 @@ mason_use(earcut VERSION 0.12.1 HEADER_ONLY)
mason_use(protozero VERSION 1.4.2 HEADER_ONLY)
mason_use(pixelmatch VERSION 0.10.0 HEADER_ONLY)
mason_use(geojson VERSION 0.4.0 HEADER_ONLY)
+mason_use(polylabel VERSION 1.0.2 HEADER_ONLY)
if(WITH_COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
diff --git a/cmake/core.cmake b/cmake/core.cmake
index bc5e7eb718..8d8a942d9f 100644
--- a/cmake/core.cmake
+++ b/cmake/core.cmake
@@ -45,6 +45,7 @@ target_add_mason_package(mbgl-core PRIVATE supercluster)
target_add_mason_package(mbgl-core PRIVATE kdbush)
target_add_mason_package(mbgl-core PRIVATE earcut)
target_add_mason_package(mbgl-core PRIVATE protozero)
+target_add_mason_package(mbgl-core PRIVATE polylabel)
mbgl_platform_core()
diff --git a/package.json b/package.json
index f99653d184..c32bdd8032 100644
--- a/package.json
+++ b/package.json
@@ -24,7 +24,7 @@
"lodash": "^4.16.4",
"mapbox-gl": "mapbox/mapbox-gl-js#ab836206d415ca3a74257a3066d11a54ab2838cb",
"mapbox-gl-style-spec": "mapbox/mapbox-gl-style-spec#49e8b407bdbbe6f7c92dbcb56d3d51f425fc2653",
- "mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#e1ada02a706fd124fc3441fd3a2b3cda67960ff5",
+ "mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#da53a81453068f4c2b440f9077d6bd5e7e14ff3d",
"mkdirp": "^0.5.1",
"node-cmake": "^1.2.1",
"pixelmatch": "^4.0.2",
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) {