arcgis官方提供了 javascript sdk,也提供了 arcgis-runtime-sdk-ios,但是并没有提供 react native的版本,所以这里使用了 react-native-arcgis-mapview 库,这个库比较老,支持的 arcgis-runtime-sdk-ios 版本是100.4,但是在使用的时候发现,在使用pod install安装的时候总是会下载失败,所以后面手动将 arcgis-runtime-sdk-ios 的版本改为 100.14.1。
创建工程
初始化工程(需要科学上网)
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
验证
运行项目,验证是否成功。
npm start
到此这篇关于react native 集成 arcgis 地图的文章就介绍到这了,更多相关react native arcgis 地图内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论