huiyan-fe / mapv

a library of geography visualization-地理信息可视化库
http://mapv.baidu.com
BSD 3-Clause "New" or "Revised" License
2.58k stars 787 forks source link

源码疑问 #200

Open cuitwangshicheng opened 5 years ago

cuitwangshicheng commented 5 years ago

在初始化DataSet的时候

function DataSet(data, options) {
    Event.bind(this)();

    this._options = options || {};
    this._data = []; // map with data indexed by id

    // add initial data when provided
    if (data) {
        this.add(data);
    }

}

调用了add方法,而在add方法(如下)

/**
 * Add data.
 */
DataSet.prototype.add = function (data, senderId) {
    if (Array.isArray(data)) {
        // Array
        for (var i = 0, len = data.length; i < len; i++) {
            if (data[i].time && data[i].time.length == 14 && data[i].time.substr(0, 2) == '20') {
                var time = data[i].time;
                data[i].time = new Date(time.substr(0, 4) + '-' + time.substr(4, 2) + '-' + time.substr(6, 2) + ' ' + time.substr(8, 2) + ':' + time.substr(10, 2) + ':' + time.substr(12, 2)).getTime();
            }
            this._data.push(data[i]);
        }
    } else if (data instanceof Object) {
        // Single item
        this._data.push(data);
    } else {
        throw new Error('Unknown dataType');
    }

    this._dataCache = JSON.parse(JSON.stringify(this._data));
};

如果传入的data数组中不包含time属性,在add中的循环是不是就没有意义了?白白的进行了一个循环,如果这个数组很长,这个开销就太大了

cuitwangshicheng commented 5 years ago

并且这个time的格式有严格要求,并且time只能是20XX年才会生效?

Junior2Ran commented 4 years ago

time单纯的传数字也可以,比如0-100这样的