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

Make compass and zoom controls optional #5348

Merged
merged 6 commits into from
Jan 10, 2018
Merged

Make compass and zoom controls optional #5348

merged 6 commits into from
Jan 10, 2018

Conversation

matijs
Copy link
Contributor

@matijs matijs commented Sep 25, 2017

Add options to NavigationControl. showZoom and showCompass both default to true can be used to hide either the zoom buttons or the compass button from the Navigation Control.

  • briefly describe the changes in this PR
  • document any changes to public APIs
  • manually test the debug page
  • conditionally add dragRotateHandler

Fixes #1554

Copy link
Contributor

@anandthakker anandthakker left a comment

Choose a reason for hiding this comment

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

Thanks for this contribution @matijs !

Looks good overall, just a couple of small changes needed.

@@ -15,6 +15,9 @@ const defaultOptions = {
* A `NavigationControl` control contains zoom buttons and a compass.
*
* @implements {IControl}
* @param {Object} [options]
* @param {Object} [options.showCompass=true] If `false` will omit the compass button from the Navigation Control. The default is `true` to show a compass button.
Copy link
Contributor

Choose a reason for hiding this comment

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

Small edit:

@param {boolean} [options.showCompass=true] If true, the compass button is included.
@param {boolean} [options.showZoom=true] If true, the zoom-in and zoom-out buttons are included.

Note the type should be marked {boolean}, not {Object}.

The default value is shown in the generated docs, so no need to state it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

if (this.options.showCompass) {
this._compass = this._createButton('mapboxgl-ctrl-icon mapboxgl-ctrl-compass', 'Reset North', () => this._map.resetNorth());
this._compassArrow = DOM.create('span', 'mapboxgl-ctrl-compass-arrow', this._compass);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If the this._compass element is not created for showCompass: false, then we should also make sure in onAdd() not to create the DragRotateHandler, whose constructor accepts that element as an argument.

Copy link
Contributor Author

@matijs matijs Oct 3, 2017

Choose a reason for hiding this comment

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

I thought the same, but if no element it passed in the DragRotateHandler will default to the canvasContainer :)

It would take a bit more refactoring to uncouple what's currently quite tightly coupled. Especially not to break stuff that's already out there.

Copy link
Contributor

Choose a reason for hiding this comment

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

if no element it passed in the DragRotateHandler will default to the canvasContainer

Ah, I see! Good point... but even so, I think we should avoid it: that default behavior of DragRotateHandler isn't documented as part of its internal API, and it could easily end up being removed in a refactor.

Especially not to break stuff that's already out there.

What do you see as potentially breaking?

Copy link
Contributor

Choose a reason for hiding this comment

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

As @anandthakker suggests, we do need this change. In addition to the potential future compatibility issues, there is also the fact that the map creates and registers a DragRotateHandler of its own. If we let the navigation control create a second one bound to the same element, that will result in duplicate event handlers and probably produce unexpected behavior.

@matijs
Copy link
Contributor Author

matijs commented Nov 29, 2017

@anandthakker is there anything else I need to do for this? :)

@anandthakker
Copy link
Contributor

Hi @matijs - yes, this comment #5348 (comment) still stands -- the DragRotateHandler should only be added if the this._compass element exists.

@matijs
Copy link
Contributor Author

matijs commented Nov 29, 2017

@anandthakker Ugh… I'm so sorry. That conversation was hidden from me by GitHub 😔

I'll probably have some time to look into this later this week.

@anandthakker
Copy link
Contributor

No problem - thanks for following up!

matijs and others added 6 commits December 28, 2017 21:47
Instead of having every control button have a bottom border, make stacked
buttons have a top-border. This gets rid of the :last-child selector
too.
The compass button of the navigation control is now optional. Creating a
new navigation control with `{showCompass: false}` will leave out the
compass button. Defaults to showing the compass button.
They still default to showing, but make them optional.
- Remove check from `_rotateCompassArrow`
- Add checks to `onAdd` and `onRemove`
@matijs
Copy link
Contributor Author

matijs commented Jan 9, 2018

@anandthakker finally got round to fixing this :)

Copy link
Contributor

@anandthakker anandthakker 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, thanks @matijs !

@anandthakker anandthakker merged commit da74713 into mapbox:master Jan 10, 2018
@matijs matijs deleted the improvement/make-compass-optional branch December 3, 2018 09:09
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.

3 participants