Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

85
Visualizações
Sending parameters from different functions to a function
    function layerQuery(objectId) {
    const featureLayer = view.map.layers.getItemAt(0);
    const queryParams = featureLayer.createQuery();
   

    queryParams.where = "objectid=" + objectId;
    queryParams.outFields = ["x", "y", "z"];

    featureLayer.queryFeatures(queryParams).then(function (results) {
      const coords = results.features[0].attributes;
      direction_lookup(Promise, Promise,coords.x,coords.y)
    });
    const objectIdNext = objectId + 1
    const queryParamsTb = featureLayer.createQuery();
    queryParamsTb.where = "objectid=" + objectIdNext;
    queryParamsTb.outFields = ["x", "y", "z"];
    featureLayer.queryFeatures(queryParamsTb).then(function (results) {
      var coordstb = results.features[0].attributes;
      direction_lookup(coordstb.x, coordstb.y,Promise,Promise)
    });
    //console.log(coordstb.x)
    
  }

I want to send the four parameters we obtained as a result of the above two functions to the following function.

function direction_lookup(destination_x, origin_x, destination_y, origin_y) {
    var compass_brackets, compass_lookup, degrees_final, degrees_temp, deltaX, deltaY;
    deltaX = destination_x - origin_x;
    deltaY = destination_y - origin_y;
    degrees_temp = Math.atan2(deltaX, deltaY) / Math.PI * 180;
    

    if (degrees_temp < 0) {
      degrees_final = 360 + degrees_temp;
    } else {
      degrees_final = degrees_temp;
    }

    compass_brackets = ["N", "NE", "E", "SE", "S", "SW", "W", "NW", "N"];
    compass_lookup = Math.round(degrees_final / 45);
    return [compass_brackets[compass_lookup], degrees_final];
  }

  console.log(direction_lookup(destination_x, origin_x, destination_y, origin_y));

The 'direction lookup' function takes four parameters. I want to send these four parameters two by two from different functions. can i do this

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

What you're trying to do isn't possible because your direction_lookup function needs those four parameters to be the numeric co-ordinates, it isn't expecting to see any Promise objects or resolve them. The standard way to do this is to wait until you know all the values before you call the function, like this:

function layerQuery(objectId) {
    const featureLayer = view.map.layers.getItemAt(0);
    const queryParams = featureLayer.createQuery();
   

    queryParams.where = "objectid=" + objectId;
    queryParams.outFields = ["x", "y", "z"];

    featureLayer.queryFeatures(queryParams).then((results) => {
      const feature1Coords = results.features[0].attributes;
      const objectIdNext = objectId + 1
      const queryParamsTb = featureLayer.createQuery();
      queryParamsTb.where = "objectid=" + objectIdNext;
      queryParamsTb.outFields = ["x", "y", "z"];
      featureLayer.queryFeatures(queryParamsTb).then((secondResults) => {
         const feature2Coords = secondResults.features[0].attributes;
         direction_lookup(feature2Coords.x, features2Coords.y,feature1Coords.x,feature1Coords.y);
      });
    }); 
   }

Now you perform your first query and keep the results from that in scope while you perform the second query and finally call direction_lookup when you have both sets of co-ordinates ready to go.

Arrow functions behave like regular functions but maintain the parent scope, which can save a lot of confusion, so for this kind of task it's a slightly more convenient notation.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda