反应本机和WMS

Chr*_*uín 9 wms reactjs react-native

我正在React Native中开发一个需要使用Web Map Services的移动应用程序。我尚未找到任何允许同时使用WMS并进行本机响应的库或框架。在React(Web)中,我找到了一个。我的问题是:

您是否知道是否存在允许我使用WMS和React Native的任何库或框架,或者是否有可能在React native中集成React(web)库?

谢谢!

Chr*_*uín 7

我决定使用的方法如下:

  1. 使用WebViewfrom react-native

  2. 使用openlayers

从您的react-native类中声明render方法中的一个变量,其中包含来自openlayers地图的HTML代码: render() { var html = ` <!DOCTYPE html> <html> <head> <title>Simple Map</title> <link rel="stylesheet" href="https://openlayers.org/en/v3.20.0/css/ol.css" type="text/css"> <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x --> <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script> <script src="https://openlayers.org/en/v3.20.0/build/ol.js"></script> </head> <body> <div id="map" class="map"></div> <script> var map = new ol.Map({ layers: [ new ol.layer.Tile({ source: new ol.source.OSM() }) ], target: 'map', view: new ol.View({ center: [0, 0], zoom: 2 }) }); </script> </body> </html> `

然后将此变量传递给WebView: return ( <View style={styles.container}> <WebView ref={webview => { this.webview = webview; }} source={{html}} onMessage={this.onMessage}/> </View> ); } }

如果您想将react-native端与WebView端进行通信,请查看react-native的WebView示例。

您可以在openlayers示例页面中找到更多示例。