Skip to content

Commit 56642cc

Browse files
a-tokyoPessimistress
authored andcommitted
✨ add support for style prop in Marker (#1696)
1 parent c4dc868 commit 56642cc

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

docs/api-reference/marker.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ Stop propagation of dblclick event to the map component. Can be used to stop map
144144

145145
Stop propagation of pointermove event to the map component. Can be used to stop map from calling the `onMouseMove` or `onTouchMove` callback when this component is hovered.
146146

147+
##### `style` (object)
148+
149+
- default: `undefined`
150+
151+
Optional extra style object to be applied to the marker. Can be used to add properties like `zIndex` to the marker as inline style.
152+
147153
## Styling
148154

149155
Like its Mapbox counterpart, this control relies on the mapbox-gl stylesheet to work properly. Make sure to add the stylesheet to your page.

src/components/marker.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import type {DraggableControlProps} from './draggable-control';
44
export type MarkerProps = DraggableControlProps & {
55
className?: string,
66
longitude: number,
7-
latitude: number
7+
latitude: number,
8+
style?: { [key: string]: string | number }
89
};
910

1011
export default function Marker(props: MarkerProps): ReactElement;

src/components/marker.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ const propTypes = Object.assign({}, draggableControlPropTypes, {
3333
// Longitude of the anchor point
3434
longitude: PropTypes.number.isRequired,
3535
// Latitude of the anchor point
36-
latitude: PropTypes.number.isRequired
36+
latitude: PropTypes.number.isRequired,
37+
// Custom style
38+
style: PropTypes.object
3739
});
3840

3941
const defaultProps = Object.assign({}, draggableControlDefaultProps, {
@@ -70,7 +72,7 @@ function Marker(props) {
7072
const thisRef = useDraggableControl(props);
7173
const {state, containerRef} = thisRef;
7274

73-
const {children, className, draggable} = props;
75+
const {children, className, draggable, style} = props;
7476
const {dragPos} = state;
7577

7678
const [x, y] = getPosition(thisRef);
@@ -84,7 +86,8 @@ function Marker(props) {
8486
left: 0,
8587
top: 0,
8688
transform,
87-
cursor
89+
cursor,
90+
...style
8891
};
8992

9093
return (

0 commit comments

Comments
 (0)