0

I have a function:

    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;
}

You see that this function create WFS Layer and GeoExt.FeatureStore. I dont know how long function will work.
So now i call this function and want ot wait function result before make next code. How to make this?

Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
Kliver Max
  • 5,107
  • 22
  • 95
  • 148
  • you can create a function to check the result continuously by certain interval, until the result appears – jondinham Jan 16 '13 at 09:39

1 Answers1

1

Just pass it your own callback:

function createWFS(callback) {
    //WMS
    ...
    if (callback)
        callback();
}


function Main() {
    createWFS(NextStep);
}

function NextStep() {
    //stuff here
}
Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
  • `function NextStep() { //stuff here }` For wtat is it? What this do? – Kliver Max Jan 16 '13 at 09:44
  • 1
    @Kliver: It should contain the code you want to execute when loading the base layer is completed. It contains the "next code" as call it in your question. Maybe this helps you understand the issue and solution, although it does not fit 100% your case: http://stackoverflow.com/a/14220323/218196. – Felix Kling Jan 16 '13 at 09:47
  • @Felix Kling: I try but `function NextStep() ` works before createWFS is end. – Kliver Max Jan 16 '13 at 09:53
  • @KliverMax this can only mean that something in createWFS is asynchronous. In such case, it's up to that asynchronous code to provide you with a callback. I am not familiar with OpenLayers but it's likely documented on their side. – Shadow The GPT Wizard Jan 16 '13 at 10:42