0 Replies Latest reply on Dec 6, 2006 9:42 PM by JohnHokkanen

    Javascript to CF Function

    JohnHokkanen
      Is there anyone out there that is really good with Javascript that could
      take these two functions and turn them into CF functions. I threw <cfscript> tags
      around them, but they generate errors, and I'm assuming it's a cfscript syntax
      incompatibility. Anyway, as you might guess, I'm not that great with Javascript
      even though I know my way around CF.

      These are the functions to do encoded polylines from Google maps. I want to
      do a mashup using them, but need to encode the data on the fly, which is why
      I need the CF code.

      John H.

      JS CODE
      =======================
      function encodeSignedNumber(num) {
      var sgn_num = num << 1;

      if (num < 0) {
      sgn_num = ~(sgn_num);
      }

      return(encodeNumber(sgn_num));
      }

      function encodeNumber(num) {
      var encodeString = "";
      var nextValue;

      while (num >= 0x20) {
      nextValue = (0x20 | (num & 0x1f)) + 63;
      if (nextValue == 92) {
      encodeString += (String.fromCharCode(nextValue));
      }
      encodeString += (String.fromCharCode(nextValue));
      num >>= 5;
      }

      finalValue = num + 63;
      if (finalValue == 92) {
      encodeString += (String.fromCharCode(finalValue));
      }
      encodeString += (String.fromCharCode(finalValue));
      return encodeString;
      }