I have seen this info: https://stackshare.io/stackups/leaflet-vs-mapbox-vs-openlayers
I'm developing at the same time a web application with react using OpenLayers. And I have to make the same app on mobile using react native but I don't know how to make it works.
Here is my code to web app using React + Openlayers:
import React, { Component } from 'react';
import './App.css';
// openlayers
import View from 'ol/view';
import Projection from 'ol/proj/projection';
import Map from 'ol/map';
import Zoom from 'ol/control/zoom';
import Tile from 'ol/layer/tile';
import OSM from 'ol/source/osm';
class App extends Component {
constructor(props) {
super(props);
this.view = new View({
center: [-41925.302985762304, 4789880.268977703],
zoom: 12,
minZoom: 2,
maxZoom: 28,
projection: new Projection({
code: 'EPSG:3857',
units: 'm'
})
});
}
componentDidMount() {
this.map = new Map({
view: this.view,
controls: [ new Zoom() ],
layers: [new Tile({ source: new OSM() })],
target: 'map'
});
}
render() {
console.log('-> render App')
return (
<div id="map" class="map"></div>
);
}
}
export default App;
And here is my problem, I don't know how to make it works in react native.
How can you add this.map ( javascript Map object ) inside WebView?
I have seen this example in other question React Native and WMS but I would like to work with React because I need to modify, add layers dynamically, etc.
import React, { Component } from 'react';
import { StyleSheet, View, WebView } from 'react-native';
// openlayers
import View from 'ol/view';
import Projection from 'ol/proj/projection';
import Map from 'ol/map';
import Zoom from 'ol/control/zoom';
import Tile from 'ol/layer/tile';
import OSM from 'ol/source/osm';
type Props = {};
export default class App extends Component<Props> {
constructor(props) {
super(props);
this.view = new View({
center: [-41925.302985762304, 4789880.268977703],
zoom: 12,
minZoom: 2,
maxZoom: 28,
projection: new Projection({
code: 'EPSG:3857',
units: 'm'
})
});
}
componentDidMount() {
this.map = new Map({
view: this.view,
controls: [ new Zoom() ],
layers: [new Tile({ name:'tile', source: new OSM() })],
target: 'map'
});
}
render() {
var html = '<div id="map" class="map"></div>';
return (
<View style={styles.container}>
<WebView
ref={webview => { this.webview = webview; }}
source={{html}}
onMessage={this.onMessage}/>
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
}
});