greenT恤 2018-12-24 11:30 采纳率: 0%
浏览 653

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() {
                //获取地图当前视图
  • 写回答

2条回答 默认 最新

  • weixin_42118919 2018-12-24 04:35
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?