mapbox-gl-native icon indicating copy to clipboard operation
mapbox-gl-native copied to clipboard

getAnnotationsInBounds not returning in bounds annotations

Open tobrun opened this issue 10 years ago • 11 comments

Prior

In the Android release 3.1.0 we made the touch target of touch event smaller #3156.

2d48ad00-be8c-11e5-94a4-57b2f20b8cd8

This was needed to be able to properly select annotations when they are just side by side.

screen shot 2016-01-21 at 10 22 47

See the result from that issue here.

Issue

While making touch target smaller was great for selecting annotations side by side. It did make selecting annotations in general more difficult. I believe the source of this problem can be found in C++ implementation of getAnnotationsInBounds.

Visual

In next screenshot I visualised the BoundingBox passed to the getAnnotationsInBounds:

screen shot 2016-01-21 at 10 39 54

In that case an InfoWindow is not shown because getAnnotationsInBounds returns an empty list.

More examples shown in this clip.

Problem

I'm currently not sure where to pinpoint this on:

  • Is the C++ code not taking the size of the Marker image in account? only the base of the marker?
  • Is the C++ code not taking in account the current zoom level when determining?
  • Should the java code calculate a different bounding box based on zoom level?

tobrun avatar Jan 21 '16 09:01 tobrun

Let's take a trip down to C++ land and figure this out:

  • getAnnotationsInBounds() is calling nativeGetAnnotationsInBounds() in jni.cpp
  • nativeGetAnnotationsInBounds() is calling getMap().getPointAnnotationsInBounds() on native_map_view.cpp / map.cpp
  • getPointsAnnotationsInBounds() is calling getPointAnnotationsInBounds in annotation_manager.cpp
AnnotationIDs AnnotationManager::getPointAnnotationsInBounds(const LatLngBounds& bounds) const {
    AnnotationIDs result;

    pointTree.query(boost::geometry::index::intersects(bounds),
        boost::make_function_output_iterator([&](const auto& val){
            result.push_back(val->id);
        }));

    return result;
}

The code above is used for all annotations and doesn't take in account the height/width of a Marker icon.

tobrun avatar Jan 21 '16 14:01 tobrun

As mentioned in the follow up ticket, we should look into fixing this at the Android SDK level by introducing appropriate padding. We used to do fixed padding but that is not the way iOS or OS X are handling this.

tobrun avatar Mar 03 '16 06:03 tobrun

To resolve above I will calculate the average width and average height of a marker icon and take that in account when calculation the touch area.

tobrun avatar Mar 05 '16 14:03 tobrun

I initially wanted to manage this in IconFactory, but this will indicate the average will be used in all maps in one application. The average should only be used per map.

tobrun avatar Mar 05 '16 15:03 tobrun

I'm starting to understand why I was not really able to get the same ux with the default marker vs custom:

screen shot 2016-03-05 at 11 01 32

This should be changed to a normal image as a end developer would also use.

tobrun avatar Mar 05 '16 16:03 tobrun

After changing the default marker image, the markers are placed to low on the map. To workaround this I used setTopOffsetPixels with the height of the marker. In the same way an end developer would do.

tobrun avatar Mar 05 '16 16:03 tobrun

It seems I'm currently not able to use setTopOffsetPixels.. this is one adjustment needed for dynamic marker support.

tobrun avatar Mar 05 '16 16:03 tobrun

Since there are a lot of moving pieces and this fits more in the story of 4.1.0, I'm going to postpone this.

tobrun avatar Mar 05 '16 16:03 tobrun

Hope this will be released soon.

vfaSonnt avatar Mar 31 '16 06:03 vfaSonnt

The idea here is to add a fixed amount of padding + an average padding calculated from all the different icons used. For the default icon (that has extra whitespace to work around not having the anchor method from #2916) I'm just subtracting the whitespace from it before calculating the average padding (iOS is doing the same).

tobrun avatar Apr 06 '16 10:04 tobrun

The calculated padding in action: https://www.dropbox.com/s/f6do1utnqdad4sm/device-2016-04-06-121147.mp4?dl=0

and the side-by-side selection in action: https://www.dropbox.com/s/h8knv67kz7qkrlk/device-2016-04-06-121603.mp4?dl=0

tobrun avatar Apr 06 '16 10:04 tobrun