javascript里面定时器可用,执行代码可用,把执行代码放到定时器就没用了

这里定时器可行,执行代码也可以执行,但是把执行代码放到定时器就不能执行了,控制台显示:无法获取未定义或null引用的属性“ol_uid",有大神可以帮忙看看吗?急!!!

map.on('postcompose', function (event) {
                var greenX, greenY;
                if(greenPoints){
                    for (var i = 0; i < greenPoints.length; i++) {
                        greenX = pxOrigin[0] + (greenPoints[i].x / pxRes);
                        greenY = pxOrigin[1] + (greenPoints[i].y / pxRes);
                        var featureport = source.getFeatureById(greenPoints[i].label_id);
                        var featureId=greenPoints[i].label_id;
                        var status=greenPoints[i].status;
                        var timed=null;
                        if (featureport != null) {
                            featureport.setId(greenPoints[i].label_id);
                            featureport.setStyle(getFeatureStyleByStatus(greenPoints[i].status, greenPoints[i].user_type, greenPoints[i].user_name));
                            var geo = featureport.getGeometry();
                            geo.setCoordinates([ greenX, greenY ]);
                            if(status =='1'){
                                clearTimeout(timed);
                                timed = setTimeout(function(){
                                    source.removeFeature(source.getFeatureById(featureId));
                                },5000);
                            };
                        } else {
                            featureport = new ol.Feature({
                                id : greenPoints[i].label_id,
                                geometry : new ol.geom.Point([ greenX, greenY ]),
                                name : 'point' + greenPoints[i].label_id
                            });
                            featureport.setId(greenPoints[i].label_id);
                            //点的样式
                            featureport.setStyle(getFeatureStyleByStatus(greenPoints[i].status, greenPoints[i].user_type, greenPoints[i].user_name));
                            //添加在线的点
                            if(status != "1"){
                                source.addFeature(featureport);
                            }
                        }
                    }
                }
            })
            //地图缩小
            document.getElementById("zoom-out").onclick = function() {
                //获取地图当前视图

作用域问题把,哪个标量不不能用,

建议写个小demo,定时器会出现作用域问题