arcgislink/src/arcgislink.js
function fromGeometryToJSON_(geom) {
  function fromPointsToJSON(pts) {
    var arr = [];
    for (var i = 0, c = pts.length; i < c; i++) {
      arr.push('[' + pts[i][0] + ',' + pts[i][1] + ']');
    }
    return '[' + arr.join(',') + ']';
  }
  function fromLinesToJSON(lines) {
    var arr = [];
    for (var i = 0, c = lines.length; i < c; i++) {
      arr.push(fromPointsToJSON(lines[i]));
    }
    return '[' + arr.join(',') + ']';
  }
  
  var json = '{';
  if (geom.x) {
    json += 'x:' + geom.x + ',y:' + geom.y;
  } else if (geom.xmin) {
    json += 'xmin:' + geom.xmin + ',ymin:' + geom.ymin + ',xmax:' + geom.xmax + ',ymax:' + geom.ymax;
  } else if (geom.points) {
    json += 'points:' + fromPointsToJSON(geom.points);
  } else if (geom.paths) {
    json += 'paths:' + fromLinesToJSON(geom.paths);
  } else if (geom.rings) {
    json += 'rings:' + fromLinesToJSON(geom.rings);
  }
  json += '}';
  return json;
}
function fromGeometryToJSON_(geom) {
  function fromPointsToJSON(pts) {
    var arr = [];
    for (var i = 0, c = pts.length; i < c; i++) {
      arr.push('[' + pts[i][0] + ',' + pts[i][1] + ']');
    }
    return '[' + arr.join(',') + ']';
  }
  function fromLinesToJSON(lines) {
    var arr = [];
    for (var i = 0, c = lines.length; i < c; i++) {
      arr.push(fromPointsToJSON(lines[i]));
    }
    return '[' + arr.join(',') + ']';
  }
  
  var json = '{';
  if (geom.x) {
    json += 'x:' + geom.x + ',y:' + geom.y;
  } else if (geom.xmin) {
    json += 'xmin:' + geom.xmin + ',ymin:' + geom.ymin + ',xmax:' + geom.xmax + ',ymax:' + geom.ymax;
  } else if (geom.points) {
    json += 'points:' + fromPointsToJSON(geom.points);
  } else if (geom.paths) {
    json += 'paths:' + fromLinesToJSON(geom.paths);
  } else if (geom.rings) {
    json += 'rings:' + fromLinesToJSON(geom.rings);
  }
  json += '}';
  return json;
}
function fromGeometryToJSON_ ( geom ) { function fromPointsToJSON ( pts ) { var arr = [ ] ; for ( var i = 0 , c = pts . length ; i < c ; i ++ ) { arr . push ( '[' + pts [ i ] [ 0 ] + ',' + pts [ i ] [ 1 ] + ']' ) ; } return '[' + arr . join ( ',' ) + ']' ; } function fromLinesToJSON ( lines ) { var arr = [ ] ; for ( var i = 0 , c = lines . length ; i < c ; i ++ ) { arr . push ( fromPointsToJSON ( lines [ i ] ) ) ; } return '[' + arr . join ( ',' ) + ']' ; } var json = '{' ; if ( geom . x ) { json += 'x:' + geom . x + ',y:' + geom . y ; } else if ( geom . xmin ) { json += 'xmin:' + geom . xmin + ',ymin:' + geom . ymin + ',xmax:' + geom . xmax + ',ymax:' + geom . ymax ; } else if ( geom . points ) { json += 'points:' + fromPointsToJSON ( geom . points ) ; } else if ( geom . paths ) { json += 'paths:' + fromLinesToJSON ( geom . paths ) ; } else if ( geom . rings ) { json += 'rings:' + fromLinesToJSON ( geom . rings ) ; } json += '}' ; return json ; }
From ESRI geometry format to JSON String, primarily used in Geometry service
@param {Object} geom
From ESRI geometry format to JSON String primarily used in Geometry service