2014-03-25 16 views
1

我嘗試使用phonegap打包我的sencha-touch應用程序時遇到問題。一切工作正常,除了訪問電話中的WFS。 (和瀏覽器運行應用程序沒有問題,WFS訪問是OK)phonegap WFS代理問題

我的phonegap版本是2.9;插入式版本是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應用程序中訪問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() { 

     }); 
    } 

回答

0

您是否將承載WFS的域添加到白名單?

http://docs.phonegap.com/en/1.9.0/guide_whitelist_index.md.html

+0

謝謝您的回覆。在xml文件夾下的config.xml文件中,我可以找到這個「」,這意味着所有的域都可以訪問,但是phonegap仍然會忽略我對WFS的訪問。你能否提供更多的提示,我真的很感激。 – Will

+0

另外,當我禁止訪問phonegap中的所有域時,WMS將變得無法訪問,這意味着「」確實有效。 – Will

+0

您是否嘗試過通過safari移除檢查員或提琴手或其他東西來查看請求?看看他們是否真的擺脫了phonegap,他們看起來像什麼。 – Scott

0

Android上的PhoneGap window.location.protocol是 '文件:' 和window.location.hostname是 「」,這樣你的應用程序可能會尋找文件://proxy.py?這在您的設備上不存在。

相應地解決這個問題我測試協議,併成立了OpenLayers.Proxy,即:

if(location.protocol == 'file:') { 
    OpenLayers.ProxyHost = ""; 
} else { 
    OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url="; 
} 
你的情況

所以,如果協議是「文件:」我認爲你需要刪除「 proxy.py?

提示:在PC上使用Chrome調試你的android應用(chrome:// inspect /#devices),你會看到android正在做的請求。