Source: formats/kml/util/KmlRefreshListener.js

  1. define([], function(){
  2. /**
  3. * Utility class which is associated with every Kml file. It allows parts of the KML to ask for the refresh which will happen in the correct time.
  4. * Main usage is in the different modes of refresh in the NetworkLink / Link.
  5. * The refresh listener works in this fashion:
  6. * User, which is some of the classes supporting refreshes adds event to the Refresh listener. Event has some content and
  7. * @constructor
  8. * @alias KmlRefreshListener
  9. */
  10. var KmlRefreshListener = function(){
  11. this.currentActiveEvents = [];
  12. };
  13. /**
  14. * It adds event which should be scheduled later on. It is necessary to store it in a structure, which will return
  15. * what is to be scheduled in a fast manner.
  16. * @param event {KmlRefreshListener.Event} Event which should be part of the Refresh listeners internals.
  17. */
  18. KmlRefreshListener.prototype.addEvent = function(event) {
  19. var self = this;
  20. setTimeout(function(){
  21. self.currentActiveEvents.push(event);
  22. }, event.time);
  23. };
  24. /**
  25. * All events, which weren't scheduled and should still be.
  26. * @return {KmlRefreshListener.Event[]} It returns all events which should have been scheduled by now.
  27. */
  28. KmlRefreshListener.prototype.getActiveEvents = function() {
  29. var activeEvents = this.currentActiveEvents.slice();
  30. this.currentActiveEvents = [];
  31. return activeEvents;
  32. };
  33. /**
  34. * It represents simple Event used inside of the KmlRefreshListener.
  35. * @alias KmlRefreshListener.Event
  36. * @constructor
  37. * @param type {String} type of the event. The consumers decides whether the event is relevant for them based on this type.
  38. * @param payload {Object} Object representing payload of the event. It is possible to schedule event with some additional information
  39. * @param time {Number} Number of milliseconds before the event should occur.
  40. */
  41. KmlRefreshListener.Event = function(type, time, payload) {
  42. this.type = type;
  43. this.payload = payload;
  44. this.time = time;
  45. };
  46. return KmlRefreshListener;
  47. });