function scan_file(ta,the_file)
{
	var ta_struct={};
	ta_struct.ta=ta;
	ta_struct.cursor=0;
	var start_cursor=0;
	var n_workers=0;
	var n=0;
	var antal_klara=0;
	var num=0;
	var tree=rbush(20);
	var the_size;
	//The length of the whole binary data bulk
	var the_length=ta.byteLength;
	
	var size_per_worker=the_length/max_workers;

	if(the_length==0)
		return 0;
		
//We check if the first byte flag shows that we have sizes. If the first geometry has sizes we asssume all have
	var flag = ta[ta_struct.cursor];
	if(!(flag&0x02))
		return 0;
	
	while(ta_struct.cursor<the_length)
	{	
		n++
		//we just jump over the first byte
		ta_struct.cursor++;
		
		//Read the geometry size
		the_size=ReadVarInt64(ta_struct);
		//Jump to the start of the next geoemtry
		ta_struct.cursor+=the_size;
		
		//Check if we have enough data to send to a worker
		if(((ta_struct.cursor-start_cursor)>=size_per_worker)||(ta_struct.cursor==the_length))
		{

			var worker = webworkers.w[webworkers.n++] = new Worker('find_bbox_worker.js');
			 
			worker.onmessage = function(e) {
				tree.load(e.data);
				num++;
				if(num==n_workers)
				{
					terminate_workers();
					index_ok();					
				}
			  };

			  worker.onerror = function(e) {
			    document.querySelector('#error').textContent = [
				'ERROR: Line ', e.lineno, ' in ', e.filename, ': ', e.message].join('');
			  };
			  n_workers++;
			 worker.postMessage({"the_file":layers[the_file].the_file,"start":start_cursor,"end":ta_struct.cursor,"n_geometries":n});
			  start_cursor=ta_struct.cursor; 
		}
	}
	//Store the index so we can create more indexes for more layers
	layers[the_file].index=tree;
	delete ta_struct;
}
/*Scan the twkb-file and distribute the work to be done to web workers.
ta is the binary data and the_file is a reference to the file.
*/
Scan the twkb-file and distribute the work to be done to web workers.
ta is the binary data and the_file is a reference to the file.
Scan the twkb - file and distribute the work to be done to web workers . ta is the binary data and the_file is a reference to the file .
function scan_file(ta,the_file)
{
	var ta_struct={};
	ta_struct.ta=ta;
	ta_struct.cursor=0;
	var start_cursor=0;
	var n_workers=0;
	var n=0;
	var antal_klara=0;
	var num=0;
	var tree=rbush(20);
	var the_size;
	var the_length=ta.byteLength;
	var size_per_worker=the_length/max_workers;
	if(the_length==0)
		return 0;
	var flag = ta[ta_struct.cursor];
	if(!(flag&0x02))
		return 0;
	while(ta_struct.cursor<the_length)
	{	
		n++
		ta_struct.cursor++;
		the_size=ReadVarInt64(ta_struct);
		ta_struct.cursor+=the_size;
		if(((ta_struct.cursor-start_cursor)>=size_per_worker)||(ta_struct.cursor==the_length))
		{
			var worker = webworkers.w[webworkers.n++] = new Worker('find_bbox_worker.js');
			worker.onmessage = function(e) {
				tree.load(e.data);
				num++;
				if(num==n_workers)
				{
					terminate_workers();
					index_ok();					
				}
			  };
			  worker.onerror = function(e) {
			    document.querySelector('#error').textContent = [
				'ERROR: Line ', e.lineno, ' in ', e.filename, ': ', e.message].join('');
			  };
			  n_workers++;
			 worker.postMessage({"the_file":layers[the_file].the_file,"start":start_cursor,"end":ta_struct.cursor,"n_geometries":n});
			  start_cursor=ta_struct.cursor; 
		}
	}
	layers[the_file].index=tree;
	delete ta_struct;
}
function scan_file ( ta , the_file ) { var ta_struct = { } ; ta_struct . ta = ta ; ta_struct . cursor = 0 ; var start_cursor = 0 ; var n_workers = 0 ; var n = 0 ; var antal_klara = 0 ; var num = 0 ; var tree = rbush ( 20 ) ; var the_size ; var the_length = ta . byteLength ; var size_per_worker = the_length / max_workers ; if ( the_length == 0 ) return 0 ; var flag = ta [ ta_struct . cursor ] ; if ( ! ( flag & 0x02 ) ) return 0 ; while ( ta_struct . cursor < the_length ) { n ++ ta_struct . cursor ++ ; the_size = ReadVarInt64 ( ta_struct ) ; ta_struct . cursor += the_size ; if ( ( ( ta_struct . cursor - start_cursor ) >= size_per_worker ) || ( ta_struct . cursor == the_length ) ) { var worker = webworkers . w [ webworkers . n ++ ] = new Worker ( 'find_bbox_worker.js' ) ; worker . onmessage = function ( e ) { tree . load ( e . data ) ; num ++ ; if ( num == n_workers ) { terminate_workers ( ) ; index_ok ( ) ; } } ; worker . onerror = function ( e ) { document . querySelector ( '#error' ) . textContent = [ 'ERROR: Line ' , e . lineno , ' in ' , e . filename , ': ' , e . message ] . join ( '' ) ; } ; n_workers ++ ; worker . postMessage ( { "the_file" : layers [ the_file ] . the_file , "start" : start_cursor , "end" : ta_struct . cursor , "n_geometries" : n } ) ; start_cursor = ta_struct . cursor ; } } layers [ the_file ] . index = tree ; delete ta_struct ; }
Scan the twkb-file and distribute the work to be done to web workers.
Scan the twkb - file and distribute the work to be done to web workers .
//The length of the whole binary data bulk //We check if the first byte flag shows that we have sizes. If the first geometry has sizes we asssume all have //we just jump over the first byte //Read the geometry size //Jump to the start of the next geoemtry //Check if we have enough data to send to a worker //Store the index so we can create more indexes for more layers