英文:
How to know, whether leaflet layer is fully rendered or not in browser?
问题
我试图检查图层渲染事件。我尝试了以下代码,但它不起作用。我漏掉了什么吗?
var renderer = new L.canvas(); // 我也尝试了 L.svg()
var latlngs = [[37, -109.05], [41, -109.03], [41, -102.05], [37, -102.04]];
var polygon = L.polygon(latlngs, { color: 'red', renderer: renderer }).addTo(map);
// 更新事件
renderer.on('update', () => {
console.log('多边形已加载')
renderer.off('update')
})
我注意到渲染器上的更新方法只在地图平移或缩放事件之后才起作用。但在第一次地图渲染时,它没有触发。请帮忙,谢谢。
我已经在
leaflet
的讨论区中提出了同样的问题。
PS:以下代码对于 tilelayer
完美运行,但对于其他类型的图层则不起作用。
tile_layer.on("load", function() { console.log("所有可见瓦片已加载") });
英文:
I am trying to check the layer rendering event. I have tried the following code, but it is not working. Am I missing something?
var renderer = new L.canvas(); // I tried with L.svg() too
var latlngs = [[37, -109.05], [41, -109.03], [41, -102.05], [37, -102.04]];
var polygon = L.polygon(latlngs, { color: 'red', renderer: renderer }).addTo(map);
//update event
renderer.on('update', () => {
console.log('polygon loaded')
renderer.off('update')
})
I notice that the update method on the renderer only works after a map pan or zoom event. But on the first map render, it didn't trigger. Any help, please?
> I have added the same question in leaflet
discussion section
PS: The following code works perfectly for the tilelayer
but not on the other type of layers.
tile_layer.on("load",function() { console.log("all visible tiles have been loaded") });
答案1
得分: 3
只需更改您的代码顺序,特别是这些行。
renderer.on('update', () => {
console.log('多边形已加载');
renderer.off('update');
});
var polygon = L.polygon(latlngs, { color: '红色', renderer: renderer }).addTo(map);
英文:
just change the order of your code.Specially these lines.<br>
renderer.on('update', () => {
console.log('polygon loaded')
renderer.off('update')
})
var polygon = L.polygon(latlngs, { color: 'red', renderer: renderer }).addTo(map);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论