动态设置Resource

// 处理结果返回给客户端
  2          public   string  GetCallbackResult()
  3          {
  4            return m_CallbackResponse;
  5        }

  6 // 处理客户端请求
  7          public   void  RaiseCallbackEvent( string  eventArgs)
  8          {
  9            //分割请求字符串
 10            char[] charToParse = ',' };
 11            string[] messages = eventArgs.Split(charToParse);
 12
 13            if (eventArgs.Contains("changeresource"))
 14            {
 15                //SourceType
 16                string dataSourceType = messages[1];
 17                //CheckBox是否选中
 18                bool isChecked = Boolean.Parse(messages[2]);
 19                //根据请求类型不同用不同的Resource
 20                switch (dataSourceType)
 21                {
 22                    case "ArcGIS Server Local":
 23                        m_ResourceName = AGSLocalName;
 24                        break;
 25                    case "ArcGIS Server Internet":
 26                        m_ResourceName = AGSInternetName;
 27                        break;
 28                    default:
 29                        break;
 30                }

 31                //更换Resource
 32                MapResourceChange(isChecked);
 33            }

 34        }

 35 // 更换Resource
 36          void  MapResourceChange( bool  isChecked)
 37          {
 38            //获取当前MapResourceManager1的ResourceItems
 39            ESRI.ArcGIS.ADF.Web.UI.WebControls.GISResourceItemCollection<ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceItem> mapResourceItemCollection =MapResourceManager1.ResourceItems;
 40            
 41            ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceItem mapResourceItem = null;
 42            //获取当前MapResourceManager1的ResourceItems的数
 43            int mapResourceCount = mapResourceItemCollection.Count;
 44            if (!isChecked)
 45            {
 46                //如果未勾选就删除未勾选的ResourceItem
 47                mapResourceItem = mapResourceItemCollection.Find(m_ResourceName);
 48                mapResourceItemCollection.Remove(mapResourceItem);
 49            }

 50            else
 51            {
 52                //实例化ResourceItem
 53                mapResourceItem = new ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceItem();
 54                ESRI.ArcGIS.ADF.Web.UI.WebControls.GISResourceItemDefinition definition =new ESRI.ArcGIS.ADF.Web.UI.WebControls.GISResourceItemDefinition();
 55
 56                switch (m_ResourceName)
 57                {
 58                    case (AGSLocalName)://设置本地Resource名称
 59                        //Name
 60                        mapResourceItem.Name = AGSLocalName;
 61                        //Data Source
 62                        definition.DataSourceDefinition = "jh-53a435fbc0e8";
 63                        //Type
 64                        definition.DataSourceType = "ArcGIS Server Local";
 65                        //Resource
 66                        definition.ResourceDefinition = "Layers@usa";
 67                        break;
 68                    case (AGSInternetName)://设置Internet Resource名称
 69                        //Name
 70                        mapResourceItem.Name = AGSInternetName;
 71                        //Data Source
 72                        definition.DataSourceDefinition = "http://jh-53a435fbc0e8/arcgis/services/";
 73                        //Type
 74                        definition.DataSourceType = "ArcGIS Server Internet";
 75                        //Identity
 76                        Identity id = new Identity("Administrator""zsycl1231""");
 77                        definition.Identity = id.ToString();
 78                        //Resource
 79                        definition.ResourceDefinition = "(default)@world";
 80                        break;
 81                }

 82                
 83                definition.DataSourceShared = true;
 84                mapResourceItem.Parent = MapResourceManager1;
 85                mapResourceItem.Definition = definition;
 86
 87                //mapResourceItem的展示设置
 88                ESRI.ArcGIS.ADF.Web.DisplaySettings displaySettings = new ESRI.ArcGIS.ADF.Web.DisplaySettings();
 89                displaySettings.Transparency = 50.0F;
 90                displaySettings.Visible = true;
 91                displaySettings.ImageDescriptor.TransparentColor = System.Drawing.Color.White;
 92                displaySettings.ImageDescriptor.TransparentBackground = true;
 93                mapResourceItem.DisplaySettings = displaySettings;
 94
 95                //把上面的MapResourceItem添加到MapResourceManager1
 96                MapResourceManager1.ResourceItems.Insert(0, mapResourceItem);
 97
 98                //建立MapResource根据MapResourceManager1
 99                ESRI.ArcGIS.ADF.Web.DataSources.IMapResource mapResource =MapResourceManager1.CreateResource(mapResourceItem);
100
101                if (mapResourceCount < 1)
102                {
103                    Map1.PrimaryMapResource = mapResourceItem.Name;
104                    //初始化
105                    Map1.InitializeFunctionalities();
106                    Map1.InitializeTileFunctionalities();
107                }

108                else
109                {
110
111                    // 刷新地图显示
112                    if (Map1.ImageBlendingMode == ESRI.ArcGIS.ADF.Web.UI.WebControls.ImageBlendingMode.WebTier)
113                    {
114                        Map1.Refresh();
115                    }

116                    else
117                    {
118                        Map1.RefreshResource(mapResourceItem.Name);
119                    }

120                }

121            }

122
123            if (mapResourceCount < 1)
124            {
125                Map1.Extent = Map1.Extent.Expand(0.1);
126            }

127            //刷新Toc1
128            Toc1.Refresh();
129            ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult tocCallbackResult = RefreshControlHtml(Toc1);
130            Map1.CallbackResults.Add(tocCallbackResult);
131
132            // Convert the Map's collection of callback results to a string 
133            m_CallbackResponse = Map1.CallbackResults.ToString();
134        }

135
136          private  ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult RefreshControlHtml(Control control)
137          {
138            StringWriter stringWriter = new StringWriter();
139            HtmlTextWriter writer = new HtmlTextWriter(stringWriter);
140            control.RenderControl(writer);
141            string htmlContent = stringWriter.ToString();
142            stringWriter.Close();
143            return new ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult(control, "content", htmlContent);
144        }

145
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值