Select to view content in your preferred language

How to load geojson geometric data and drawing grapics in background

262
0
01-23-2024 07:45 PM
AbramhumHsu
New Contributor III

I meet a problem when trying to load geojson geometric data and drawing grapics in background ; 

The main problem is drawing grapics in backgroud, I use graphicLayer and hope each graphic in geojson can be drawn on it. I try use web worker to make this processing performed in the background, but it failed.

The main problem is many esri library such as  "esri/Graphic", is a complex object, and inside that has some 

infinite loop function, that cause the web worker can not pass the object to another file, like worker.js.

The code snippet is as following:

main.ejs:
 var usingObject = {
  Graphic: Graphic
 }
 const binaryData = msgpack.encode(usingObject);
 const base64String = btoa(String.fromCharCode.apply(null, binaryData));
 const worker = new Worker("worker.js");
 worker.postMessage(base64String);
...

worker.js:
 onmessage = function(event) {
    const binaryData = atob(event.dat);
    const uint8Array = new Uint8Array(binaryData.length);
    for (let i = 0; i < binaryData.length; i++) {
    uint8Array[i] = binaryData.charCodeAt(i);
   }
  const usingObject = json.msgpack.decode(uint8Array);
   var graphicsLayer = PlottingOnBackground(usingObject.Graphic);
   postMessage(graphicsLayer);
   };

 

my envioronement is node.js, and is there any other way to help load geojson geometric data and drawing 

graphics in background?  any instruction is appreciated, thanks a lot.

 
0 Kudos
0 Replies