control.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. (function (window, document, undefined) {
  2. L.Control.Custom = L.Control.extend({
  3. version: '1.0.1',
  4. options: {
  5. position: 'topright',
  6. id: '',
  7. title: '',
  8. classes: '',
  9. content: '',
  10. style: {},
  11. datas: {},
  12. events: {},
  13. },
  14. container: null,
  15. onAdd: function (map) {
  16. this.container = L.DomUtil.create('div');
  17. this.container.id = this.options.id;
  18. this.container.title = this.options.title;
  19. this.container.className = this.options.classes;
  20. this.container.innerHTML = this.options.content;
  21. for (var option in this.options.style)
  22. {
  23. this.container.style[option] = this.options.style[option];
  24. }
  25. for (var data in this.options.datas)
  26. {
  27. this.container.dataset[data] = this.options.datas[data];
  28. }
  29. /* Prevent click events propagation to map */
  30. L.DomEvent.disableClickPropagation(this.container);
  31. /* Prevent right click event propagation to map */
  32. L.DomEvent.on(this.container, 'contextmenu', function (ev)
  33. {
  34. L.DomEvent.stopPropagation(ev);
  35. });
  36. /* Prevent scroll events propagation to map when cursor on the div */
  37. L.DomEvent.disableScrollPropagation(this.container);
  38. for (var event in this.options.events)
  39. {
  40. L.DomEvent.on(this.container, event, this.options.events[event], this.container);
  41. }
  42. return this.container;
  43. },
  44. onRemove: function (map) {
  45. for (var event in this.options.events)
  46. {
  47. L.DomEvent.off(this.container, event, this.options.events[event], this.container);
  48. }
  49. },
  50. });
  51. L.control.custom = function (options) {
  52. return new L.Control.Custom(options);
  53. };
  54. }(window, document));