天地图js跨域访问实现输入地名搜索定位地图上的点function getgeocode()
{
//关于跨域访问,请自行解决,目前示例是通过服务器端转发的方式解决
//关于服务参数的设置请自行参考网站 http://221.2.153.36:8719/newmapserver4/SDK/REST/index.html?service/capabilities.html
//下面仅以属性查询为例
var url = "http://221.2.153.36:8719/newmapserver4/rest/services/whjiazheng/dmdz/featureserver/query?layer=dmdz&page=1&maxitems=10&format=json&where=";
var querytext = document.getElementById('dmtxt').value;
var where = " NAME like '%"+querytext+"%'";
url += where;
url = encodeURI(url);
var proxyStr ="./proxy.php?url=";
var fullRequestURL = proxyStr + encodeURIComponent(url);
alert(fullRequestURL);
//alert(encodeURIComponent("http://127.0.0.1:8719/newmap/rest/services/samples/china/FeatureServer/query?layer=首都和省级行政中心&page=1&maxitems=10&format=json&where=NAME like '%济南%'"));
NRequest.GET({
url: fullRequestURL,
success: SCallBack,
failure: FCallBack
});
//注意:上面仅仅提供了怎么组织url,服务器端的服务url中有中文,要求编码是utf-8
}
{
//关于跨域访问,请自行解决,目前示例是通过服务器端转发的方式解决
//关于服务参数的设置请自行参考网站 http://221.2.153.36:8719/newmapserver4/SDK/REST/index.html?service/capabilities.html
//下面仅以属性查询为例
var url = "http://221.2.153.36:8719/newmapserver4/rest/services/whjiazheng/dmdz/featureserver/query?layer=dmdz&page=1&maxitems=10&format=json&where=";
var querytext = document.getElementById('dmtxt').value;
var where = " NAME like '%"+querytext+"%'";
url += where;
url = encodeURI(url);
var proxyStr ="./proxy.php?url=";
var fullRequestURL = proxyStr + encodeURIComponent(url);
alert(fullRequestURL);
//alert(encodeURIComponent("http://127.0.0.1:8719/newmap/rest/services/samples/china/FeatureServer/query?layer=首都和省级行政中心&page=1&maxitems=10&format=json&where=NAME like '%济南%'"));
NRequest.GET({
url: fullRequestURL,
success: SCallBack,
failure: FCallBack
});
//注意:上面仅仅提供了怎么组织url,服务器端的服务url中有中文,要求编码是utf-8
}
或者通过后台实现简单一点 纯js好像不能的样子
之前做个一个,最终使用iframe 做中间桥梁 实现的。
public String downloadFile(String fileId) {
String downFile = "";
StorageClient1 client = null;
try {
client = getDfsClient();
// 从服务器端下载文件
byte[] bFlie = client.download_file1(fileId); downFile = new String(bFlie, "UTF-8");
} catch (Exception e) {
connList.remove(client);
destroy();
}
return downFile; }
/**
* 确保获取有效通信
*
* @return
*/
public StorageClient1 getDfsClient() {
StorageClient1 client = null;
if (connList.size() == 0)
createDFSConn();
while (client == null) {
synchronized (connList) {
client = connList.get(0);
if (client == null)
createDFSConn();
}
}
return client;
}
这种方式java的方式,但是我想php,也是这个原理,具体的php代码,自己写