How to run javascript function?

  • Автор темы Автор темы myndeswx
  • Дата начала Дата начала

myndeswx

Client
Регистрация
15.05.2017
Сообщения
437
Реакции
104
Баллы
43
Hello, maybe a little stupid question, but how to run such javascript function in zenno? Never really needed to do so, but using external services for this job is not suitable for the job. Thank you!

JavaScript:
Развернуть Свернуть Копировать
 function decompress (encoded, precision) {
   precision = Math.pow (10, -precision);
   var len = encoded.length, index = 0, lat = 0, lng = 0, array = [];
   while (index <len) {
      var b, shift = 0, result = 0;
      do {
         b = encoded.charCodeAt (index ++) - 63;
         result | = (b & 0x1f) << shift;
         shift + = 5;
      } while (b> = 0x20);
      var dlat = ((result & 1)? ~ (result >> 1): (result >> 1));
      lat + = dlat;
      shift = 0;
      result = 0;
      do {
         b = encoded.charCodeAt (index ++) - 63;
         result | = (b & 0x1f) << shift;
         shift + = 5;
      } while (b> = 0x20);
      var dlng = ((result & 1)? ~ (result >> 1): (result >> 1));
      lng + = dlng;
      array.push (lat * precision);
      array.push (lng * precision);
   }
   return array;
}
 
Try insert your code above without 'function decompress (encoded, precision) {' and '}' in Zenno JS action (run on local window) and set up the variables before this code:
JavaScript:
Развернуть Свернуть Копировать
var  encoded = {-Variable.encoded-};
var  precision = {-Variable.precision-};
 
  • Оценить
Реакции: myndeswx
Try insert your code above without 'function decompress (encoded, precision) {' and '}' in Zenno JS action (run on local window) and set up the variables before this code:
[CODE = javascript] var encoded = {-Variable.encoded-};
var precision = {-Variable.precision -}; [/ CODE]
Thank you for answer, but for some reason it still doesn't work, here in this example I am using the snippet wihout the variables at all (with actuall values) and result is still empty :(
JavaScript:
Развернуть Свернуть Копировать
var encoded = 'yhdoIo~xiCk@?gA?aA?c@@gAB';
var precision = 5;

   precision = Math.pow (10, -precision);
   var len = encoded.length, index = 0, lat = 0, lng = 0, array = [];
   while (index <len) {
      var b, shift = 0, result = 0;
      do {
         b = encoded.charCodeAt (index ++) - 63;
         result | = (b & 0x1f) << shift;
         shift + = 5;
      } while (b> = 0x20);
      var dlat = ((result & 1)? ~ (result >> 1): (result >> 1));
      lat + = dlat;
      shift = 0;
      result = 0;
      do {
         b = encoded.charCodeAt (index ++) - 63;
         result | = (b & 0x1f) << shift;
         shift + = 5;
      } while (b> = 0x20);
      var dlng = ((result & 1)? ~ (result >> 1): (result >> 1));
      lng + = dlng;
      array.push (lat * precision);
      array.push (lng * precision);
   }
   return array;
 
Hello, maybe a little stupid question, but how to run such javascript function in zenno? Never really needed to do so, but using external services for this job is not suitable for the job. Thank you!

JavaScript:
Развернуть Свернуть Копировать
 function decompress (encoded, precision) {
   precision = Math.pow (10, -precision);
   var len = encoded.length, index = 0, lat = 0, lng = 0, array = [];
   while (index <len) {
      var b, shift = 0, result = 0;
      do {
         b = encoded.charCodeAt (index ++) - 63;
         result | = (b & 0x1f) << shift;
         shift + = 5;
      } while (b> = 0x20);
      var dlat = ((result & 1)? ~ (result >> 1): (result >> 1));
      lat + = dlat;
      shift = 0;
      result = 0;
      do {
         b = encoded.charCodeAt (index ++) - 63;
         result | = (b & 0x1f) << shift;
         shift + = 5;
      } while (b> = 0x20);
      var dlng = ((result & 1)? ~ (result >> 1): (result >> 1));
      lng + = dlng;
      array.push (lat * precision);
      array.push (lng * precision);
   }
   return array;
}

No need to look for how to run the script.
You need to look for how to do in C # what is done in JavaScript. It is likely that compression and decompression is already built into the C # language and can be used in ZennoPoster without any problems.
But in order to find what you need, you need to say what data you submit to the input, and what data you want to receive at the output. And also what exactly is happening (suddenly there is some additional information that will help solve the problem easier than a way to rewrite the code in C #).

P.S. Google Translater...
 
  • Оценить
Реакции: myndeswx
Thank you for answer, but for some reason it still doesn't work, here in this example I am using the snippet wihout the variables at all (with actuall values) and result is still empty :(
JavaScript:
Развернуть Свернуть Копировать
var encoded = 'yhdoIo~xiCk@?gA?aA?c@@gAB';
var precision = 5;

   precision = Math.pow (10, -precision);
   var len = encoded.length, index = 0, lat = 0, lng = 0, array = [];
   while (index <len) {
      var b, shift = 0, result = 0;
      do {
         b = encoded.charCodeAt (index ++) - 63;
         result | = (b & 0x1f) << shift;
         shift + = 5;
      } while (b> = 0x20);
      var dlat = ((result & 1)? ~ (result >> 1): (result >> 1));
      lat + = dlat;
      shift = 0;
      result = 0;
      do {
         b = encoded.charCodeAt (index ++) - 63;
         result | = (b & 0x1f) << shift;
         shift + = 5;
      } while (b> = 0x20);
      var dlng = ((result & 1)? ~ (result >> 1): (result >> 1));
      lng + = dlng;
      array.push (lat * precision);
      array.push (lng * precision);
   }
   return array;
Your code is not valid. Test it on this page https://esprima.org/demo/validate.html
 
  • Оценить
Реакции: myndeswx
No need to look for how to run the script.
You need to look for how to do in C # what is done in JavaScript. It is likely that compression and decompression is already built into the C # language and can be used in ZennoPoster without any problems.
But in order to find what you need, you need to say what data you submit to the input, and what data you want to receive at the output. And also what exactly is happening (suddenly there is some additional information that will help solve the problem easier than a way to rewrite the code in C #).

PS Google Translater ...

Thank you both for the replies, I have used this snippet from here - https://developer.mapquest.com/documentation/common/encode-decode/
It's quite specific thing, so I don't think it's implemented in zp ..
This function is used to decode the compressed "polylines", that are returned from google maps api,
google returns such compressed values - _k~nE`s{pUk@zCWjAu@~DMn@G\K`@
and we can decompress them in this page ( https://developer.mapquest.com/documentation/common/encode-decode/ )
after decompression we get a list of coordinates. Will try to look for a C # snippet for that: |
 
We are moving somewhere...
In the original JS code
JavaScript:
Развернуть Свернуть Копировать
return array;
is used, but zenno doesn't like it.
BUT, we can see that coordinates are being generated and stored in to the array, we can access them from array[0], array[1] etc.
now only need to find a way how to merge this array to the variable
Tried like this, but doesn't work.
JavaScript:
Развернуть Свернуть Копировать
array.forEach((coord) => {
    return(coord);
});

87178
 
Moving forward, using Console.log we can send this array to our instances console, but how to save this to a variable instead :an:

87179
 
URA!
we don't need to use any loops .. Instead of return array;
we use -

return JSON.stringify(array);

:ar:
 

Кто просматривает тему: (Всего: 0, Пользователи: 0, Гости: 0)