events.js

  1. /**
  2. * Wire up any supplied handlers to the corresponding dojo .on events on layer.
  3. * Purpose is to keep Dojo .on events contained in geoApi.
  4. *
  5. * @param {esriObject} esriObject which contains the dojo events to be wrapped
  6. * @param {handlers} handlers is an object which contains all handlers needed
  7. */
  8. function wrapEvents(esriObject, handlers) {
  9. Object.keys(handlers).forEach(ourEventName => {
  10. // replace camelCase name to dojo event name format
  11. const dojoName = ourEventName.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
  12. // TODO: Validity checking on inputs for dojoName
  13. // make dojo call
  14. esriObject.on(dojoName, (e) => {
  15. // check if needs special handling to point at layer calling event
  16. const layerEvents = ['update-start', 'update-end', 'error'];
  17. if (layerEvents.indexOf(dojoName) >= 0) {
  18. e.layer = e.target;
  19. }
  20. handlers[ourEventName](e);
  21. });
  22. });
  23. }
  24. module.exports = () => {
  25. return {
  26. wrapEvents
  27. };
  28. };