React Native 集成 ArcGIS 地图

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。

创建工程

  • 初始化工程(需要科学上网)
shell 复制代码
npx react-native init MyReactNativeApp
  • 安装依赖
shell 复制代码
cd MyReactNativeApp/ios
pod install

安装react-native-arcgis-mapview

  • 使用 npm 安装 react-native-arcgis-mapview 库
shell 复制代码
cd MyReactNativeApp
npm install react-native-arcgis-mapview
  • 修改 ios/Podfile 文件,在最后添加
shell 复制代码
pod 'RNArcGISMapView', :path => "../node_modules/react-native-arcgis-mapview/ios"
  • 编辑 node_modules/react-native-arcgis-mapview/ios/RNArcGISMapView.podspec,修改 dependency 版本为 100.14.1。
shell 复制代码
s.dependency 'ArcGIS-Runtime-SDK-iOS', '100.4'
=>
s.dependency 'ArcGIS-Runtime-SDK-iOS', '100.14.1'
  • 使用 pod install 安装 ArcGIS-Runtime-SDK-iOS
shell 复制代码
cd MyReactNativeApp/ios
pod install

使用 react-native-arcgis-mapview

  • 在 App.js 中使用 react-native-arcgis-mapview 库,完整代码如下
JavaScript 复制代码
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

验证

  • 运行项目,验证是否成功。
shell 复制代码
npm start
相关推荐
~ rainbow~12 小时前
vue3集成高德地图绘制轨迹地图
arcgis
EndingCoder1 天前
React Native UI 框架与动画系统:打造专业移动应用界面
react native·react.js·ui
GIS思维2 天前
ArcGIS Pro+ArcGIS给你的地图加上北回归线!
arcgis·arcgis pro·arcgis pro中国制图
GIS思维2 天前
ArcGIS Pro制作水平横向图例+多级标注
arcgis·arcgispro·水平图例·arcgis pro水平图例
安迁岚2 天前
ArcGIS中坐标系一致但图层无法重叠问题解决
arcgis·坐标系·地理范围
程序员小张丶2 天前
基于React Native的HarmonyOS 5.0休闲娱乐类应用开发
react native·娱乐·harmonyos5.0
新中地GIS开发老师2 天前
2025武汉考研形势分析,趋势、挑战与应对策略
学习·考研·arcgis·大学生·gis开发·webgis·地理信息科学
EndingCoder2 天前
网络请求与本地存储:Axios 与 AsyncStorage 在 React Native 中的应用
网络·react native·php
程序员小刘2 天前
React Native 跨平台开发:iOS 与安卓原生模块高效交互
android·react native·react.js·ios
zm-v-159304339862 天前
GPT-ArcGIS 在生态评价中的综合应用:多因子权重分析与适宜性制图
gpt·arcgis