在文件中添加全图的类:注意添加引用
namespace CustomWebTools
{
/// <summary>
/// 查看全图
/// </summary>
[Serializable]
public class FullExtent : MapInfo.WebControls.MapBaseCommand
{
/// <summary>
/// Constructor for this command, sets the name of the command
/// </summary>
/// <remarks>None</remarks>
public FullExtent()
{
Name = "FullExtent";
}
public override void Process()
{
MapControlModel model = MapControlModel.GetModelFromSession();
if (MapAlias == null) return;
model.SetMapSize(MapAlias, MapWidth, MapHeight);
MapInfo.Mapping.Map map = model.GetMapObj(MapAlias);
if (map == null) return;
map.Bounds = map.Layers.Bounds;
MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);
StreamImageToClient(ms);
}
}
}
2 新建JScript.js文件
添加方法:
//看全图
function fullExtent1(){
var url = "MapController.ashx?Command=FullExtent&Ran=" + Math.random();
var mapImage = document.getElementById("MapControl1_Image");
if (mapImage.mapAlias)
url += "&MapAlias=" + mapImage.mapAlias;
url+="&Width="+mapImage.width+"&Height="+mapImage.height+"&ExportFormat="+mapImage.exportFormat;
mapImage.src =url;
}
3 在设计中添加HTML控件
<img src="images/fullExtent.gif" id="fullExtent" οnclick="fullExtent()" alt="点击查看全图"/>
4 在MapForm1.cs中添加
using CustomWebTools;
在page_load中添加
MapInfo.WebControls.MapControlModel controlModel = MapControlModel.SetDefaultModelInSession();
// add custom commands to control model
controlModel.Commands.Add(new CustomWebTools.FullExtent());
完成。