Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

95
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda