天天看點

一個spatialReference引發的血案

實作功能:用QueryTask類似拉框查詢

本機環境:ArcGIS Server10.0、FlexViewer 2.4

正式環境:ArcGIS Server9.3、 FlexViewer 2.4

代碼:

//假設graphicsExtent是拉框得到的範圍
						var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(featureSet.features);
						if (graphicsExtent)
						{


							var query2:Query = new Query();
							query2.returnGeometry = true;
							query2.geometry = graphicsExtent.extent;
							query2.outSpatialReference = map.spatialReference;


							var queryTask:QueryTask = new QueryTask();
							queryTask.url = logicMapQueryAddress2;
							queryTask.useAMF = false;
							queryTask.showBusyCursor = true;
							queryTask.execute(query2, new AsyncResponder(onResul2, onFault2));

							function onResul2(featureSet:FeatureSet, token:Object = null):void
							{
								if (featureSet.features.length == 0)
								{
									Alert.show("Please try again.");
								}
								else
								{
									trace(featureSet.features);
									var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(featureSet.features);
									map.extent = graphicsExtent.expand(1.5);
									globalCache.putData("initExtent",graphicsExtent);
								}
								mapExtentLock.lock(map);
							}
							function onFault2(info:Object, token:Object = null):void
							{
								Alert.show(info.toString());
							}

						}
           

這樣在本機環境沒有錯誤,但在正式環境就會報錯,錯誤資訊:[RPC Fault faultString="Cannot perform query. Invalid query parameters." faultCode="500" faultDetail="inSR param is invalid: {"wkt":"PROJCS[\"XiAn80\",GEOGCS[\"XiAn80\",DATUM[\"D_XiAn_1980\",SPHEROID[\"GRS_1980_China\",6378140.0,298.257]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Gauss_Kruger\"],PARAMETER[\"False_Easting\",500000.0],PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",117.0],PARAMETER[\"Scale_Factor\",1.0],PARAMETER[\"Latitude_Of_Origin\",0.0],UNIT[\"Meter\",1.0]]"}"]

是由于空間參考問題引起的,最後解決方法:代碼如下:

var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(featureSet.features);
						if (graphicsExtent)
						{
							[b]var xmi:Number = graphicsExtent.extent.xmin;
							var ymi:Number = graphicsExtent.extent.ymin;
							var xma:Number = graphicsExtent.extent.xmax;
							var yma:Number = graphicsExtent.extent.ymax;
							var newExtent:Extent = new Extent(xmi,ymi,xma,yma);[/b]

							var query2:Query = new Query();
							query2.returnGeometry = true;
						[b]query2.geometry = newExtent.extent;[/b]

							var queryTask:QueryTask = new QueryTask();
							queryTask.url = logicMapQueryAddress2;
							queryTask.useAMF = false;
							queryTask.showBusyCursor = true;
							queryTask.execute(query2, new AsyncResponder(onResul2, onFault2));

							function onResul2(featureSet:FeatureSet, token:Object = null):void
							{
								if (featureSet.features.length == 0)
								{
									Alert.show("Please try again.");
								}
								else
								{
									trace(featureSet.features);
									var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(featureSet.features);
									map.extent = graphicsExtent.expand(1.5);
									globalCache.putData("initExtent",graphicsExtent);
								}
								mapExtentLock.lock(map);
							}
							function onFault2(info:Object, token:Object = null):void
							{
								Alert.show(info.toString());
							}

						}