|
阅读:952回复:0
createline生成线出现坐标误差。 请各位兄台赐教
<P>我想做一个画电力接线图的程序。 </P>
<P>在对线的修改过程中碰到了问题;<BR>我的思路是这样的:<BR>用户选择一条线取下线ALine的第一个点(静点) 作为点集对象pts的第一个点,并依据鼠标当前位置得到第二、三个点。并用pts 来createline一条的折线(虚线)TempLine。如果用户确认的修改。就用这条线替换原来那条线,并修改成实线样式。同时删除虚线。 但现在碰到的问题就是ALine.parts.item[1].item[1] = pts[1] <> TempLine.parts.item[1].item[1]; 也就是出现了误差。 好象有那种网格对齐的感觉;<BR>产生的效果如下图:<BR>请赐教; thx. QQ:59606207</P> <P>themap.mapunit = cm;<BR>proj = non-earth; (10000*10000) </P> <P><BR>procedure TLine.SingleBreakPointLineTo(pX,pY:double);//freePoint要到达的位置<BR>var<BR> x,y:Double;<BR> Count:integer;<BR> i:integer;<BR> pts:CMapxPoints;<BR> TempLine:Feature;<BR>begin<BR> Count:=APts.Count;<BR> //Apts来自ALine.parts.item[1];<BR> if Count = 0 then //线原来不存在,设置起点<BR> begin<BR> APts.AddXY(pX,pY,emptyparam);//设置起点<BR> APts.AddXY(pX,pY,emptyparam);//设置终点</P> <P> initLine(ATempLine,APts.Item[1]);//初始化线<BR> InitLine(ALine,APts.Item[1]); //初始化临时线(虚线)<BR> end else//线已存在<BR> begin<BR> if ATempLine = nil then initLine(ATempLine,APts.Item[1]);//初始化临时线(虚线)<BR> Pts:=CoPoints.Create;<BR> Pts.Add(APts.Item[1],emptyparam);//得到线的起点<BR> if (pX = Pts.Item[1].X) or (pY = Pts.Item[1].Y) then //就是一条直线<BR> begin<BR> Pts.AddXY(pX,pY,emptyparam);//末点<BR> end else //折线<BR> begin<BR> if abs((pX-Pts.Item[1].X)) >= abs(pY-Pts.Item[1].Y) then//得到折点的位置<BR> begin<BR> x:=pX;<BR> y:=Pts.Item[1].Y;<BR> end else<BR> begin<BR> x:=Pts.Item[1].X;<BR> y:=pY;<BR> end;<BR> Pts.AddXY(x,y,emptyparam);//折点<BR> pts.AddXY(pX,pY,emptyparam);//当前点(末点)<BR> end;</P> <P> //ClearSpilthPts(pts);//删除线上的垃圾点,让线自然</P> <P> TempLine:=AMap.FeatureFactory.CreateLine(Pts,stBrokenLine);//创建虚线<BR> TempLine:=AMap.Layers._Item(nFeatureLine).AddFeature(TempLine,emptyparam);//在线图层上增加虚线</P> <P> {showmessage('ALine['+floattostr(ALine.parts.item[1].item[1].x)+','+floattostr(ALine.parts.item[1].item[1].y)+']'+chr(13)+<BR> 'PTS ['+floattostr(pts.item[1].x)+','+floattostr(pts.item[1].y)+']'+chr(13)+<BR> 'ATemp['+floattostr(TempLine.parts.item[1].item[1].x)+','+floattostr(TempLine.parts.item[1].item[1].y)+']');<BR> }<BR> UpDateBrokenLine(TempLine);//更新临时线</P> <P> Pts.RemoveAll;<BR> Pts:=nil;<BR> end;</P> <P>测试坐标打印结果: </P> <P> <P>起点偏差效果显示:<BR> |
|