ArcServer动态切换服务
for Java
http://bbs.esrichina-bj.cn/ESRI/thread-27851-1-1.html
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
// get current instance
FacesContext fc = FacesContext.getCurrentInstance();
AGSLocalMapResource ags = null;
WebContext mctx = null;
try {
// get current web context
mctx = event.getWebContext();
// create and init the new ags souce now
// ValueBinding vb = fc.getApplication().createValueBinding("#{ags}");
// ags = (AGSLocalMapResource) vb.getValue(fc);
ags = (AGSLocalMapResource)mctx.getResources().get("ags1");
if (ags == null)
ags = new AGSLocalMapResource();
// user and object
AGSUser user = new AGSUser(domain,userName, password, false);
ags.setUser(user);
ags.setServerObjectName(serviceName);
// server
List<String> hosts = new ArrayList<String>();
hosts.add(serverName);
ags.setHosts(hosts);
ags.setAlias(serviceAlias);
// refresh map and restore the extent
WebMap mmap = (WebMap) mctx.getWebMap();
mmap.setInitExtent(mmap.getCurrentExtent());
mctx.addResource("ags" + (mctx.getResources().size() + 1), ags, 0);
// System.out.println("Overview Image! :" + mctx.getWebOverview().getImageUrl());
mctx.refresh();
} catch (Throwable e) {
e.printStackTrace();
fc.addMessage(contextControl.getClientId(fc), new FacesMessage(
"Unable to add source: " + serviceName + "@"
+ serverName));
if (ags != null)
mctx.removeResource(ags);
}for .Net
http://www.cnblogs.com/tuncaysanli/archive/2009/03/22/1419225.html
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
//前台函数
function BasicMap() {
Coolite.AjaxMethods.ShowBasicMap({ //ShowBasicMap为后台地图处理AjaxMethod
success: function(result) {
var context='Map1';
processCallbackResult(result, context);
//processCallbackResult是安装目录下ESRI.ADF.System.debug文件中的ESRI自带函数。处理后台返回的结果字符串,并将其展示在页面(包括地图)上。
});
}
//后台函数主要实现动态加载地图
private static int i = 0;
[AjaxMethod]
public string ShowBasicMap()
{
MapResourceManager1.ResourceItems.Clear();
MapResourceItem mapResourceItem = new MapResourceItem();
GISResourceItemDefinition definition = new GISResourceItemDefinition();
definition.DataSourceDefinition = "http://10.150.38.34/arcgis/services/";
definition.DataSourceType = "ArcGIS Server Internet";
definition.ResourceDefinition = "Layers@BaseMap";
mapResourceItem.Definition = definition;
ESRI.ArcGIS.ADF.Web.DisplaySettings displaysettings =
new ESRI.ArcGIS.ADF.Web.DisplaySettings();
displaysettings.Transparency = 0;
displaysettings.Visible = true;
mapResourceItem.Name = "basicmap"+i;
mapResourceItem.DisplaySettings = displaysettings;
int n = MapResourceManager1.ResourceItems.Count;
MapResourceManager1.ResourceItems.Insert(n, mapResourceItem);
mapResourceItem.InitializeResource();
Map1.Refresh();
i++;
return Map1.CallbackResults.ToString();
}
http://bbs.esrichina-bj.cn/ESRI/thread-27851-1-1.html
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
// get current instance
FacesContext fc = FacesContext.getCurrentInstance();
AGSLocalMapResource ags = null;
WebContext mctx = null;
try {
// get current web context
mctx = event.getWebContext();
// create and init the new ags souce now
// ValueBinding vb = fc.getApplication().createValueBinding("#{ags}");
// ags = (AGSLocalMapResource) vb.getValue(fc);
ags = (AGSLocalMapResource)mctx.getResources().get("ags1");
if (ags == null)
ags = new AGSLocalMapResource();
// user and object
AGSUser user = new AGSUser(domain,userName, password, false);
ags.setUser(user);
ags.setServerObjectName(serviceName);
// server
List<String> hosts = new ArrayList<String>();
hosts.add(serverName);
ags.setHosts(hosts);
ags.setAlias(serviceAlias);
// refresh map and restore the extent
WebMap mmap = (WebMap) mctx.getWebMap();
mmap.setInitExtent(mmap.getCurrentExtent());
mctx.addResource("ags" + (mctx.getResources().size() + 1), ags, 0);
// System.out.println("Overview Image! :" + mctx.getWebOverview().getImageUrl());
mctx.refresh();
} catch (Throwable e) {
e.printStackTrace();
fc.addMessage(contextControl.getClientId(fc), new FacesMessage(
"Unable to add source: " + serviceName + "@"
+ serverName));
if (ags != null)
mctx.removeResource(ags);
}
http://www.cnblogs.com/tuncaysanli/archive/2009/03/22/1419225.html
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
//前台函数
function BasicMap() {
Coolite.AjaxMethods.ShowBasicMap({ //ShowBasicMap为后台地图处理AjaxMethod
success: function(result) {
var context='Map1';
processCallbackResult(result, context);
//processCallbackResult是安装目录下ESRI.ADF.System.debug文件中的ESRI自带函数。处理后台返回的结果字符串,并将其展示在页面(包括地图)上。
});
}
//后台函数主要实现动态加载地图
private static int i = 0;
[AjaxMethod]
public string ShowBasicMap()
{
MapResourceManager1.ResourceItems.Clear();
MapResourceItem mapResourceItem = new MapResourceItem();
GISResourceItemDefinition definition = new GISResourceItemDefinition();
definition.DataSourceDefinition = "http://10.150.38.34/arcgis/services/";
definition.DataSourceType = "ArcGIS Server Internet";
definition.ResourceDefinition = "Layers@BaseMap";
mapResourceItem.Definition = definition;
ESRI.ArcGIS.ADF.Web.DisplaySettings displaysettings =
new ESRI.ArcGIS.ADF.Web.DisplaySettings();
displaysettings.Transparency = 0;
displaysettings.Visible = true;
mapResourceItem.Name = "basicmap"+i;
mapResourceItem.DisplaySettings = displaysettings;
int n = MapResourceManager1.ResourceItems.Count;
MapResourceManager1.ResourceItems.Insert(n, mapResourceItem);
mapResourceItem.InitializeResource();
Map1.Refresh();
i++;
return Map1.CallbackResults.ToString();
}