Code
package com.esri.adf.web.templates;
import java.util.ArrayList;
import java.util.List;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import com.esri.adf.web.ags.data.AGSLocalMapResource;
import com.esri.adf.web.ags.data.AGSMapResource;
import com.esri.adf.web.ags.data.AGSUser;
import com.esri.adf.web.data.WebContext;
import com.esri.adf.web.data.WebMap;
public class MapResource {
WebContext context;
public WebContext getContext() {
return context;
}
public void setContext(WebContext context) {
this.context = context;
}
//添加资源
public void addMapResource()
{
AGSLocalMapResource ags = null;
FacesContext fc = FacesContext.getCurrentInstance();
//这个配置需要和faces-config.xml中的情况相一致
ValueBinding vb = fc.getApplication().createValueBinding("#{ags0}");
ags = (AGSLocalMapResource) vb.getValue(fc);
// user and object
AGSUser user = new AGSUser("domin","username", "password",false);
ags.setUser(user);
ags.setServerObjectName("map1");
ags.setAlias("map1");
// server
List<String> hosts = new ArrayList<String>();
hosts.add("hostname");
ags.setHosts(hosts);
// refresh map and restore the extent
WebMap mmap = (WebMap) context.getWebMap();
mmap.setInitExtent(mmap.getCurrentExtent());
context.addResource("ags0", ags);
context.refresh();
}
//移除资源
public void removeMapResource()
{
AGSMapResource rec = (AGSMapResource) context.getResources().get("ags0");
if(rec!=null)
context.removeResource(rec);
context.refresh();
}
}
package com.esri.adf.web.templates;
import java.util.ArrayList;
import java.util.List;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import com.esri.adf.web.ags.data.AGSLocalMapResource;
import com.esri.adf.web.ags.data.AGSMapResource;
import com.esri.adf.web.ags.data.AGSUser;
import com.esri.adf.web.data.WebContext;
import com.esri.adf.web.data.WebMap;
public class MapResource {
WebContext context;
public WebContext getContext() {
return context;
}
public void setContext(WebContext context) {
this.context = context;
}
//添加资源
public void addMapResource()
{
AGSLocalMapResource ags = null;
FacesContext fc = FacesContext.getCurrentInstance();
//这个配置需要和faces-config.xml中的情况相一致
ValueBinding vb = fc.getApplication().createValueBinding("#{ags0}");
ags = (AGSLocalMapResource) vb.getValue(fc);
// user and object
AGSUser user = new AGSUser("domin","username", "password",false);
ags.setUser(user);
ags.setServerObjectName("map1");
ags.setAlias("map1");
// server
List<String> hosts = new ArrayList<String>();
hosts.add("hostname");
ags.setHosts(hosts);
// refresh map and restore the extent
WebMap mmap = (WebMap) context.getWebMap();
mmap.setInitExtent(mmap.getCurrentExtent());
context.addResource("ags0", ags);
context.refresh();
}
//移除资源
public void removeMapResource()
{
AGSMapResource rec = (AGSMapResource) context.getResources().get("ags0");
if(rec!=null)
context.removeResource(rec);
context.refresh();
}
}