mapbox getsource返回对象返回未定义值

发布于 2025-02-03 18:24:31 字数 678 浏览 4 评论 0原文

我正在调用getsource方法load> load事件类似:

map.on('load', () => {

map.addSource("country-boundary-source", {
    type: "vector",
    url: "mapbox://mapbox.country-boundaries-v1"
});

const source = map.getSource("country-boundary-source");

console.log("Source:", source);

})

在输出中,该对象具有诸如vectorlayers and code>和vectorLayerIds之类的字段。但是,当我使用source.vectorlayers调用这些值时,我会返回给我一个未定义的值。我不太确定为什么会发生这种情况,因为它正在输出。

I am calling the getSource method inside a load event like so:

map.on('load', () => {

map.addSource("country-boundary-source", {
    type: "vector",
    url: "mapbox://mapbox.country-boundaries-v1"
});

const source = map.getSource("country-boundary-source");

console.log("Source:", source);

})

In the output, the object has fields such as vectorLayers and vectorLayerIds. However when I call these values using source.vectorLayers I get an undefined value returned to me. I'm not really sure why this would be happening, since it is being outputted.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文