当我尝试使用phonegap打包我的sencha-touch应用程序时,我遇到了一个问题。一切正常,除了在phonegap中访问WFS。(该应用程序在浏览器中运行没有问题,WFS访问正常)
我的phonegap版本是2.9;openlayer版本是2.13
在这里,我展示了我的简单代码。您还可以在以下站点中查看示例代码:http://openlayers.org/dev/examples/wfs-filter.html
var rootUrl = window.location.protocol + "//“+ window.location.host + '/';var map;
function init() {
map = new OpenLayers.Map({
div: "map",
layers: [
new OpenLayers.Layer.WMS(
"Natural Earth",
"http://demo.opengeo.org/geoserver/wms",
{ layers: "topp:naturalearth" }
),
new OpenLayers.Layer.Vector("WFS", {
strategies: [new OpenLayers.Strategy.BBOX()],
protocol: new OpenLayers.Protocol.WFS({
url: rootUrl + 'proxy.py?url=http://demo.opengeo.org/geoserver/wfs',
featureType: "tasmania_roads",
featureNS: "http://www.openplans.org/topp"
}),
styleMap: new OpenLayers.StyleMap({
strokeWidth: 3,
strokeColor: "#333333"
}),
})
],
center: new OpenLayers.LonLat(146.7, -41.8),
zoom: 6
});
}在phonegap中,访问WMS是没有问题的,但当我尝试WFS时,它永远不会工作。
与我之前展示的链接相比,地图中显示了一条道路,它是通过WFS获得的。在我的phonegap应用程序中,道路将不会显示。
我想知道这是WFS问题,还是phonegap问题。有东西阻止我在我的phonegap应用程序中访问WFS。
朋友们,请给我一些建议和提示!我会非常感激的。
function getLayerList() {
$.ajax({ url: rootUrl + 'proxy.py?url=http://192.168.0.23/LBEService/Service1.svc/GetEventList',
//async: false,
data: JSON.stringify({}),
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (result) {
console.log(result);
$("#demo").html(result[0].event_NAME);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
}).done(function () {
});
}发布于 2014-03-27 01:01:55
您是否已将托管WFS的域添加到白名单中?
http://docs.phonegap.com/en/1.9.0/guide_whitelist_index.md.html
发布于 2015-12-13 18:09:45
在安卓文件上,文件是‘window.location.protocol:’,window.location.hostname是‘“,所以你的应用程序可能会查找file://proxy.py?它不存在于你的设备上。
为了解决这个问题,我测试了协议,并相应地设置了OpenLayers.Proxy,如下所示:
if( location.protocol == 'file:' ) {
OpenLayers.ProxyHost = "";
} else {
OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";
}所以在你的例子中,如果协议是'file:',我认为你需要去掉'proxy.py?‘
小贴士:在你的PC上使用Chrome调试你的android应用程序(chrome://inspect/#devices),你就会看到android发出的请求。
https://stackoverflow.com/questions/22623006
复制相似问题