Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Polylabel-based "pole of inaccessibility" symbol placement
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Dec 16, 2016
1 parent da7486b commit bc6e768
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions cmake/core.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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#d30b002b39507925d4f0ee9e20f58685b3b5af30",
"mkdirp": "^0.5.1",
"node-cmake": "^1.2.1",
"pixelmatch": "^4.0.2",
Expand Down
20 changes: 15 additions & 5 deletions src/mbgl/layout/symbol_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <mbgl/util/platform.hpp>
#include <mbgl/util/logging.hpp>

#include <mapbox/polylabel.hpp>

namespace mbgl {

using namespace style;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit bc6e768

Please sign in to comment.