因为已经写过加载dwg了,dxf应该不陌生,dxf是个开源格式,所以加载比较简单这里直接附上as的代码,但是真正使用场景还是比较少,dwg文件比较多

 package widgetscadastre.SZ_ImportCAD
{
/**
* ...
* @author haibalai
*/
import com.esri.ags.Graphic;
import com.esri.ags.geometry.Extent;
import com.esri.ags.geometry.MapPoint;
import com.esri.ags.geometry.Polygon;
import com.esri.ags.geometry.Polyline;
import com.szpl.extension.base.impl.AccessPoint;
import flash.events.Event;
import flash.net.FileFilter;
import flash.net.FileReference;
import flash.utils.Dictionary; import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.utils.ObjectUtil;
import mx.utils.StringUtil; public class DxfTool
{ public function DxfTool()
{ } [Bindable]
private var layerList:ArrayCollection = null; private var coorArray:Array = null;
private var initExtent:Extent = null; private var _callFun:Function;
public function dxfLoad(bytedata:String,callFun:Function = null)
{
_callFun = callFun;
dxfHandle(bytedata); } private function dxfHandle(coorStr:String):void
{ layerList = new ArrayCollection;
try
{ coorArray = StringUtil.trim(coorStr).split("\r\n"); var i:int=0; //当前读取的行数
var entitiesRowNum:int = 0; //实体所在行数
initExtent = new Extent; while(i<coorArray.length)
{
if(StringUtil.trim(coorArray[i]).toUpperCase()=="$LIMMIN") //读取地图范围
{
i = i + 2;
initExtent.xmin = Number(StringUtil.trim(coorArray[i])); //最小x
i = i + 2;
initExtent.ymin = Number(StringUtil.trim(coorArray[i])); //最小y
}
else if(StringUtil.trim(coorArray[i]).toUpperCase()=="$LIMMAX")
{
i = i + 2;
initExtent.xmax = Number(StringUtil.trim(coorArray[i])); //最大x
i = i + 2;
initExtent.ymax = Number(StringUtil.trim(coorArray[i])); //最大y
}
else if(StringUtil.trim(coorArray[i]).toUpperCase()=="ENTITIES")
{
entitiesRowNum=i; //记录实体所在行位置
i++;
break;
}
i++;
} var dictionary:Dictionary = new Dictionary;
//加载图层
while(i<coorArray.length)
{
if(StringUtil.trim(coorArray[i])=="8") //读取到图层
{
i++;
if (dictionary[StringUtil.trim(coorArray[i])]==null) //判断图层是否存在
{
var obj:Object = {name:StringUtil.trim(coorArray[i]), RowNum:i}; //图层名及图层所在行数
dictionary[StringUtil.trim(coorArray[i])]=obj;
this.layerList.addItem(obj);
} i++;
}
if(StringUtil.trim(coorArray[i])=="") //遇到空行则终止循环
{
i++;
break;
}
i++;
}
}
catch(e:Error)
{
Alert.show("读取有误:"+e.message.toString());
}
loadLayer() } private function loadLayer():void
{
var coord:String = "";
var graphicArr:Array = new Array();
if(layerList!=null)
{
for (var j:int = 0; j < layerList.length; j++ )
{ var layerObj:Object = layerList[j];
var i:Number = layerObj.RowNum; //当前图层所在行数
while(i < coorArray.length)
{
if(StringUtil.trim(coorArray[i]) == layerObj.name) //找到对应图层
{
i++;
while(i<coorArray.length)
{
if(StringUtil.trim(coorArray[i])=="100")
{
i++;
break;
}
i++;
} switch(StringUtil.trim(coorArray[i]))
{
case "AcDbPolyline":
{
i = i + 2;
var iNodeCount:Number = Number(StringUtil.trim(coorArray[i])); //顶点个数
i = i + 2;
var geomeryType:String = StringUtil.trim(coorArray[i]); //图形类型 i = i + 2;
var pointArray:Array = new Array; while(pointArray.length < iNodeCount)
{
var mapPoint:MapPoint = new MapPoint;
i = i + 2; mapPoint.x = Number(StringUtil.trim(coorArray[i])); //x坐标
i = i + 2; mapPoint.y = Number(StringUtil.trim(coorArray[i])); //y坐标 pointArray.push(mapPoint); }
if(geomeryType == "0") // 0代表折线
{
//var paths:Array = new Array;
//paths.push(pointArray);
//
//var polyline:Polyline = new Polyline;
//polyline.paths = paths;
//
//var gra:Graphic = new Graphic;
//gra.geometry = polyline; }
else if(geomeryType == "1") // 1代表折线闭合为多边形
{
var rings:Array = new Array;
rings.push(pointArray); var polygon:Polygon = new Polygon;
polygon.rings = rings; var graphic:Graphic = new Graphic;
graphic.geometry = polygon;
graphicArr.push(graphic); }
break;
}
case "AcDbLine":
break;
case "AcDbPoint":
break;
case "AcDbSpline": break;
}
i++;
}
else
{
i++;
}
} } }
if (graphicArr.length > 0)
{
for each(var graphic:Graphic in graphicArr)
{
coord += AccessPoint.exchange.polygon_to_CoordText(graphic.geometry as Polygon) + "*";
}
coord = coord.substring(0,coord.length - 1) } _callFun.call(null, coord);
} } }
05-11 14:03