2015-10-14 43 views
1

我正在使用React Native構建應用程序,並且想要使用MapBox GL Component來渲染地圖並添加註釋。我正試圖從github回購中實施this example看不到MapBox React Native GL註釋

我按照安裝說明操作,盡我所能,但在地圖加載,註釋不存在。我得到這個:

enter image description here

此錯誤在Xcode(3次):

Oct 14 20:45:08 MapBoxDemo[9268] <Error>: CGContextRestoreGState: invalid context 0x0. Backtrace: 
     <-[UIStatusBarItemView updateContentsAndWidth]+33> 
     <-[UIStatusBarItemView initWithItem:data:actions:style:]+477> 
     <+[UIStatusBarItemView createViewForItem:withData:actions:foregroundStyle:]+134> 
     <-[UIStatusBarLayoutManager _createViewForItem:withData:actions:]+163> 
      <-[UIStatusBarLayoutManager _prepareEnabledItemType:withEnabledItems:withData:actions:itemAppearing:itemDisappearing:]+36 
      <-[UIStatusBarLayoutManager prepareEnabledItems:withData:actions:]+92> 
      <-[UIStatusBarForegroundView _setStatusBarData:actions:animated:]+797> 
      <-[UIStatusBarForegroundView setStatusBarData:actions:animated:]+332> 
       <__51-[UIStatusBar _prepareToSetStyle:animation:forced:]_block_invoke+360> 
       <+[UIView(Animation) performWithoutAnimation:]+65> 
       <-[UIStatusBar _prepareToSetStyle:animation:forced:]+866> 
       <-[UIStatusBar _requestStyleAttributes:animationParameters:forced:]+391> 
        <-[UIStatusBar requestStyle:animationParameters:forced:]+437> 
        <-[UIStatusBar requestStyle:animated:forced:]+90> 
        <-[UIStatusBar _evaluateServerRegistration]+250> 
        <__45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke+590> 
         <-[UIView(Hierarchy) _postMovedFromSuperview:]+544> 
         <-[UIView(Internal) _addSubview:positioned:relativeTo:]+1967> 
         <-[UIStatusBarWindow setStatusBar:]+288> 
         <-[UIApplication _createStatusBarWithRequestedStyle:orientation:hidden:]+340> 
          <-[UIApplication _runWithMainScene:transitionContext:completion:]+950> 
          <-[UIApplication workspaceDidEndTransaction:]+188> 
          <-[FBSSerialQueue _performNext]+192> 
          <-[FBSSerialQueue _performNextFromRunLoopSource]+45> 
           <__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__+17> 
           <__CFRunLoopDoSources0+556> 
           <__CFRunLoopRun+867> 
           <CFRunLoopRunSpecific+488> 
            <-[UIApplication _run]+402> 
            <UIApplicationMain+171> 
            <main+111> 
            <start+1> 

而這一次(僅一次):

2015-10-14 20:45:09.328 [warn][tid:com.facebook.React.JavaScript] 'Warning: Failed propType: typeChecker is not a function. (In \'typeChecker(\npropValue,\ni,\ncomponentName,\nlocation,\npropFullName + \'[\' + i + \']\')\', \'typeChecker\' is undefined) Check the render method of `MapBoxDemo`.' 

我已經設置了地圖中心與第一個註釋的位置相同,因此它肯定應該在視圖中。

所有其他功能似乎工作(重新映射地圖,縮放等)。我也看到了example used here,它起作用(至少在iOS 8上)。

任何想法?它可以與iOS9相關嗎?我的代碼如下:

'use strict'; 

var React = require('react-native'); 
var MapboxGLMap = require('react-native-mapbox-gl'); 
var mapRef = 'mapRef'; 
var { 
    AppRegistry, 
    StyleSheet, 
    Text, 
    StatusBarIOS, 
    View 
} = React; 

