flex 중심점

1467 단어 Flex
public static function getGeomCenter(gra:Graphic):MapPoint
		{
			var pt:MapPoint;
           	switch (gra.geometry.type)
           	{
               case Geometry.MAPPOINT:
               {
                    pt = gra.geometry as MapPoint;
                    break;
               }
               
               case Geometry.POLYLINE:
               {
               		var pl:Polyline = gra.geometry as Polyline;
               		var pathCount:Number = pl.paths.length;
           			var pathIndex:int = int((pathCount / 2) - 1);
               		var midPath:Array = pl.paths[pathIndex];
               		var ptCount:Number = midPath.length;
               		if( pl.paths[0].length < 3){
               			pt = new MapPoint( (pl.extent.xmax + pl.extent.xmin)/2, (pl.extent.ymax + pl.extent.ymin)/2);
               		}else{
               			var ptIndex:int = int(ptCount / 2);
               			pt = pl.getPoint(pathIndex, ptIndex);
               		}
               		break;
               }
               
               case Geometry.POLYGON:
               {
                    var poly:Polygon = gra.geometry as Polygon;
               		pt = poly.extent.center;
                    break;
               }
            }
			return pt;
		}

좋은 웹페이지 즐겨찾기