/DocumentsandSettings/Administrator/桌面/Web/路线/ditu.mws”/>将路径改为相应的目录。
3、将resicharfont.ttf文件拷到C:
\WINDOWS\Fonts目录下。
4、建立人员结构类。
打开clsUserType.cs文件,在类文件中填入如下代码:
publicclassclsUserType
{
privatestringstrBMID;
privatestringpersonID;
privatestringpersonName;
privateMapInfo.Geometry.DPointDPoint;
privatestringstrUserType()
{
this.strBMID="电子信0901";
this.personID="0111";
this.personName="++";
this.DPoint=newMapInfo.Geometry.DPoint(1,1);
this.strFileName=@"LITE2-32.BMP";
}
publicvoidsetstrBMID(stringstrBMID)
{
this.strBMID=strBMID;
}
publicvoidsetpersonID(stringpersonID)
{
this.personID=personID;
}
publicvoidsetpersonName(stringpersonName)
{
this.personName=personName;
}
publicvoidsetDPoint(MapInfo.Geometry.DPointDPoint)
{
this.DPoint=DPoint;
}
publicvoidsetstrFIleName(stringstrFIleName)
{
this.strFIleName=strFIleName;
}
publicstringgetstrBMID()
{
returnthis.strBMID;
}
publicstringgetpersonID()
{
returnthis.personID;
}
publicstringgetpersonName()
{
returnthis.personName;
}
publicMapInfo.Geometry.DPointgetDPoint()
{
returnthis.DPoint;
}
publicstringgetstrFIleName()
{
returnthis.strFIleName;
}
}
5、建立取得屏幕坐标点的类文件。
打开WebInfoGetXY.cs类并输入下图所示代码。
publicclassWebInfoGetXY:
MapInfo.WebControls.MapBaseCommand
{
publicWebInfoGetXY()
{
base.Name="GetXY";
}
publicoverridevoidProcess()
{
MapControlModelmodel=MapControlModel.GetModelFromSession();
MapInfo.Mapping.Mapmap=model.GetMapObj(MapAlias);
System.Drawing.Point[]points=ExtractPoints(DataString);
MapInfo.Geometry.DPointdpoint=newMapInfo.Geomtry.Dpoint();
map.DisplayTransform.FromDisplay(points[0],outdpoint);
stringoutText="屏幕xy:
"+points[0].X+","+points[0].Y;
outText+="
经纬度xy:
"+dpoint.x","+dpoint.y;
HttpContext.Current.Response.Write(outText);
}
}
6、建立地图操作命令类。
clsMapCommand.cs并输入下图代码。
publicclassclsMapCommand:
MapInfo.WebControls.MapBaseCommand
{
privateMapControlModelmodel;
privateMapInfo.Mapping.Mapmap;
publicclsMapCommand()
{
bass.Name="MapCommand":
}
publicoverridevoidProcess()
{
stringCommad_type=Convert.ToString(HttpContext.Current.Request["Commad_type"]);
stringLayerTable_name=Convert.ToString(HttpContext.Current.Request["LayerTable_name"]);
stringfeature_name=Convert.ToString(HttpContext.Current.Request["feature_name"]);
stringfeature_kind=Convert.ToString(HttpContext.Current.Request["feature+kind"]);
Doublepoint_x=Convert.ToString(HttpContext.Current.Request["point_x"]);
Doublepoint_y=Convert.ToString(HttpContext.Current.Request["point_y"]);
CommonUserGisFuncyion_CommonUserGisFunction=newCommonUserGisFunction();
model=MapControlModel.GetModelFromSession();
map=model.GetMapObj(MapAlias);
if(LayerTable_name==nill)LayerTable_name="newLayer";
switch(Commad_type)
{
case"Select":
_CommonUserGisFunction.SearchWithSearch(map,LayerTable_name,feature_name,feature_kind);
break;
case"Move":
_CommonUserGisFunction.MoveObject(map,LayerTable_name,feature_name,
feature_kind,newMapInfo.Geometry.DPoint(point_x,point_y));
break;
case"ClearAllObject":
_CommonUserGisFunction.clear_feature(map,LayerTable_name);
break;
case"ClearObject":
_CommonUserGisFunction.clear_feature(map,LayerTable_name,feature_name,feature_kind;
break;
case"Refresh":
_CommonUserGisFunction.Update_Person_Position(map,LayerTable_name);
break;
default:
break;
}
}
}
7、在main.aspx.cs文件的pageLoad函数中输入添加图层人员的代码。
#region
if(myMap!
=null)
{
if(myMap.Layers["newLayer"]!
=null)
{
myMap.Layers.Remove("newLayer");
}
if(myMap.Layers["roadLayer"]!
=null)
{
myMap.Layers.Remove("roadLayer");
}
}
CommonUserGisFunction_CommonUserGisFunction=newCommonUserGisFunction()
MapInfo.Mapping.IMapLayerly=_CommonUserGisFunction.CreatNewLayer(myMap,"newLayer","mewLayer");
myMap.Layers.Insert(2,ly);
clsUserType_clsUserType=newclsUserType();
_clsUserType.setDPoint(newMapInfo.Geometry.DPoint(2,2));
_clsUserType.setpersonName("自定义点");
_clsUserType.setpersonID("0000");
CommonUserGisFunction.AddPointToLayer(myMap,"newLayer","newLayer",_clsUserType);
FontPointStylefStyle=newFontPontPointStyle();
fStyle.Code=76;
fStyle.PointSize=24;
fStyle.Color=System.Drawing.Color.Red;
fStyle..Font.Name="residentevilcharacters";
fStyle.Font.FontWeight=MapInfo.Styles.FontWeight.Bold;
fStyle.Angle=400;
_clsUserType.setDPoint(newMapInfo.Geometry.DPoint(1.6,1.6));
_clsUserType.setpersonID("0111");
_clsUserType.setpersonName("佟环");
CommonUserGisFunction.AddPointToLayer(myMap,"newLayer","newLayer",_clsUserType,fStyle);
SimpleVectorPointStylevStyle=newSimpleVectorPointStyle();
vStyle.Code=67;
vStyle.Color=System.Drawing.Color.Red;
vStyle.PointSize=Convert.ToInt16(24);
vStyle.Attributes=StyleAttributes.PointAttributes.BaseAll;
vStyle.SetApplyAll();
_clsUserType.setDPoint(newMapInfo.Geometry.DPoint(1,1));
CommonUserGisFunction.AddPointToLayer(myMap,"newLayer","newLayer",_clsUserType,vStyle);
#endregion
完成上面步骤后运行程序可以实现地图显示功能,在显示的地图中出现三个位图点。
8、图元查找、移动、删除功能实现。
在main.aspx文件中填入如下代码。
A、在
位置填入下列代码。
属性名称
属性值
B、在
位置添加如下图所示的SelectObject()函数。
functionSelectObject()
{
varmapImage=document.getElementById("MapControl1_Image");
varfeature_name=document.forms[0].feature_name.value;
varfeature_value=document.forms[0].feature_value.value;
varurl="MapController.ashx?
Command=MapCommand&Width="+mapImage.width+"&Height="+mapImage.height+"&ExportFormat="+mapImage.exportFormat+"&Ran="+Math.random()+"&Commad_type=Select&feature_name="+feature_name+"&feature_kind="佟环"";
if(mapImage.mapAlias)
url+="&MapAlias="+mapImage.mapAlias;
varxmlHttp=null;
if(BrowserType()==IE)
{
xmlHttp=newActiveXObject("Microsoft.XMLHTTP");
}
elseif(BrowserType()==NS)
{
xmlHttp=newXMLHttpRequest();
}
xmlHttp.open("GET",url,false);
xmlHttp.send(null);
varresult=xmlHttp.responseText;
alert(result);
UpdateMap();
ShowMapArea();
}
C、在
位置输入如下所示的移动图元代码。
functionMoveObject()
{
varmapImage=document.getElementById("MapControl1_Image");
varfeature_name=document.forms[0].feature_name.value;
varfeature_value=document.forms[0].feature_value.value;
varurl="MapController.ashx?
Command=MapCommand&Width="+mapImage.width+"&Height="+mapImage.height+"&ExportFormat="+mapImage.exportFormat+"&Ran="+Math.random()+"&Commad_type=Move&feature_name="+feature_name+"&feature_kind="佟环"&point_x=2.2&point_y=2.2";
varxmlHttp=null;
if(BrowserType()==IE)
{
xmlHttp=newActiveXObject("Microsoft.XMLHTTP");
}
elseif(BrowserType()==NS)
{
xmlHttp=newXMLHttpRequest();
}
xmlHttp.open("GET",url,false);
xmlHttp.send(null);
varresult=xmlHttp.responseText;
alert(result);
UpdateMap();
ShowMapArea();
}
D、在
位置输入如下删除所有图元代码。
functionClearAllObject()
{
varmapImage=document.getElementById("MapControl1_Image");
varurl="MapController.ashx?
Command=MapCommand&Width="+mapImage.width+"&Height="+mapImage.height+"&ExportFormat="+mapImage.exportFormat+"&Ran="+Math.random()+"&Commad_type=ClearAllObject";
varxmlHttp=null;
if(BrowserType()==IE)
{
xmlHttp=newActiveXObject("Microsoft.XMLHTTP");
}
elseif(BrowserType()==NS)
{
xmlHttp=newXMLHttpRequest();
}
xmlHttp.open("GET",url,false);
xmlHttp.send(null);
varresult=xmlHttp.responseText;
alert(result);
UpdateMap();
ShowMapArea();
}
E、在
位置输入删除图元代码。
functionClearObject()
{
varmapImage=document.getElementById("MapControl1_Image");
varfeature_name=document.forms[0].feature_name.value;
varfeature_value=document.forms[0].feature_value.value;
varurl="MapController.ashx?
Command=MapCommand&Width="+mapImage.width+"&Height="+mapImage.height+"&ExportFormat="+mapImage.exportFormat+"&Ran="+Math.random()+"&Commad_type=ClearObject&feature_name="+feature_name+"&feature_kind="佟环"";
varxmlHttp=null;
if(BrowserType()==IE)
{
xmlHttp=newActiveXObject("Microsoft.XMLHTTP");
}
elseif(BrowserType()==NS)
{
xmlHttp=newXMLHttpRequest();
}
xmlHttp.open("GET",url,false);
xmlHttp.send(null);
varresult=xmlHttp.responseText;
alert(result);
UpdateMap();
ShowMapArea();
}
9、参照步骤步骤6添加班级其他同学,并显示。
10、实现按文本框中的内容查找、删除图元功能:
参照下列代码修改main.aspx文件中的SelectObject()、MoveObject()、ClearObject()函数,在函数中添加下列代码
并将url中的Name和XXX改为下图所示的形式。
functionSelectObject()
{
varmapImage=document.getElementById("MapControl1_Image");
varfeature_name=document.forms[0].feature_name.value;
varfeature_value=document.forms[0].feature_value.value;
varurl="MapController.ashx?
Command=MapCommand&Width="+mapImage.width+"&Height="+mapImage.height+"&ExportFormat="+mapImage.exportFormat+"&Ran="+Math.random()+"&Commad_type=Select&feature_name="+feature_name+"&feature_kind="+feature_value+"";
if(mapImage.mapAlias)
url+="&MapAlias="+mapImage.mapAlias;