首页 > 解决方案 > tile.setFeatures() 函数的数据结构

问题描述

我正在尝试使用 tileLoadFunction 向 TileSource 添加功能。这就是函数的样子。

tileLoadFunction: function(tile, url) {


         var z = String(url[0]);
         var x = String(url[1]);
         var y = String(url[2]);
         

         const format = new GeoJSON({featureProjection: view.getProjection()});
          

         fetch("some-url-here"+z+"/"+x+"/"+y+"").then(function (response) {
                   

             if(response.status == 200 || response.status == 201)
              {
                
                   response.json().then(function(data) 
                   { 

                    tile.setFeatures(format.readFeatures(data));
                                            
                  });
              }
          })
     
      },

我在控制台中看到的是错误:Uncaught TypeError: Cannot read property 'ol_uid' of undefined 显然,添加到 setFeatures 函数的数据格式似乎不是必需的。试图在他们的文档中找到它,但无法找到。知道什么结构应该具有“数据”以便以正确的方式设置功能。我的端点提供正常的 GeoJson 数据。

谢谢

标签: openlayers-6

解决方案


推荐阅读