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

Revert "added anchor option for marker" #3

Merged
merged 1 commit into from
Jan 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions src/ui/marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,11 @@ import type Popup from './popup';
import type {LngLatLike} from "../geo/lng_lat";
import type {MapMouseEvent} from './events';

export type Anchor = number | PointLike;
export type Offset = number | PointLike | Anchor;

export type MarkerOptions = {
anchor: Anchor,
offset: Offset
}

/**
* 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.offset The offset in pixels as a {@link PointLike} object to apply relative to the element's center. Negatives indicate left and up.
*@param options.anchor The sets anchor 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()
* .setLngLat([30.5, 50.5])
Expand All @@ -33,17 +24,14 @@ export type MarkerOptions = {
*/
class Marker {
_map: Map;
options: MarkerOptions;
_offset: Point;
_anchor: Anchor;
_element: HTMLElement;
_popup: ?Popup;
_lngLat: LngLat;
_pos: ?Point;

constructor(element: ?HTMLElement, options?: {offset: PointLike, anchor: Anchor}) {
constructor(element: ?HTMLElement, options?: {offset: PointLike}) {
this._offset = Point.convert(options && options.offset || [0, 0]);
this._anchor = Point.convert(options && options.anchor || [0, 0]);

bindAll(['_update', '_onMapClick'], this);

Expand Down Expand Up @@ -280,7 +268,7 @@ class Marker {
this._lngLat = smartWrap(this._lngLat, this._pos, this._map.transform);
}

this._pos = this._map.project(this._lngLat)._add(this._anchor)._add(this._offset);
this._pos = this._map.project(this._lngLat)._add(this._offset);

// because rounding the coordinates at every `move` event causes stuttered zooming
// we only round them when _update is called with `moveend` or when its called with
Expand All @@ -289,7 +277,7 @@ class Marker {
this._pos = this._pos.round();
}

DOM.setTransform(this._element, `translate(${this._pos.x}px, ${this._pos.y}px)`);
DOM.setTransform(this._element, `translate(-50%, -50%) translate(${this._pos.x}px, ${this._pos.y}px)`);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/unit/ui/marker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ test('Marker', (t) => {
const element = window.document.createElement('div');
const marker = new Marker(element).setLngLat([0, 0]).addTo(map);
const translate = Math.round(map.getContainer().offsetWidth / 2);
t.equal(marker.getElement().style.transform, `translate(${translate}px, ${translate}px)`, 'Marker centered');
t.equal(marker.getElement().style.transform, `translate(-50%, -50%) translate(${translate}px, ${translate}px)`, 'Marker centered');
t.end();
});

Expand Down