2017-07-30 25 views
1

Hellow,我正在使用react-native爲我的應用程序創建一個用戶界面。我正在使用Genymotion在虛擬Android上測試我的代碼。我想在我的網絡地圖應用程序中使用Openlayers JavaScript庫。我按照這些步驟:從反應原生態的開放層進口OL

  1. npm install openlayers
  2. 我加import ol from 'openlayers';爲「index.android.js」 然後當我測試與Genymotion代碼我得到一個錯誤。 我用import {ol} from 'openlayers';插入import ol from 'openlayers';但它不起作用。

enter image description here

+0

終端說什麼? – Avdept

+0

我正在使用Windows 8.1。命令提示符說:'at _transform.then.catch.error(C:\ Users \ my_user \ some_directory \ PropertyFinder \ node_modules \ metro-bundler \ build \ JSTransformer \ index.js:138:28)' –

+0

是否可以添加openlayers庫反應 - 本機? –

回答

1

編輯:ANSWER NOT FOR REACT本地(我的壞)

您可能已經發現了這一點,或許它是你正在使用的包,但如果你是嘗試在原生反應項目中使用標準Web版本的開放圖層,您可能會遇到問題。我做了搜索,發現這個包,它似乎是專門爲開放層反應本土

注意這個包只支持打開圖層3,因此,如果您使用的是開放層4,它將會失敗。

這裏的步驟,以得到它的工作

npm install react-openlayers --save-dev 

然後

import { 
    interaction, layer, custom, control, //name spaces 
    Interactions, Overlays, Controls,  //group 
    Map, Layers, Overlay, Util //objects 
} from "react-openlayers"; 

工作示例可以在這裏找到:

https://github.com/allenhwkim/react-openlayers

希望它能幫助!

+0

嗨,謝謝你的回答。你的答案是爲react.js,但我有一個與原生反應的問題。 –

+1

作爲我的不好的答案的懺悔,我做了一些更多的研究,並且我發現了這個線程用於react-native-maps插件。 https://github.com/airbnb/react-native-maps/issues/1098它現在取決於谷歌地圖,但有人正在努力消除這種依賴性,我試圖尋找替代選項,但沒有拿出任何令人滿意的東西:/抱歉 –

+0

沒問題,再次感謝。我在Openlayers3的Web上創建了一個I路由映射應用程序,並且希望使用此模塊(Openlayers on react native)爲Android和IOS創建一個路由映射應用程序,並使其具有原生性。我在後端使用Geoserver REST API。你有好的選擇嗎? –