how can I determine when Google Maps loadGeoJson completes?

后端 未结 3 949
粉色の甜心
粉色の甜心 2020-12-18 10:09

I have a scenario where users can store their mapping styling. When a user navigates back to that page with the map it should display the map the way it was previously.

3条回答
  •  心在旅途
    2020-12-18 10:41

    One would assume, if you are using knockout, to maybe bind onto some listeners, or attach listeners to an event.

    Most events through JavaScript always have a callback function, this is good practive so that once a function has finished executing some long I/O or Database query it will immediately execute that function. Obviously that callback will be defined by you.

    someLongTimeFunction(function (data) {
      // usually this callback will be fired when the function has finished.
    });
    

    If you are familiar with knockout, then you would know that once the data has been retrieved and you pass through an observable that observable would update its binding.

    Here is the link for extending observables: knockout js

    As far as I can understand from you question, this loadGeoJson, is it server side? If so, you do a long poll from client side and tie into that:

    function doRequest() {
      var request = $.ajax({
        dataType: "json",
        url: 'loadGeoJson',
        data: data,
      });
    
      request.done(function(data, result) {
        if (result !== "success") {
          setTimeout(doRequest, 10000);
        }
      });
    }
    

提交回复
热议问题