Created
October 13, 2018 11:57
-
-
Save hrishimittal/de4ac8996802776cf86f7eaf0f5e880d to your computer and use it in GitHub Desktop.
react-native-webview-leaflet on iOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { StyleSheet } from 'react-native'; | |
import WebViewLeaflet from 'react-native-webview-leaflet'; | |
onLoad = (event) => { | |
const mapLayers = [ | |
{ | |
name: 'OpenStreetMap', | |
checked: 'true', | |
type: 'TileLayer', | |
baseLayer: true, | |
url: `https://tile.openstreetmap.org/7/63/42.png`, | |
attribution: | |
'&copy <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' | |
} | |
]; | |
// optionally set state | |
this.setState( | |
{ | |
...this.state, | |
mapState: { ...this.state.mapState, mapLoaded: true } | |
}, | |
() => { | |
// send an array of map layer information to the map | |
this.webViewLeaflet.sendMessage({ | |
mapLayers | |
}); | |
} | |
); | |
console.log('onLoad received : ', event); | |
} | |
export default class LinksScreen extends React.Component { | |
render() { | |
return ( | |
<WebViewLeaflet | |
ref={(component) => (this.webViewLeaflet = component)} | |
onLoad={this.onLoad} | |
eventReceiver={this} // the component that will receive map events | |
/> | |
); | |
} | |
} | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
paddingTop: 15, | |
backgroundColor: '#fff', | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment