javascript – Applying bezier line with turf js?

بدون دیدگاه


I’m building an app that need to translate the line into curved version.

Here’s the code. load polyline on database:

//======= Load data Polyline ==========
          var line = new Polyline(wgs84);
          var b = 0; 
          var a = 0;
             // console.log(hasilarray);
          arrayUtils.forEach(hasilarray, function(ple){
            // console.log();
            if(a==0){
              var jumlah = akhir.length;
              for(c=0;c<jumlah;c++){
                var load = JSON.stringify(hasilarray[0][c]);
                console.log(load +" jalur "+c);
                var jumlah_k = hasilarray[0][c].length;
                for(d=0;d<jumlah_k;d++){
                  // array_koordinat.push(hasilarray[0][c][d]);
                  var koor_x_p = hasilarray[1][d][0].toString();
                  var koor_y_p = hasilarray[1][d][1].toString();
                  var x_ = Number(koor_x_p);
                  var y_ = Number(koor_y_p);
                  array_koordinat.push(x_,y_);
                  koordinat_a.push(array_koordinat);
                  array_koordinat=[];
                }
                line.addPath(hasilarray[0][c]);
              }
            }else{
              var load = JSON.stringify(hasilarray[1]);
              // console.log(JSON.stringify(hasilarray[1]));
              //console.log(load +" jalur terakhir");
              var jumlah_k = hasilarray[1].length;
              for(e=0;e<jumlah_k;e++){
                  var koor_x_p = hasilarray[1][e][0].toString();
                  var koor_y_p = hasilarray[1][e][1].toString();
                  var x_ = Number(koor_x_p);
                  var y_ = Number(koor_y_p);
                  array_koordinat.push(x_,y_);
                  koordinat_a.push(array_koordinat);
                  array_koordinat=[];
                }
              // array_koordinat.push(hasilarray[1]);
              line.addPath(hasilarray[1]);

            }
            a++;
            b++;
          }) ;


          var bg = new Graphic(line, basicSymbol, {}, null);
          var curved = turf.bezier(bg);
                    graphicsLayer.add(curved);

          directionalSymbols.push(basicSymbol);     

When I tried to console log the line it comes [[["114.067"],["-1.198"],"polyline0"],[["124.174"],["1.175"],"polyline0"]] jalur 0 and when I tried to console log the curved var it comes:

{“type”:”polyline”,”paths”:[[[[“114.067”],[“-1.198″],”polyline0”],[[“124.174”],[“1.175″],”polyline0”]],[[[“124.174”],[“1.175″],”polyline1”],[[“126.240”],[“-5.452″],”polyline1″]]],”_path”:1,”spatialReference”:{“wkid”:4326}}

Not so familiar with turf js, but I can’t figure out where am I doing wrong. The code is work, before I’m trying to apply this one.

Any help would be appreciated, thank you.



لینک منبع

برچسب‌ها: ,,,,,
  • نویسنده
    A-brand
  • تعداد بازدید
    17 views
0دیدگاه فرستاده شده است.
شما هم دیدگاه خود را بنویسید