用博客记录点滴……

flex 生成多边形时内、外环计算

//顺时钟                                      
                var pA:Array = [{x:"2969925.6674000006",y:"476254.4874999998"},{x:"2969991.6831",y:"476503.1002000002"},{x:"2969581.7171",y:"476502.3365000002"},
                                                   {x:"2969582.1823999994",y:"476253.8409000002"},{x:"2969925.6674000006",y:"476254.4874999998"}];                                                                                    
                //大于0法向量向外(逆时针 、外环) 小于0      (顺时钟、内环)                               
                var total:Number = 0;
                for(var i:int = 0; i < pA.length - 1; i++){
                   total += (Number(pA[i+1].x) - Number(pA[i].x))*(Number(pA[i+1].y) + Number(pA[i].y)) * 0.5; 
                }

二、通过点生成多边形代码(可以显示环状图斑)

     var str1:String = "1,2963645.3619999997,475138.83210000023,7,2975656.2609,475162.4922000002,8,2975642.649,483438.3672000002,9,2966401.804199999,483426.2240000004,18,2971952.3038999997,476814.8313999995,23,2963642.2057000007,476799.56379999965";    
                 var str2:String = "1,2969925.6674000006,476254.4874999998,2,2969582.1823999994,476253.8409000002,3,2969581.7171,476502.3365000002,4,2969991.6831,476503.1002000002";          
                 var str2Arr:Array = str2.split(",");
                 var str1Arr:Array = str1.split(",");
                 var points1:Array = new Array();
                 var points2:Array = new Array();
                  for(var i:int =0;i<str2Arr.length;i+=3){
                      var mapPoint:MapPoint = new MapPoint(str2Arr[i+2],str2Arr[i+1]);
                      points2.push(mapPoint);
                  }                                    
                  for(var j:int = 0;j<str1Arr.length;j+=3){
                      var mapPoint:MapPoint = new MapPoint(str1Arr[j+2],str1Arr[j+1]);
                      points1.push(mapPoint);
                  }                                    
                   var rings:Array = new Array();
                   rings.push(points1);   
                   rings.push(points2);                               
                   var tempPoly:Polygon = new Polygon(rings);
                   var graphicPoly:Graphic = new Graphic(tempPoly);

 

posted @ 2015-04-21 14:47  aegisada  阅读(291)  评论(0编辑  收藏  举报