天天看点

SuperMap iServer使用数据服务查询并进行动态投影

作者:Sniper
地图动态投影之后又做了切片?数据量太大没办法对数据集做坐标转换?使用数据服务查询出的结果不能叠加在地图上显示?不要急!SuperMap iServer 8C(2017)新特性:对数据服务查询结果动态投影!

	让我们来看一看具体怎么做吧。
           

####1、向服务器发送请求

由于iClient for JavaScript还没有对数据服务查询动态投影对接,所以我们需要使用REST API来向服务器发送请求。使用SQL查询作为例子,代码如下:

var commit=new XMLHttpRequest();
var uri="http://localhost:8090/iserver/services/data-China400/rest/data/featureResults.rjson?returnContent=true";
//设置请求体参数
var entry={
	getFeatureMode:"SQL", 
	targetEpsgCode:4326,
	datasetNames:["China400:TraStation_A_pt"], 
	maxFeatures:1000, 
	queryParameter:{
		"sortClause":null, 
		"ids":null, 
		"name":"Capital", 
		"attributeFilter":"SMID=400", 
		"groupClause":null, 
		"linkItems":null, 
		"joinItems":null, 
		"fields":null
	}
};
commit.open("POST",encodeURI(uri),false,"","");
commit.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
commit.send(JSON.stringify(entry));
//解析从服务器端返回的 json 字符串,解析为一个 JavaScript 对象。
var response = JSON.parse(commit.responseText);   
           

其中需要注意的就是targetEpsgCode这个参数,这个参数的意义就是对查询的结果动态投影的目标坐标系。与之相关的还有一个targetPrj参数,当目标投坐标系无对应的EpsgCode时,使用targetPrj。

SuperMap iServer使用数据服务查询并进行动态投影

####2、获取返回结果

在这里得到的response就是我们的查询结果,来看看response的结构。

SuperMap iServer使用数据服务查询并进行动态投影

对查询结果显示出来的代码和效果如下:

var container = document.getElementById('container');
container.innerHTML="";
		    
//判断查询是否成功
if(response.featureCount<1)
	{
		//查询失败
		container.innerHTML+="<p>查询失败</p>";
	}else
	{
		//查询成功
		container.innerHTML+="<p>查询成功</p>";
		for(var i=0;i<response.features[0].fieldNames.length;i++){
		    container.innerHTML+="<p>"+response.features[0].fieldNames[i]+":"+response.features[0].fieldValues[i]+"</p>";
		}      
}
           
SuperMap iServer使用数据服务查询并进行动态投影

####3、将查询结果添加在地图上

在这里我们可以看到,查询得到的数据原始坐标系是EPSG:3857,也就是墨卡托投影坐标系。但是我们的地图是动态投影到EPSG:4326(WGS84地理坐标系)上的,显然无法直接进行叠加。

不要着急,北京西站在4326坐标系中坐标其实就隐藏在我们的查询结果中。

SuperMap iServer使用数据服务查询并进行动态投影

在geometry中显示的就是动态投影之后的坐标。下面我们根据这个坐标添加一个矢量要素来看看效果。

SuperMap iServer使用数据服务查询并进行动态投影

代码范例如下:http://download.csdn.net/download/supermapsupport/9615553

继续阅读