使用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後,發現https://community.esri.com/thread/225677-how-to-add-a-proxy-to-the-arcgis-js-api-webpack-typescript-demo-app提到上述問題,並給出如下解決方法
將import urlUtils from "esri/core/urlUtils"修改爲
import urlUtils=require("esri/core/urlUtils")
即可解決上述問題