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

CP changes to release-boba #11989

Merged
merged 6 commits into from
May 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,28 +96,30 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
@UiThread
public MapView(@NonNull Context context) {
super(context);
initialise(context, MapboxMapOptions.createFromAttributes(context, null));
initialize(context, MapboxMapOptions.createFromAttributes(context, null));
}

@UiThread
public MapView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
initialise(context, MapboxMapOptions.createFromAttributes(context, attrs));
initialize(context, MapboxMapOptions.createFromAttributes(context, attrs));
}

@UiThread
public MapView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initialise(context, MapboxMapOptions.createFromAttributes(context, attrs));
initialize(context, MapboxMapOptions.createFromAttributes(context, attrs));
}

@UiThread
public MapView(@NonNull Context context, @Nullable MapboxMapOptions options) {
super(context);
initialise(context, options == null ? MapboxMapOptions.createFromAttributes(context, null) : options);
initialize(context, options == null ? MapboxMapOptions.createFromAttributes(context, null) : options);
}

private void initialise(@NonNull final Context context, @NonNull final MapboxMapOptions options) {
@CallSuper
@UiThread
protected void initialize(@NonNull final Context context, @NonNull final MapboxMapOptions options) {
if (isInEditMode()) {
// in IDE layout editor, just return
return;
Expand Down
2 changes: 1 addition & 1 deletion platform/android/gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ext {

versions = [
mapboxServices : '3.0.1',
mapboxTelemetry: '3.1.1',
mapboxTelemetry: '3.1.2',
mapboxGestures : '0.2.0',
supportLib : '25.4.0',
espresso : '3.0.1',
Expand Down
18 changes: 18 additions & 0 deletions platform/node/test/ignores.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
{
"expression-tests/collator/accent-equals-de": "https://github.com/mapbox/mapbox-gl-native/issues/11692",
"expression-tests/collator/accent-lt-en": "https://github.com/mapbox/mapbox-gl-native/issues/11692",
"expression-tests/collator/accent-not-equals-en": "https://github.com/mapbox/mapbox-gl-native/issues/11692",
"expression-tests/collator/base-default-locale": "https://github.com/mapbox/mapbox-gl-native/issues/11692",
"expression-tests/collator/base-equals-en": "https://github.com/mapbox/mapbox-gl-native/issues/11692",
"expression-tests/collator/base-gt-en": "https://github.com/mapbox/mapbox-gl-native/issues/11692",
"expression-tests/collator/case-lteq-en": "https://github.com/mapbox/mapbox-gl-native/issues/11692",
"expression-tests/collator/case-not-equals-en": "https://github.com/mapbox/mapbox-gl-native/issues/11692",
"expression-tests/collator/case-omitted-en": "https://github.com/mapbox/mapbox-gl-native/issues/11692",
"expression-tests/collator/comparison-number-error": "https://github.com/mapbox/mapbox-gl-native/issues/11692",
"expression-tests/collator/diacritic-omitted-en": "https://github.com/mapbox/mapbox-gl-native/issues/11692",
"expression-tests/collator/equals-non-string-error": "https://github.com/mapbox/mapbox-gl-native/issues/11692",
"expression-tests/collator/non-object-error": "https://github.com/mapbox/mapbox-gl-native/issues/11692",
"expression-tests/collator/variant-equals-en": "https://github.com/mapbox/mapbox-gl-native/issues/11692",
"expression-tests/collator/variant-gteq-en": "https://github.com/mapbox/mapbox-gl-native/issues/11692",
"expression-tests/is-supported-script/default": "https://github.com/mapbox/mapbox-gl-native/issues/11693",
"expression-tests/resolved-locale/basic": "https://github.com/mapbox/mapbox-gl-native/issues/11692",
"expression-tests/to-string/basic": "https://github.com/mapbox/mapbox-gl-native/issues/11719",
"query-tests/circle-pitch-scale/viewport-inside-align-map": "https://github.com/mapbox/mapbox-gl-native/issues/10615",
"query-tests/circle-pitch-scale/viewport-inside-align-viewport": "https://github.com/mapbox/mapbox-gl-native/issues/10615",
"query-tests/edge-cases/box-cutting-antimeridian-z0": "https://github.com/mapbox/mapbox-gl-native/issues/11607",
Expand Down
5 changes: 3 additions & 2 deletions src/mbgl/annotation/render_annotation_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ std::unordered_map<std::string, std::vector<Feature>>
RenderAnnotationSource::queryRenderedFeatures(const ScreenLineString& geometry,
const TransformState& transformState,
const std::vector<const RenderLayer*>& layers,
const RenderedQueryOptions& options) const {
return tilePyramid.queryRenderedFeatures(geometry, transformState, layers, options);
const RenderedQueryOptions& options,
const mat4& projMatrix) const {
return tilePyramid.queryRenderedFeatures(geometry, transformState, layers, options, projMatrix);
}

std::vector<Feature> RenderAnnotationSource::querySourceFeatures(const SourceQueryOptions&) const {
Expand Down
3 changes: 2 additions & 1 deletion src/mbgl/annotation/render_annotation_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class RenderAnnotationSource : public RenderSource {
queryRenderedFeatures(const ScreenLineString& geometry,
const TransformState& transformState,
const std::vector<const RenderLayer*>& layers,
const RenderedQueryOptions& options) const final;
const RenderedQueryOptions& options,
const mat4& projMatrix) const final;

std::vector<Feature>
querySourceFeatures(const SourceQueryOptions&) const final;
Expand Down
32 changes: 20 additions & 12 deletions src/mbgl/geometry/feature_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,40 @@ void FeatureIndex::insert(const GeometryCollection& geometries,
const std::string& bucketName) {
for (const auto& ring : geometries) {
auto envelope = mapbox::geometry::envelope(ring);
grid.insert(IndexedSubfeature(index, sourceLayerName, bucketName, sortIndex++),
{convertPoint<float>(envelope.min), convertPoint<float>(envelope.max)});
if (envelope.min.x < util::EXTENT &&
envelope.min.y < util::EXTENT &&
envelope.max.x >= 0 &&
envelope.max.y >= 0) {
grid.insert(IndexedSubfeature(index, sourceLayerName, bucketName, sortIndex++),
{convertPoint<float>(envelope.min), convertPoint<float>(envelope.max)});
}
}
}

void FeatureIndex::query(
std::unordered_map<std::string, std::vector<Feature>>& result,
const GeometryCoordinates& queryGeometry,
const float bearing,
const TransformState& transformState,
const mat4& posMatrix,
const double tileSize,
const double scale,
const RenderedQueryOptions& queryOptions,
const UnwrappedTileID& tileID,
const std::vector<const RenderLayer*>& layers,
const float additionalQueryRadius) const {
const float additionalQueryPadding) const {

if (!tileData) {
return;
}

// Determine query radius
const float pixelsToTileUnits = util::EXTENT / tileSize / scale;
const int16_t additionalRadius = std::min<int16_t>(util::EXTENT, additionalQueryRadius * pixelsToTileUnits);
const int16_t additionalPadding = std::min<int16_t>(util::EXTENT, additionalQueryPadding * pixelsToTileUnits);

// Query the grid index
mapbox::geometry::box<int16_t> box = mapbox::geometry::envelope(queryGeometry);
std::vector<IndexedSubfeature> features = grid.query({ convertPoint<float>(box.min - additionalRadius),
convertPoint<float>(box.max + additionalRadius) });
std::vector<IndexedSubfeature> features = grid.query({ convertPoint<float>(box.min - additionalPadding),
convertPoint<float>(box.max + additionalPadding) });


std::sort(features.begin(), features.end(), [](const IndexedSubfeature& a, const IndexedSubfeature& b) {
Expand All @@ -67,7 +73,7 @@ void FeatureIndex::query(
if (indexedFeature.sortIndex == previousSortIndex) continue;
previousSortIndex = indexedFeature.sortIndex;

addFeature(result, indexedFeature, queryOptions, tileID.canonical, layers, queryGeometry, bearing, pixelsToTileUnits);
addFeature(result, indexedFeature, queryOptions, tileID.canonical, layers, queryGeometry, transformState, pixelsToTileUnits, posMatrix);
}
}

Expand Down Expand Up @@ -104,7 +110,8 @@ std::unordered_map<std::string, std::vector<Feature>> FeatureIndex::lookupSymbol
});

for (const auto& symbolFeature : sortedFeatures) {
addFeature(result, symbolFeature, queryOptions, tileID.canonical, layers, GeometryCoordinates(), 0, 0);
mat4 unusedMatrix;
addFeature(result, symbolFeature, queryOptions, tileID.canonical, layers, GeometryCoordinates(), {}, 0, unusedMatrix);
}
return result;
}
Expand All @@ -116,8 +123,9 @@ void FeatureIndex::addFeature(
const CanonicalTileID& tileID,
const std::vector<const RenderLayer*>& layers,
const GeometryCoordinates& queryGeometry,
const float bearing,
const float pixelsToTileUnits) const {
const TransformState& transformState,
const float pixelsToTileUnits,
const mat4& posMatrix) const {

auto getRenderLayer = [&] (const std::string& layerID) -> const RenderLayer* {
for (const auto& layer : layers) {
Expand Down Expand Up @@ -147,7 +155,7 @@ void FeatureIndex::addFeature(
}

if (!renderLayer->is<RenderSymbolLayer>() &&
!renderLayer->queryIntersectsFeature(queryGeometry, *geometryTileFeature, tileID.z, bearing, pixelsToTileUnits)) {
!renderLayer->queryIntersectsFeature(queryGeometry, *geometryTileFeature, tileID.z, transformState, pixelsToTileUnits, posMatrix)) {
continue;
}

Expand Down
12 changes: 8 additions & 4 deletions src/mbgl/geometry/feature_index.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <mbgl/tile/tile_id.hpp>
#include <mbgl/util/grid_index.hpp>
#include <mbgl/util/feature.hpp>
#include <mbgl/util/mat4.hpp>

#include <vector>
#include <string>
Expand All @@ -14,6 +15,7 @@ namespace mbgl {

class RenderedQueryOptions;
class RenderLayer;
class TransformState;

class CollisionIndex;

Expand Down Expand Up @@ -56,13 +58,14 @@ class FeatureIndex {
void query(
std::unordered_map<std::string, std::vector<Feature>>& result,
const GeometryCoordinates& queryGeometry,
const float bearing,
const TransformState&,
const mat4& posMatrix,
const double tileSize,
const double scale,
const RenderedQueryOptions& options,
const UnwrappedTileID&,
const std::vector<const RenderLayer*>&,
const float additionalQueryRadius) const;
const float additionalQueryPadding) const;

static optional<GeometryCoordinates> translateQueryGeometry(
const GeometryCoordinates& queryGeometry,
Expand All @@ -88,8 +91,9 @@ class FeatureIndex {
const CanonicalTileID&,
const std::vector<const RenderLayer*>&,
const GeometryCoordinates& queryGeometry,
const float bearing,
const float pixelsToTileUnits) const;
const TransformState& transformState,
const float pixelsToTileUnits,
const mat4& posMatrix) const;

GridIndex<IndexedSubfeature> grid;
unsigned int sortIndex = 0;
Expand Down
13 changes: 13 additions & 0 deletions src/mbgl/map/transform_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,4 +421,17 @@ float TransformState::getCameraToTileDistance(const UnwrappedTileID& tileID) con
return projectedCenter[3];
}

float TransformState::maxPitchScaleFactor() const {
if (size.isEmpty()) {
return {};
}
auto latLng = screenCoordinateToLatLng({ 0, static_cast<float>(getSize().height) });
mat4 mat = coordinatePointMatrix(getZoom());
Point<double> pt = Projection::project(latLng, scale) / double(util::tileSize);
vec4 p = {{ pt.x, pt.y, 0, 1 }};
vec4 topPoint;
matrix::transformMat4(topPoint, p, mat);
return topPoint[3] / getCameraToCenterDistance();
}

} // namespace mbgl
1 change: 1 addition & 0 deletions src/mbgl/map/transform_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class TransformState {
}

float getCameraToTileDistance(const UnwrappedTileID&) const;
float maxPitchScaleFactor() const;

private:
bool rotatedNorth() const;
Expand Down
66 changes: 57 additions & 9 deletions src/mbgl/renderer/layers/render_circle_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,27 +108,75 @@ void RenderCircleLayer::render(PaintParameters& parameters, RenderSource*) {
}
}

GeometryCoordinate projectPoint(const GeometryCoordinate& p, const mat4& posMatrix, const Size& size) {
vec4 pos = {{ static_cast<double>(p.x), static_cast<double>(p.y), 0, 1 }};
matrix::transformMat4(pos, pos, posMatrix);
return {
static_cast<int16_t>((static_cast<float>(pos[0] / pos[3]) + 1) * size.width * 0.5),
static_cast<int16_t>((static_cast<float>(pos[1] / pos[3]) + 1) * size.height * 0.5)
};
}

GeometryCoordinates projectQueryGeometry(const GeometryCoordinates& queryGeometry, const mat4& posMatrix, const Size& size) {
GeometryCoordinates projectedGeometry;
for (auto& p : queryGeometry) {
projectedGeometry.push_back(projectPoint(p, posMatrix, size));
}
return projectedGeometry;
}

bool RenderCircleLayer::queryIntersectsFeature(
const GeometryCoordinates& queryGeometry,
const GeometryTileFeature& feature,
const float zoom,
const float bearing,
const float pixelsToTileUnits) const {
const TransformState& transformState,
const float pixelsToTileUnits,
const mat4& posMatrix) const {

// Translate query geometry
auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry(
const GeometryCoordinates& translatedQueryGeometry = FeatureIndex::translateQueryGeometry(
queryGeometry,
evaluated.get<style::CircleTranslate>(),
evaluated.get<style::CircleTranslateAnchor>(),
bearing,
pixelsToTileUnits);
transformState.getAngle(),
pixelsToTileUnits).value_or(queryGeometry);

// Evaluate functions
auto radius = evaluated.evaluate<style::CircleRadius>(zoom, feature) * pixelsToTileUnits;
auto stroke = evaluated.evaluate<style::CircleStrokeWidth>(zoom, feature) * pixelsToTileUnits;
auto radius = evaluated.evaluate<style::CircleRadius>(zoom, feature);
auto stroke = evaluated.evaluate<style::CircleStrokeWidth>(zoom, feature);
auto size = radius + stroke;

// For pitch-alignment: map, compare feature geometry to query geometry in the plane of the tile
// Otherwise, compare geometry in the plane of the viewport
// A circle with fixed scaling relative to the viewport gets larger in tile space as it moves into the distance
// A circle with fixed scaling relative to the map gets smaller in viewport space as it moves into the distance
bool alignWithMap = evaluated.evaluate<style::CirclePitchAlignment>(zoom, feature) == AlignmentType::Map;
const GeometryCoordinates& transformedQueryGeometry = alignWithMap ?
translatedQueryGeometry :
projectQueryGeometry(translatedQueryGeometry, posMatrix, transformState.getSize());
auto transformedSize = alignWithMap ? size * pixelsToTileUnits : size;

auto geometry = feature.getGeometries();
for (auto& ring : geometry) {
for (auto& point : ring) {
const GeometryCoordinate& transformedPoint = alignWithMap ? point : projectPoint(point, posMatrix, transformState.getSize());

float adjustedSize = transformedSize;
vec4 center = {{ static_cast<double>(point.x), static_cast<double>(point.y), 0, 1 }};
matrix::transformMat4(center, center, posMatrix);
auto pitchScale = evaluated.evaluate<style::CirclePitchScale>(zoom, feature);
auto pitchAlignment = evaluated.evaluate<style::CirclePitchAlignment>(zoom, feature);
if (pitchScale == CirclePitchScaleType::Viewport && pitchAlignment == AlignmentType::Map) {
adjustedSize *= center[3] / transformState.getCameraToCenterDistance();
} else if (pitchScale == CirclePitchScaleType::Map && pitchAlignment == AlignmentType::Viewport) {
adjustedSize *= transformState.getCameraToCenterDistance() / center[3];
}

if (util::polygonIntersectsBufferedPoint(transformedQueryGeometry, transformedPoint, adjustedSize)) return true;
}
}

// Test intersection
return util::polygonIntersectsBufferedMultiPoint(translatedQueryGeometry.value_or(queryGeometry), feature.getGeometries(), radius + stroke);
return false;
}

} // namespace mbgl
3 changes: 2 additions & 1 deletion src/mbgl/renderer/layers/render_circle_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ class RenderCircleLayer: public RenderLayer {
const GeometryCoordinates&,
const GeometryTileFeature&,
const float,
const TransformState&,
const float,
const float) const override;
const mat4&) const override;

std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const override;

Expand Down
7 changes: 4 additions & 3 deletions src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,15 @@ bool RenderFillExtrusionLayer::queryIntersectsFeature(
const GeometryCoordinates& queryGeometry,
const GeometryTileFeature& feature,
const float,
const float bearing,
const float pixelsToTileUnits) const {
const TransformState& transformState,
const float pixelsToTileUnits,
const mat4&) const {

auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry(
queryGeometry,
evaluated.get<style::FillExtrusionTranslate>(),
evaluated.get<style::FillExtrusionTranslateAnchor>(),
bearing,
transformState.getAngle(),
pixelsToTileUnits);

return util::polygonIntersectsMultiPolygon(translatedQueryGeometry.value_or(queryGeometry), feature.getGeometries());
Expand Down
3 changes: 2 additions & 1 deletion src/mbgl/renderer/layers/render_fill_extrusion_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ class RenderFillExtrusionLayer: public RenderLayer {
const GeometryCoordinates&,
const GeometryTileFeature&,
const float,
const TransformState&,
const float,
const float) const override;
const mat4&) const override;

std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const override;

Expand Down
7 changes: 4 additions & 3 deletions src/mbgl/renderer/layers/render_fill_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,15 @@ bool RenderFillLayer::queryIntersectsFeature(
const GeometryCoordinates& queryGeometry,
const GeometryTileFeature& feature,
const float,
const float bearing,
const float pixelsToTileUnits) const {
const TransformState& transformState,
const float pixelsToTileUnits,
const mat4&) const {

auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry(
queryGeometry,
evaluated.get<style::FillTranslate>(),
evaluated.get<style::FillTranslateAnchor>(),
bearing,
transformState.getAngle(),
pixelsToTileUnits);

return util::polygonIntersectsMultiPolygon(translatedQueryGeometry.value_or(queryGeometry), feature.getGeometries());
Expand Down
Loading