Skip to content

Commit f9f15f7

Browse files
authored
✨ add support for style prop in Marker (#1698)
1 parent 77cc634 commit f9f15f7

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
@@ -32,7 +32,9 @@ const propTypes = Object.assign({}, draggableControlPropTypes, {
3232
// Longitude of the anchor point
3333
longitude: PropTypes.number.isRequired,
3434
// Latitude of the anchor point
35-
latitude: PropTypes.number.isRequired
35+
latitude: PropTypes.number.isRequired,
36+
// Custom style
37+
style: PropTypes.object
3638
});
3739

3840
const defaultProps = Object.assign({}, draggableControlDefaultProps, {
@@ -66,7 +68,7 @@ function Marker(props) {
6668
const thisRef = useDraggableControl(props);
6769
const {state, containerRef} = thisRef;
6870

69-
const {children, className, draggable} = props;
71+
const {children, className, draggable, style} = props;
7072
const {dragPos} = state;
7173

7274
const [x, y] = getPosition(thisRef);
@@ -80,7 +82,8 @@ function Marker(props) {
8082
left: 0,
8183
top: 0,
8284
transform,
83-
cursor
85+
cursor,
86+
...style
8487
};
8588

8689
return (

0 commit comments

Comments
 (0)