Skip to content

Commit

Permalink
fix(marker): add new Marker props (#289)
Browse files Browse the repository at this point in the history
`anchor`, `rotation`, `pitchAlignment`, and `rotationAlignment`
  • Loading branch information
stepankuzmin authored Apr 29, 2020
1 parent bc81f16 commit 3f25e74
Showing 1 changed file with 52 additions and 14 deletions.
66 changes: 52 additions & 14 deletions src/components/Marker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ type Props = {
/** Marker content */
children: React$Node,

/**
* A string indicating the part of the Marker
* that should be positioned closest to the coordinate
*/
anchor:
| 'center'
| 'top'
| 'bottom'
| 'left'
| 'right'
| 'top-left'
| 'top-right'
| 'bottom-left'
| 'bottom-right',

/** The longitude of the center of the marker. */
longitude: number,

Expand All @@ -32,6 +47,28 @@ type Props = {
*/
draggable?: boolean,

/**
* The rotation angle of the marker in degrees, relative to its
* respective `rotationAlignment` setting. A positive value will
* rotate the marker clockwise.
*/
rotation: number,

/**
* map aligns the `Marker` to the plane of the map. `viewport`
* aligns the Marker to the plane of the viewport. `auto` automatically
* matches the value of `rotationAlignment`.
*/
pitchAlignment: string,

/**
* map aligns the `Marker`'s rotation relative to the map, maintaining
* a bearing as the map rotates. `viewport` aligns the `Marker`'s rotation
* relative to the viewport, agnostic to map rotations.
* `auto` is equivalent to `viewport`.
*/
rotationAlignment: string,

/** Fired when the marker is finished being dragged */
onDragEnd?: (lngLat: LngLat) => any,

Expand All @@ -52,8 +89,12 @@ class Marker extends PureComponent<Props> {
static displayName = 'Marker';

static defaultProps = {
anchor: 'center',
offset: null,
draggable: false
draggable: false,
rotation: 0,
pitchAlignment: 'auto',
rotationAlignment: 'auto'
};

constructor(props: Props) {
Expand All @@ -62,19 +103,16 @@ class Marker extends PureComponent<Props> {
}

componentDidMount() {
const {
longitude,
latitude,
offset,
draggable,
onDragEnd,
onDragStart,
onDrag
} = this.props;

this._marker = new mapboxgl.Marker(this._el, {
draggable,
offset
const { longitude, latitude, onDragEnd, onDragStart, onDrag } = this.props;

this._marker = new mapboxgl.Marker({
element: this._el,
anchor: this.props.anchor,
draggable: this.props.draggable,
offset: this.props.offset,
rotation: this.props.rotation,
pitchAlignment: this.props.pitchAlignment,
rotationAlignment: this.props.rotationAlignment
});

this._marker.setLngLat([longitude, latitude]).addTo(this._map);
Expand Down

0 comments on commit 3f25e74

Please sign in to comment.