【20110302-01】ArcGIS Server9.3从web.config中读地图服务配置(贴源码)

原文链接:http://bbs.esrichina-bj.cn/ESRI/viewthread.php?tid=50399&highlight=%C5%E4%D6%C3

本文参考《总结基于ArcGIS Server 9.2 Dot Net ADF的WebGIS项目部署问题 》

(flyingfish 博客)

(为了让大家省钱,我把代码贴出来吧)

Web.Config中代码如下:

<appSettings>

    <!--地图数据源-->

    <add key="MapDataSource" value ="localhost"/>

    <add key="MapServerName" value="Layers@newdata]Layers@newdata"/>

</appSettings>



自定义方法类代码如下:
首先添加引用:

 

  
    
1 using ESRI.ArcGIS.ADF.Web.UI.WebControls;
2 public class CommonUntility
3 {
4 static MapResourceManager m_MapResourceManager;
5 static MapResourceItem resourceItem;
6 string QueryLayer;
7 static private void setResourMng()
8 {
9 if (resourceItem != null )
10 {
11 return ;
12 }
13 resourceItem = new MapResourceItem();
14 resourceItem.Name = " MapResourceItem0 " ;
15 resourceItem .Definition = new GISResourceItemDefinition ();
16 string MapDataSource = ConfigurationManager .AppSettings [ " MapDataSource " ];
17 string MapServerName = ConfigurationManager .AppSettings [ " MapServerName " ];
18 resourceItem .Definition .DataSourceDefinition = MapDataSource ;
19 resourceItem .Definition .DataSourceType = " ArcGIS Server Local " ;
20 resourceItem .Definition .ResourceDefinition = MapServerName ;
21 resourceItem .Definition .DataSourceShared = true ;
22 resourceItem .DisplaySettings = new ESRI.ArcGIS.ADF.Web.DisplaySettings ();
23 resourceItem .DisplaySettings .DisplayInTableOfContents = true ;
24 resourceItem .DisplaySettings .Visible = true ;
25 m_MapResourceManager = new MapResourceManager ();
26 m_MapResourceManager .ResourceItems .Insert ( 0 ,resourceItem );
27 m_MapResourceManager .CreateResource (resourceItem );
28 resourceItem .InitializeResource ();
29 }
30 static public MapResourceItem GetResourceItem()
31 {
32 setResourMng();
33 return resourceItem;
34 }
35 }
36
37 // 页面初始化调用代码如下:
38 if ( ! IsPostBack)
39 {
40 if (MapResourceManager1.ResourceItems.Count == 0 )
41 {
42 MapResourceManager1.ResourceItems.Add(CommonUntility.GetResourceItem());
43 }
44 }

你可能感兴趣的:(server)