Web Worker未返回执行操作的结果

时间:2015-06-25 09:10:46

标签: javascript web-worker lodash turfjs

我有一个没有返回执行计算结果的Web worker,方法如下:

 self.checkIntersectionForLayerWith = function checkIntersectionForLayerWith(data) {

var checkIntersectionForLayer = function checkIntersectionForLayer() {

    var checkEachConflict = function checkEachConflict(feature){

        var conflict = turf.intersect(feature,data.rectFeature);

            if(conflict != null) {
                _.extend(conflict.properties,feature.properties);
                conflict.id = feature.id;
            }

            return conflict;
        };

    var intersectiontest = self._(data.features)
                                .map(checkEachConflict)
                                .pull(void 0)
                                .thru(self.turf.featurecollection)
                                .value();

    return {
            layerLabel:data.layerLabel,
            query:data.rectFeature,
            result:data.intersectiontest
        };


};

return checkIntersectionForLayer;
}; 

我调用这样的方法:

    self.startQuery = function startQuery(data) {

    if(data != null) {
        var checkIntersectionForLayer = self.checkIntersectionForLayerWith(data);
        var result = checkIntersectionForLayer();
        var payload = {
                type:'rectangle_query_worker_result',
                result:result
        };
        self.postMessage(payload);
    }
};

self.onmessage = function startQueryWorker(e) {
    if(e.data.type === 'start') {
        console.log("Inside the web worker,",e,e.data,e.data.payload);
        self.startQuery(e.data.payload);
    }
    else if(e.data.type === 'setup') { 
        self.setup();
    }
};

我像这样调用nessecary库:

self.setup = function setup() {

    importScripts('/MapErpMobileDev/leaflet/mobile/js/lib/turf.js');
    importScripts('/MapErpMobileDev/leaflet/mobile/js/lib/lodash.compat.min.js');
};

0 个答案:

没有答案