How to send custom JSON request from Cesium and process it's request

I’m trying to send a parallel request to a local server(in Nodejs) to get a custom json file(not geojson) like:

app.get('/json/:z/:x/:y', function (req, res) {
    return res.status(200).send(JSON.stringify({name:'hello'}));
});

Now I want to request from Cesium whenever any imagery tile is loading by passing z/x/y
To achieve that I’ve created a separate ImageryLayer as given below:

viewer.scene.imageryLayers.addImageryProvider(new 
  Cesium.UrlTemplateImageryProvider({
   url: `http://localhost:2020/json/{z}/{x}/{y}`
}));

However, Above ImageryLayer is sending request to the server But as the server is not returning any image, i’m getting execptions. Also I don’t know how to add it’s callback to process the response.

So, Is there any best way to send a custom request and process it’s response on the basis of current tile request (z/x/y) ? OR Is there any callback on can we create on default ImageryLayer to know what (z/x/y) was requested?

@Jacky

Welcome to the CesiumJS community! Thank you for taking the time to create a detailed community forum post :grinning: :rocket:

To be candid, I do not have a lot of experience writing parallel requests to local servers in Node.js. I will take some time to learn a little bit more about this topic and get back to you. In the meantime, input from the rest of the community would be very helpful! Please let me know if you have any other questions, updates, or concerns.

-Sam

@sam.rothstein Thank you for giving your time to reply my question. I’ve figured out that customTags can help to send custom and parallel requests.

viewer.scene.imageryLayers.addImageryProvider(new 
  Cesium.UrlTemplateImageryProvider({
   url: `http://localhost:2020/json/{z}/{x}/{y}?u={sz}`,
   customTags: {
             sz: function (imageryProvider, x, y, z) {
                  // Can send Parallel request here after getting z/x/y
                     return "";
                   }
   }
}));

This code worked !

  • Jacky

@Jacky

Sorry for the delayed response - I was at GEOINT all of last week. I am happy to hear that you resolved this issue :grinning: :rocket: Please let me know if any other questions arise.

-Sam

1 Like