ArcGis无法加载层:无法读取未定义的属性(读取' bind')

发布于 2025-01-25 20:27:25 字数 3695 浏览 4 评论 0原文

脚本查询公共

[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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

以歌曲疗慰 2025-02-01 20:27:25

只是为了证明代码应该起作用。我使用另一个具有较少功能的服务来轻松工作。

<html>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    />
    <title>
      Intro to FeatureLayer | Sample | ArcGIS API for JavaScript 4.23
    </title>

    <link
      rel="stylesheet"
      href="https://js.arcgis.com/4.23/esri/themes/light/main.css"
    />
    <script src="https://js.arcgis.com/4.23/"></script>

    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }
    </style>

    <script>
      require([
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/FeatureLayer",
        "esri/rest/support/Query",
        "esri/geometry/SpatialReference"
      ], (
        Map,
        MapView,
        FeatureLayer,
        Query,
        SpatialReference
      ) => {
        // Carbon storage of trees in Warren Wilson College.
        const featureLayer = new FeatureLayer({
          url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/ArcGIS/rest/services/subway_tcl_stations_center_wgs84/FeatureServer/0"
        });

        let query = featureLayer.createQuery({
          outSpatialReference: SpatialReference.WGS84
        });
        featureLayer.queryFeatures(query)
          .then(function(response){
            console.log(response);
            document.getElementById("response").innerText = JSON.stringify(response.features);
          });
      });
    </script>
  </head>

  <body>
    <div id="response"></div>
  </body>
</html>

Just to prove that the code should work. I use another service that has less features in order to work easy.

<html>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    />
    <title>
      Intro to FeatureLayer | Sample | ArcGIS API for JavaScript 4.23
    </title>

    <link
      rel="stylesheet"
      href="https://js.arcgis.com/4.23/esri/themes/light/main.css"
    />
    <script src="https://js.arcgis.com/4.23/"></script>

    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }
    </style>

    <script>
      require([
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/FeatureLayer",
        "esri/rest/support/Query",
        "esri/geometry/SpatialReference"
      ], (
        Map,
        MapView,
        FeatureLayer,
        Query,
        SpatialReference
      ) => {
        // Carbon storage of trees in Warren Wilson College.
        const featureLayer = new FeatureLayer({
          url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/ArcGIS/rest/services/subway_tcl_stations_center_wgs84/FeatureServer/0"
        });

        let query = featureLayer.createQuery({
          outSpatialReference: SpatialReference.WGS84
        });
        featureLayer.queryFeatures(query)
          .then(function(response){
            console.log(response);
            document.getElementById("response").innerText = JSON.stringify(response.features);
          });
      });
    </script>
  </head>

  <body>
    <div id="response"></div>
  </body>
</html>

喜你已久 2025-02-01 20:27:25

看来我正在使用的库严格用于浏览器使用情况。我应该使用@esri/arcgis-rest-feature-service

package.json

{
  "name": "arcgis-query",
  "version": "0.0.0",
  "main": "./src/main.ts",
  "type": "module",
  "license": "GPL",
  "private": true,
  "dependencies": {
    "@esri/arcgis-rest-feature-service": "^4.0.3",
    "@esri/arcgis-rest-portal": "^4.0.3",
    "@esri/arcgis-rest-request": "^4.0.3",
    "typescript": "^4.6.3"
  },
  "scripts": {
    "build": "tsc",
    "start": "node ./out/main.js"
  }
}

src/main.ts

import * as arcgisRest from "@esri/arcgis-rest-request"
import * as arcgisRestFeatureService from "@esri/arcgis-rest-feature-service"

const main = async (): Promise<void> => {
  const url: string =
    'https://services.arcgis.com/V6ZHFr6zdgNZuVG0/ArcGIS/rest/services/subway_tcl_stations_center_wgs84/FeatureServer/0'
  const featureSet = await arcgisRestFeatureService.queryFeatures({
    url
  })
  console.log('Feature Set', featureSet)
}

main()

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

{
  "name": "arcgis-query",
  "version": "0.0.0",
  "main": "./src/main.ts",
  "type": "module",
  "license": "GPL",
  "private": true,
  "dependencies": {
    "@esri/arcgis-rest-feature-service": "^4.0.3",
    "@esri/arcgis-rest-portal": "^4.0.3",
    "@esri/arcgis-rest-request": "^4.0.3",
    "typescript": "^4.6.3"
  },
  "scripts": {
    "build": "tsc",
    "start": "node ./out/main.js"
  }
}

src/main.ts

import * as arcgisRest from "@esri/arcgis-rest-request"
import * as arcgisRestFeatureService from "@esri/arcgis-rest-feature-service"

const main = async (): Promise<void> => {
  const url: string =
    'https://services.arcgis.com/V6ZHFr6zdgNZuVG0/ArcGIS/rest/services/subway_tcl_stations_center_wgs84/FeatureServer/0'
  const featureSet = await arcgisRestFeatureService.queryFeatures({
    url
  })
  console.log('Feature Set', featureSet)
}

main()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文