module.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import React from 'react';
  2. import { PanelPlugin } from '@grafana/data';
  3. import { config } from '@grafana/runtime';
  4. import { commonOptionsBuilder } from '@grafana/ui';
  5. import { GeomapInstanceState, GeomapPanel } from './GeomapPanel';
  6. import { LayersEditor } from './editor/LayersEditor';
  7. import { MapViewEditor } from './editor/MapViewEditor';
  8. import { getLayerEditor } from './editor/layerEditor';
  9. import { mapPanelChangedHandler, mapMigrationHandler } from './migrations';
  10. import { defaultView, GeomapPanelOptions, TooltipMode } from './types';
  11. export const plugin = new PanelPlugin<GeomapPanelOptions>(GeomapPanel)
  12. .setNoPadding()
  13. .setPanelChangeHandler(mapPanelChangedHandler)
  14. .setMigrationHandler(mapMigrationHandler)
  15. .useFieldConfig({
  16. useCustomConfig: (builder) => {
  17. commonOptionsBuilder.addHideFrom(builder);
  18. },
  19. })
  20. .setPanelOptions((builder, context) => {
  21. let category = ['Map view'];
  22. builder.addCustomEditor({
  23. category,
  24. id: 'view',
  25. path: 'view',
  26. name: 'Initial view', // don't show it
  27. description: 'This location will show when the panel first loads.',
  28. editor: MapViewEditor,
  29. defaultValue: defaultView,
  30. });
  31. builder.addBooleanSwitch({
  32. category,
  33. path: 'view.shared',
  34. description: 'Use the same view across multiple panels. Note: this may require a dashboard reload.',
  35. name: 'Share view',
  36. defaultValue: defaultView.shared,
  37. });
  38. const state = context.instanceState as GeomapInstanceState;
  39. if (!state?.layers) {
  40. // TODO? show spinner?
  41. } else {
  42. builder.addCustomEditor({
  43. category: ['Data layer'],
  44. id: 'layers',
  45. path: '',
  46. name: '',
  47. editor: LayersEditor,
  48. });
  49. const selected = state.layers[state.selected];
  50. if (state.selected && selected) {
  51. builder.addNestedOptions(
  52. getLayerEditor({
  53. state: selected,
  54. category: ['Data layer'],
  55. basemaps: false,
  56. })
  57. );
  58. }
  59. const baselayer = state.layers[0];
  60. if (config.geomapDisableCustomBaseLayer) {
  61. builder.addCustomEditor({
  62. category: ['Base layer'],
  63. id: 'layers',
  64. path: '',
  65. name: '',
  66. // eslint-disable-next-line react/display-name
  67. editor: () => <div>The base layer is configured by the server admin.</div>,
  68. });
  69. } else if (baselayer) {
  70. builder.addNestedOptions(
  71. getLayerEditor({
  72. state: baselayer,
  73. category: ['Base layer'],
  74. basemaps: true,
  75. })
  76. );
  77. }
  78. }
  79. // The controls section
  80. category = ['Map controls'];
  81. builder
  82. .addBooleanSwitch({
  83. category,
  84. path: 'controls.showZoom',
  85. description: 'Show zoom control buttons in the upper left corner',
  86. name: 'Show zoom control',
  87. defaultValue: true,
  88. })
  89. .addBooleanSwitch({
  90. category,
  91. path: 'controls.mouseWheelZoom',
  92. description: 'Enable zoom control via mouse wheel',
  93. name: 'Mouse wheel zoom',
  94. defaultValue: true,
  95. })
  96. .addBooleanSwitch({
  97. category,
  98. path: 'controls.showAttribution',
  99. name: 'Show attribution',
  100. description: 'Show the map source attribution info in the lower right',
  101. defaultValue: true,
  102. })
  103. .addBooleanSwitch({
  104. category,
  105. path: 'controls.showScale',
  106. name: 'Show scale',
  107. description: 'Indicate map scale',
  108. defaultValue: false,
  109. })
  110. .addBooleanSwitch({
  111. category,
  112. path: 'controls.showDebug',
  113. name: 'Show debug',
  114. description: 'Show map info',
  115. defaultValue: false,
  116. })
  117. .addRadio({
  118. category,
  119. path: 'tooltip.mode',
  120. name: 'Tooltip',
  121. defaultValue: TooltipMode.Details,
  122. settings: {
  123. options: [
  124. { label: 'None', value: TooltipMode.None, description: 'Show contents on click, not hover' },
  125. { label: 'Details', value: TooltipMode.Details, description: 'Show popup on hover' },
  126. ],
  127. },
  128. });
  129. });