MapPoint中常规方法插入Pushpin是:
MapPoint.Pushpin pii = map.AddPushpin(loc, "name1");
if(balloonState == 0)
pii.BalloonState = GeoBalloonState.geoDisplayBalloon;
else if(balloonState == 1)
pii.BalloonState = GeoBalloonState.geoDisplayName;
else
pii.BalloonState = GeoBalloonState.geoDisplayNone;
pii.Symbol = symbol;
pii.Highlight = highLight;
pii.Note = "info1";
但这种方法地插入大量标记时速度非常慢,在4000个时大约需要9分钟。
机器配置是Pentium(R) D CPU 2.80GHz, 1.00GB内存。
在微软MapPoint论坛提问,回答说用VC写一个插件来批量插入Pushpin,可以避免Com/Interop的包装时间损耗,速度会快一些。
但那样的话,客户端布置麻烦。
因此,我试着用以下方式来提速。
如果不要求加亮或BalloonState,则速度更快,在5秒钟左右。
从数据库中读取数据并生成如下格式字符串,
其中, Name为pushpin的名称, info为提示字段, Latitude和Longitude为点的经纬度坐标
Name Info Latitude Longitude
name1 info1 39.9456 75.0861
nam2 info2 39.9625 75.0875
再写一个函数实现导入pushpin功能, 并可以设定pushpin的符号, 是否加亮, 提示状态BalloonState.
protected bool ImportData(string content, int balloonState, bool highLight, short symbol)


{


construct the fields array#region construct the fields array
object[,] ary = new object[5,2];

ary[0,0] = "Name";
ary[0,1] = GeoFieldType.geoFieldName;

ary[1,0] = "Name";
ary[1,1] = GeoFieldType.geoFieldData;

ary[2,0] = "Info";
ary[2,1] = GeoFieldType.geoFieldInformation;

ary[3,0] = "Latitude";
ary[3,1] = GeoFieldType.geoFieldLatitude | GeoFieldType.geoFieldSkipped;

ary[4,0] = "Longitude";
ary[4,1] = GeoFieldType.geoFieldLongitude | GeoFieldType.geoFieldSkipped;
#endregion


write temp file#region write temp file
string tempFile = Path.GetTempFileName();
StreamWriter sw = new StreamWriter(tempFile);
sw.Write(content);
sw.Flush();
sw.Close();
#endregion


import data and set pushpin features#region import data and set pushpin features
try

{
DataSet ds = map.DataSets.ImportData(tempFile, ary,
GeoCountry.geoCountryUnitedStates,
GeoDelimiter.geoDelimiterTab,
GeoImportFlags.geoImportFirstRowIsHeadings);
if(ds != null)

{
ds.Symbol = symbol;

GeoBalloonState bState = GeoBalloonState.geoDisplayNone;
if(highLight || balloonState != 2)

{
if(balloonState == 0)
bState = GeoBalloonState.geoDisplayBalloon;
else if(balloonState == 1)
bState = GeoBalloonState.geoDisplayName;

Recordset rs = ds.QueryAllRecords();
//
rs.MoveFirst();
while(!rs.EOF)

{
if(rs.Pushpin != null)

{
rs.Pushpin.BalloonState = bState;
if(highLight)
rs.Pushpin.Highlight = highLight;
}
rs.MoveNext();
}
}
}
return true;
}

catch
{return false;}
#endregion

}
