naftali

loading barriers from a dataset

Discussion created by naftali on Sep 27, 2011
Latest reply on Sep 27, 2011 by DSwingley-esristaff
There's a bug when loading barriers from a dataset

That because the coordinate  y, x in the dataset have many digits father the decimal point.

This code work fine:

var mypoint = new esri.geometry.Point(221967.496, 643632.837, new esri.SpatialReference({ wkid: 2039 }))
addBarrierPoint(mypoint);

But this code cause a error in the api

var mypoint = new esri.geometry.Point(221967.49658284057, 643632.8372346461, new   esri.SpatialReference({ wkid: 2039 }))
addBarrierPoint(mypoint);


Walk around:

Instead of load directly from dataset you have to loop .

And round the decimal digits :

function loadBarriers(fset) {
          try {
              // This line cause a error
              //  routeParams.barriers = fset;

              var mypoint, attr;
              var features = fset.features;
              for (var i = 0, il = features.length; i < il; i++) {
                  attr = features[i].geometry;
                  mypoint = new esri.geometry.Point(roundNumber(attr.x), roundNumber(attr.y), new esri.SpatialReference({ wkid: 2039 }));
                  addBarrierPoint(mypoint);                                        
              }
             
          }
          catch (ex) {
              alert("loadBarriers" + ex);
          }

      }


      function roundNumber(num) {
          var result = Math.round(num * Math.pow(10, 4)) / Math.pow(10, 3);
          return result;
      }

Outcomes