String inSR, String spatialRel, String where, String outFields,
boolean returnGeometry, String outSR, boolean returnIdsOnly) {
String result = null;
try {
MapService mapService = ServiceManager.getMapService(serviceName);
if (mapService != null) {
MapDesc mapDesc = mapService.getMapDesc();
MapServiceDesc mapServiceDesc = mapService.getMapServiceDesc();
if (mapServiceDesc.isNeedToken()) {
boolean htmlNoParams = "html".equals(f)
&& objectIds == null && geometry == null
&& geometryType == null && inSR == null
&& spatialRel == null && where == null
&& outFields == null && outSR == null;
if (!TokenService.verifyToken(token) && !htmlNoParams) {
return TokenService.TOKEN_INVALID_TIP;
}
}
// Handle layerId
int nLayerId = Integer.parseInt(layerId);
// Handle SRs
String sr = mapDesc.getWkid();
if (inSR == null || "".equals(inSR)) {
inSR = sr;
}
if (outSR == null || "".equals(outSR)) {
outSR = sr;
}
String[] featureIds = null;
com.gi.engine.carto.QueryParam queryParam = null;
// Handle objectids
if (objectIds != null && !"".equals(objectIds)) {
featureIds = objectIds.split(",");
} else {
// Handle geometry
Geometry geo = null;
if (geometry != null && !"".equals(geometry)) {
geo = EsriJsonUtil.json2Geometry(geometry);
if (!sr.equals(inSR)) {
geo = GeometryToolkit.project(geo, inSR, sr);
}
}
// Handle spatialRel
SpatialFilterType relation;
if ("esriSpatialRelContains".equals(spatialRel)) {
relation = SpatialFilterType.CONTAINS;
} else if ("esriSpatialRelCrosses".equals(spatialRel)) {
relation = SpatialFilterType.CROSSES;
} else if ("esriSpatialRelEnvelopeIntersects"
.equals(spatialRel)) {
relation = SpatialFilterType.ENVELOPE_INTERSECTS;
} else if ("esriSpatialRelIndexIntersects"
.equals(spatialRel)) {
relation = SpatialFilterType.INDEX_INTERSECTS;
} else if ("esriSpatialRelOverlaps".equals(spatialRel)) {
relation = SpatialFilterType.OVERLAPS;
} else if ("esriSpatialRelTouches".equals(spatialRel)) {
relation = SpatialFilterType.TOUCHES;
} else if ("esriSpatialRelWithin".equals(spatialRel)) {
relation = SpatialFilterType.WITHIN;
} else {
relation = SpatialFilterType.INTERSECTS;
}
queryParam = new com.gi.engine.carto.QueryParam();
queryParam.setGeometry(geo);
queryParam.setSpatialFilterType(relation);
queryParam.setWhere(where);
}
FeatureCollection<? extends FeatureType, ? extends Feature> featureCollection = null;
MapServiceInstance instance = (MapServiceInstance) mapService
.getMapServicePool().checkoutIdleInstance();
try {
Layer layer = instance.getMap().getLayer(nLayerId);
if (featureIds != null) {
featureCollection = layer.query(featureIds);
} else {
featureCollection = layer.query(queryParam);
}
} finally {
if (instance != null) {
mapService.getMapServicePool().checkinIdelInstance(
instance);
}
}
// Various out format