Skip to content

Instantly share code, notes, and snippets.

@hrishimittal
Created October 13, 2018 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hrishimittal/de4ac8996802776cf86f7eaf0f5e880d to your computer and use it in GitHub Desktop.
Save hrishimittal/de4ac8996802776cf86f7eaf0f5e880d to your computer and use it in GitHub Desktop.
react-native-webview-leaflet on iOS
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:
'&amp;copy <a href=&quot;http://osm.org/copyright&quot;>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