Skip to content

Commit

Permalink
Consistency with icon-anchor
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Mar 16, 2018
1 parent c9187f7 commit 61278bc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/ui/anchor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow

export type Anchor =
| 'middle'
| 'center'
| 'top'
| 'bottom'
| 'left'
Expand All @@ -12,7 +12,7 @@ export type Anchor =
| 'bottom-right';

export const anchorTranslate: {[Anchor]: string} = {
'middle': 'translate(-50%,-50%)',
'center': 'translate(-50%,-50%)',
'top': 'translate(-50%,0)',
'top-left': 'translate(0,0)',
'top-right': 'translate(-100%,0)',
Expand Down
8 changes: 4 additions & 4 deletions src/ui/marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ type Options = {
* Creates a marker component
* @param element DOM element to use as a marker. If left unspecified a default SVG will be created as the DOM element to use.
* @param options
* @param options.anchor A string indicating the Marker's location relative to the coordinate set via {@link Marker#setLngLat}.
* Options are `'middle'`, `'top'`, `'bottom'`, `'left'`, `'right'`, `'top-left'`, `'top-right'`, `'bottom-left'`, and `'bottom-right'`.
* The default is `'middle'`.
* @param options.anchor A string indicating the part of the Marker that should be positioned closest to the coordinate set via {@link Marker#setLngLat}.
* Options are `'center'`, `'top'`, `'bottom'`, `'left'`, `'right'`, `'top-left'`, `'top-right'`, `'bottom-left'`, and `'bottom-right'`.
* The default is `'center'`.
* @param options.offset The offset in pixels as a {@link PointLike} object to apply relative to the element's center. Negatives indicate left and up.
* @example
* var marker = new mapboxgl.Marker()
Expand All @@ -44,7 +44,7 @@ export default class Marker {
constructor(element: ?HTMLElement, options?: Options) {
bindAll(['_update', '_onMapClick'], this);

this._anchor = options && options.anchor || 'middle';
this._anchor = options && options.anchor || 'center';

if (!element) {
element = DOM.create('div');
Expand Down
10 changes: 5 additions & 5 deletions src/ui/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export type PopupOptions = {
* top right corner of the popup.
* @param {boolean} [options.closeOnClick=true] If `true`, the popup will closed when the
* map is clicked.
* @param {string} [options.anchor] - A string indicating the popup's location relative to
* the coordinate set via {@link Popup#setLngLat}.
* @param {string} [options.anchor] - A string indicating the part of the Popup that should
* be positioned closest to the coordinate set via {@link Popup#setLngLat}.
* Options are `'top'`, `'bottom'`, `'left'`, `'right'`, `'top-left'`,
* `'top-right'`, `'bottom-left'`, and `'bottom-right'`. If unset the anchor will be
* dynamically set to ensure the popup falls within the map container with a preference
Expand Down Expand Up @@ -324,7 +324,7 @@ function normalizeOffset(offset: ?Offset) {
// input specifies a radius from which to calculate offsets at all positions
const cornerOffset = Math.round(Math.sqrt(0.5 * Math.pow(offset, 2)));
return {
'middle': new Point(0, 0),
'center': new Point(0, 0),
'top': new Point(0, offset),
'top-left': new Point(cornerOffset, cornerOffset),
'top-right': new Point(-cornerOffset, cornerOffset),
Expand All @@ -339,7 +339,7 @@ function normalizeOffset(offset: ?Offset) {
// input specifies a single offset to be applied to all positions
const convertedOffset = Point.convert(offset);
return {
'middle': convertedOffset,
'center': convertedOffset,
'top': convertedOffset,
'top-left': convertedOffset,
'top-right': convertedOffset,
Expand All @@ -353,7 +353,7 @@ function normalizeOffset(offset: ?Offset) {
} else {
// input specifies an offset per position
return {
'middle': Point.convert(offset['middle'] || [0, 0]),
'center': Point.convert(offset['center'] || [0, 0]),
'top': Point.convert(offset['top'] || [0, 0]),
'top-left': Point.convert(offset['top-left'] || [0, 0]),
'top-right': Point.convert(offset['top-right'] || [0, 0]),
Expand Down
4 changes: 2 additions & 2 deletions test/unit/ui/marker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ test('Marker#togglePopup closes a popup that was open', (t) => {
t.end();
});

test('Marker anchor defaults to middle', (t) => {
test('Marker anchor defaults to center', (t) => {
const map = createMap();
const marker = new Marker()
.setLngLat([0, 0])
.addTo(map);

t.ok(marker.getElement().classList.contains('mapboxgl-marker-anchor-middle'));
t.ok(marker.getElement().classList.contains('mapboxgl-marker-anchor-center'));
t.match(marker.getElement().style.transform, /translate\(-50%,-50%\)/);

map.remove();
Expand Down

0 comments on commit 61278bc

Please sign in to comment.