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

Feature querying ignores antimeridian (was: MGLAnnotationView flickers if annotations are around the antimeridian) #10479

Closed
captainbarbosa opened this issue Nov 16, 2017 · 5 comments
Labels
archived Archived because of inactivity bug Core The cross-platform C++ core, aka mbgl querying Issues with querySourceFeatures or queryRenderedFeatures

Comments

@captainbarbosa
Copy link
Contributor

captainbarbosa commented Nov 16, 2017

Platform: iOS
Mapbox SDK version: 3.6.4, 3.7.0-rc.1

When placing MGLAnnotationViews on a map that closely straddle both sides of the antimeridian, the annotations flicker when zooming/panning.

  • The issue is not seen if MGLAnnotationViews are replaced with MGLAnnotationImage.
  • The issue is not seen if the MGLAnnotationViews reside on one side of the antimeridian.

Steps to trigger behavior

  1. Create annotations that straddle the antimeridian on both sides
Coordinates used for annotations:
let coordinates = [CLLocationCoordinate2D(latitude: 28, longitude: -177),
          CLLocationCoordinate2D(latitude: 30.0, longitude: -178.0),
          CLLocationCoordinate2D(latitude: 35.0, longitude: 180.0),
          CLLocationCoordinate2D(latitude: 40.0, longitude: 175.0),
          CLLocationCoordinate2D(latitude: 45.0, longitude: 170.0),
          CLLocationCoordinate2D(latitude: 46.0, longitude: 170.0),
          CLLocationCoordinate2D(latitude: 51, longitude: 175),
          CLLocationCoordinate2D(latitude: 52, longitude: 174)]
  1. Zoom/pan map

  2. Observe flickering

Expected behavior

MGLAnnotationView should not flicker when zooming and panning on the map.

Actual behavior

MGLAnnotationView flickers when zooming and panning on the map.

giphy 7

@captainbarbosa captainbarbosa added bug iOS Mapbox Maps SDK for iOS labels Nov 16, 2017
@ericdeveloper
Copy link

ericdeveloper commented Dec 19, 2017

I tested this in 3.7 using a circle and symbol layer to see if we could provide a workaround. While the individual annotations didn't flicker, the entire tiles appeared to flicker at the antimeridian. Trying the same with just the base map displays the same behavior.
dec-19-2017 13-43-25

@1ec5
Copy link
Contributor

1ec5 commented Dec 19, 2017

entire tiles appeared to flicker at the antimeridian

@ericdeveloper, I would imagine that’s a separate issue, since it occurs even in the absence of annotations.

@1ec5
Copy link
Contributor

1ec5 commented Dec 19, 2017

I believe the root cause of the original issue above is that, in mbgl, the assumption is that a bbox straddling the antimeridian would have one side beyond ±180° longitude. But mbgl::TilePyramid::queryRenderedFeatures independently converts each screen coordinate in the query’s bounding polygon to a geographic coordinate:

return impl->queryRenderedFeatures(
{
box.min,
{box.max.x, box.min.y},
box.max,
{box.min.x, box.max.y},
box.min
},
options
);

for (const auto& p : geometry) {
queryGeometry.push_back(TileCoordinate::fromScreenCoordinate(
transformState, 0, { p.x, transformState.getSize().height - p.y }).p);
}
mapbox::geometry::box<double> box = mapbox::geometry::envelope(queryGeometry);
std::vector<std::reference_wrapper<const RenderTile>> sortedTiles{ renderTiles.begin(),
renderTiles.end() };
std::sort(sortedTiles.begin(), sortedTiles.end(), [](const RenderTile& a, const RenderTile& b) {
return std::tie(a.id.canonical.z, a.id.canonical.y, a.id.wrap, a.id.canonical.x) <
std::tie(b.id.canonical.z, b.id.canonical.y, b.id.wrap, b.id.canonical.x);
});

mbgl::TilePyramid::queryRenderedFeatures needs to add 180° to any converted coordinate that’s on a different hemisphere (has a differently signed longitude) than the first coordinate.

The reason this only affects annotation views is that non-view-backed annotations (MGLAnnotationImage) and symbol layers don’t rely on feature querying to determine whether to show a given marker. But if you were to use feature querying on a symbol layer, for example to implement interactivity, you’d run into the same problem of symbols becoming non-interactive near the antimeridian.

/ref #4664 #9731 mapbox/mapbox-gl-js#2321
/cc @kkaefer

@1ec5 1ec5 changed the title MGLAnnotationView flickers if annotations are around the antimeridian Feature querying ignores antimeridian (was: MGLAnnotationView flickers if annotations are around the antimeridian) Dec 19, 2017
@1ec5 1ec5 added Core The cross-platform C++ core, aka mbgl and removed iOS Mapbox Maps SDK for iOS labels Dec 19, 2017
@kkaefer kkaefer added querying Issues with querySourceFeatures or queryRenderedFeatures and removed querying Issues with querySourceFeatures or queryRenderedFeatures labels Sep 25, 2018
@stale stale bot added the archived Archived because of inactivity label Mar 24, 2019
@stale
Copy link

stale bot commented Mar 25, 2019

This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

@stale stale bot closed this as completed Mar 25, 2019
@julianrex julianrex reopened this Mar 26, 2019
@stale stale bot removed the archived Archived because of inactivity label Mar 26, 2019
@stale stale bot added the archived Archived because of inactivity label Sep 22, 2019
@stale
Copy link

stale bot commented Sep 22, 2019

This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

@stale stale bot closed this as completed Sep 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived Archived because of inactivity bug Core The cross-platform C++ core, aka mbgl querying Issues with querySourceFeatures or queryRenderedFeatures
Projects
None yet
Development

No branches or pull requests

5 participants