当前位置: 代码网 > it编程>编程语言>Javascript > React Native 集成 ArcGIS 地图的详细过程

React Native 集成 ArcGIS 地图的详细过程

2024年07月02日 Javascript 我要评论
arcgis官方提供了 javascript sdk,也提供了 arcgis-runtime-sdk-ios,但是并没有提供 react native的版本,所以这里使用了 react-native-

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 地图内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com