使用TypeScript封装了一下地图相关模块,需要在初始化的时候,统一配置代理。所以使用 esri/core/urlUtils进行配置。
在js中,一般如下使用,相关ARCGIS请求则转发至代理处理。
require(["esri/core/urlUtils"],function(urlUtils){
urlUtils.addProxyRule({
urlPrefix: "http://llcgreat",
proxyUrl: "http://localhost/GRSH.XCSmartWaterOneMap.Proxy/Proxy.ashx"
});
//其他代码。。。。
})
在TypeScript中,也按照上述方式修改
import urlUtils from "esri/core/urlUtils";
//其他相关 import
class mapinitial{
constructor(){
urlUtils.addProxyRule({
urlPrefix: "http://llcgreat",
proxyUrl: "http://localhost/GRSH.XCSmartWaterOneMap.Proxy/Proxy.ashx"
});
//其他初始化代码
}
}
运行后报错:Uncaught TypeError: Cannot read property 'addProxyRule' of undefined
Google后,发现Solved: How to add a proxy to the arcgis-js-api Webpack Ty... - Esri Community提到上述问题,并给出如下解决方法
将import urlUtils from "esri/core/urlUtils"修改为
import urlUtils=require("esri/core/urlUtils")
即可解决上述问题
经过测试,发现 webMercatorUtils,watchUtils也存在上述问题