主题:C# OWC和MAPX组件问题
//所帖代码需要定义或者赋值的都已经解决.
//错误提示为:访问受保护的内存,说明部分可用内存已坏.
foreach( MapXLib.Feature ftr in ftrs) //**********老是在这里出现问题1
{
try
{
pnts = ftr.Parts._Item(1); //整条高速路上的点集
}
catch { }
//搜索在起始和终止点之间的点集合
foreach(MapXLib.Point pnt in pnts) //**********老是在这里出现问题2
{
//函数作用是判断pnt点是否在spnt和dpnt之间.
if (MidTwoPoints(pnt.X, pnt.Y, spnt.X, spnt.Y, dpnt.X, dpnt.Y))
{
try
{
ceshipnts.Add(pnt, MapXLib.PositionConstants.miPositionCC );
}
catch { }
}
}
//设置地图默认属性
axMap1.DefaultStyle.LineColor =System.Convert.ToUInt32( MapXLib.ColorConstants.miColorRed);
//判断ceshipnts内点个数是否大于2个,否则不能画线
if (ceshipnts.Count >= 2)
{
switch(loaddirect)
{
case "左行":
textpnt.Set(dpnt.X, dpnt.Y);
break;
case "右行":
textpnt.Set((spnt.X + dpnt.X)/2, (spnt.Y + dpnt.Y)/2);
break;
case "上行":
textpnt.Set(dpnt.X, dpnt.Y);
break;
case "下行":
textpnt.Set((spnt.X + dpnt.X)/2, (spnt.Y + dpnt.Y)/2);
break;
}
ceshiftr = axMap1.FeatureFactory.CreateLine(ceshipnts,axMap1.DefaultStyle);
textftr = axMap1.FeatureFactory.CreateText(textpnt, locationid[j],MapXLib.PositionConstants.miPositionCC,axMap1.DefaultStyle);
textftr = newload.AddFeature(textftr, new MapXLib.RowValues());
ceshiftr = newload.AddFeature(ceshiftr, new MapXLib.RowValues());
textftr = null;
ceshiftr = null;
}
}
//错误提示为:访问受保护的内存,说明部分可用内存已坏.
foreach( MapXLib.Feature ftr in ftrs) //**********老是在这里出现问题1
{
try
{
pnts = ftr.Parts._Item(1); //整条高速路上的点集
}
catch { }
//搜索在起始和终止点之间的点集合
foreach(MapXLib.Point pnt in pnts) //**********老是在这里出现问题2
{
//函数作用是判断pnt点是否在spnt和dpnt之间.
if (MidTwoPoints(pnt.X, pnt.Y, spnt.X, spnt.Y, dpnt.X, dpnt.Y))
{
try
{
ceshipnts.Add(pnt, MapXLib.PositionConstants.miPositionCC );
}
catch { }
}
}
//设置地图默认属性
axMap1.DefaultStyle.LineColor =System.Convert.ToUInt32( MapXLib.ColorConstants.miColorRed);
//判断ceshipnts内点个数是否大于2个,否则不能画线
if (ceshipnts.Count >= 2)
{
switch(loaddirect)
{
case "左行":
textpnt.Set(dpnt.X, dpnt.Y);
break;
case "右行":
textpnt.Set((spnt.X + dpnt.X)/2, (spnt.Y + dpnt.Y)/2);
break;
case "上行":
textpnt.Set(dpnt.X, dpnt.Y);
break;
case "下行":
textpnt.Set((spnt.X + dpnt.X)/2, (spnt.Y + dpnt.Y)/2);
break;
}
ceshiftr = axMap1.FeatureFactory.CreateLine(ceshipnts,axMap1.DefaultStyle);
textftr = axMap1.FeatureFactory.CreateText(textpnt, locationid[j],MapXLib.PositionConstants.miPositionCC,axMap1.DefaultStyle);
textftr = newload.AddFeature(textftr, new MapXLib.RowValues());
ceshiftr = newload.AddFeature(ceshiftr, new MapXLib.RowValues());
textftr = null;
ceshiftr = null;
}
}