React Native 集成 ArcGIS 地圖的詳細(xì)過程
ArcGIS官方提供了 JavaScript SDK,也提供了 ArcGIS-Runtime-SDK-iOS,但是并沒有提供 React Native的版本,所以這里使用了 react-native-arcgis-mapview 庫,這個(gè)庫比較老,支持的 ArcGIS-Runtime-SDK-iOS 版本是100.4,但是在使用的時(shí)候發(fā)現(xiàn),在使用pod install安裝的時(shí)候總是會(huì)下載失敗,所以后面手動(dòng)將 ArcGIS-Runtime-SDK-iOS 的版本改為 100.14.1。
創(chuàng)建工程
初始化工程(需要科學(xué)上網(wǎng))
npx react-native init MyReactNativeApp
安裝依賴
cd MyReactNativeApp/ios pod install
安裝react-native-arcgis-mapview
使用 npm 安裝 react-native-arcgis-mapview 庫
cd MyReactNativeApp npm install react-native-arcgis-mapview
修改 ios/Podfile 文件,在最后添加
pod 'RNArcGISMapView', :path => "../node_modules/react-native-arcgis-mapview/ios"
編輯 node_modules/react-native-arcgis-mapview/ios/RNArcGISMapView.podspec,修改 dependency 版本為 100.14.1。
s.dependency 'ArcGIS-Runtime-SDK-iOS', '100.4' => s.dependency 'ArcGIS-Runtime-SDK-iOS', '100.14.1'
使用 pod install 安裝 ArcGIS-Runtime-SDK-iOS
cd MyReactNativeApp/ios pod install
使用 react-native-arcgis-mapview
在 App.js 中使用 react-native-arcgis-mapview 庫,完整代碼如下
import React, {useRef, useState}from 'react'
import {View, Text, Button, StyleSheet } from 'react-native'
import ArcGISMapView, { setLicenseKey } from 'react-native-arcgis-mapview'
function App() {
const key = '<key>'
setLicenseKey(key)
const mapView = useRef(null)
const basemap = 'https://www.arcgis.com/home/item.html?id=6b6b9cea06964cb38d8a654964c347ab'
return (
<View style={styles.container}>
<ArcGISMapView
style={styles.map}
initialMapCenter={[{latitude: 32.788, longitude: -79.940, scale: 10000.0}]}
basemapUrl={basemap}
ref={mapView}
/>
<Button title="Test" onPress={() => {
console.log(mapView.current.props.basemapUrl)
}} />
</View>
);
}
var styles = StyleSheet.create({
container: {
flex: 1,
},
map: {
flex: 1,
},
})
export default App驗(yàn)證
運(yùn)行項(xiàng)目,驗(yàn)證是否成功。
npm start
到此這篇關(guān)于React Native 集成 ArcGIS 地圖的文章就介紹到這了,更多相關(guān)React Native ArcGIS 地圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
解決React報(bào)錯(cuò)The?tag?is?unrecognized?in?this?browser
這篇文章主要為大家介紹了解決React報(bào)錯(cuò)The?tag?is?unrecognized?in?this?browser示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12
React?Flux與Redux設(shè)計(jì)及使用原理
這篇文章主要介紹了React?Flux與Redux設(shè)計(jì)及使用,Redux最主要是用作應(yīng)用狀態(tài)的管理。簡言之,Redux用一個(gè)單獨(dú)的常量狀態(tài)樹(state對象)保存這一整個(gè)應(yīng)用的狀態(tài),這個(gè)對象不能直接被改變2023-03-03
react路由v6版本NavLink的兩個(gè)小坑及解決
這篇文章主要介紹了react路由v6版本NavLink的兩個(gè)小坑及解決,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10

