2013-01-16 64 views
0

我有一個函數:如何等待函數結果?

function createWFS(){ 
    //WMS 
    wms_proj = new OpenLayers.Projection("EPSG:900913");  
    //WFS 
    SS=new OpenLayers.Strategy.Save(); 
    FS=new OpenLayers.Strategy.Filter({filter:Ffilter}); 
    var myStyle = OpenLayers.Util.extend({}, 
     OpenLayers.Feature.Vector.style['default']); 
    myStyle.strokeWidth = 1.5; 
    myStyle.strokeColor = "#ff0000"; 
    myStyle.fillOpacity = 0.1; 

    myVecLayer= new OpenLayers.Layer.Vector("Редактируемый участок"); 
    myVecLayer.projection=wms_proj; 
    app.mapPanel.map.addLayers([myVecLayer]); 
    myVecLayer.visibility=false; 

    //Стор для зума 
    zoom_tab = new GeoExt.data.FeatureStore({ 
     layer: myVecLayer, 
     fields: [ 
      {name: 'id', type: 'int'}, 
      {name: 'filedata', type: 'String'} 
     ], 
     proxy: new GeoExt.data.ProtocolProxy({ 
      protocol: new OpenLayers.Protocol.HTTP({ 
       //url: "/geoserver/ows?service=WFS&request=GetFeature&typeName=mrsk:parcels_temp&srsName=EPSG:4326&outputFormat=GML2", 
       url: "/geoserver/ows?service=WFS&request=GetFeature&typeName=cite:parcels_temp&srsName=EPSG:4326&outputFormat=GML2", 
       format: new OpenLayers.Format.GML() 
      }) 
     }), 
     autoLoad: true 
    }); 
    zoom_store=zoom_tab; 
} 

你看,這個函數創建WFS層和GeoExt.FeatureStore。我不知道函數將工作多久。
所以現在我調用這個函數,並希望等待函數結果,然後再下一個代碼。如何做到這一點?

+0

你可以創建一個函數來通過一定時間間隔進行連續檢查結果,直到結果出現 – jondinham

回答

1

只是通過它自己的回調:

​​
+0

'函數NextStep自動(){// 的東西在這裏 }'對於wtat是嗎?這是做什麼的? –

+1

@Kliver:它應該包含您在加載基礎層完成時要執行的代碼。它包含「下一個代碼」在您的問題中調用它。也許這可以幫助你理解問題和解決方案,儘管它不適合100%你的情況:http://stackoverflow.com/a/14220323/218196。 –

+0

@Felix Kling:我嘗試了'但NextStep()'在createWFS結束之前工作。 –