Skip to content

Commit

Permalink
markers with props
Browse files Browse the repository at this point in the history
flow issues? ¯\_(ツ)_/¯
  • Loading branch information
chrisdrackett committed Jun 12, 2018
1 parent 707cc45 commit a9e99d5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/Marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type MapKitType, {
MarkerAnnotationConstructorOptions,
Map,
Annotation,
FeatureVisibility,
} from 'mapkit'

declare var mapkit: MapKitType
Expand All @@ -15,23 +16,25 @@ type Props = MarkerAnnotationConstructorOptions & {
map: Map,
latitude: number,
longitude: number,

title?: string,
subtitle?: string,
}

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

getMarkerConstructionProps = (props: Props) => {
const { map, latitude, longitude, ...otherProps } = props

return otherProps
}

constructor(props: Props) {
super(props)

const markerProps = this.getMarkerConstructionProps(props)

this.marker = new mapkit.MarkerAnnotation(
new mapkit.Coordinate(props.latitude, props.longitude),
{
title: props.title,
subtitle: props.subtitle,
},
markerProps,
)

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

this.marker.title = nextProps.title
this.marker.subtitle = nextProps.subtitle
const markerProps = this.getMarkerConstructionProps(nextProps)

Object.keys(markerProps).forEach((key) => {
this.marker[key] = markerProps[key]
})

return false
}
Expand Down
3 changes: 3 additions & 0 deletions stories/index.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ storiesOf('MapKit', module)
longitude={number('marker longitude', -122.3308333)}
title={text('title', 'marker title')}
subtitle={text('subtitle', 'marker subtitle')}
glyphText={text('glyphText', '')}
color={text('color', '#ff5b40')}
glyphColor={text('glyphColor', 'white')}
/>
</MapKit>
))

0 comments on commit a9e99d5

Please sign in to comment.