File tree Expand file tree Collapse file tree 3 files changed +71
-16
lines changed Expand file tree Collapse file tree 3 files changed +71
-16
lines changed Original file line number Diff line number Diff line change 77npm-debug.log *
88.DS_Store
99/keygen /key.p8
10+ /src /dist
Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ import usWebDesignStandardsTheme from 'typography-theme-us-web-design-standards'
88
99import { css } from 'glamor'
1010
11+ import MapKit from '../../src'
12+
1113css . global ( 'html, body' , { padding : 0 , margin : 0 } )
1214css . global ( 'body' , {
1315 backgroundColor : '#18d7fd' ,
3436`
3537
3638class Demo extends React . Component {
37- componentDidMount ( ) {
38- load ( 'https://cdn.apple-mapkit.com/mk/5.x.x/mapkit.js' , function ( err ) {
39- mapkit . init ( {
40- authorizationCallback : function ( done ) {
41- done (
42- 'eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IkY2N0c4OTM3RjUifQ.eyJpYXQiOjE1MjgzNTQwOTYuNzI2LCJpc3MiOiJHOERBODY0VVlLIiwib3JpZ2luIjoiaHR0cHM6Ly9jaHJpc2RyYWNrZXR0LmdpdGh1Yi5pbyJ9.Z9FW9wYDO0AfOyWnf0d3vLGbu62GTu7WKtxPXAuVFiimr1DR4JN_s6YB8wG9kvZl4ACp4j857U4bOV5NIi55HA' ,
43- )
44- } ,
45- language : 'en' ,
46- } )
47-
48- const map = new mapkit . Map ( 'map' )
49- } )
50- }
51-
5239 render ( ) {
5340 const white = '#ffffff'
5441
@@ -79,7 +66,10 @@ class Demo extends React.Component {
7966 < section { ...css ( styles . sidebar ) } >
8067 < Markdown source = { content } />
8168 </ section >
82- < section { ...css ( styles . content ) } id = "map" />
69+ < MapKit
70+ { ...css ( styles . content ) }
71+ token = "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IkY2N0c4OTM3RjUifQ.eyJpYXQiOjE1MjgzNTQwOTYuNzI2LCJpc3MiOiJHOERBODY0VVlLIiwib3JpZ2luIjoiaHR0cHM6Ly9jaHJpc2RyYWNrZXR0LmdpdGh1Yi5pbyJ9.Z9FW9wYDO0AfOyWnf0d3vLGbu62GTu7WKtxPXAuVFiimr1DR4JN_s6YB8wG9kvZl4ACp4j857U4bOV5NIi55HA"
72+ />
8373 </ div >
8474 )
8575 }
Original file line number Diff line number Diff line change 1+ // @flow
2+
3+ import * as React from 'react'
4+ import load from 'little-loader'
5+
6+ type Props = {
7+ /**
8+ * Prop Description
9+ */
10+ callbackUrl ?: string ,
11+ token ?: string ,
12+ }
13+
14+ type State = {
15+ mapKitIsReady : boolean ,
16+ makKitIsStarted : boolean ,
17+ }
18+
19+ export default class ComponentTemplate extends React . Component < Props , State > {
20+ map = null
21+
22+ state = {
23+ mapKitIsReady : false ,
24+ makKitIsStarted : false ,
25+ }
26+
27+ constructor ( props : Props ) {
28+ super ( props )
29+
30+ load (
31+ 'https://cdn.apple-mapkit.com/mk/5.x.x/mapkit.js' ,
32+ function ( err ) {
33+ this . setState ( { mapKitIsReady : true } )
34+ } ,
35+ this ,
36+ )
37+ }
38+
39+ componentDidUpdate ( ) {
40+ if ( this . state . mapKitIsReady && ! this . state . makKitIsStarted ) {
41+ mapkit . init ( {
42+ authorizationCallback : ( done ) => {
43+ if ( this . props . callbackUrl ) {
44+ fetch ( this . props . callbackUrl )
45+ . then ( ( res ) => res . text ( ) )
46+ . then ( done )
47+ } else {
48+ done ( this . props . token )
49+ }
50+ } ,
51+ } )
52+
53+ this . map = new mapkit . Map ( 'map' )
54+
55+ this . setState ( { makKitIsStarted : true } )
56+ }
57+ }
58+
59+ render ( ) {
60+ const { callbackUrl, token, ...otherProps } = this . props
61+
62+ return < div id = "map" { ...otherProps } />
63+ }
64+ }
You can’t perform that action at this time.
0 commit comments