先在工具箱里面添加mapinfo.webcontrols 命名空间的控件全选上
然后找到mapcontrol往地图上面丢.顺手在丢几个zoomin.zoomout进去.
mapcontrol的地图可以从web.config中指定。不过我还是喜欢手动指定。
HTML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebForm1.aspx.cs" Inherits="WebForm1" %>
<%@ Register assembly="MapInfo.Web, Version=6.8.0.536, Culture=neutral, PublicKeyToken=1687fa7c79f74305" namespace="MapInfo.Web.UI.WebControls" tagprefix="MapInfoWebUIWebControls" %>
<%@ Register assembly="MapInfo.WebControls, Version=6.8.0.536, Culture=neutral, PublicKeyToken=0a9556cc66c0af57" namespace="MapInfo.WebControls" tagprefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<cc1:MapControl ID="MapControl1" runat="server" Height="339" Width="622" /><br/>
<cc1:ZoomInTool ID="ZoomInTool1" runat="server" MapControlID="MapControl1" />
<cc1:ZoomOutTool ID="ZoomOutTool1" runat="server" MapControlID="MapControl1" />
<cc1:PanTool ID="PanTool1" runat="server" MapControlID="MapControl1" />
<cc1:CenterTool ID="CenterTool1" runat="server" MapControlID="MapControl1" />
</div>
</form>
</body>
</html>
<%@ Register assembly="MapInfo.Web, Version=6.8.0.536, Culture=neutral, PublicKeyToken=1687fa7c79f74305" namespace="MapInfo.Web.UI.WebControls" tagprefix="MapInfoWebUIWebControls" %>
<%@ Register assembly="MapInfo.WebControls, Version=6.8.0.536, Culture=neutral, PublicKeyToken=0a9556cc66c0af57" namespace="MapInfo.WebControls" tagprefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<cc1:MapControl ID="MapControl1" runat="server" Height="339" Width="622" /><br/>
<cc1:ZoomInTool ID="ZoomInTool1" runat="server" MapControlID="MapControl1" />
<cc1:ZoomOutTool ID="ZoomOutTool1" runat="server" MapControlID="MapControl1" />
<cc1:PanTool ID="PanTool1" runat="server" MapControlID="MapControl1" />
<cc1:CenterTool ID="CenterTool1" runat="server" MapControlID="MapControl1" />
</div>
</form>
</body>
</html>
接下来就是写cs了。
代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MapInfo.Mapping;
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
MapInfo.Mapping.Map myMap = GetMapObj();
if (myMap == null) return;
}
private Map GetMapObj()
{
// Get the map
MapInfo.Mapping.Map myMap = MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias];
if (myMap == null)
{
if (MapInfo.Engine.Session.Current.MapFactory.Count == 0)
{
loadmap("\\GDMap\\GDMap.mws");
}
myMap = MapInfo.Engine.Session.Current.MapFactory[0];
}
return myMap;
}
private void loadmap(string mappath)
{
Map map = MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias];
if (map == null)
{
//手动加载地图
string rootPath = HttpContext.Current.Server.MapPath("");
//MapInfo.Engine.Session.Current.MapFactory.Clear();
map = MapInfo.Engine.Session.Current.MapFactory.CreateEmptyMap(MapControl1.MapAlias, MapControl1.MapAlias, new System.Drawing.Size((int)(MapControl1.Width.Value), (int)(MapControl1.Height.Value)));
MapWorkSpaceLoader tl = new MapWorkSpaceLoader(rootPath + mappath);
if (map != null && tl != null)
{
map.Load(tl);
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MapInfo.Mapping;
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
MapInfo.Mapping.Map myMap = GetMapObj();
if (myMap == null) return;
}
private Map GetMapObj()
{
// Get the map
MapInfo.Mapping.Map myMap = MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias];
if (myMap == null)
{
if (MapInfo.Engine.Session.Current.MapFactory.Count == 0)
{
loadmap("\\GDMap\\GDMap.mws");
}
myMap = MapInfo.Engine.Session.Current.MapFactory[0];
}
return myMap;
}
private void loadmap(string mappath)
{
Map map = MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias];
if (map == null)
{
//手动加载地图
string rootPath = HttpContext.Current.Server.MapPath("");
//MapInfo.Engine.Session.Current.MapFactory.Clear();
map = MapInfo.Engine.Session.Current.MapFactory.CreateEmptyMap(MapControl1.MapAlias, MapControl1.MapAlias, new System.Drawing.Size((int)(MapControl1.Width.Value), (int)(MapControl1.Height.Value)));
MapWorkSpaceLoader tl = new MapWorkSpaceLoader(rootPath + mappath);
if (map != null && tl != null)
{
map.Load(tl);
}
}
}
}
这例子里面webconfig中的sessionState 可以是 Inproc 或者 stateServer,因为还没有画自定义图元。