try{
String result = WebServiceUtils.getMapLayers();
InputStream inputStream = new ByteArrayInputStream(result.getBytes());
LayerInfo.parse(inputStream);
}catch(Exception e){
e.printStackTrace();
}
}
public static String getMapLayers(){
String result ="";
try{
String endPoint = AppContext.url + "/ZZMobileService.asmx";
String methodName ="getMapLayers";
String soapAction = NAMESPACE + methodName;
SoapObject rpc = new SoapObject(NAMESPACE, methodName);
rpc.addProperty("checkCode", PWD);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER10);
envelope.bodyOut = rpc;
envelope.dotNet = true;
envelope.setOutputSoapObject(rpc);
HttpTransportSE transport = new HttpTransportSE(endPoint);
transport.call(soapAction, envelope);
// 获取返回的数据
SoapObject object = (SoapObject) envelope.bodyIn;
// 获取返回的结果
result = object.getProperty(0).toString();
}catch(Exception e){
e.printStackTrace();
}
Log.i("TAG", "result="+result);
return result;
}
public static void parse(InputStream inputStream) throws IOException{
AppContext.pLayerList.removeAll(AppContext.pLayerList);
AppContext.cLayerList.removeAll(AppContext.cLayerList);
LayerInfo info = null;
XmlPullParser xmlParser = Xml.newPullParser();
try{
xmlParser.setInput(inputStream, "UTF-8");
int evtType=xmlParser.getEventType();
while(evtType!=XmlPullParser.END_DOCUMENT){
String tag = xmlParser.getName();
switch (evtType) {
case XmlPullParser.START_DOCUMENT:
break;
case XmlPullParser.START_TAG:
if(tag.equalsIgnoreCase("layer")){
info = new LayerInfo();
String pid = xmlParser.getAttributeValue(null, "pid");
if(pid ==null){
info.setName(xmlParser.getAttributeValue(null, "name"));
info.setChecked(xmlParser.getAttributeValue(null, "checked"));
info.setIsShow(xmlParser.getAttributeValue(null, "isShow"));
info.setLayerUrl(xmlParser.getAttributeValue(null, "url"));
info.setType(xmlParser.getAttributeValue(null,"type"));
AppContext.pLayerList.add(info);
}
}else if(tag.equalsIgnoreCase("clayer")){
if(info!=null){
ChildLayerInfo child = new ChildLayerInfo();
child.setId(xmlParser.getAttributeValue(null,"id"));
child.setName(xmlParser.getAttributeValue(null,"name"));
child.setType(xmlParser.getAttributeValue(null,"type"));
info.addChildInfo(child);
}
}
break;
case XmlPullParser.END_TAG:
break;
}
evtType=xmlParser.next();
}
}catch(Exception e){
e.printStackTrace();
}finally{
inputStream.close();
}
}