String tolerance, String mapExtent, String imageDisplay,
String returnGeometry) {
String result = null;
try {
MapService mapService = ServiceManager.getMapService(serviceName);
if (mapService != null) {
MapDesc mapDesc = mapService.getMapDesc();
MapServiceDesc mapServiceDesc = mapService.getMapServiceDesc();
if (mapServiceDesc.isNeedToken()) {
if (!TokenService.verifyToken(token)
&& !("html".equals(f) && geometry == null)) {
return TokenService.TOKEN_INVALID_TIP;
}
}
// Handle geometry
Geometry identifyGeometry = EsriJsonUtil
.json2Geometry(geometry);
// Handle SRs
String mapSR = mapDesc.getWkid();
if (sr == null || "".equals(sr)) {
sr = mapSR;
}
if (!sr.equals(mapSR)) {
identifyGeometry = GeometryToolkit.project(
identifyGeometry, sr, mapSR);
}
// Handle layers
IdentifyType identifyType = IdentifyType.TOP;
ArrayList<String> layerIds = new ArrayList<String>();
if (layers != null && !"".equals(layers)) {
String type = null;
String ids = layers;
if (layers.indexOf(":") > 0) {
String[] str = layers.split(":");
type = str[0];
ids = str[1];
if (ids != null && !"".equals(ids)) {
try {
String[] strLayers = ids.split(",");
int layerCount = strLayers.length;
for (int i = 0; i < layerCount; i++) {
layerIds.add(strLayers[i]);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
} else {
type = layers;
for (int i = 0, count = mapDesc.getLayerInfos().size(); i < count; i++) {
layerIds.add(String.valueOf(i));
}
}
if ("top".equals(type.toLowerCase())) {
identifyType = IdentifyType.TOP;
} else if ("visible".equals(type.toLowerCase())) {
identifyType = IdentifyType.VISIBLE;
} else if ("all".equals(type.toLowerCase())) {
identifyType = IdentifyType.ALL;
}
}
// Handle tolerance
int nTolerance = Integer.parseInt(tolerance);
// Handle mapExtent
Envelope env = null;
if (mapExtent != null && !"".equals(mapExtent)) {
String[] mapStrs = mapExtent.split(",");
double xmin = Double.parseDouble(mapStrs[0]);
double ymin = Double.parseDouble(mapStrs[1]);
double xmax = Double.parseDouble(mapStrs[2]);
double ymax = Double.parseDouble(mapStrs[3]);
env = new Envelope(xmin, xmax, ymin, ymax);
if (!sr.equals(mapSR)) {
env = GeometryToolkit.project(env, sr, mapSR);
}
}
// Handle imageDisplay
int width = 0;
int height = 0;
@SuppressWarnings("unused")
int dpi = 0;
if (mapExtent != null && !"".equals(mapExtent)) {
String[] imageStrs = imageDisplay.split(",");
width = Integer.parseInt(imageStrs[0]);
height = Integer.parseInt(imageStrs[1]);
dpi = Integer.parseInt(imageStrs[2]);
}
// Handle returnGeometry
boolean isReturnGeometry = Boolean.parseBoolean(returnGeometry);
ArrayList<FeatureResult> featureResults = null;
if (env != null) {
// Handle resolution
double resolutionX = env.getWidth() / width;
double resolutionY = env.getHeight() / height;
double resolution = Math.max(resolutionX, resolutionY);
IdentifyParam identifyParam = new IdentifyParam();
identifyParam.setGeometry(identifyGeometry);
identifyParam.setIdentifyType(identifyType);
identifyParam.setResolution(resolution);
identifyParam.setTolerance(nTolerance);
MapServiceInstance instance = (MapServiceInstance) mapService
.getMapServicePool().checkoutIdleInstance();
try {
featureResults = instance.identify(layerIds,
identifyParam);
} finally {
if (instance != null) {
mapService.getMapServicePool().checkinIdelInstance(
instance);
}
}
}