zoukankan      html  css  js  c++  java
  • 多层数据注入同一个图层源时,要批量删除某一种要素

    问题:因为多种类型要素放入同一个源,在删除某一类要素时需要遍历整个图层源,符合条件后才执行

    source.removeFeature(feature);
    

      这样后导致程序执行速度很慢。

    解决方案:在将各类要素添加到source的同时,将所有要素都存入一个数组FeatureList[]中,在需要删除一类要素时,首先直接将source清空(source.clear()),再遍历该数组并将符合条件的数组元素在数组中删除,最后将数组剩余的要素添加到source中。

    示例代码:

    //添加要素 
    for (var i = 0; i < obj.length; i++) { var coodinate = [Number(obj[i].lon), Number(obj[i].lat)]; var point = new ol.geom.Point(coodinate); //根据坐标生成要素点 var feature = new ol.Feature({ geometry: point, tablename: tablename, featureId: obj[i].id }); //设置样式 feature.setStyle(new ol.style.Style({ image: new ol.style.Icon({ anchor: [0.5, 30], anchorXUnits: 'fraction', anchorYUnits: 'pixels', src: icons[4] }), text: new ol.style.Text({ text: obj[i].name, font: '700 12px 微软雅黑', fill: new ol.style.Fill({ color: "#000" }), stroke: new ol.style.Stroke({ color: "rgb(253,252,252)", 0.5 }), offsetY: -35, }) })); features.push(feature);
    //将各类要素同时加入到featureList
    featureList.push(feature) 

    }
    //遍历删除要素
    buliding_source.clear();
            for (var i = 0; i < featureList.length; i++) {
                if (featureList[i].N.tablename == tablename) {
                    featureList.splice(i, 1);
                    i--;
                }
            }
            buliding_source.addFeatures(featureList);
    
    
    




  • 相关阅读:
    java插入语句中有单引号的处理
    mybatis批量插入
    用Resttemple从数据接口中取出数据
    java1.8Stream流式算法
    rabbitmq启动命令
    【MySQL】Mysql模糊查询like提速优化
    Mybatis基础知识点:trim标签的使用
    java8 array、list操作 汇【20】)- (FlatMap)用法汇总
    编写一个定制的收集器
    mysql
  • 原文地址:https://www.cnblogs.com/weixiaoxiang/p/13139199.html
Copyright © 2011-2022 走看看