Skip to content

Commit a9e99d5

Browse files
committed
markers with props
flow issues? ¯\_(ツ)_/¯
1 parent 707cc45 commit a9e99d5

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

src/Marker.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type MapKitType, {
55
MarkerAnnotationConstructorOptions,
66
Map,
77
Annotation,
8+
FeatureVisibility,
89
} from 'mapkit'
910

1011
declare var mapkit: MapKitType
@@ -15,23 +16,25 @@ type Props = MarkerAnnotationConstructorOptions & {
1516
map: Map,
1617
latitude: number,
1718
longitude: number,
18-
19-
title?: string,
20-
subtitle?: string,
2119
}
2220

2321
class Marker extends React.Component<Props> {
2422
marker: Annotation
2523

24+
getMarkerConstructionProps = (props: Props) => {
25+
const { map, latitude, longitude, ...otherProps } = props
26+
27+
return otherProps
28+
}
29+
2630
constructor(props: Props) {
2731
super(props)
2832

33+
const markerProps = this.getMarkerConstructionProps(props)
34+
2935
this.marker = new mapkit.MarkerAnnotation(
3036
new mapkit.Coordinate(props.latitude, props.longitude),
31-
{
32-
title: props.title,
33-
subtitle: props.subtitle,
34-
},
37+
markerProps,
3538
)
3639

3740
this.props.map.addAnnotation(this.marker)
@@ -48,8 +51,11 @@ class Marker extends React.Component<Props> {
4851
)
4952
}
5053

51-
this.marker.title = nextProps.title
52-
this.marker.subtitle = nextProps.subtitle
54+
const markerProps = this.getMarkerConstructionProps(nextProps)
55+
56+
Object.keys(markerProps).forEach((key) => {
57+
this.marker[key] = markerProps[key]
58+
})
5359

5460
return false
5561
}

stories/index.stories.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ storiesOf('MapKit', module)
105105
longitude={number('marker longitude', -122.3308333)}
106106
title={text('title', 'marker title')}
107107
subtitle={text('subtitle', 'marker subtitle')}
108+
glyphText={text('glyphText', '')}
109+
color={text('color', '#ff5b40')}
110+
glyphColor={text('glyphColor', 'white')}
108111
/>
109112
</MapKit>
110113
))

0 commit comments

Comments
 (0)