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

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

Closed

Description

@picciano

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.

Activity

  1. incanus commented on Mar 26, 2015

    @incanus
    Contributor

    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?

  2. added this to the iOS Beta 2 milestone on Mar 26, 2015
  3. picciano commented on Mar 26, 2015

    @picciano
    Author

    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

  4. incanus commented on Mar 26, 2015

    @incanus
    Contributor

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

  5. modified the milestones: iOS Beta 1, iOS Beta 2 on Mar 26, 2015
  6. picciano commented on Mar 26, 2015

    @picciano
    Author

    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

  7. self-assigned this
    on Mar 27, 2015
  8. 1ec5 commented on Mar 27, 2015

    @1ec5
    Contributor

    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

  9. incanus commented on Mar 27, 2015

    @incanus
    Contributor

    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

  10. ansis commented on Mar 27, 2015

    @ansis
    Contributor

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

  11. incanus commented on Mar 27, 2015

    @incanus
    Contributor

    @ansis It's made on the fly here:

    // create point annotations layer
    //
    const std::string& id = AnnotationManager::layerID;
    std::map<ClassID, ClassProperties> paints;
    util::ptr<StyleLayer> annotations = std::make_shared<StyleLayer>(id, std::move(paints));
    annotations->type = StyleLayerType::Symbol;
    layers.emplace(id, std::pair<JSVal, util::ptr<StyleLayer>> { JSVal(id), annotations });
    root->layers.emplace_back(annotations);
    util::ptr<StyleBucket> pointBucket = std::make_shared<StyleBucket>(annotations->type);
    pointBucket->name = annotations->id;
    pointBucket->source_layer = annotations->id;
    rapidjson::Document d;
    rapidjson::Value iconImage(rapidjson::kObjectType);
    iconImage.AddMember("icon-image", "{sprite}", d.GetAllocator());
    parseLayout(iconImage, pointBucket);
    rapidjson::Value iconOverlap(rapidjson::kObjectType);
    iconOverlap.AddMember("icon-allow-overlap", true, d.GetAllocator());
    parseLayout(iconOverlap, pointBucket);
    SourceInfo& info = sources.emplace(id, std::make_shared<StyleSource>()).first->second->info;
    info.type = SourceType::Annotations;
    auto source_it = sources.find(id);
    pointBucket->style_source = source_it->second;
    annotations->bucket = pointBucket;
    //
    // end point annotations

  12. assigned and unassigned on Mar 28, 2015
  13. assigned and unassigned on Apr 1, 2015
  14. incanus commented on Apr 1, 2015

    @incanus
    Contributor

    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.

  15. incanus commented on Apr 1, 2015

    @incanus
    Contributor
  16. jfirebaugh commented on Apr 1, 2015

    @jfirebaugh
    Contributor

    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.

  17. incanus commented on Apr 1, 2015

    @incanus
    Contributor

    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.

  18. jfirebaugh commented on Apr 1, 2015

    @jfirebaugh
    Contributor

    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?

  19. incanus commented on Apr 1, 2015

    @incanus
    Contributor

    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.
  20. jfirebaugh commented on Apr 2, 2015

    @jfirebaugh
    Contributor

    👍, makes sense. Thanks for the explanation.

  21. incanus commented on Apr 2, 2015

    @incanus
    Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions