Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加多个TileLayer,控制台报错 #1936

Closed
luxiousCoder opened this issue Apr 20, 2023 · 5 comments
Closed

添加多个TileLayer,控制台报错 #1936

luxiousCoder opened this issue Apr 20, 2023 · 5 comments

Comments

@luxiousCoder
Copy link
Contributor

描述:在map中添加超过16个tilelayer图层,会报错:Uncaught Error: Failed to create the buffer object
image

代码如下:
// 最多只能创建16个tileLayer,超过16个,会报错:Uncaught Error: Failed to create the buffer object
for (let index = 0; index < 16; index++) {
new maptalks.TileLayer(index, {
urlTemplate: 'https://{s}.basemaps.cartocdn.com/light_nolabels/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c', 'd']
}).addTo(map)
}

@deyihu
Copy link
Collaborator

deyihu commented Apr 20, 2023

@liuxuechao01 这个是正常的,浏览器里webglcontext个数是有限制的
如果业务里确实有很多tilelayer,解决方法:

  • 利用 TileGroupLayer来将多个tilelayer放到一起 https://maptalks.org/examples/en/tilelayer-projection/grouptilelayer/#tilelayer-projection_grouptilelayer
  • 可以创建多个tilelayer,但是不要一股脑的加到地图,根据业务的需要动态添加和移除
  • 如果这些tilelayer是可以合并的,应该想法在数据源出就把这些图源合并掉,即将多个tilelayer服务合并成一个tilelayer服务,如果tilelayer不是自己的发布的而是第三方的,可以在自己的后台把这个tilelayer的对应的请求服务合并成一个tilelayer在返回个前台

@luxiousCoder
Copy link
Contributor Author

@deyihu 目前业务确实有很多个TileLayer,而且要控制图层的叠加顺序和透明度,我用GroupTileLayer尝试过了,如果把图层加载到GroupTileLayer中,就无法单独控制图层的透明度和图层的叠加顺序(ZIndex修改无效),另外这些图层也是无法合并的~~~业务场景就这么设计的~~~

@deyihu
Copy link
Collaborator

deyihu commented Apr 20, 2023

这么多tilelayer光是网络请求就可怕的要死,这个我也没法子了🙄,浏览器的限制摆在那里
这种问题就像需求要在浏览器加载一个100G的文件一样

@luxiousCoder
Copy link
Contributor Author

@deyihu 可能要有3~4十个图层,当然这个是最多的情况,一般不会加载这么多,但是产品设计,是支持这么多图层的,这个问题我跟镇讲了,镇说优化,也不知道怎么优化,哈哈哈

@deyihu
Copy link
Collaborator

deyihu commented Apr 20, 2023

@liuxuechao01 怎样优化都么有用,你知道30-40个tilelayer图层,单位时间内有多少个网络请求?,假设一个图层有20个瓦片,30个图层就 600个网络请求,浏览器会一直排队的,甚至超时,那个体验。。。。。。。。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants