h***@qq.com
h***@qq.com
  • 发布:2024-03-05 22:39
  • 更新:2024-03-06 18:28
  • 阅读:86

【报Bug】unicloud-map回调函数@updated引起无限循环的问题

分类:uniCloud

产品分类: uniCloud/App

操作步骤:


<unicloud-map
ref="map"
......
@updated="onUpdated"

</unicloud-map>

onUpdated(e){
//作用:
//一旦地图重载数据,识别自己,并重新进行绘制。

            this.markers = this.$refs.map.getMarkers();  

            console.log("onReload get markers",this.markers );  
            //遍历数组,找到自己的标记点,更新各标记点的图标、文字,  
            for(var i in this.markers){  

                //如果当前显示所有用户方向  
                if(this.markers[i].ariaLabel==this.userInfo._id){  
                    //自己  
                    this.myMarker= Object.assign(this.markers[i]);                        
                    if(this.showDir)this.markers[i].iconPath=this.directionMyImg;                         
                }else if(this.showDir){  
                    this.markers[i].iconPath=this.directionImg;   
                }  

                if(this.hasNewCenter){  
                    //如果当前在设计中心点,查看是否被选中,选中文字变色  
                    if(this.paternerIDArr.indexOf(this.markers[i].ariaLabel)!=-1){  
                        this.markers[i].callout.color="#ff0000";  
                    }                     
                }  

            }  
            //计算绘制中心点及各标记点  
            if(this.hasNewCenter){  
                //如果当前正在设计中心点  
                this.centerMarker=-1;  
                this.computerCenter();  //重新计算绘制中心点(同时绘制所有点)                  

            }else{  
                this.$refs.map.setMarkers(this.markers);   
            }  
        },

预期结果:

onUpdated()函数中执行:
this.$refs.map.setMarkers(this.markers);
会引起该函数再次被调用,形成无限循环。

实际结果:

onUpdated()函数中执行:
this.$refs.map.setMarkers(this.markers);
会引起该函数再次被调用,形成无限循环。

bug描述:

unicloud-map的回调函数@updated在地图渲染更新完成时触发,这个设计不好,因为每次刷新都会重新读取后台数据库中来生成marker数组,然后重新渲染地图中的标记点。这样会把用户对标记点的修改全部冲掉。为了保持用户的修改,只能在这个回调口再改回去,但是会导致无限循环,因为改完会引起新一轮的渲染,渲染结束后会再次调用回调函数,如此循环。

建议给unicloud-map增加一个@reload的回调函数,一旦数据从后台重新读取就触发这个回调。用户在此维护标记点信息,不会引起无限循环的问题。

2024-03-05 22:39 负责人:无 分享
已邀请:
DCloud_uniCloud_VK

DCloud_uniCloud_VK

已确认,下版本新增 @load 事件 代表数据请求完成后的事件

  • h***@qq.com (作者)

    点赞!响应迅速!我已经在官方代码上加了这个事件,名字叫@reload

    2024-03-07 08:43

要回复问题请先登录注册