-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[core] geometry@0.8.0 / geojsonvt@6.0.0 #5514
Conversation
@@ -12,6 +12,16 @@ enum class FeatureType : uint8_t { | |||
Polygon = 3 | |||
}; | |||
|
|||
struct ToFeatureType { | |||
FeatureType operator()(mapbox::geometry::point<int16_t>) const { return FeatureType::Point; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should all take their argument as const __ &
to avoid copying, and use the CamelCase aliases defined below.
mapbox::geojsonvt::Options options; | ||
options.maxZoom = maxZoom; | ||
options.maxZoom = mbgl::util::clamp((int)maxZoom, 0, 18); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shape annotation tests were failing without this clamp -- the maxZoom
passed here is the map's mapZoom (20). I need to dig further in master to understand what's changed (was geojson-vt-cpp clamping this?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
util::clamp<uint8_t>(maxZoom, 0, 18)
@brunoabinader can you check if this fixes that maxZoom issue? |
return; | ||
|
||
AnnotationTileLayer& layer = *data.layers.emplace(layerID, | ||
std::make_unique<AnnotationTileLayer>(layerID)).first->second; | ||
|
||
ToGeometryCollection toGeometryCollection; | ||
ToFeatureType toFeatureType; | ||
for (auto& shapeFeature : shapeTile.features) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can replace this auto&
with a const auto&
.
Just did a rebase of my patches from #5517 on top of this branch. I removed the zoom clamping introduced by @yhahn otherwise the app crashes inside GeoJSONVT's
Although the unit test I introduce passes (all zoom levels returns non-empty features when queried with This comes along with a console filled with |
3bb5010
to
b851c94
Compare
421d0e1
to
ebd29c1
Compare
Once 🍏 this PR will be ready for another review! Here are some known issues/open questions remaining:
Strictness changesDetermine what to do about two known API behavior changes:
Question: do we need to smooth these changes out for developers or should we nudge them toward more strictness? |
What that the rendering issue you were seeing earlier? For the annotations API, it would be easy enough to close any unclosed polygon rings, right?
Note that features with |
Yes. I started to poke at this but it looks like a slippery slope to me -- we would need to add an early closed-ring validator + corrector for fixing any polygons/multipolygons (ie. before shape annotations are passed to
Yep, this condition is handled properly. |
After re-reading the discussion on #5517 I think we should land this first (get fully up to date on |
return mapbox::geojson::feature_collection { value }; | ||
} | ||
mapbox::geojson::feature_collection operator()(const mapbox::geojson::geometry value) const { | ||
return mapbox::geojson::feature_collection { { value } }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C++ should deduct the return type so this can be just return { ... }
, right?
Looked through the code and this looks great to me! Looking forward to this being merged. I'll follow-up with supercluster.hpp integration after that. |
@@ -18,14 +20,30 @@ using namespace mapbox::geojsonvt; | |||
namespace mbgl { | |||
namespace style { | |||
namespace conversion { | |||
|
|||
struct ToFeatureCollection { | |||
mapbox::geojson::feature_collection operator()(const mapbox::geojson::feature_collection value) const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The value
in each visitor here could be passed by const &
to avoid an unneeded copy. That said, the compiler will likely optimize away the copy so its not certain my suggestion will run any faster.
My sense is this will be an unexpected / breaking change for users and we should retain the loose API for annotations. We've never documented the annotations API as requiring closed rings or strict GeoJSON geometry.
In contrast this seems like an acceptable change. It's reasonable to require a GeoJSON source have valid GeoJSON data. Making the parser more conformant can be construed as a bug fix. And use of GeoJSON sources is low in any case. |
ToFeatureCollection toFeatureCollection; | ||
const auto geojson = mapbox::geojson::convert(value); | ||
const auto features = apply_visitor(toFeatureCollection, geojson); | ||
return GeoJSON { std::make_unique<GeoJSONVT>(features, options) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's awkward to be unable to directly compose mapbox::geojson::convert
and mapbox::GeoJSONVT::GeoJSONVT
. We should add a GeoJSONVT
constructor that accepts mapbox::util::variant<geometry, feature, feature_collection>
. cc @mourner
GeometryCoordinates coordinates; | ||
coordinates.reserve(geom.size()); | ||
for (const auto& point : geom) { | ||
coordinates.emplace_back(point.x, point.y); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/emplace_back(point.x, point.y)/emplace_back(point)/g
This is fine from the iOS and macOS SDKs’ perspective: for compatibility with MapKit, we’ve documented a requirement that MGLPolygon be closed, and the behavior is undefined otherwise. |
@jfirebaugh ready whenever you have a chance for another 👀 Only major change besides the cleanup from notes is the addition of the ring-closer for fill annotations: |
Ring closing should only apply to polygons and multipolygons, not line strings. |
Since #5514, feature IDs may be integers, unsigned integers, floating-point numbers, or strings, not just unsigned integers.
8ca8e2c updates the MGLFeature documentation in the iOS and macOS SDKs to reflect the fact that a feature identifier may be one of several types, not necessarily an NSNumber. We deliberately made the identifier as broadly typed as possible ( |
geometry.hpp
-based geojsonvt.geometry-0.8.0