0

我有一个网络工作者没有返回执行计算的结果,该方法如下所示:

 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');
};
4

0 回答 0