ArcGis无法加载层:无法读取未定义的属性(读取' bind')
脚本查询公共
[esri.layers.FeatureLayer] #load() Failed to load layer (title: 'Subway tcl stations center wgs84', id: '180b472baf2-layer-0') {
error: TypeError: Cannot read properties of undefined (reading 'bind')
at H (file:///home/cheezsteak/Code/Typescript/arcgis-query/node_modules/@arcgis/core/request.js:5:3006)
at C (file:///home/cheezsteak/Code/Typescript/arcgis-query/node_modules/@arcgis/core/request.js:5:1588)
at l._fetchService (file:///home/cheezsteak/Code/Typescript/arcgis-query/node_modules/@arcgis/core/layers/graphics/sources/FeatureLayerSource.js:5:7865)
at load (file:///home/cheezsteak/Code/Typescript/arcgis-query/node_modules/@arcgis/core/layers/graphics/sources/FeatureLayerSource.js:5:2197)
at load (file:///home/cheezsteak/Code/Typescript/arcgis-query/node_modules/@arcgis/core/core/Loadable.js:5:999)
at l.createGraphicsSource (file:///home/cheezsteak/Code/Typescript/arcgis-query/node_modules/@arcgis/core/layers/FeatureLayer.js:5:13567)
at async file:///home/cheezsteak/Code/Typescript/arcgis-query/node_modules/@arcgis/core/layers/FeatureLayer.js:5:7341
at async Promise.all (index 2)
}
打字稿
中的一些节点
{
"name": "arcgis-query",
"version": "0.0.0",
"main": "./src/main.ts",
"type": "module",
"license": "GPL",
"private": true,
"dependencies": {
"@arcgis/core": "^4.23.7",
"typescript": "^4.6.3"
},
"scripts": {
"build": "tsc",
"start": "node ./out/main.js"
}
}
ArcGIS
{
"compilerOptions": {
"target": "ES2020",
"module": "ES2020",
"rootDir": "src",
"moduleResolution": "node",
"outDir": "./out",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitAny": true,
"skipLibCheck": true
}
}
服务器
import FeatureLayer from '@arcgis/core/layers/FeatureLayer.js'
import Query from '@arcgis/core/rest/support/Query.js'
import SpatialReference from '@arcgis/core/geometry/SpatialReference.js'
const main = async (): Promise<void> => {
const url: string =
'https://services.arcgis.com/V6ZHFr6zdgNZuVG0/ArcGIS/rest/services/subway_tcl_stations_center_wgs84/FeatureServer/0'
const featureLayer = new FeatureLayer({ url })
const query = new Query({
outSpatialReference: SpatialReference.WGS84,
})
const featureSet = await featureLayer.queryFeatures(query)
console.log('Feature Set', featureSet)
}
main()
我正在尝试使用 ;&amp;纱构建&amp;&amp;纱线启动,我在上面会出现错误。
如果我插入等待featurelayer.load()
在查询之前,我会遇到相同的错误。
“未定义的'绑定'”消息对我来说意味着它正在尝试将特征层显示到某个地方,但是我还没有告诉它,因为我根本不想显示它。严格来说,这是一个控制台应用程序。
更新:打字条不是问题。它似乎是在节点中运行ArcGIS代码,这是问题所在。如果我将src/main.ts
转换为src/main.js
so:
import FeatureLayer from '@arcgis/core/layers/FeatureLayer.js'
import Query from '@arcgis/core/rest/support/Query.js'
import SpatialReference from '@arcgis/core/geometry/SpatialReference.js'
const main = () => {
const url =
'https://services.arcgis.com/V6ZHFr6zdgNZuVG0/ArcGIS/rest/services/subway_tcl_stations_center_wgs84/FeatureServer/0'
const featureLayer = new FeatureLayer({ url })
const query = new Query({
outSpatialReference: SpatialReference.WGS84,
})
featureLayer.queryFeatures(query).then(featureSet => {
console.log('Feature Set', featureSet)
})
}
main()
并使用node> node src/main.js
运行相同的错误。
I'm trying to query a public ArcGIS server using a some a node script in Typescript but I'm getting the error:
[esri.layers.FeatureLayer] #load() Failed to load layer (title: 'Subway tcl stations center wgs84', id: '180b472baf2-layer-0') {
error: TypeError: Cannot read properties of undefined (reading 'bind')
at H (file:///home/cheezsteak/Code/Typescript/arcgis-query/node_modules/@arcgis/core/request.js:5:3006)
at C (file:///home/cheezsteak/Code/Typescript/arcgis-query/node_modules/@arcgis/core/request.js:5:1588)
at l._fetchService (file:///home/cheezsteak/Code/Typescript/arcgis-query/node_modules/@arcgis/core/layers/graphics/sources/FeatureLayerSource.js:5:7865)
at load (file:///home/cheezsteak/Code/Typescript/arcgis-query/node_modules/@arcgis/core/layers/graphics/sources/FeatureLayerSource.js:5:2197)
at load (file:///home/cheezsteak/Code/Typescript/arcgis-query/node_modules/@arcgis/core/core/Loadable.js:5:999)
at l.createGraphicsSource (file:///home/cheezsteak/Code/Typescript/arcgis-query/node_modules/@arcgis/core/layers/FeatureLayer.js:5:13567)
at async file:///home/cheezsteak/Code/Typescript/arcgis-query/node_modules/@arcgis/core/layers/FeatureLayer.js:5:7341
at async Promise.all (index 2)
}
The relevant code is:
package.json
{
"name": "arcgis-query",
"version": "0.0.0",
"main": "./src/main.ts",
"type": "module",
"license": "GPL",
"private": true,
"dependencies": {
"@arcgis/core": "^4.23.7",
"typescript": "^4.6.3"
},
"scripts": {
"build": "tsc",
"start": "node ./out/main.js"
}
}
tsconfig.json
{
"compilerOptions": {
"target": "ES2020",
"module": "ES2020",
"rootDir": "src",
"moduleResolution": "node",
"outDir": "./out",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitAny": true,
"skipLibCheck": true
}
}
src/main.ts
import FeatureLayer from '@arcgis/core/layers/FeatureLayer.js'
import Query from '@arcgis/core/rest/support/Query.js'
import SpatialReference from '@arcgis/core/geometry/SpatialReference.js'
const main = async (): Promise<void> => {
const url: string =
'https://services.arcgis.com/V6ZHFr6zdgNZuVG0/ArcGIS/rest/services/subway_tcl_stations_center_wgs84/FeatureServer/0'
const featureLayer = new FeatureLayer({ url })
const query = new Query({
outSpatialReference: SpatialReference.WGS84,
})
const featureSet = await featureLayer.queryFeatures(query)
console.log('Feature Set', featureSet)
}
main()
Run with yarn install && yarn build && yarn start
and I get the error above.
If I insert await featureLayer.load()
before querying I get the same error.
The "undefined 'bind'" message implies to me that it's trying display the feature layer to somewhere, but I haven't told it where yet, because I don't want to display it at all. This is strictly a console application.
update: Typescript isn't the issue. It seems to be running arcgis code in node that's the problem. If I translate src/main.ts
to src/main.js
like so:
import FeatureLayer from '@arcgis/core/layers/FeatureLayer.js'
import Query from '@arcgis/core/rest/support/Query.js'
import SpatialReference from '@arcgis/core/geometry/SpatialReference.js'
const main = () => {
const url =
'https://services.arcgis.com/V6ZHFr6zdgNZuVG0/ArcGIS/rest/services/subway_tcl_stations_center_wgs84/FeatureServer/0'
const featureLayer = new FeatureLayer({ url })
const query = new Query({
outSpatialReference: SpatialReference.WGS84,
})
featureLayer.queryFeatures(query).then(featureSet => {
console.log('Feature Set', featureSet)
})
}
main()
and run with node src/main.js
I get the same error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只是为了证明代码应该起作用。我使用另一个具有较少功能的服务来轻松工作。
Just to prove that the code should work. I use another service that has less features in order to work easy.
看来我正在使用的库严格用于浏览器使用情况。我应该使用
@esri/arcgis-rest-feature-service
。package.json
src/main.ts
It looks like the library I was using is strictly for in-browser usage. I should've been using
@esri/arcgis-rest-feature-service
instead.package.json
src/main.ts