问题描述
我必须使用ArcGis API 4.16做出反应应用程序。它可以与Internet一起使用,但是我需要使其在本地工作,因为我需要在Intranet网络内部使用api调用。另外,我在公用文件夹中添加了带有用于版本4.16的arc gis库的整个文件夹。
这是我的代码: App.js
import React,{ useEffect,useRef } from 'react';
import { loadModules} from 'esri-loader'
import "./App.css";
export const WebMapView = () => {
const mapRef = useRef();
useEffect(
() => {
loadModules(['esri/Map','esri/views/MapView','esri/layers/FeatureLayer'])
.then(([ArcGISMap,MapView,FeatureLayer]) => {
const map = new ArcGISMap({
basemap: 'topo-vector'
});
const view = new MapView({
container: mapRef.current,map: map,center: [21,44],zoom: 13
});
// load the map view at the ref's DOM node
const trailheadsLayer = new FeatureLayer({
url: "http://11.1.4.162:6080/arcgis/rest/services/BASEMAP/xxxx/xxx"
});
map.add(trailheadsLayer);
const parksLayer = new FeatureLayer({
url: "http://11.1.4.162:6080/arcgis/rest/services/xxxx/xxx"
});
map.add(parksLayer,0);
return () => {
if (view) {
// destroy the map view
view.container = null;
}
};
});
}
);
return (<div className="webmap" ref={mapRef} />)
};
index.js
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script src="./4.16/dojo/dojo.js"></script>
</body>
</html>
当我通过Internet运行应用程序并从index.js删除脚本dojo时,它运行良好。但是,当我要脱机运行它时,它说:“尝试加载https://js.arcgis.com/4.16/'时出错。当我放回dojo脚本时,出现错误“未处理的拒绝(TypeError):MapView不是构造函数”。
我也在dojo.js里面对baseUrl进行了编辑,例如baseUrl:“ http:// localhost:3000 / 4.16 /”。
任何人都可以告诉我谁有经验如何设置此项目以在本地网络上工作吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)