Source

widgets/circleWorldMap.js

  1. import processStructure from '@devoinc/applications-data-library/structures/googleMap';
  2. import widgetFactory from '@devoinc/applications-builder/widgetFactory';
  3. import dependencies from '../data/dependencies';
  4. const CircleWorldMapWidget =
  5. dependencies.require('widgets').CircleWorldMapWidget;
  6. /**
  7. * The circle world map widget shows a map where the number of
  8. * values for each area is represented by colored circles.
  9. * @category Widgets
  10. * @module CircleWorldMap
  11. * @see [base](module-base.html)
  12. * @see [collapser](module-collapser.html)
  13. * @see [dataSearch](module-dataSearch.html)
  14. * @see [download](module-download.html)
  15. * @see [info](module-info.html)
  16. * @see [lifeCycle](module-lifeCycle.html)
  17. * @see [listeners](module-listeners.html)
  18. * @see [loading](module-loading.html)
  19. * @see [menu](module-menu.html)
  20. * @see [screenshot](module-screenshot.html)
  21. * @see [zoom](module-zoom.html)
  22. * @tutorial widgets-circle-world-map
  23. */
  24. function mixin(self) {
  25. return {
  26. /**
  27. * Shows the MapType control in the map.
  28. * @param {boolean} bool - Enable or disable.
  29. * @see https://developers.google.com/maps/documentation/javascript/controls
  30. * @instance
  31. */
  32. setMapTypeControl: (bool) => (self.settings.mapTypeControl = bool),
  33. /**
  34. * Sets the Google maps type.
  35. * @param {string} type - Type of map.
  36. * @see https://developers.google.com/maps/documentation/javascript/maptypes#BasicMapTypes
  37. * @instance
  38. */
  39. setMapTypeId(type) {
  40. self.settings.mapTypeId = type;
  41. },
  42. /**
  43. * Displays a small circular icon which allows you to rotate maps.
  44. * @param {boolean} bool - Enable or disable.
  45. * @see https://developers.google.com/maps/documentation/javascript/controls
  46. * @instance
  47. */
  48. setRotateControl: (bool) => {
  49. self.settings.rotateControl = bool;
  50. },
  51. /**
  52. * Displays a map scale element.
  53. * @param {boolean} bool - Enable or disable.
  54. * @see https://developers.google.com/maps/documentation/javascript/controls
  55. * @instance
  56. */
  57. setScaleControl: (bool) => {
  58. self.settings.scaleControl = bool;
  59. },
  60. /**
  61. * Displays a Pegman icon which can be dragged to the map to enable
  62. * Street View.
  63. * @param {boolean} bool - Enable or disable.
  64. * @see https://developers.google.com/maps/documentation/javascript/controls
  65. * @instance
  66. */
  67. setStreetViewControl(bool) {
  68. self.settings.streetViewControl = bool;
  69. },
  70. /**
  71. * Displays a slider or "+/-" buttons to control the zoom level of
  72. * the map.
  73. * @param {boolean} bool - Enable or disable.
  74. * @see https://developers.google.com/maps/documentation/javascript/controls
  75. * @instance
  76. */
  77. setZoomControl(bool) {
  78. self.settings.zoomControl = bool;
  79. },
  80. /**
  81. * Set the keys to show.
  82. * @param {Object[]} arr - Object with <i>lat</i> and <i>lon</i> values.
  83. * @instance
  84. */
  85. setKeys: (arr) => (self.settings.keys = arr),
  86. /**
  87. * Set the column nae with the value.
  88. * @param {string} value - Column name.
  89. * @instance
  90. */
  91. setValue(values) {
  92. self.settings.valueToShow = values;
  93. },
  94. /**
  95. * Set custom styles.
  96. * @param {Object[]} styles - CSS styles properties.
  97. * @instance
  98. */
  99. setStyles(obj) {
  100. self.settings.styles = obj;
  101. },
  102. /**
  103. * Set styles by presets.
  104. *
  105. * The following values are supported:
  106. * - <b>standard</b>
  107. * - <b>silver</b>
  108. * - <b>retro</b>
  109. * - <b>dark</b>
  110. * - <b>night</b>
  111. * - <b>aubergine</b>
  112. * @param {string} str - Style name.
  113. * @instance
  114. */
  115. setPresetStyles(str) {
  116. const styles = require(`@devoinc/applications-builder/widgets/presets/googleMaps/${str}.json`);
  117. if (styles !== null) this.setStyles(styles);
  118. },
  119. // Common
  120. // -------------------------------------------------------------------------
  121. /**
  122. * Resize
  123. * @ignore
  124. */
  125. resize() {
  126. // This widget resize itself
  127. },
  128. // Life Cycle
  129. // -------------------------------------------------------------------------
  130. /**
  131. * Render function
  132. * @param {object} orig - Data for process
  133. * @ignore
  134. */
  135. render(orig) {
  136. if (!self.el) return; // If not have element not render
  137. let cfg = Object.assign(
  138. {},
  139. {
  140. scrollwheel: true,
  141. },
  142. self.settings
  143. );
  144. let data = processStructure(orig, cfg.keyToShow, cfg.valueToShow);
  145. if (data) {
  146. self.widget = new CircleWorldMapWidget(cfg);
  147. self.widget.setData(data);
  148. self.widget.display({ force: true, data: true });
  149. } else {
  150. this.debugError({
  151. msg: 'NO DATA',
  152. console: {
  153. method: 'error',
  154. msg: 'No data arrive to render function',
  155. },
  156. });
  157. }
  158. },
  159. };
  160. }
  161. export default widgetFactory(mixin);