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

Sprite location appears to move when map is zoomed in and out

Open picciano opened this issue 11 years ago • 16 comments

The default marker has a visual indication of a pointer, however the sprite is centered above the annotations location. Because of this, the marker appears to point to different locations as the map is zoomed in and out. Possible solution, the sprite data should contain an offset location to indicate the "visual" center of the image.

picciano avatar Mar 26 '15 19:03 picciano

The default marker, like our markers API, uses a partially-transparent image where the point of the pin is actually at the image center. So this shouldn't be happening?

incanus avatar Mar 26 '15 19:03 incanus

Here is a quick example. The marker is at a fixed lat/lon, only the map zoom is changed. As you can see, the marker sometime appears to point north of the road when zoomed in, but south of the road when zoomed out. Obviously, the more extreme the zooming, the more obvious the discrepancy.

But I do agree with your reasoning that this should not be happening.

ios simulator screen shot mar 26 2015 1 20 10 pm ios simulator screen shot mar 26 2015 1 19 59 pm

picciano avatar Mar 26 '15 19:03 picciano

Hmm, weird. This is in GL, so it shouldn't be a sync or screen conversion issue. Will check on the sprite centering etc.

incanus avatar Mar 26 '15 19:03 incanus

I suspect it may be an @2x issue when calculating the image size or center point. The same this happens with our custom marker when I adjust the height so the the point "should" be in the center.

screen shot 2015-03-26 at 1 33 28 pm

picciano avatar Mar 26 '15 19:03 picciano

Here’s an interesting experiment: place the pin directly atop a label, such that the visual tip of the pin pierces the label. Center the map on the pin. Then zoom out slowly. The pin and label are in sync as they both begin to drift. Below, the label “Emerald” should be near the center of the station building, but as you zoom out it wanders onto the tracks:

drift

/cc @ansis

1ec5 avatar Mar 27 '15 22:03 1ec5

Well, that's interesting. I don't know offhand how labels' anchor points are specified, but it would seem that whatever is wrong affects them both. I'm not sure if it's problematic for labels, but it definitely proves the bug for points.

/cc @ansis

incanus avatar Mar 27 '15 22:03 incanus

What is the style for this point's layer? the point and icon are in gl-land right?

ansis avatar Mar 27 '15 23:03 ansis

@ansis It's made on the fly here:

https://github.com/mapbox/mapbox-gl-native/blob/5c6809fc367416268794be0445ae17f23bb2cb8f/src/mbgl/style/style_parser.cpp#L34-L63

incanus avatar Mar 27 '15 23:03 incanus

Ha, this was a sprite size specification miscomm between @peterqliu and I. Check out old vs. new, where new specifies that the marker was twice as tall, encompassing the blank space at the bottom like Maki markers do, so that the point of the marker is in the image center:

anigif-1427925807

The "point" actually switches sides of the street and the latter, north-side one is correct — and doesn't move.

@peterqliu's rolling some style updates including this to fix now.

incanus avatar Apr 01 '15 22:04 incanus

Slider quick-zooming test code for later: https://gist.github.com/incanus/5638f2466416b9c4ed57

incanus avatar Apr 01 '15 22:04 incanus

Hmm, are you saying that we changed the marker image to contain blank space at the bottom? Let's not do that -- it was a mistake in our markers API / mapbox.js that we shouldn't repeat.

jfirebaugh avatar Apr 01 '15 22:04 jfirebaugh

We then need to communicate a marker offset in the sprite JSON back to the code so that it knows how to place the marker — its style is created on-the-fly in code and we shouldn't require the user to specify an offset at runtime when they specify an image. It makes an already-clumsy stopgap marker method that much more clumsy.

I looked into adding an offset property in the sprite JSON but it seemed like high overhead for a holdover method of annotation styling.

incanus avatar Apr 01 '15 22:04 incanus

I don't think a sprite JSON property is required -- the intended way to do this type of relative positioning of symbol icons is via the style properties icon-translate and icon-translate-anchor: viewport. Can you ticket this as a post-beta 1 issue?

jfirebaugh avatar Apr 01 '15 23:04 jfirebaugh

My point is twofold:

  1. Specifying style properties at runtime for each marker is awkward when the imagery is already put into the sprite sheet statically before runtime. For b1 we are telling the user to add a marker and specify e.g. default_marker as the marker to use at runtime. We don't also want them to have to know anything in code about the translation properties of this image and/or pass those as well, either per-marker or at map setup time with some sort of registration for each marker image being used. It just makes an awkward holdover API more awkward.
  2. Post-beta 1, we will hopefully be passing bitmap imagery across the wire instead of relying on pre-made sprite sheets, so this point is moot. At that point, since you are supplying imagery at runtime (which might be created on-the-fly anyway), passing things like calloutOffset and centerOffset is much more natural.

incanus avatar Apr 01 '15 23:04 incanus

:+1:, makes sense. Thanks for the explanation.

jfirebaugh avatar Apr 02 '15 00:04 jfirebaugh

Fixed in @peterqliu's Emerald sprite update in 523295af7eb591b364fa721191cd96a031106914.

incanus avatar Apr 02 '15 00:04 incanus