Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add anchor option to Marker #6350

Merged
merged 3 commits into from Mar 16, 2018
Merged

Add anchor option to Marker #6350

merged 3 commits into from Mar 16, 2018

Conversation

jfirebaugh
Copy link
Contributor

Fixes #5640.

Launch Checklist

  • briefly describe the changes in this PR
  • write tests for all new functionality
  • document any changes to public APIs
  • manually test the debug page

Copy link
Contributor

@mollymerp mollymerp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me! just one comment/suggestion. 🙇‍♀️

src/ui/marker.js Outdated
bindAll(['_update', '_onMapClick'], this);

this._anchor = options && options.anchor || 'middle';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add a check here so that if a user provides something like new mapboxgl.Marker({anchor: 'left'}) it is valid instead of having to use new mapboxgl.Marker(null, {anchor: 'left'})?

if we don't want the former to be valid, we should fire a better error because right now it is just Uncaught TypeError: Cannot read property 'add' of undefined

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gonna send a separate PR for this in a sec.

@mollymerp
Copy link
Contributor

Hmm actually I think the offset's might be backwards
In these screenshots the red dots are markers with [0, 0] offset and anchor: middle
anchor: left
screen shot 2018-03-16 at 3 25 23 pm

anchor: right
image

the docs state:

A string indicating the Marker's location relative to the coordinate set via {@link Marker#setLngLat}.

I would expect the results to be flipped 🤔

@jfirebaugh
Copy link
Contributor Author

The behavior is chosen for consistency with icon-anchor. The anchor is the part of the popup/marker/icon that's closest to its coordinate.

Though now looking at icon-anchor, I see that it should be 'center' rather than 'middle'.

@mollymerp
Copy link
Contributor

gotcha – makes sense when looking with a popup that has the same anchor setting (blue dot is the one with the top-left anchor):

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants