ArcGIS Flex API 2.0开始支持访问ArcGIS Server 10 的Feature Service进行编辑。
Flex:
minWidth="955" minHeight="600"
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:esri="http://www.esri.com/2008/ags" >
url="http://localhost:8399/arcgis/rest/services/sde/world/MapServer"/ >
map="{map}"
graphicsLayer="{drawLayer}"
drawEnd="drawTool_drawEnd(event)"/>
url="http://localhost:8399/arcgis/rest/services/sde/world/FeatureServer/0"
editsComplete="{featureLayer0_editsComplete(event)}"
fault="trace(event)"/>
url="http://localhost:8080/ArcObjectsServer/rest/update_cache"
result="httpUpdateCache_resultHandler(event)"
fault="trace(event)"/>
更新数据完成后,再通过基于ArcObjects开发的Web服务更新切图
Java:
private String result(String objectids) {
String result = "false";
IServerContext serverContext = null;
try {
ResourceBundle rb = ResourceBundle.getBundle("wuyf.Config");
String host = rb.getString("HOST");
String username = rb.getString("USERNAME");
String password = rb.getString("PASSWORD");
String service = rb.getString("MAP_SERVER");
int layerId = Integer.valueOf(rb.getString("LAYER_ID"));
ServerInitializer serverInitializer = new ServerInitializer();
serverInitializer.initializeServer(host, username, password);
ServerConnection conn = new ServerConnection();
conn.connect(host);
IServerObjectManager som = conn.getServerObjectManager();
serverContext = som.createServerContext(service, "MapServer");
MapServer mapServer = (MapServer) serverContext.getServerObject();
IFeatureLayer feaLayer = (IFeatureLayer) mapServer.getLayer(
mapServer.getDefaultMapName(), layerId);
IFeatureClass feaClass = feaLayer.getFeatureClass();
String mapName = mapServer.getDefaultMapName();
Map map = (Map) mapServer.getMap(mapName);
ILODInfos lodInfos = mapServer.getCacheDescriptionInfo(
map.getName()).getTileCacheInfo().getLODInfos();
String layers = "";
for (int i = 0, count = map.getLayerCount(); i < count; i++) {
String layerName = map.getLayer(i).getName();
if (layers != "") {
layers += ";";
}
layers += layerName;
}
String levels = "";
for (int i = 0, count = lodInfos.getCount(); i < count; i++) {
ILODInfo lodInfo = lodInfos.getElement(i);
if (levels != "") {
levels += ";";
}
levels += String.format("%f", lodInfo.getScale());
}
String[] ids = objectids.split(",");
String where = "";
for (int i = 0, count = ids.length; i < count; i++) {
if (where != "") {
where += " AND ";
}
where += "OBJECTID=" + ids[i];
}
QueryFilter filter = (QueryFilter) serverContext
.createObject(QueryFilter.getClsid());
filter.setWhereClause(where);
IFeatureCursor feaCursor = feaClass.search(filter, false);
IFeature fea = feaCursor.nextFeature();
while (fea != null) {
IGeometry geo = fea.getShape();
IEnvelope env = geo.getEnvelope();
GeoProcessor gp = (GeoProcessor) serverContext
.createObject(GeoProcessor.getClsid());
gp.setOverwriteOutput(true);
ManageMapServerCacheTiles mc = new ManageMapServerCacheTiles();
VarArray var = (VarArray) serverContext.createObject(VarArray
.getClsid());
var.add(host);
var.add(service);
var.add(mapName);
var.add(layers);
var.add(levels);
var.add("Recreate All Tiles");
String extent =
String.format("%f", env.getXMin()) + " " +
String.format("%f", env.getYMin()) + " " +
String.format("%f", env.getXMax()) + " " +
String.format("%f", env.getYMax());
var.add(extent);
//注意,执行这个GP需要将soc帐号加入到agsadmin组
IGeoProcessorResult gpResult = gp.execute(mc.getToolName() + "_" + mc.getToolboxAlias(),var, null);
if (gp.getMessageCount() > 0) {
for (int i = 0, count = gp.getMessageCount(); i < count; i++) {
System.err.print(gp.getMessage(i));
}
}
fea = feaCursor.nextFeature();
}
result = "true";
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
serverContext.releaseContext();
} catch (Exception ex) {
ex.printStackTrace();
}
}
return result;
}