var MapBoxDemo = React.createClass({ 
    mixins: [MapboxGLMap.Mixin], 
    getInitialState() { 
    return { 
     center: { 
     latitude: 40.72052634, 
     longitude: -73.97686958312988 
     }, 
     zoom: 11, 
     annotations: [{ 
     coordinates: [40.72052634, -73.97686958312988], 
     "type": "point", 
     title: 'This is marker 1', 
     subtitle: 'It has a rightCalloutAccessory too', 
     rightCalloutAccessory: { 
      url: 'https://cldup.com/9Lp0EaBw5s.png', 
      height: 25, 
      width: 25 
     }, 
     annotationImage: { 
      url: 'https://cldup.com/CnRLZem9k9.png', 
      height: 25, 
      width: 25 
     }, 
     id: 'marker1' 
     }, { 
     coordinates: [40.714541341726175,-74.00579452514648], 
     "type": "point", 
     title: 'Important!', 
     subtitle: 'Neat, this is a custom annotation image', 
     annotationImage: { 
      url: 'https://cldup.com/7NLZklp8zS.png', 
      height: 25, 
      width: 25 
     }, 
     id: 'marker2' 
     }, { 
     "coordinates": [[40.76572150042782,-73.99429321289062],[40.743485405490695, -74.00218963623047],[40.728266950429735,-74.00218963623047],[40.728266950429735,-73.99154663085938],[40.73633186448861,-73.98983001708984],[40.74465591168391,-73.98914337158203],[40.749337730454826,-73.9870834350586]], 
     "type": "polyline", 
     "strokeColor": "#00FB00", 
     "strokeWidth": 4, 
     "strokeAlpha": .5, 
     "id": "foobar" 
     }, { 
     "coordinates": [[40.749857912194386, -73.96820068359375], [40.741924698522055,-73.9735221862793], [40.735681504432264,-73.97523880004883], [40.7315190495212,-73.97438049316406], [40.729177554196376,-73.97180557250975], [40.72345355209305,-73.97438049316406], [40.719290332250544,-73.97455215454102], [40.71369559554873,-73.97729873657227], [40.71200407096382,-73.97850036621094], [40.71031250340588,-73.98691177368163], [40.71031250340588,-73.99154663085938]], 
     "type": "polygon", 
     "fillAlpha":1, 
     "strokeColor": "#fffff", 
     "fillColor": "blue", 
     "id": "zap" 
     }] 
    }; 
    }, 

    render: function() { 
    StatusBarIOS.setHidden(true); 
    return (
     <View style={styles.container}> 

     <Text style={styles.text} onPress={() => this.addAnnotations(mapRef, [{ 
      coordinates: [40.73312,-73.989], 
      type: 'point', 
      title: 'This is a new marker', 
      id: 'foo' 
     }, { 
      "coordinates": [[40.749857912194386, -73.96820068359375], [40.741924698522055,-73.9735221862793], [40.735681504432264,-73.97523880004883], [40.7315190495212,-73.97438049316406], [40.729177554196376,-73.97180557250975], [40.72345355209305,-73.97438049316406], [40.719290332250544,-73.97455215454102], [40.71369559554873,-73.97729873657227], [40.71200407096382,-73.97850036621094], [40.71031250340588,-73.98691177368163], [40.71031250340588,-73.99154663085938]], 
      "type": "polygon", 
      "fillAlpha": 1, 
      "fillColor": "#000", 
      "strokeAlpha": 1, 
      "id": "new-black-polygon" 
     }])}> 
      Add new marker 
     </Text> 
     <Text style={styles.text} onPress={() => this.selectAnnotationAnimated(mapRef, 0)}> 
      Open first popup 
     </Text> 
     <Text style={styles.text} onPress={() => this.removeAnnotation(mapRef, 0)}> 
      Remove first annotation 
     </Text> 
     <MapboxGLMap 
      style={styles.map} 
      direction={0} 
      rotateEnabled={true} 
      scrollEnabled={true} 
      zoomEnabled={true} 
      showsUserLocation={true} 
      ref={mapRef} 
      accessToken={'pk.eyJ1IjoibWF0dGhld2JldGEiLCJhIjoiY2lmcGZxdnpnMDFqOXVlbHllazRwcWxqZSJ9.M0lbiLNHcd-WT-Ps_MkCvA'} 
      styleURL={'asset://styles/streets-v8.json'} 
      centerCoordinate={this.state.center} 
      userLocationVisible={true} 
      zoomLevel={this.state.zoom} 
      onRegionChange={this.onRegionChange} 
      onRegionWillChange={this.onRegionWillChange} 
      annotations={this.state.annotations} 
      onOpenAnnotation={this.onOpenAnnotation} 
      onRightAnnotationTapped={this.onRightAnnotationTapped} 
      onUpdateUserLocation={this.onUpdateUserLocation} /> 
     </View> 
    ); 
    } 
}); 

var styles = StyleSheet.create({ 
    container: { 
    flex: 1 
    }, 
    map: { 
    flex: 1 
    }, 
    text: { 
    padding: 3 
    } 
}); 

AppRegistry.registerComponent('MapBoxDemo',() => MapBoxDemo); 
+0

我遇到了同樣的問題。似乎與「座標」鍵有關的問題。 – Jaec

回答

0

Xcode中是否有錯誤?此外,刪除不必要的代碼可能是一個好主意,只需嘗試向地圖添加註釋即可。

如果您也可以嘗試和運行上反應操場代碼,我也許能幫助調試這更好的,這裏有一個例子:https://rnplay.org/apps/KR9WOw

+0

嗨。已更新我的問題並分叉您的代碼。把我的代碼放進去,我沒有看到標記 - 這表明我做錯了什麼。代碼在這裏:https://rnplay.org/apps/94SIyw – matthewbeta

+0

阿哈,比較我的代碼和你的註釋經緯度是對象上的獨立鍵。礦是一個「座標」鍵的數組(按照回購示例)。我現在將去調整應用程序代碼並報告。語法是否改變? – matthewbeta

+0

我已經在我的應用中更新了它們,並可以看到標記。創建折線/多邊形的語法是什麼?數組的座標數組似乎不起作用。 (感謝您的幫助順便說一句:D) – matthewbeta