-
I'm losing my mind trying to figure out why this isn't working. I just want to render geojson data on the map as circles, but nothing is showing up on the map. The map renders successfully, just no points on it. I'm running this using
import { StatusBar } from 'expo-status-bar'
import { StyleSheet } from 'react-native'
import { Map } from './components/map'
const MainScreen = () => {
return (
<>
<Map />
<StatusBar style="auto" />
</>
)
}
const App = () => (
<MainScreen />
)
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
})
export default App
import Mapbox from '@rnmapbox/maps'
import { useEffect, useRef } from 'react'
import { StyleSheet, Text, View } from 'react-native'
import { FeatureCollection } from 'geojson'
Mapbox.setAccessToken(
'pk.ey...',
)
const styles = StyleSheet.create({
page: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
container: {
flex: 1,
backgroundColor: 'tomato',
},
map: {
flex: 1,
},
})
interface MapProps {
data?: FeatureCollection
}
const Map = ({ data }: MapProps) => {
return (
<View style={styles.container}>
<Mapbox.MapView
style={styles.map}
scaleBarEnabled={false}
>
<Mapbox.Camera />
<Mapbox.ShapeSource
shape={
{
type: 'FeatureCollection',
features: [
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [-82.679306, 41.47792], // Ohio, US
},
},
],
} as FeatureCollection
}>
<Mapbox.SymbolLayer
id="markers"
style={
{
circleRadius: 10,
circleColor: 'black',
} as Mapbox.SymbolLayerStyle
}
/>
</Mapbox.ShapeSource>
</Mapbox.MapView>
</View>
)
}
export { Map }
{
"extends": "expo/tsconfig.base",
"compilerOptions": {
"strict": true,
"jsx": "react-jsx"
}
} Any help is greatly appreciated. Can provide more context if needed. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
In the web version I also see this error:
Line 50 is |
Beta Was this translation helpful? Give feedback.
-
Hi @xharris, It looks like you're missing the id in <Mapbox.ShapeSource>. Also, for rendering circles, you should use CircleLayer instead of SymbolLayer. Here’s an example that demonstrates the correct usage: |
Beta Was this translation helpful? Give feedback.
Hi @xharris,
It looks like you're missing the id in <Mapbox.ShapeSource>. Also, for rendering circles, you should use CircleLayer instead of SymbolLayer.
Here’s an example that demonstrates the correct usage:
BugReportExample.js