Skip to content

Commit b9bdfe1

Browse files
committed
adding initial map options to MapKit
1 parent 0909404 commit b9bdfe1

File tree

2 files changed

+103
-11
lines changed

2 files changed

+103
-11
lines changed

src/index.js

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,25 @@ import invariant from 'invariant'
66

77
import ErrorBoundry from './ErrorBoundry'
88

9+
type MapKitFeatureVisibility = 'adaptive' | 'hidden' | 'visible'
10+
type MapKitMapType = 'hybrid' | 'satellite' | 'standard'
11+
912
type Props = {
1013
callbackUrl?: string,
1114
token?: string,
15+
16+
mapType: MapKitMapType,
17+
padding:
18+
| number
19+
| { top?: number, bottom?: number, left?: number, right?: number },
20+
showsCompass: MapKitFeatureVisibility,
21+
showsMapTypeControl: boolean,
22+
showsZoomControl: boolean,
23+
showsUserLocationControl: boolean,
24+
showsPointsOfInterest: boolean,
25+
showsScale: MapKitFeatureVisibility,
1226
tintColor?: string,
27+
1328
showsUserLocationControl: boolean,
1429
}
1530

@@ -25,7 +40,14 @@ class MapKit extends React.Component<Props, State> {
2540
map = null
2641

2742
static defaultProps = {
43+
mapType: 'standard',
44+
padding: 0,
45+
showsCompass: 'adaptive',
46+
showsMapTypeControl: true,
47+
showsZoomControl: true,
2848
showsUserLocationControl: false,
49+
showsPointsOfInterest: true,
50+
showsScale: 'hidden',
2951
}
3052

3153
state = {
@@ -50,9 +72,39 @@ class MapKit extends React.Component<Props, State> {
5072

5173
this.map = new mapkit.Map('map')
5274

75+
console.log(mapkit.Map.MapTypes.Standard)
76+
77+
this.updateMapProps(props)
78+
5379
this.setState({ mapKitIsReady: true })
5480
}
5581

82+
updateMapProps = (props: Props) => {
83+
// Update map based on props
84+
this.map.showsMapTypeControl = props.showsMapTypeControl
85+
this.map.mapType = props.mapType
86+
87+
const padding = new mapkit.Padding(
88+
typeof props.padding === 'number'
89+
? {
90+
top: props.padding,
91+
right: props.padding,
92+
bottom: props.padding,
93+
left: props.padding,
94+
}
95+
: { top: 0, right: 0, bottom: 0, left: 0, ...props.padding },
96+
)
97+
98+
this.map.padding = padding
99+
this.map.showsCompass = props.showsCompass
100+
this.map.showsMapTypeControl = props.showsMapTypeControl
101+
this.map.showsZoomControl = props.showsZoomControl
102+
this.map.showsUserLocationControl = props.showsUserLocationControl
103+
this.map.showsPointsOfInterest = props.showsPointsOfInterest
104+
this.map.showsScale = props.showsScale
105+
this.map.tintColor = props.tintColor
106+
}
107+
56108
constructor(props: Props) {
57109
super(props)
58110

@@ -84,9 +136,7 @@ class MapKit extends React.Component<Props, State> {
84136
}
85137

86138
if (this.state.mapKitIsReady) {
87-
// Update map based on props
88-
this.map.tintColor = nextProps.tintColor
89-
this.map.showsUserLocationControl = nextProps.showsUserLocationControl
139+
this.updateMapProps(nextProps)
90140
}
91141

92142
return ComponentShouldUpdate
@@ -96,8 +146,17 @@ class MapKit extends React.Component<Props, State> {
96146
const {
97147
callbackUrl,
98148
token,
149+
150+
mapType,
151+
padding,
152+
showsCompass,
153+
showsMapTypeControl,
154+
showsZoomControl,
99155
showsUserLocationControl,
156+
showsPointsOfInterest,
157+
showsScale,
100158
tintColor,
159+
101160
...otherProps
102161
} = this.props
103162

stories/index.stories.js

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,48 @@
11
import React from 'react'
22

33
import { storiesOf } from '@storybook/react'
4-
import { text, boolean, number } from '@storybook/addon-knobs/react'
4+
import { text, boolean, number, select } from '@storybook/addon-knobs/react'
55

66
import devToken from '../devToken'
77
import MapKit from '../src'
88

9-
storiesOf('MapKit', module).add('with token', () => (
10-
<MapKit
11-
style={{ width: '100vw', height: '100vh' }}
12-
token={text('token', devToken)}
13-
tintColor={text('tintColor', undefined)}
14-
/>
15-
))
9+
storiesOf('MapKit', module)
10+
.add('all props', () => (
11+
<MapKit
12+
style={{ width: '100vw', height: '100vh' }}
13+
token={text('token', devToken)}
14+
mapType={select(
15+
'mapType',
16+
{ standard: 'standard', satellite: 'satellite', hybrid: 'hybrid' },
17+
'standard',
18+
)}
19+
padding={number('padding', 0)}
20+
showsCompass={select(
21+
'showsCompass',
22+
{ adaptive: 'adaptive', hidden: 'hidden', visible: 'visible' },
23+
'adaptive',
24+
)}
25+
showsMapTypeControl={boolean('showsMapTypeControl', true)}
26+
showsZoomControl={boolean('showsZoomControl', true)}
27+
showsUserLocationControl={boolean('showsUserLocationControl', false)}
28+
showsPointsOfInterest={boolean('showsPointsOfInterest', true)}
29+
showsScale={select(
30+
'showsScale',
31+
{ adaptive: 'adaptive', hidden: 'hidden', visible: 'visible' },
32+
'hidden',
33+
)}
34+
tintColor={text('tintColor', '')}
35+
/>
36+
))
37+
.add('individual padding values', () => (
38+
<MapKit
39+
style={{ width: '100vw', height: '100vh' }}
40+
token={devToken}
41+
padding={{
42+
top: number('top', 0),
43+
right: number('right', 0),
44+
bottom: number('bottom', 0),
45+
left: number('left', 0),
46+
}}
47+
/>
48+
))

0 commit comments

Comments
 (0)