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

Improve Popup/Marker positioning logic #4620

Merged
merged 2 commits into from
May 1, 2017
Merged

Improve Popup/Marker positioning logic #4620

merged 2 commits into from
May 1, 2017

Conversation

jfirebaugh
Copy link
Contributor

@jfirebaugh jfirebaugh commented Apr 20, 2017

  • Wrap only on map move events; otherwise preserve requested LngLat
  • Wrap in a way that best preserves object constancy; i.e. minimizes perceived changes in position

Fixes #4577; see discussion there.

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

@jfirebaugh
Copy link
Contributor Author

jfirebaugh commented Apr 20, 2017

Just realized all this math is totally wrong if the map is rotated. 🤦‍♂️

src/ui/popup.js Outdated
if (this.options.closeOnClick) {
this._map.on('click', this._onClickClose);
}
this._update();
this._update(false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

The problem with this is a marker added within -180 to 180 long might not be shown on the map initially.

eg. in this view australia is world -1 and I've added a marker at long 170 but it doesn't show up until I move the map.
selection_561

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed -- I've changed this to always apply the wrapping. Only the logic based on prior position is bypassed on the update immediately following setLatLng.

src/ui/marker.js Outdated
@@ -85,6 +86,7 @@ class Marker {
*/
setLngLat(lnglat) {
this._lngLat = LngLat.convert(lnglat);
this._wrappedLnLat = this._pos = null;
Copy link
Member

Choose a reason for hiding this comment

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

Let's use _wrappedLngLat for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I decided to eliminate the variable entirely and just mutate this._lngLat .

src/ui/marker.js Outdated

if (this._map.transform.renderWorldCopies) {
this._wrappedLnLat = smartWrap(this._wrappedLnLat, this._pos, this._map.transform);
}
Copy link
Member

Choose a reason for hiding this comment

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

Could be shorter:

this._wrappedLngLat = this._map.transform.renderWorldCopies ? 
    smartWrap(this._lngLat, this._pos, this._map.transform) : this._lngLat;

@andrewharvey
Copy link
Collaborator

I tested the updated branch, looks good to me. 👍

Wrap in a way that best preserves object constancy; i.e. minimizes perceived changes in position
@jfirebaugh jfirebaugh merged commit b45a683 into master May 1, 2017
@jfirebaugh jfirebaugh deleted the fix-4577 branch May 1, 2017 18:38
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

3 participants