@corpsmap/corpsmap 3.2.93 → 3.2.98

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (276) hide show
  1. package/README.md +33 -0
  2. package/dist/corpsmap.css +1 -0
  3. package/dist/corpsmap.es.js +90955 -0
  4. package/dist/corpsmap.umd.js +401 -0
  5. package/dist/vite.svg +1 -0
  6. package/package.json +70 -87
  7. package/src/App.css +42 -0
  8. package/src/App.jsx +12 -0
  9. package/src/application-bundles/api-bundle.js +76 -74
  10. package/src/application-bundles/basic-toolbar-bundle.js +57 -57
  11. package/src/application-bundles/create-ol-map-bundle.jsx +278 -0
  12. package/src/application-bundles/identify-bundle.js +119 -119
  13. package/src/application-bundles/index.js +1 -1
  14. package/src/application-bundles/map-basemap-bundle.js +73 -69
  15. package/src/application-bundles/map-layers-bundle.js +42 -35
  16. package/src/application-bundles/map-view-bundle.jsx +334 -0
  17. package/src/application-bundles/notification-bundle.js +37 -32
  18. package/src/application-bundles/primary-panel-bundle.js +85 -85
  19. package/src/application-bundles/search-bundle.js +122 -122
  20. package/src/application-bundles/south-region-bundle.js +96 -88
  21. package/src/application-bundles/vertical-layout-bundle.js +88 -88
  22. package/src/application-bundles/viewport-bundle.js +19 -18
  23. package/src/application-bundles-old/ui-bundle.js +240 -179
  24. package/src/application-containers/{basic-toolbar.js → basic-toolbar.jsx} +24 -24
  25. package/src/application-containers/{corpsmap.js → corpsmap.jsx} +7 -2
  26. package/src/application-containers/{left-sidebar.js → left-sidebar.jsx} +3 -6
  27. package/src/application-containers/{lower-right-toolbar.js → lower-right-toolbar.jsx} +12 -11
  28. package/src/application-containers/map.jsx +57 -0
  29. package/src/application-containers/{modal-window.js → modal-window.jsx} +13 -15
  30. package/src/application-containers/{north-region.js → north-region.jsx} +26 -25
  31. package/src/application-containers/{notification-pane.js → notification-pane.jsx} +37 -37
  32. package/src/application-containers/{notification-quadrant.js → notification-quadrant.jsx} +20 -20
  33. package/src/application-containers/{notification.js → notification.jsx} +91 -91
  34. package/src/application-containers/{primary-panel.js → primary-panel.jsx} +94 -94
  35. package/src/application-containers/right-sidebar.jsx +44 -0
  36. package/src/application-containers/{south-region-tab.js → south-region-tab.jsx} +26 -17
  37. package/src/application-containers/south-region.jsx +75 -0
  38. package/src/application-containers/upper-right-toolbar.jsx +28 -0
  39. package/src/application-controls/{basic-toolbar-button.js → basic-toolbar-button.jsx} +124 -124
  40. package/src/application-controls/{index.js → index.jsx} +34 -34
  41. package/src/application-controls/{search-results-list-item.js → search-results-list-item.jsx} +50 -50
  42. package/src/application-controls/{sidebar-button.js → sidebar-button.jsx} +69 -69
  43. package/src/application-controls/{sidebar-panel-opener.js → sidebar-panel-opener.jsx} +4 -4
  44. package/src/application-controls/{tree-list-folder.js → tree-list-folder.jsx} +46 -46
  45. package/src/application-controls/tree-list-item.jsx +83 -0
  46. package/src/application-exports/{map-provider.js → map-provider.jsx} +122 -100
  47. package/src/assets/react.svg +1 -0
  48. package/src/config/default-config.js +53 -68
  49. package/src/core-plugins/add-data/{add-data-button.js → add-data-button.jsx} +34 -34
  50. package/src/core-plugins/add-data/{add-geojson.js → add-geojson.jsx} +47 -47
  51. package/src/core-plugins/add-data/{add-kmlfile.js → add-kmlfile.jsx} +46 -46
  52. package/src/core-plugins/add-data/add-shapefile.jsx +47 -0
  53. package/src/core-plugins/add-data/bundle.js +226 -225
  54. package/src/core-plugins/basemap-switcher/{basemap-switcher-list-item.js → basemap-switcher-list-item.jsx} +48 -45
  55. package/src/core-plugins/basemap-switcher/{basemap-switcher-list.js → basemap-switcher-list.jsx} +1 -1
  56. package/src/core-plugins/bookmarks/{bookmark-list-item.js → bookmark-list-item.jsx} +26 -22
  57. package/src/core-plugins/bookmarks/{bookmark-list.js → bookmark-list.jsx} +1 -1
  58. package/src/core-plugins/bookmarks/bookmark-panel.jsx +191 -0
  59. package/src/core-plugins/catalog/catalog-button.jsx +33 -0
  60. package/src/core-plugins/catalog/catalog-list-item.jsx +118 -0
  61. package/src/core-plugins/catalog/catalog-list.jsx +78 -0
  62. package/src/core-plugins/catalog/{catalog-modal-window.js → catalog-modal-window.jsx} +35 -25
  63. package/src/core-plugins/change-log/bundle.js +2 -2
  64. package/src/core-plugins/change-log/{change-log-button.js → change-log-button.jsx} +40 -44
  65. package/src/core-plugins/change-log/{change-log-modal.js → change-log-modal.jsx} +4 -11
  66. package/src/core-plugins/change-log/index.js +14 -14
  67. package/src/core-plugins/change-log/{select-district.js → select-district.jsx} +73 -73
  68. package/src/core-plugins/contact-form/bundle.js +239 -244
  69. package/src/core-plugins/contact-form/index.js +17 -17
  70. package/src/core-plugins/contact-form/{question-button.js → question-button.jsx} +36 -36
  71. package/src/core-plugins/contact-form/{question-modal.js → question-modal.jsx} +215 -189
  72. package/src/core-plugins/coordinate-display/bundle.jsx +269 -0
  73. package/src/core-plugins/coordinate-display/{coordinate-display-bar.js → coordinate-display-bar.jsx} +66 -66
  74. package/src/core-plugins/coordinate-display/{coordinate-display-settings.js → coordinate-display-settings.jsx} +3 -7
  75. package/src/core-plugins/coordinate-display/{coordinate-interaction-bar.js → coordinate-interaction-bar.jsx} +1 -1
  76. package/src/core-plugins/coordinate-display/{coordinate-lat-lon-input.js → coordinate-lat-lon-input.jsx} +35 -35
  77. package/src/core-plugins/coordinate-display/{coordinate-popup.js → coordinate-popup.jsx} +27 -27
  78. package/src/core-plugins/draw-tools/create-draw-bundle.js +148 -138
  79. package/src/core-plugins/draw-tools/draw-button.jsx +204 -0
  80. package/src/core-plugins/draw-tools-old/create-draw-bundle.js +137 -127
  81. package/src/core-plugins/draw-tools-old/draw-button.js +90 -78
  82. package/src/core-plugins/editor/editor-base.js +8 -10
  83. package/src/core-plugins/editor/editor-button.js +122 -92
  84. package/src/core-plugins/editor/editor-table.js +62 -61
  85. package/src/core-plugins/geocoder/{bundle.js → bundle.jsx} +186 -186
  86. package/src/core-plugins/geocoder/index.js +14 -14
  87. package/src/core-plugins/geocoder/{overlay.js → overlay.jsx} +30 -30
  88. package/src/core-plugins/geocoder/search-bar.js copy.save +123 -123
  89. package/src/core-plugins/geocoder/{search-bar.js → search-bar.jsx} +121 -122
  90. package/src/core-plugins/identify/{bundle.js → bundle.jsx} +709 -707
  91. package/src/core-plugins/identify/{identify-buffer-section.js → identify-buffer-section.jsx} +52 -52
  92. package/src/core-plugins/identify/{identify-buffer-settings.js → identify-buffer-settings.jsx} +48 -48
  93. package/src/core-plugins/identify/{identify-button.js → identify-button.jsx} +100 -100
  94. package/src/core-plugins/identify/{identify-details-table.js → identify-details-table.jsx} +121 -118
  95. package/src/core-plugins/identify/identify-details.js +69 -69
  96. package/src/core-plugins/identify/{identify-sidebar-list-item.js → identify-sidebar-list-item.jsx} +106 -99
  97. package/src/core-plugins/identify/{identify-sidebar.js → identify-sidebar.jsx} +103 -99
  98. package/src/core-plugins/identify/{identify-table-cell.js → identify-table-cell.jsx} +49 -49
  99. package/src/core-plugins/identify/{identify-table.js → identify-table.jsx} +319 -334
  100. package/src/core-plugins/identify/index.js +27 -27
  101. package/src/core-plugins/identify/listeners/arcgis.js +158 -158
  102. package/src/core-plugins/identify/listeners/geojson.jsx +164 -0
  103. package/src/core-plugins/identify/listeners/raster.js +89 -89
  104. package/src/core-plugins/identify/listeners/{vector.js → vector.jsx} +106 -106
  105. package/src/core-plugins/identify-arcgis-rest/bundle.js +169 -169
  106. package/src/core-plugins/identify-cm/bundle.js +82 -82
  107. package/src/core-plugins/identify-geojson/bundle.js +164 -143
  108. package/src/core-plugins/identify-vector/{bundle.js → bundle.jsx} +135 -135
  109. package/src/core-plugins/identify-wms/bundle.js +138 -138
  110. package/src/core-plugins/legend/bundle.js +753 -730
  111. package/src/core-plugins/legend/{legend-header.js → legend-header.jsx} +1 -1
  112. package/src/core-plugins/legend/{legend-item-multiple.js → legend-item-multiple.jsx} +32 -32
  113. package/src/core-plugins/legend/{legend-panel.js → legend-panel.jsx} +1 -1
  114. package/src/core-plugins/login/login-button.jsx +49 -0
  115. package/src/core-plugins/map-loading-indicator/{loading-indicator.js → loading-indicator.jsx} +1 -1
  116. package/src/core-plugins/measure-tools/{measure-options.js → measure-options.jsx} +5 -8
  117. package/src/core-plugins/measure-tools/{measure-tools-button.js → measure-tools-button.jsx} +1 -1
  118. package/src/core-plugins/permalink/{permalink-button.js → permalink-button.jsx} +13 -13
  119. package/src/core-plugins/permalink/permalink-modal.jsx +67 -0
  120. package/src/core-plugins/print-map/{bundle.js → bundle.jsx} +316 -316
  121. package/src/core-plugins/print-map/{button.js → button.jsx} +1 -1
  122. package/src/core-plugins/resources/bundle.js +55 -50
  123. package/src/core-plugins/resources/resources-button.jsx +40 -0
  124. package/src/core-plugins/resources/{resources-modal.js → resources-modal.jsx} +9 -3
  125. package/src/core-plugins/rotate-north/{rotate-north-button.js → rotate-north-button.jsx} +2 -2
  126. package/src/core-plugins/theme-switcher/{theme-list-item.js → theme-list-item.jsx} +3 -3
  127. package/src/core-plugins/theme-switcher/{theme-list.js → theme-list.jsx} +1 -1
  128. package/src/core-plugins/three-d/three-d-button.jsx +44 -0
  129. package/src/core-plugins/tree-view/bundle.js +513 -513
  130. package/src/core-plugins/tree-view/{dataset-info-modal.js → dataset-info-modal.jsx} +141 -141
  131. package/src/core-plugins/tree-view/{dataset-legend.js → dataset-legend.jsx} +122 -122
  132. package/src/core-plugins/tree-view/{defaults-container.js → defaults-container.jsx} +27 -27
  133. package/src/core-plugins/tree-view/download-bundle.js +156 -156
  134. package/src/core-plugins/tree-view/{favorites-container.js → favorites-container.jsx} +27 -27
  135. package/src/core-plugins/tree-view/index.js +25 -25
  136. package/src/core-plugins/tree-view/layer-subpanel/{defaults-toggle.js → defaults-toggle.jsx} +28 -28
  137. package/src/core-plugins/tree-view/layer-subpanel/{download-layer.js → download-layer.jsx} +54 -54
  138. package/src/core-plugins/tree-view/layer-subpanel/{favorites-toggle.js → favorites-toggle.jsx} +28 -28
  139. package/src/core-plugins/tree-view/layer-subpanel/{label-toggle.js → label-toggle.jsx} +15 -14
  140. package/src/core-plugins/tree-view/layer-subpanel/{layer-subpanel.js → layer-subpanel.jsx} +179 -180
  141. package/src/core-plugins/tree-view/layer-subpanel/{natick-rgb.js → natick-rgb.jsx} +49 -37
  142. package/src/core-plugins/tree-view/layer-subpanel/remove-layer.jsx +75 -0
  143. package/src/core-plugins/tree-view/{tree-list-container.js → tree-list-container.jsx} +2 -5
  144. package/src/core-plugins/tree-view/{tree-list-item-dataset.js → tree-list-item-dataset.jsx} +1 -1
  145. package/src/core-plugins/tree-view/{tree-list-item-folder.js → tree-list-item-folder.jsx} +161 -163
  146. package/src/core-plugins/tree-view/{tree-list-item.js → tree-list-item.jsx} +2 -2
  147. package/src/core-plugins/tree-view/{tree-list.js → tree-list.jsx} +37 -29
  148. package/src/core-plugins/tree-view/{tree-view-panel.js → tree-view-panel.jsx} +139 -148
  149. package/src/core-plugins/tree-view/tree-view-toolbar/{add-all.js → add-all.jsx} +1 -1
  150. package/src/core-plugins/tree-view/tree-view-toolbar/{defaults.js → defaults.jsx} +40 -40
  151. package/src/core-plugins/tree-view/tree-view-toolbar/{favorites.js → favorites.jsx} +40 -40
  152. package/src/core-plugins/tree-view/tree-view-toolbar/{remove-all.js → remove-all.jsx} +1 -1
  153. package/src/core-plugins/tree-view/tree-view-toolbar/{toggle-expand.js → toggle-expand.jsx} +1 -1
  154. package/src/core-plugins/tree-view/tree-view-toolbar/{toggle-filter.js → toggle-filter.jsx} +1 -1
  155. package/src/core-plugins/zoom-home/bundle.js +28 -22
  156. package/src/core-plugins/zoom-home/index.js +5 -3
  157. package/src/core-plugins/zoom-home/{zoom-home-button.js → zoom-home-button.jsx} +2 -2
  158. package/src/core-plugins/zoom-in-out/index.js +19 -14
  159. package/src/core-plugins/zoom-in-out/{zoom-in-button.js → zoom-in-button.jsx} +7 -10
  160. package/src/core-plugins/zoom-in-out/{zoom-out-button.js → zoom-out-button.jsx} +7 -10
  161. package/src/core-plugins/zoom-level/bundle.js +35 -32
  162. package/src/core-plugins/zoom-level/index.js +17 -16
  163. package/src/core-plugins/zoom-level/{zoom-indicator.js → zoom-indicator.jsx} +34 -35
  164. package/src/core-plugins/zoom-to-box/bundle.js +52 -42
  165. package/src/core-plugins/zoom-to-box/{zoom-to-box-button.js → zoom-to-box-button.jsx} +9 -13
  166. package/src/css/_deprecated_bootstrap/css/bootstrap-paper.css +399 -124
  167. package/src/css/_deprecated_bootstrap/css/bootstrap-paper.min.css +8075 -3
  168. package/src/css/_deprecated_bootstrap/css/bootstrap-simplex.min.css +7320 -3
  169. package/src/css/_deprecated_bootstrap/css/bootstrap.css +582 -202
  170. package/src/css/_deprecated_bootstrap/css/bootstrap.css.map +142 -1
  171. package/src/css/_deprecated_bootstrap/css/bootstrap.min.css +7128 -2
  172. package/src/css/_deprecated_bootstrap/css/bootstrap.min.css.map +143 -1
  173. package/src/css/bg-colors.css +120 -120
  174. package/src/css/corpsmap-namespaced.css +9505 -9505
  175. package/src/css/corpsmap.css +10067 -9161
  176. package/src/css/navigation.css +174 -174
  177. package/src/index.css +68 -0
  178. package/src/{index.js → index.jsx} +113 -109
  179. package/src/main.jsx +3 -0
  180. package/src/openlayers-utils/format-utilities.js +87 -71
  181. package/src/openlayers-utils/layer-utilities.js +309 -302
  182. package/src/openlayers-utils/vector-style.js +131 -131
  183. package/src/utils/load-plugins.test.js +35 -35
  184. package/src/utils/redux-bundler-react.jsx +69 -0
  185. package/src/utils/scale-to-zoom-level.js +18 -22
  186. package/.babelrc +0 -7
  187. package/css/corpsmap.css +0 -10178
  188. package/fonts/cm.eot +0 -0
  189. package/fonts/cm.svg +0 -27
  190. package/fonts/cm.ttf +0 -0
  191. package/fonts/cm.woff +0 -0
  192. package/fonts/glyphicons-halflings-regular.eot +0 -0
  193. package/fonts/glyphicons-halflings-regular.svg +0 -288
  194. package/fonts/glyphicons-halflings-regular.ttf +0 -0
  195. package/fonts/glyphicons-halflings-regular.woff +0 -0
  196. package/fonts/glyphicons-halflings-regular.woff2 +0 -0
  197. package/fonts/maki.eot +0 -0
  198. package/fonts/maki.svg +0 -98
  199. package/fonts/maki.ttf +0 -0
  200. package/fonts/maki.woff +0 -0
  201. package/fonts/mapskin.eot +0 -0
  202. package/fonts/mapskin.svg +0 -282
  203. package/fonts/mapskin.ttf +0 -0
  204. package/fonts/mapskin.woff +0 -0
  205. package/fonts/materialdesignicons-webfont.eot +0 -0
  206. package/fonts/materialdesignicons-webfont.svg +0 -7467
  207. package/fonts/materialdesignicons-webfont.ttf +0 -0
  208. package/fonts/materialdesignicons-webfont.woff +0 -0
  209. package/fonts/materialdesignicons-webfont.woff2 +0 -0
  210. package/fonts/roboto/Roboto-Black.ttf +0 -0
  211. package/fonts/roboto/Roboto-BlackItalic.ttf +0 -0
  212. package/fonts/roboto/Roboto-Bold.ttf +0 -0
  213. package/fonts/roboto/Roboto-BoldItalic.ttf +0 -0
  214. package/fonts/roboto/Roboto-Italic.ttf +0 -0
  215. package/fonts/roboto/Roboto-Light.ttf +0 -0
  216. package/fonts/roboto/Roboto-LightItalic.ttf +0 -0
  217. package/fonts/roboto/Roboto-Medium.ttf +0 -0
  218. package/fonts/roboto/Roboto-MediumItalic.ttf +0 -0
  219. package/fonts/roboto/Roboto-Regular.ttf +0 -0
  220. package/fonts/roboto/Roboto-Thin.ttf +0 -0
  221. package/fonts/roboto/Roboto-ThinItalic.ttf +0 -0
  222. package/index.js +0 -5
  223. package/lib/dev.js +0 -171156
  224. package/lib/prod.js +0 -171070
  225. package/rollup.config.js +0 -50
  226. package/src/application-bundles/create-ol-map-bundle.js +0 -257
  227. package/src/application-bundles/map-view-bundle.js +0 -312
  228. package/src/application-containers/map.js +0 -45
  229. package/src/application-containers/old_corpsmap.js +0 -97
  230. package/src/application-containers/right-sidebar.js +0 -41
  231. package/src/application-containers/secondary-panel.js +0 -0
  232. package/src/application-containers/south-region.js +0 -79
  233. package/src/application-containers/upper-right-toolbar.js +0 -27
  234. package/src/application-controls/tree-list-item.js +0 -71
  235. package/src/core-plugins/add-data/add-shapefile.js +0 -43
  236. package/src/core-plugins/basemap-switcher/basemap-switcher-list-item copy.js +0 -59
  237. package/src/core-plugins/bookmarks/bookmark-panel.js +0 -157
  238. package/src/core-plugins/catalog/catalog-button.js +0 -36
  239. package/src/core-plugins/catalog/catalog-list-item.js +0 -83
  240. package/src/core-plugins/catalog/catalog-list.js +0 -70
  241. package/src/core-plugins/coordinate-display/bundle.js +0 -246
  242. package/src/core-plugins/draw-tools/draw-button.js +0 -192
  243. package/src/core-plugins/identify/listeners/geojson.js +0 -158
  244. package/src/core-plugins/login/login-button.js +0 -49
  245. package/src/core-plugins/permalink/permalink-modal.js +0 -64
  246. package/src/core-plugins/resources/resources-button.js +0 -44
  247. package/src/core-plugins/three-d/three-d-button.js +0 -44
  248. package/src/core-plugins/tree-view/layer-subpanel/remove-layer.js +0 -61
  249. /package/src/application-controls/{basic-toolbar-menu-divider.js → basic-toolbar-menu-divider.jsx} +0 -0
  250. /package/src/application-controls/{basic-toolbar-menu-item.js → basic-toolbar-menu-item.jsx} +0 -0
  251. /package/src/application-controls/{basic-toolbar-menu-up.js → basic-toolbar-menu-up.jsx} +0 -0
  252. /package/src/application-controls/{basic-toolbar-menu.js → basic-toolbar-menu.jsx} +0 -0
  253. /package/src/application-controls/{basic-toolbar-submenu.js → basic-toolbar-submenu.jsx} +0 -0
  254. /package/src/application-controls/{loading-indicator.js → loading-indicator.jsx} +0 -0
  255. /package/src/application-controls/{search-input.js → search-input.jsx} +0 -0
  256. /package/src/application-controls/{search-results-list.js → search-results-list.jsx} +0 -0
  257. /package/src/application-controls/{tree-list.js → tree-list.jsx} +0 -0
  258. /package/src/application-controls/{tree-view.js → tree-view.jsx} +0 -0
  259. /package/src/core-plugins/basemap-switcher/{basemap-switcher-button.js → basemap-switcher-button.jsx} +0 -0
  260. /package/src/core-plugins/bookmarks/{bookmark-button.js → bookmark-button.jsx} +0 -0
  261. /package/src/core-plugins/catalog/{catalog-error-item.js → catalog-error-item.jsx} +0 -0
  262. /package/src/core-plugins/catalog/{catalog-list-item-loader.js → catalog-list-item-loader.jsx} +0 -0
  263. /package/src/core-plugins/coordinate-display/{coordinate-display-proj-item.js → coordinate-display-proj-item.jsx} +0 -0
  264. /package/src/core-plugins/draw-tools/{draw-save-bundle.js → draw-save-bundle.jsx} +0 -0
  265. /package/src/core-plugins/draw-tools/{draw-tool-item.js → draw-tool-item.jsx} +0 -0
  266. /package/src/core-plugins/identify/{identify-popup.js → identify-popup.jsx} +0 -0
  267. /package/src/core-plugins/identify/{identify-sidebar-list.js → identify-sidebar-list.jsx} +0 -0
  268. /package/src/core-plugins/legend/{legend-button.js → legend-button.jsx} +0 -0
  269. /package/src/core-plugins/legend/{legend-item.js → legend-item.jsx} +0 -0
  270. /package/src/core-plugins/theme-switcher/{theme-switcher-button.js → theme-switcher-button.jsx} +0 -0
  271. /package/src/core-plugins/tree-view/{boundary-drop-target.js → boundary-drop-target.jsx} +0 -0
  272. /package/src/core-plugins/tree-view/layer-subpanel/{natick-rgb-options.js → natick-rgb-options.jsx} +0 -0
  273. /package/src/core-plugins/tree-view/layer-subpanel/{opacity-slider.js → opacity-slider.jsx} +0 -0
  274. /package/src/core-plugins/tree-view/{tree-view-button.js → tree-view-button.jsx} +0 -0
  275. /package/src/core-plugins/zoom-to-box/{index.js → index.jsx} +0 -0
  276. /package/src/utils/{plugin-region.js → plugin-region.jsx} +0 -0
@@ -32,68 +32,53 @@ export default {
32
32
  }
33
33
  };
34
34
  },
35
- doFetchLegendInfo: (layers) => ({ dispatch, store }) => {
36
- if (req) req.abort();
37
- let legendLayers = store.selectLegendLayers();
38
- let legendCanvases = store.selectLegendCanvases();
39
-
40
- layers.forEach((lyr) => {
41
- const { url, type, layerList, uid, displayName, layerDescription, attributions, legendOverride } = lyr;
42
- legendCanvases[uid] = {
43
- displayName: displayName,
44
- layerDescription: layerDescription,
45
- attributions: attributions,
46
- canvas: [],
47
- widths: [],
48
- heights: [],
49
- };
50
-
51
- let src = url;
52
- switch (type) {
53
- case "ArcGIS":
54
- src = `${src}/legend?f=pjson`;
55
- break;
56
- case "ArcGISImage":
57
- src = `${src}/legend?bandIds=&renderingRule=&f=pjson`;
58
- break;
59
- case "EsriFeatureService":
60
- if (legendOverride === true) {
35
+ doFetchLegendInfo:
36
+ (layers) =>
37
+ ({ dispatch, store }) => {
38
+ if (req) req.abort();
39
+ let legendLayers = store.selectLegendLayers();
40
+ let legendCanvases = store.selectLegendCanvases();
41
+
42
+ layers.forEach((lyr) => {
43
+ const {
44
+ url,
45
+ type,
46
+ layerList,
47
+ uid,
48
+ displayName,
49
+ layerDescription,
50
+ attributions,
51
+ legendOverride,
52
+ } = lyr;
53
+ legendCanvases[uid] = {
54
+ displayName: displayName,
55
+ layerDescription: layerDescription,
56
+ attributions: attributions,
57
+ canvas: [],
58
+ widths: [],
59
+ heights: [],
60
+ };
61
+
62
+ let src = url;
63
+ switch (type) {
64
+ case "ArcGIS":
61
65
  src = `${src}/legend?f=pjson`;
62
- }
63
- else {
64
- src = `${src}/${layerList}?f=pjson`;
65
- }
66
- break;
67
- default:
68
- break;
69
- }
70
- req = xhr.get(src, (err, response, body) => {
71
- if (err || response.statusCode !== 200) {
72
- legendLayers[uid] = ["Legend not available!"];
73
-
74
- dispatch({
75
- type: "LEGEND_LAYERS_UPDATE_ERROR",
76
- payload: {
77
- legendLayers: legendLayers,
78
- legendCanvases: legendCanvases,
79
- loading: false,
80
- },
81
- });
82
- } else {
83
- try {
84
- const data = JSON.parse(body);
85
- console.log(data)
86
- if (type === "EsriFeatureService") {
87
- if (legendOverride === true) {
88
- store.doGenerateArcImages(data, lyr);
89
- } else {
90
- store.doGenerateEsriImages(data, lyr);
91
- }
66
+ break;
67
+ case "ArcGISImage":
68
+ src = `${src}/legend?bandIds=&renderingRule=&f=pjson`;
69
+ break;
70
+ case "EsriFeatureService":
71
+ if (legendOverride === true) {
72
+ src = `${src}/legend?f=pjson`;
92
73
  } else {
93
- store.doGenerateArcImages(data, lyr);
74
+ src = `${src}/${layerList}?f=pjson`;
94
75
  }
95
- } catch (err) {
96
- console.log(err);
76
+ break;
77
+ default:
78
+ break;
79
+ }
80
+ req = xhr.get(src, (err, response, body) => {
81
+ if (err || response.statusCode !== 200) {
97
82
  legendLayers[uid] = ["Legend not available!"];
98
83
 
99
84
  dispatch({
@@ -104,62 +89,179 @@ export default {
104
89
  loading: false,
105
90
  },
106
91
  });
92
+ } else {
93
+ try {
94
+ const data = JSON.parse(body);
95
+ console.log(data);
96
+ if (type === "EsriFeatureService") {
97
+ if (legendOverride === true) {
98
+ store.doGenerateArcImages(data, lyr);
99
+ } else {
100
+ store.doGenerateEsriImages(data, lyr);
101
+ }
102
+ } else {
103
+ store.doGenerateArcImages(data, lyr);
104
+ }
105
+ } catch (err) {
106
+ console.log(err);
107
+ legendLayers[uid] = ["Legend not available!"];
108
+
109
+ dispatch({
110
+ type: "LEGEND_LAYERS_UPDATE_ERROR",
111
+ payload: {
112
+ legendLayers: legendLayers,
113
+ legendCanvases: legendCanvases,
114
+ loading: false,
115
+ },
116
+ });
117
+ }
107
118
  }
108
- }
119
+ });
120
+
121
+ // timeout after 60s.
122
+ req.timeout = 60000;
109
123
  });
124
+ },
125
+ doGenerateArcImages:
126
+ (data, lyr) =>
127
+ ({ dispatch, store }) => {
128
+ const { uid, layerList, displayName, layerDescription, attributions } =
129
+ lyr;
130
+ let legendLayers = store.selectLegendLayers();
131
+ let legendCanvases = store.selectLegendCanvases();
132
+ const activeLayers = layerList
133
+ .replace(/show:/g, "")
134
+ .split(",")
135
+ .map(Number);
110
136
 
111
- // timeout after 60s.
112
- req.timeout = 60000;
113
- });
114
- },
115
- doGenerateArcImages: (data, lyr) => ({ dispatch, store }) => {
116
- const { uid, layerList, displayName, layerDescription, attributions } = lyr;
117
- let legendLayers = store.selectLegendLayers();
118
- let legendCanvases = store.selectLegendCanvases();
119
- const activeLayers = layerList.replace(/show:/g, "").split(",").map(Number);
120
-
121
- legendCanvases[uid] = {
122
- displayName: displayName,
123
- layerDescription: layerDescription,
124
- attributions: attributions,
125
- canvas: [],
126
- widths: [],
127
- heights: [],
128
- };
137
+ legendCanvases[uid] = {
138
+ displayName: displayName,
139
+ layerDescription: layerDescription,
140
+ attributions: attributions,
141
+ canvas: [],
142
+ widths: [],
143
+ heights: [],
144
+ };
145
+
146
+ const legends = data.layers.filter((item) => {
147
+ return activeLayers.indexOf(item.layerId) !== -1;
148
+ });
149
+ const items = legends.map((legendLyr) => {
150
+ return legendLyr.legend.map((legend) => {
151
+ let img = new Image();
152
+ img.addEventListener(
153
+ "load",
154
+ function () {
155
+ let canvas = document.createElement("canvas");
156
+ let ctx = canvas.getContext("2d");
157
+ const labelWidth = Number(ctx.measureText(legend.label).width);
158
+
159
+ //set canvas width & height
160
+ canvas.width = Number(legend.width) + labelWidth + 4;
161
+ canvas.height = legend.height;
162
+
163
+ //store width & height for larger canvas calculation
164
+ legendCanvases[uid].widths.push(canvas.width);
165
+ legendCanvases[uid].heights.push(canvas.height);
166
+
167
+ //set background
168
+ ctx.fillStyle = "white";
169
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
170
+
171
+ ctx.drawImage(img, 0, 0); //add image to canvas
172
+
173
+ //add label to the right of image
174
+ ctx.font = "10px Arial";
175
+ ctx.fillStyle = "black";
176
+ ctx.fillText(legend.label, legend.width + 2, legend.height / 2);
177
+ legendCanvases[uid].canvas.push(canvas);
178
+
179
+ dispatch({
180
+ type: "LEGEND_CANVAS_ADDED",
181
+ payload: {
182
+ legendCanvases: legendCanvases,
183
+ loading: false,
184
+ },
185
+ });
186
+ },
187
+ false
188
+ );
189
+ img.src = `data:${legend.contentType};base64,${legend.imageData}`;
190
+ img.alt = `Style for ${legend.label}`;
191
+ img.crossOrigin = "anonymous";
192
+ img.title = legend.label;
193
+
194
+ return img;
195
+ });
196
+ });
197
+ legendLayers[uid] = flatten(items);
198
+
199
+ dispatch({
200
+ type: "LEGEND_LAYERS_UPDATED",
201
+ payload: {
202
+ legendLayers: legendLayers,
203
+ loading: false,
204
+ },
205
+ });
206
+ },
207
+
208
+ doGenerateEsriImages:
209
+ (data, lyr) =>
210
+ ({ dispatch, store }) => {
211
+ const { uid, displayName, layerDescription, attributions } = lyr;
212
+ let legendLayers = store.selectLegendLayers();
213
+ let legendCanvases = store.selectLegendCanvases();
214
+ const drawingInfo = data.drawingInfo;
215
+ legendCanvases[uid] = {
216
+ displayName: displayName,
217
+ layerDescription: layerDescription,
218
+ attributions: attributions,
219
+ canvas: [],
220
+ widths: [],
221
+ heights: [],
222
+ };
223
+ legendLayers[uid] = [];
224
+ //TODO Logic below is needs to include other Esri styles.
225
+ console.log(drawingInfo.renderer);
226
+ console.log(drawingInfo.renderer.symbol);
227
+ // debugger;
228
+ switch (data.geometryType) {
229
+ case "esriGeometryPolygon":
230
+ if (
231
+ drawingInfo.renderer.symbol &&
232
+ drawingInfo.renderer.symbol.type === "esriSFS" &&
233
+ drawingInfo.renderer.symbol.style === "esriSFSSolid"
234
+ ) {
235
+ let img = new Image();
236
+ const outlineColor = drawingInfo.renderer.symbol.outline.color;
237
+ const fillColor = drawingInfo.renderer.symbol.color;
129
238
 
130
- const legends = data.layers.filter((item) => {
131
- return activeLayers.indexOf(item.layerId) !== -1;
132
- });
133
- const items = legends.map((legendLyr) => {
134
- return legendLyr.legend.map((legend) => {
135
- let img = new Image();
136
- img.addEventListener(
137
- "load",
138
- function () {
139
239
  let canvas = document.createElement("canvas");
140
240
  let ctx = canvas.getContext("2d");
141
- const labelWidth = Number(ctx.measureText(legend.label).width);
142
241
 
143
- //set canvas width & height
144
- canvas.width = Number(legend.width) + labelWidth + 4;
145
- canvas.height = legend.height;
242
+ canvas.width = 20;
243
+ canvas.height = 20;
146
244
 
147
245
  //store width & height for larger canvas calculation
148
246
  legendCanvases[uid].widths.push(canvas.width);
149
247
  legendCanvases[uid].heights.push(canvas.height);
150
248
 
151
- //set background
152
- ctx.fillStyle = "white";
153
- ctx.fillRect(0, 0, canvas.width, canvas.height);
249
+ // Draw polygon
250
+ ctx.beginPath();
251
+ ctx.lineWidth = "2";
252
+ ctx.strokeStyle = outlineColor
253
+ ? `rgba(${outlineColor.join()})`
254
+ : null;
255
+ ctx.rect(0, 0, 20, 20);
256
+ ctx.stroke();
257
+ ctx.fillStyle = fillColor ? `rgba(${fillColor.join()})` : null;
258
+ ctx.fillRect(1, 1, 18, 18);
154
259
 
155
- ctx.drawImage(img, 0, 0); //add image to canvas
260
+ img.src = canvas.toDataURL(); //set src using data URI from canvas
261
+ img.alt = `Style for ${displayName}`;
262
+ img.crossOrigin = "anonymous";
156
263
 
157
- //add label to the right of image
158
- ctx.font = "10px Arial";
159
- ctx.fillStyle = "black";
160
- ctx.fillText(legend.label, legend.width + 2, legend.height / 2);
161
264
  legendCanvases[uid].canvas.push(canvas);
162
-
163
265
  dispatch({
164
266
  type: "LEGEND_CANVAS_ADDED",
165
267
  payload: {
@@ -167,198 +269,48 @@ export default {
167
269
  loading: false,
168
270
  },
169
271
  });
170
- },
171
- false
172
- );
173
- img.src = `data:${legend.contentType};base64,${legend.imageData}`;
174
- img.alt = `Style for ${legend.label}`;
175
- img.crossOrigin = "anonymous";
176
- img.title = legend.label;
177
-
178
- return img;
179
- });
180
- });
181
- legendLayers[uid] = flatten(items);
182
-
183
- dispatch({
184
- type: "LEGEND_LAYERS_UPDATED",
185
- payload: {
186
- legendLayers: legendLayers,
187
- loading: false,
188
- },
189
- });
190
- },
191
-
192
- doGenerateEsriImages: (data, lyr) => ({ dispatch, store }) => {
193
- const { uid, displayName, layerDescription, attributions } = lyr;
194
- let legendLayers = store.selectLegendLayers();
195
- let legendCanvases = store.selectLegendCanvases();
196
- const drawingInfo = data.drawingInfo;
197
- legendCanvases[uid] = {
198
- displayName: displayName,
199
- layerDescription: layerDescription,
200
- attributions: attributions,
201
- canvas: [],
202
- widths: [],
203
- heights: [],
204
- };
205
- legendLayers[uid] = [];
206
- //TODO Logic below is needs to include other Esri styles.
207
- console.log(drawingInfo.renderer);
208
- console.log(drawingInfo.renderer.symbol)
209
-
210
- switch (data.geometryType) {
211
- case "esriGeometryPolygon":
212
- if (
213
- drawingInfo.renderer.symbol &&
214
- drawingInfo.renderer.symbol.type === "esriSFS" &&
215
- drawingInfo.renderer.symbol.style === "esriSFSSolid"
216
- ) {
217
- let img = new Image();
218
- const outlineColor = drawingInfo.renderer.symbol.outline.color;
219
- const fillColor = drawingInfo.renderer.symbol.color;
220
-
221
272
 
222
- let canvas = document.createElement("canvas");
223
- let ctx = canvas.getContext("2d");
224
-
225
- canvas.width = 20;
226
- canvas.height = 20;
227
-
228
- //store width & height for larger canvas calculation
229
- legendCanvases[uid].widths.push(canvas.width);
230
- legendCanvases[uid].heights.push(canvas.height);
231
-
232
- // Draw polygon
233
- ctx.beginPath();
234
- ctx.lineWidth = "2";
235
- ctx.strokeStyle = `rgba(${outlineColor.join()})`;
236
- ctx.rect(0, 0, 20, 20);
237
- ctx.stroke();
238
- ctx.fillStyle = `rgba(${fillColor.join()})`;
239
- ctx.fillRect(1, 1, 18, 18);
240
-
241
- img.src = canvas.toDataURL(); //set src using data URI from canvas
242
- img.alt = `Style for ${displayName}`;
243
- img.crossOrigin = "anonymous";
244
-
245
- legendCanvases[uid].canvas.push(canvas);
246
- dispatch({
247
- type: "LEGEND_CANVAS_ADDED",
248
- payload: {
249
- legendCanvases: legendCanvases,
250
- loading: false,
251
- },
252
- });
253
-
254
- legendLayers[uid].push(img);
255
- dispatch({
256
- type: "LEGEND_LAYERS_UPDATED",
257
- payload: {
258
- legendLayers: legendLayers,
259
- loading: false,
260
- },
261
- });
262
- }
263
- else if(
264
- drawingInfo.renderer.symbol &&
265
- drawingInfo.renderer.symbol.type === "esriSFS" &&
266
- drawingInfo.renderer.symbol.style === "esriSFSBackwardDiagonal"
267
- ) {
268
- let img = new Image();
269
- const outlineColor = drawingInfo.renderer.symbol.outline.color;
270
- const fillColor = drawingInfo.renderer.symbol.color;
271
-
272
-
273
- let canvas = document.createElement("canvas");
274
- let ctx = canvas.getContext("2d");
275
-
276
- canvas.width = 20;
277
- canvas.height = 20;
278
-
279
- //store width & height for larger canvas calculation
280
- legendCanvases[uid].widths.push(canvas.width);
281
- legendCanvases[uid].heights.push(canvas.height);
282
-
283
- // // Draw polygon
284
- ctx.beginPath();
285
- ctx.moveTo(0, 10);
286
- ctx.lineTo(10, 0);
287
- ctx.moveTo(0, 20);
288
- ctx.lineTo(20, 0);
289
- ctx.moveTo(10, 20);
290
- ctx.lineTo(20, 10);
291
- ctx.lineWidth = "2";
292
- ctx.strokeStyle = `rgba(${outlineColor.join()})`;
293
- ctx.rect(0, 0, 20, 20);
294
- ctx.stroke();
295
-
296
- img.src = canvas.toDataURL(); //set src using data URI from canvas
297
- img.alt = `Style for ${displayName}`;
298
- img.crossOrigin = "anonymous";
299
-
300
- legendCanvases[uid].canvas.push(canvas);
301
- dispatch({
302
- type: "LEGEND_CANVAS_ADDED",
303
- payload: {
304
- legendCanvases: legendCanvases,
305
- loading: false,
306
- },
307
- });
308
-
309
- legendLayers[uid].push(img);
310
- dispatch({
311
- type: "LEGEND_LAYERS_UPDATED",
312
- payload: {
313
- legendLayers: legendLayers,
314
- loading: false,
315
- },
316
- });
317
- }
318
- //____________________________________________________________________________________________________________________________________
319
- else if (
320
- drawingInfo.renderer.type === "uniqueValue" &&
321
- drawingInfo.renderer.uniqueValueInfos
322
- ) {
323
- // Compare
324
- drawingInfo.renderer.uniqueValueInfos.forEach((val) => {
273
+ legendLayers[uid].push(img);
274
+ dispatch({
275
+ type: "LEGEND_LAYERS_UPDATED",
276
+ payload: {
277
+ legendLayers: legendLayers,
278
+ loading: false,
279
+ },
280
+ });
281
+ } else if (
282
+ drawingInfo.renderer.symbol &&
283
+ drawingInfo.renderer.symbol.type === "esriSFS" &&
284
+ drawingInfo.renderer.symbol.style === "esriSFSBackwardDiagonal"
285
+ ) {
325
286
  let img = new Image();
326
- console.log(val.value)
327
- if (val.value === 'BOEM') {
328
- }
329
-
330
- const fillColor = val.symbol.color;
331
- const outlineColor = val.symbol.outline && val.symbol.outline.color ? val.symbol.outline.color : fillColor;
332
-
287
+ const outlineColor = drawingInfo.renderer.symbol.outline.color;
288
+ const fillColor = drawingInfo.renderer.symbol.color;
333
289
 
334
290
  let canvas = document.createElement("canvas");
335
291
  let ctx = canvas.getContext("2d");
336
- const labelWidth = Number(ctx.measureText(val.label).width);
337
292
 
338
- //set canvas width & height
339
- canvas.width = 20 + labelWidth + 4;
293
+ canvas.width = 20;
340
294
  canvas.height = 20;
341
295
 
342
296
  //store width & height for larger canvas calculation
343
297
  legendCanvases[uid].widths.push(canvas.width);
344
298
  legendCanvases[uid].heights.push(canvas.height);
345
299
 
346
- // Draw polygon
300
+ // // Draw polygon
347
301
  ctx.beginPath();
302
+ ctx.moveTo(0, 10);
303
+ ctx.lineTo(10, 0);
304
+ ctx.moveTo(0, 20);
305
+ ctx.lineTo(20, 0);
306
+ ctx.moveTo(10, 20);
307
+ ctx.lineTo(20, 10);
348
308
  ctx.lineWidth = "2";
349
309
  ctx.strokeStyle = `rgba(${outlineColor.join()})`;
350
310
  ctx.rect(0, 0, 20, 20);
351
311
  ctx.stroke();
352
- ctx.fillStyle = `rgba(${fillColor.join()})`;
353
- ctx.fillRect(1, 1, 18, 18);
354
-
355
- //add label to the right of image
356
- ctx.font = "10px Arial";
357
- ctx.fillStyle = "black";
358
- ctx.fillText(val.label, 22, canvas.height / 2);
359
312
 
360
- //set img attributes
361
- img.src = canvas.toDataURL();
313
+ img.src = canvas.toDataURL(); //set src using data URI from canvas
362
314
  img.alt = `Style for ${displayName}`;
363
315
  img.crossOrigin = "anonymous";
364
316
 
@@ -372,77 +324,95 @@ export default {
372
324
  });
373
325
 
374
326
  legendLayers[uid].push(img);
375
- });
376
- dispatch({
377
- type: "LEGEND_LAYERS_UPDATED",
378
- payload: {
379
- legendLayers: legendLayers,
380
- loading: false,
381
- },
382
- });
383
- }
384
- break;
385
- case "esriGeometryPolyline":
386
- if (
387
- drawingInfo.renderer.symbol &&
388
- drawingInfo.renderer.symbol.type === "esriSLS" &&
389
- drawingInfo.renderer.symbol.style === "esriSLSSolid"
390
- ) {
391
- let img = new Image();
392
- let canvas = document.createElement("canvas");
393
- let ctx = canvas.getContext("2d");
394
- const lineColor = drawingInfo.renderer.symbol.color;
395
-
396
- canvas.width = 20;
397
- canvas.height = 20;
398
-
399
- //store width & height for larger canvas calculation
400
- legendCanvases[uid].widths.push(canvas.width);
401
- legendCanvases[uid].heights.push(canvas.height);
402
-
403
- // Draw line
404
- ctx.beginPath();
405
- ctx.strokeStyle = `rgba(${lineColor.join()})`;
406
- ctx.moveTo(0, 0);
407
- ctx.lineTo(20, 20);
408
- ctx.stroke();
409
-
410
- //set img attributes
411
- img.src = canvas.toDataURL(); //set src using data URI from canvas
412
- img.alt = `Style for ${displayName}`;
413
- img.crossOrigin = "anonymous";
327
+ dispatch({
328
+ type: "LEGEND_LAYERS_UPDATED",
329
+ payload: {
330
+ legendLayers: legendLayers,
331
+ loading: false,
332
+ },
333
+ });
334
+ }
335
+ //____________________________________________________________________________________________________________________________________
336
+ else if (
337
+ drawingInfo.renderer.type === "uniqueValue" &&
338
+ drawingInfo.renderer.uniqueValueInfos
339
+ ) {
340
+ // Compare
341
+ drawingInfo.renderer.uniqueValueInfos.forEach((val) => {
342
+ let img = new Image();
343
+ console.log(val.value);
344
+ if (val.value === "BOEM") {
345
+ }
414
346
 
415
- legendCanvases[uid].canvas.push(canvas);
416
- dispatch({
417
- type: "LEGEND_CANVAS_ADDED",
418
- payload: {
419
- legendCanvases: legendCanvases,
420
- loading: false,
421
- },
422
- });
347
+ const fillColor = val.symbol.color;
348
+ const outlineColor =
349
+ val.symbol.outline && val.symbol.outline.color
350
+ ? val.symbol.outline.color
351
+ : fillColor;
423
352
 
424
- legendLayers[uid].push(img);
425
- dispatch({
426
- type: "LEGEND_LAYERS_UPDATED",
427
- payload: {
428
- legendLayers: legendLayers,
429
- loading: false,
430
- },
431
- });
432
- } else if (
433
- drawingInfo.renderer.type === "uniqueValue" &&
434
- drawingInfo.renderer.uniqueValueInfos
435
- ) {
436
- drawingInfo.renderer.uniqueValueInfos.forEach((val) => {
437
- let img = new Image();
353
+ let canvas = document.createElement("canvas");
354
+ let ctx = canvas.getContext("2d");
355
+ const labelWidth = Number(ctx.measureText(val.label).width);
438
356
 
357
+ //set canvas width & height
358
+ canvas.width = 20 + labelWidth + 4;
359
+ canvas.height = 20;
360
+
361
+ //store width & height for larger canvas calculation
362
+ legendCanvases[uid].widths.push(canvas.width);
363
+ legendCanvases[uid].heights.push(canvas.height);
364
+
365
+ // Draw polygon
366
+ ctx.beginPath();
367
+ ctx.lineWidth = "2";
368
+ ctx.strokeStyle = `rgba(${outlineColor.join()})`;
369
+ ctx.rect(0, 0, 20, 20);
370
+ ctx.stroke();
371
+ ctx.fillStyle = `rgba(${fillColor.join()})`;
372
+ ctx.fillRect(1, 1, 18, 18);
373
+
374
+ //add label to the right of image
375
+ ctx.font = "10px Arial";
376
+ ctx.fillStyle = "black";
377
+ ctx.fillText(val.label, 22, canvas.height / 2);
378
+
379
+ //set img attributes
380
+ img.src = canvas.toDataURL();
381
+ img.alt = `Style for ${displayName}`;
382
+ img.crossOrigin = "anonymous";
383
+
384
+ legendCanvases[uid].canvas.push(canvas);
385
+ dispatch({
386
+ type: "LEGEND_CANVAS_ADDED",
387
+ payload: {
388
+ legendCanvases: legendCanvases,
389
+ loading: false,
390
+ },
391
+ });
392
+
393
+ legendLayers[uid].push(img);
394
+ });
395
+ dispatch({
396
+ type: "LEGEND_LAYERS_UPDATED",
397
+ payload: {
398
+ legendLayers: legendLayers,
399
+ loading: false,
400
+ },
401
+ });
402
+ }
403
+ break;
404
+ case "esriGeometryPolyline":
405
+ if (
406
+ drawingInfo.renderer.symbol &&
407
+ drawingInfo.renderer.symbol.type === "esriSLS" &&
408
+ drawingInfo.renderer.symbol.style === "esriSLSSolid"
409
+ ) {
410
+ let img = new Image();
439
411
  let canvas = document.createElement("canvas");
440
412
  let ctx = canvas.getContext("2d");
441
- const labelWidth = Number(ctx.measureText(val.label).width);
442
- const lineColor = val.symbol.color;
413
+ const lineColor = drawingInfo.renderer.symbol.color;
443
414
 
444
- //set canvas width & height
445
- canvas.width = 20 + labelWidth + 4;
415
+ canvas.width = 20;
446
416
  canvas.height = 20;
447
417
 
448
418
  //store width & height for larger canvas calculation
@@ -456,13 +426,8 @@ export default {
456
426
  ctx.lineTo(20, 20);
457
427
  ctx.stroke();
458
428
 
459
- //add label to the right of image
460
- ctx.font = "10px Arial";
461
- ctx.fillStyle = "black";
462
- ctx.fillText(val.label, 22, canvas.height / 2);
463
-
464
429
  //set img attributes
465
- img.src = canvas.toDataURL();
430
+ img.src = canvas.toDataURL(); //set src using data URI from canvas
466
431
  img.alt = `Style for ${displayName}`;
467
432
  img.crossOrigin = "anonymous";
468
433
 
@@ -476,41 +441,51 @@ export default {
476
441
  });
477
442
 
478
443
  legendLayers[uid].push(img);
479
- });
480
- dispatch({
481
- type: "LEGEND_LAYERS_UPDATED",
482
- payload: {
483
- legendLayers: legendLayers,
484
- loading: false,
485
- },
486
- });
487
- }
488
- break;
489
- case "esriGeometryPoint":
490
- if (drawingInfo.renderer.symbol && drawingInfo.renderer.symbol.type === "esriPMS") {
491
- let img = new Image();
492
- img.src = `data:image/png;base64,${data.drawingInfo.renderer.symbol.imageData}`;
493
- img.addEventListener(
494
- "load",
495
- function () {
444
+ dispatch({
445
+ type: "LEGEND_LAYERS_UPDATED",
446
+ payload: {
447
+ legendLayers: legendLayers,
448
+ loading: false,
449
+ },
450
+ });
451
+ } else if (
452
+ drawingInfo.renderer.type === "uniqueValue" &&
453
+ drawingInfo.renderer.uniqueValueInfos
454
+ ) {
455
+ drawingInfo.renderer.uniqueValueInfos.forEach((val) => {
456
+ let img = new Image();
457
+
496
458
  let canvas = document.createElement("canvas");
497
459
  let ctx = canvas.getContext("2d");
460
+ const labelWidth = Number(ctx.measureText(val.label).width);
461
+ const lineColor = val.symbol.color;
498
462
 
499
- canvas.width = drawingInfo.renderer.symbol.width;
500
- canvas.height = drawingInfo.renderer.symbol.height;
463
+ //set canvas width & height
464
+ canvas.width = 20 + labelWidth + 4;
465
+ canvas.height = 20;
501
466
 
502
467
  //store width & height for larger canvas calculation
503
468
  legendCanvases[uid].widths.push(canvas.width);
504
469
  legendCanvases[uid].heights.push(canvas.height);
505
470
 
506
- //set background
507
- ctx.fillStyle = "white";
508
- ctx.fillRect(0, 0, canvas.width, canvas.height);
509
-
510
- ctx.drawImage(img, 0, 0); //add image to canvas
471
+ // Draw line
472
+ ctx.beginPath();
473
+ ctx.strokeStyle = `rgba(${lineColor.join()})`;
474
+ ctx.moveTo(0, 0);
475
+ ctx.lineTo(20, 20);
476
+ ctx.stroke();
477
+
478
+ //add label to the right of image
479
+ ctx.font = "10px Arial";
480
+ ctx.fillStyle = "black";
481
+ ctx.fillText(val.label, 22, canvas.height / 2);
482
+
483
+ //set img attributes
484
+ img.src = canvas.toDataURL();
485
+ img.alt = `Style for ${displayName}`;
486
+ img.crossOrigin = "anonymous";
511
487
 
512
488
  legendCanvases[uid].canvas.push(canvas);
513
-
514
489
  dispatch({
515
490
  type: "LEGEND_CANVAS_ADDED",
516
491
  payload: {
@@ -518,23 +493,72 @@ export default {
518
493
  loading: false,
519
494
  },
520
495
  });
521
- },
522
- false
523
- );
524
496
 
525
- img.alt = `Style for ${displayName}`;
526
- img.crossOrigin = "anonymous";
527
- legendLayers[uid] = [img]; //TODO: Update to possibly push multiple images into array
528
- dispatch({
529
- type: "LEGEND_LAYERS_UPDATED",
530
- payload: {
531
- legendLayers: legendLayers,
532
- loading: false,
533
- },
534
- });
535
- } else if (drawingInfo.renderer.symbol && drawingInfo.renderer.symbol.type === "esriSMS") {
497
+ legendLayers[uid].push(img);
498
+ });
499
+ dispatch({
500
+ type: "LEGEND_LAYERS_UPDATED",
501
+ payload: {
502
+ legendLayers: legendLayers,
503
+ loading: false,
504
+ },
505
+ });
506
+ }
507
+ break;
508
+ case "esriGeometryPoint":
509
+ if (
510
+ drawingInfo.renderer.symbol &&
511
+ drawingInfo.renderer.symbol.type === "esriPMS"
512
+ ) {
513
+ let img = new Image();
514
+ img.src = `data:image/png;base64,${data.drawingInfo.renderer.symbol.imageData}`;
515
+ img.addEventListener(
516
+ "load",
517
+ function () {
518
+ let canvas = document.createElement("canvas");
519
+ let ctx = canvas.getContext("2d");
536
520
 
537
- let img = new Image();
521
+ canvas.width = drawingInfo.renderer.symbol.width;
522
+ canvas.height = drawingInfo.renderer.symbol.height;
523
+
524
+ //store width & height for larger canvas calculation
525
+ legendCanvases[uid].widths.push(canvas.width);
526
+ legendCanvases[uid].heights.push(canvas.height);
527
+
528
+ //set background
529
+ ctx.fillStyle = "white";
530
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
531
+
532
+ ctx.drawImage(img, 0, 0); //add image to canvas
533
+
534
+ legendCanvases[uid].canvas.push(canvas);
535
+
536
+ dispatch({
537
+ type: "LEGEND_CANVAS_ADDED",
538
+ payload: {
539
+ legendCanvases: legendCanvases,
540
+ loading: false,
541
+ },
542
+ });
543
+ },
544
+ false
545
+ );
546
+
547
+ img.alt = `Style for ${displayName}`;
548
+ img.crossOrigin = "anonymous";
549
+ legendLayers[uid] = [img]; //TODO: Update to possibly push multiple images into array
550
+ dispatch({
551
+ type: "LEGEND_LAYERS_UPDATED",
552
+ payload: {
553
+ legendLayers: legendLayers,
554
+ loading: false,
555
+ },
556
+ });
557
+ } else if (
558
+ drawingInfo.renderer.symbol &&
559
+ drawingInfo.renderer.symbol.type === "esriSMS"
560
+ ) {
561
+ let img = new Image();
538
562
  const outlineColor = drawingInfo.renderer.symbol.outline.color;
539
563
  const outlineWidth = drawingInfo.renderer.symbol.outline.width;
540
564
  const fillColor = drawingInfo.renderer.symbol.color;
@@ -553,7 +577,7 @@ export default {
553
577
  ctx.beginPath();
554
578
  ctx.strokeStyle = `rgba(${outlineColor.join()})`;
555
579
  ctx.lineWidth = outlineWidth;
556
- ctx.arc(size, size, size/1.5, 0, Math.PI * 2);
580
+ ctx.arc(size, size, size / 1.5, 0, Math.PI * 2);
557
581
  ctx.fillStyle = `rgba(${fillColor.join()})`;
558
582
  ctx.fill();
559
583
  ctx.stroke();
@@ -579,166 +603,164 @@ export default {
579
603
  loading: false,
580
604
  },
581
605
  });
582
- }
583
- //___________________________________________________________________________________________________________________________________
584
- else if (drawingInfo.renderer.uniqueValueInfos){
585
- // let canvas = document.createElement("canvas");
586
- // let ctx = canvas.getContext("2d");
587
- let result = []
588
- let images = []
589
- drawingInfo.renderer.uniqueValueInfos.forEach((val) => {
590
-
591
- let label = val.label
592
- let wkCanvas;
593
- let img = new Image();
594
- img.src = `data:image/png;base64,${val.symbol.imageData}`;
595
-
596
- // img.addEventListener(
597
- // "load",
598
- // function () {
599
- let canvas = document.createElement("canvas");
600
- let ctx = canvas.getContext("2d")
601
-
602
- const labelWidth = Number(ctx.measureText(label).width);
603
-
604
- //set canvas width & height
605
- canvas.width = Number(val.symbol.width) + labelWidth + 4;
606
- canvas.height = val.symbol.height;
607
-
608
- //store width & height for larger canvas calculation
609
- // legendCanvases[uid].widths.push(canvas.width);
610
- // legendCanvases[uid].heights.push(canvas.height);
611
-
612
- //set background
613
- ctx.fillStyle = "white";
614
- ctx.fillRect(0, 0, canvas.width, canvas.height);
615
- // // ctx.putImageData(val.symbol.imageData, 0,0)
616
-
617
- ctx.drawImage(img, 0, 0); //add image to canvas
618
-
619
- // //add label to the right of image
620
- // ctx.font = "10px Arial";
621
- // ctx.fillStyle = "black";
622
-
623
- // ctx.fillText(label, canvas.width + 2, canvas.height / 2);
624
-
625
- // legendCanvases[uid].canvas.push(canvas);
626
-
627
- // dispatch({
628
- // type: "LEGEND_CANVAS_ADDED",
629
- // payload: {
630
- // legendCanvases: legendCanvases,
631
- // loading: false,
632
- // },
633
- // });
634
- // result.push(canvas)
606
+ }
607
+ //___________________________________________________________________________________________________________________________________
608
+ else if (drawingInfo.renderer.uniqueValueInfos) {
609
+ // let canvas = document.createElement("canvas");
610
+ // let ctx = canvas.getContext("2d");
611
+ let result = [];
612
+ let images = [];
613
+ drawingInfo.renderer.uniqueValueInfos.forEach((val) => {
614
+ let label = val.label;
615
+ let wkCanvas;
616
+ let img = new Image();
617
+ img.src = `data:image/png;base64,${val.symbol.imageData}`;
618
+
619
+ // img.addEventListener(
620
+ // "load",
621
+ // function () {
622
+ let canvas = document.createElement("canvas");
623
+ let ctx = canvas.getContext("2d");
624
+
625
+ const labelWidth = Number(ctx.measureText(label).width);
626
+
627
+ //set canvas width & height
628
+ canvas.width = Number(val.symbol.width) + labelWidth + 4;
629
+ canvas.height = val.symbol.height;
630
+
631
+ //store width & height for larger canvas calculation
632
+ // legendCanvases[uid].widths.push(canvas.width);
633
+ // legendCanvases[uid].heights.push(canvas.height);
634
+
635
+ //set background
636
+ ctx.fillStyle = "white";
637
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
638
+ // // ctx.putImageData(val.symbol.imageData, 0,0)
639
+
640
+ ctx.drawImage(img, 0, 0); //add image to canvas
641
+
642
+ // //add label to the right of image
643
+ // ctx.font = "10px Arial";
644
+ // ctx.fillStyle = "black";
645
+
646
+ // ctx.fillText(label, canvas.width + 2, canvas.height / 2);
647
+
648
+ // legendCanvases[uid].canvas.push(canvas);
649
+
650
+ // dispatch({
651
+ // type: "LEGEND_CANVAS_ADDED",
652
+ // payload: {
653
+ // legendCanvases: legendCanvases,
654
+ // loading: false,
655
+ // },
656
+ // });
657
+ // result.push(canvas)
635
658
  // },
636
659
  // false
637
- // );
638
- // img.src = `data:${val.symbol.url};base64,${val.symbol.imageData}`
639
- // img.src = canvas.toDataURL()
640
-
641
- img.alt = `Style for ${label}`;
642
- img.crossOrigin = "anonymous";
643
- img.title = label;
644
- // legendLayers[uid] = [img]; //TODO: Update to possibly push multiple images into array
645
- // images.push(img)
646
-
647
- // dispatch({
648
- // type: "LEGEND_LAYERS_UPDATED",
649
- // payload: {
650
- // legendLayers: legendLayers,
651
- // },
652
- // });
653
- result.push({
654
- canvas: canvas,
655
- image: img,
656
- });
660
+ // );
661
+ // img.src = `data:${val.symbol.url};base64,${val.symbol.imageData}`
662
+ // img.src = canvas.toDataURL()
657
663
 
658
- });
659
- result.forEach((item) => {
660
- item.image.alt = `Style for ${lyr.displayName}`;
661
- legendCanvases[lyr.uid].widths.push(item.canvas.width);
662
- legendCanvases[lyr.uid].heights.push(item.canvas.height);
663
- legendCanvases[lyr.uid].canvas.push(item.canvas);
664
- legendLayers[lyr.uid].push(item.image);
664
+ img.alt = `Style for ${label}`;
665
+ img.crossOrigin = "anonymous";
666
+ img.title = label;
667
+ // legendLayers[uid] = [img]; //TODO: Update to possibly push multiple images into array
668
+ // images.push(img)
669
+
670
+ // dispatch({
671
+ // type: "LEGEND_LAYERS_UPDATED",
672
+ // payload: {
673
+ // legendLayers: legendLayers,
674
+ // },
675
+ // });
676
+ result.push({
677
+ canvas: canvas,
678
+ image: img,
679
+ });
680
+ });
681
+ result.forEach((item) => {
682
+ item.image.alt = `Style for ${lyr.displayName}`;
683
+ legendCanvases[lyr.uid].widths.push(item.canvas.width);
684
+ legendCanvases[lyr.uid].heights.push(item.canvas.height);
685
+ legendCanvases[lyr.uid].canvas.push(item.canvas);
686
+ legendLayers[lyr.uid].push(item.image);
665
687
 
666
- dispatch({
667
- type: "LEGEND_CANVAS_ADDED",
668
- payload: {
669
- legendCanvases: legendCanvases,
670
- loading: false,
671
- },
688
+ dispatch({
689
+ type: "LEGEND_CANVAS_ADDED",
690
+ payload: {
691
+ legendCanvases: legendCanvases,
692
+ loading: false,
693
+ },
694
+ });
672
695
  });
673
- });
674
- }
675
-
676
- else if (drawingInfo.renderer.classBreakInfos){
677
- drawingInfo.renderer.classBreakInfos.forEach((val) => {
678
- let img = new Image();
679
- const outlineColor = val.symbol.outline.color;
680
- const outlineWidth = val.symbol.outline.width;
681
- const fillColor = val.symbol.color;
682
- const size = val.symbol.size;
683
- let canvas = document.createElement("canvas");
684
- let ctx = canvas.getContext("2d");
696
+ } else if (drawingInfo.renderer.classBreakInfos) {
697
+ drawingInfo.renderer.classBreakInfos.forEach((val) => {
698
+ let img = new Image();
699
+ const outlineColor = val.symbol.outline.color;
700
+ const outlineWidth = val.symbol.outline.width;
701
+ const fillColor = val.symbol.color;
702
+ const size = val.symbol.size;
703
+ let canvas = document.createElement("canvas");
704
+ let ctx = canvas.getContext("2d");
685
705
 
686
- canvas.width = 20 * 2.5;
687
- canvas.height = 20;
706
+ canvas.width = 20 * 2.5;
707
+ canvas.height = 20;
688
708
 
689
- legendCanvases[uid].widths.push(canvas.width);
690
- legendCanvases[uid].heights.push(canvas.height);
691
-
692
- //text
693
- ctx.font = "11px Arial";
694
- ctx.fillText(val.label ,size * 3 , size * 2 , 30);
709
+ legendCanvases[uid].widths.push(canvas.width);
710
+ legendCanvases[uid].heights.push(canvas.height);
695
711
 
696
- // circle
697
- ctx.beginPath();
698
- ctx.strokeStyle = `rgba(${outlineColor.join()})`;
699
- ctx.lineWidth = outlineWidth;
700
- ctx.arc(size, size * 1.5, size/1.5, 0, Math.PI * 2);
701
- ctx.fillStyle = `rgba(${fillColor.join()})`;
702
- ctx.fill();
703
- ctx.stroke();
712
+ //text
713
+ ctx.font = "11px Arial";
714
+ ctx.fillText(val.label, size * 3, size * 2, 30);
715
+
716
+ // circle
717
+ ctx.beginPath();
718
+ ctx.strokeStyle = `rgba(${outlineColor.join()})`;
719
+ ctx.lineWidth = outlineWidth;
720
+ ctx.arc(size, size * 1.5, size / 1.5, 0, Math.PI * 2);
721
+ ctx.fillStyle = `rgba(${fillColor.join()})`;
722
+ ctx.fill();
723
+ ctx.stroke();
724
+
725
+ img.src = canvas.toDataURL(); //set src using data URI from canvas
726
+ img.alt = `Style for ${displayName}`;
727
+ img.crossOrigin = "anonymous";
704
728
 
705
- img.src = canvas.toDataURL(); //set src using data URI from canvas
706
- img.alt = `Style for ${displayName}`;
707
- img.crossOrigin = "anonymous";
729
+ legendCanvases[uid].canvas.push(canvas);
730
+ dispatch({
731
+ type: "LEGEND_CANVAS_ADDED",
732
+ payload: {
733
+ legendCanvases: legendCanvases,
734
+ loading: false,
735
+ },
736
+ });
708
737
 
709
- legendCanvases[uid].canvas.push(canvas);
710
- dispatch({
711
- type: "LEGEND_CANVAS_ADDED",
712
- payload: {
713
- legendCanvases: legendCanvases,
714
- loading: false,
715
- },
738
+ legendLayers[uid].push(img);
739
+ dispatch({
740
+ type: "LEGEND_LAYERS_UPDATED",
741
+ payload: {
742
+ legendLayers: legendLayers,
743
+ loading: false,
744
+ },
745
+ });
716
746
  });
717
-
718
- legendLayers[uid].push(img);
747
+ } else {
748
+ legendLayers[uid] = ["Legend not available!"];
719
749
  dispatch({
720
- type: "LEGEND_LAYERS_UPDATED",
750
+ type: "LEGEND_LAYERS_UPDATE_ERROR",
721
751
  payload: {
722
752
  legendLayers: legendLayers,
753
+ legendCanvases: legendCanvases,
723
754
  loading: false,
724
755
  },
725
756
  });
726
- });
727
- }
728
- else {
729
- legendLayers[uid] = ["Legend not available!"];
730
- dispatch({
731
- type: "LEGEND_LAYERS_UPDATE_ERROR",
732
- payload: {
733
- legendLayers: legendLayers,
734
- legendCanvases: legendCanvases,
735
- loading: false,
736
- },
737
- });
738
- }
739
- break;
740
- case "esriGeometryMultipoint" :
741
- if (drawingInfo.renderer.symbol && drawingInfo.renderer.symbol.type === "esriPMS") {
757
+ }
758
+ break;
759
+ case "esriGeometryMultipoint":
760
+ if (
761
+ drawingInfo.renderer.symbol &&
762
+ drawingInfo.renderer.symbol.type === "esriPMS"
763
+ ) {
742
764
  let img = new Image();
743
765
  img.src = `data:image/png;base64,${data.drawingInfo.renderer.symbol.imageData}`;
744
766
  img.addEventListener(
@@ -746,22 +768,22 @@ export default {
746
768
  function () {
747
769
  let canvas = document.createElement("canvas");
748
770
  let ctx = canvas.getContext("2d");
749
-
771
+
750
772
  canvas.width = drawingInfo.renderer.symbol.width;
751
773
  canvas.height = drawingInfo.renderer.symbol.height;
752
-
774
+
753
775
  //store width & height for larger canvas calculation
754
776
  legendCanvases[uid].widths.push(canvas.width);
755
777
  legendCanvases[uid].heights.push(canvas.height);
756
-
778
+
757
779
  //set background
758
780
  ctx.fillStyle = "white";
759
781
  ctx.fillRect(0, 0, canvas.width, canvas.height);
760
-
782
+
761
783
  ctx.drawImage(img, 0, 0); //add image to canvas
762
-
784
+
763
785
  legendCanvases[uid].canvas.push(canvas);
764
-
786
+
765
787
  dispatch({
766
788
  type: "LEGEND_CANVAS_ADDED",
767
789
  payload: {
@@ -772,7 +794,7 @@ export default {
772
794
  },
773
795
  false
774
796
  );
775
-
797
+
776
798
  img.alt = `Style for ${displayName}`;
777
799
  img.crossOrigin = "anonymous";
778
800
  legendLayers[uid] = [img]; //TODO: Update to possibly push multiple images into array
@@ -786,106 +808,54 @@ export default {
786
808
  }
787
809
  break;
788
810
 
789
- default:
790
- break;
791
- }
792
- },
793
- doFetchLegendImages: () => ({ dispatch, store }) => {
794
- dispatch({
795
- type: "LEGEND_FETCH_START",
796
- payload: {
797
- _shouldGetLegends: false,
798
- loading: true,
799
- },
800
- });
801
-
802
- const visibleLayers = store.selectVisibleLayers();
803
- let legendLayers = store.selectLegendLayers();
804
- let legendCanvases = store.selectLegendCanvases();
805
- let queuedLayers = [];
806
-
807
- visibleLayers.forEach((layer) => {
808
- //check if layer already added legendLayers object.
809
- if (!legendLayers.hasOwnProperty(layer.uid)) {
810
- switch (layer.type) {
811
- case "ArcGIS":
812
- case "ArcGISImage":
813
- case "EsriFeatureService":
814
- if(layer.styleFn && layer.type === "EsriFeatureService") {
815
- legendCanvases[layer.uid] = {
816
- displayName: layer.displayName,
817
- layerDescription: layer.layerDescription,
818
- attributions: layer.attributions,
819
- canvas: [],
820
- widths: [],
821
- heights: [],
822
- };
823
- legendLayers[layer.uid] = [];
824
-
825
- //Get canvases and images for legend
826
- let legendFunction = eval(layer.styleFn)[1];
827
- let legendItems = legendFunction();
828
-
829
- legendItems.forEach((item) => {
830
- item.image.alt = `Style for ${layer.displayName}`;
831
- legendCanvases[layer.uid].widths.push(item.canvas.width);
832
- legendCanvases[layer.uid].heights.push(item.canvas.height);
833
- legendCanvases[layer.uid].canvas.push(item.canvas);
834
- legendLayers[layer.uid].push(item.image);
835
-
836
- dispatch({
837
- type: "LEGEND_CANVAS_ADDED",
838
- payload: {
839
- legendCanvases: legendCanvases,
840
- loading: false,
841
- },
842
- });
843
- });
844
-
845
- dispatch({
846
- type: "LEGEND_LAYERS_UPDATED",
847
- payload: {
848
- legendLayers: legendLayers,
849
- },
850
- });
851
- }
852
- else {
853
- queuedLayers.push(layer);
854
- }
855
- break;
856
- case "WMS":
857
- legendCanvases[layer.uid] = {
858
- displayName: layer.displayName,
859
- attributions: layer.attributions,
860
- layerDescription: layer.layerDescription,
861
- canvas: [],
862
- widths: [],
863
- heights: [],
864
- };
865
- let activeLayers = layer.layerList.replace(/ /g, "").split(",");
866
- const images = activeLayers.map((lyr, i) => {
867
- let img = new Image();
868
- img.addEventListener(
869
- "load",
870
- function () {
871
- let canvas = document.createElement("canvas");
872
- let ctx = canvas.getContext("2d");
873
-
874
- //set canvas width & height
875
- canvas.width = Number(img.width) + 2;
876
- canvas.height = img.height;
877
-
878
- //store width & height for larger canvas calculation
879
- legendCanvases[layer.uid].widths.push(canvas.width);
880
- legendCanvases[layer.uid].heights.push(canvas.height);
881
-
882
- //set background
883
- ctx.fillStyle = "white";
884
- ctx.fillRect(0, 0, canvas.width, canvas.height);
885
-
886
- ctx.drawImage(img, 0, 0); //add image to canvas
811
+ default:
812
+ break;
813
+ }
814
+ },
815
+ doFetchLegendImages:
816
+ () =>
817
+ ({ dispatch, store }) => {
818
+ dispatch({
819
+ type: "LEGEND_FETCH_START",
820
+ payload: {
821
+ _shouldGetLegends: false,
822
+ loading: true,
823
+ },
824
+ });
887
825
 
888
- legendCanvases[layer.uid].canvas.push(canvas);
826
+ const visibleLayers = store.selectVisibleLayers();
827
+ let legendLayers = store.selectLegendLayers();
828
+ let legendCanvases = store.selectLegendCanvases();
829
+ let queuedLayers = [];
830
+
831
+ visibleLayers.forEach((layer) => {
832
+ //check if layer already added legendLayers object.
833
+ if (!legendLayers.hasOwnProperty(layer.uid)) {
834
+ switch (layer.type) {
835
+ case "ArcGIS":
836
+ case "ArcGISImage":
837
+ case "EsriFeatureService":
838
+ if (layer.styleFn && layer.type === "EsriFeatureService") {
839
+ legendCanvases[layer.uid] = {
840
+ displayName: layer.displayName,
841
+ layerDescription: layer.layerDescription,
842
+ attributions: layer.attributions,
843
+ canvas: [],
844
+ widths: [],
845
+ heights: [],
846
+ };
847
+ legendLayers[layer.uid] = [];
848
+
849
+ //Get canvases and images for legend
850
+ let legendFunction = eval(layer.styleFn)[1];
851
+ let legendItems = legendFunction();
852
+
853
+ legendItems.forEach((item) => {
854
+ item.image.alt = `Style for ${layer.displayName}`;
855
+ legendCanvases[layer.uid].widths.push(item.canvas.width);
856
+ legendCanvases[layer.uid].heights.push(item.canvas.height);
857
+ legendCanvases[layer.uid].canvas.push(item.canvas);
858
+ legendLayers[layer.uid].push(item.image);
889
859
 
890
860
  dispatch({
891
861
  type: "LEGEND_CANVAS_ADDED",
@@ -894,117 +864,170 @@ export default {
894
864
  loading: false,
895
865
  },
896
866
  });
897
- },
898
- false
899
- );
900
- let legendParams = `service=WMS&version=1.1.1&request=GetLegendGraphic&format=image/png&sld_version=1.1.0&layer=${lyr}`;
901
- if (layer.url.indexOf(".map") !== -1) {
902
- img.src = `${layer.url}&${legendParams}`;
867
+ });
868
+
869
+ dispatch({
870
+ type: "LEGEND_LAYERS_UPDATED",
871
+ payload: {
872
+ legendLayers: legendLayers,
873
+ },
874
+ });
903
875
  } else {
904
- img.src = `${layer.url}?${legendParams}`;
876
+ queuedLayers.push(layer);
905
877
  }
878
+ break;
879
+ case "WMS":
880
+ legendCanvases[layer.uid] = {
881
+ displayName: layer.displayName,
882
+ attributions: layer.attributions,
883
+ layerDescription: layer.layerDescription,
884
+ canvas: [],
885
+ widths: [],
886
+ heights: [],
887
+ };
888
+ let activeLayers = layer.layerList.replace(/ /g, "").split(",");
889
+ const images = activeLayers.map((lyr, i) => {
890
+ let img = new Image();
891
+ img.addEventListener(
892
+ "load",
893
+ function () {
894
+ let canvas = document.createElement("canvas");
895
+ let ctx = canvas.getContext("2d");
896
+
897
+ //set canvas width & height
898
+ canvas.width = Number(img.width) + 2;
899
+ canvas.height = img.height;
900
+
901
+ //store width & height for larger canvas calculation
902
+ legendCanvases[layer.uid].widths.push(canvas.width);
903
+ legendCanvases[layer.uid].heights.push(canvas.height);
904
+
905
+ //set background
906
+ ctx.fillStyle = "white";
907
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
908
+
909
+ ctx.drawImage(img, 0, 0); //add image to canvas
910
+
911
+ legendCanvases[layer.uid].canvas.push(canvas);
912
+
913
+ dispatch({
914
+ type: "LEGEND_CANVAS_ADDED",
915
+ payload: {
916
+ legendCanvases: legendCanvases,
917
+ loading: false,
918
+ },
919
+ });
920
+ },
921
+ false
922
+ );
923
+ let legendParams = `service=WMS&version=1.1.1&request=GetLegendGraphic&format=image/png&sld_version=1.1.0&layer=${lyr}`;
924
+ if (layer.url.indexOf(".map") !== -1) {
925
+ img.src = `${layer.url}&${legendParams}`;
926
+ } else {
927
+ img.src = `${layer.url}?${legendParams}`;
928
+ }
929
+
930
+ img.alt = `Style for ${layer.displayName}`;
931
+ img.crossOrigin = "anonymous";
932
+
933
+ return img;
934
+ });
935
+ legendLayers[layer.uid] = images;
906
936
 
907
- img.alt = `Style for ${layer.displayName}`;
908
- img.crossOrigin = "anonymous";
909
-
910
- return img;
911
- });
912
- legendLayers[layer.uid] = images;
913
-
914
- dispatch({
915
- type: "LEGEND_LAYERS_UPDATED",
916
- payload: {
917
- legendLayers: legendLayers,
918
- },
919
- });
920
- break;
921
- case "LocalVector":
922
- default:
923
- legendCanvases[layer.uid] = {
924
- displayName: layer.displayName,
925
- layerDescription: layer.layerDescription,
926
- attributions: layer.attributions,
927
- canvas: [],
928
- widths: [],
929
- heights: [],
930
- };
931
- if (layer.src) {
932
- let img = new Image();
933
- img.addEventListener(
934
- "load",
935
- function () {
936
- let canvas = document.createElement("canvas");
937
- let ctx = canvas.getContext("2d");
938
-
939
- //set canvas width & height
940
- canvas.width = Number(img.width) + 2;
941
- canvas.height = img.height;
942
-
943
- //store width & height for larger canvas calculation
944
- legendCanvases[layer.uid].widths.push(canvas.width);
945
- legendCanvases[layer.uid].heights.push(canvas.height);
946
-
947
- //set background
948
- ctx.fillStyle = "white";
949
- ctx.fillRect(0, 0, canvas.width, canvas.height);
950
-
951
- ctx.drawImage(img, 0, 0); //add image to canvas
952
-
953
- legendCanvases[layer.uid].canvas.push(canvas);
954
-
955
- dispatch({
956
- type: "LEGEND_CANVAS_ADDED",
957
- payload: {
958
- legendCanvases: legendCanvases,
959
- loading: false,
960
- },
961
- });
962
- },
963
- false
964
- );
965
- img.src = layer.src;
966
- img.alt = `Style for ${layer.displayName}`;
967
- img.crossOrigin = "anonymous";
968
- legendLayers[layer.uid] = [img];
969
937
  dispatch({
970
938
  type: "LEGEND_LAYERS_UPDATED",
971
939
  payload: {
972
940
  legendLayers: legendLayers,
973
941
  },
974
942
  });
975
- } else {
976
- legendLayers[layer.uid] = ["Legend not available!"];
977
- dispatch({
978
- type: "LEGEND_LAYERS_UPDATE_ERROR",
979
- payload: {
980
- legendLayers: legendLayers,
981
- legendCanvases: legendCanvases,
982
- loading: false,
983
- },
984
- });
985
- }
986
- break;
943
+ break;
944
+ case "LocalVector":
945
+ default:
946
+ legendCanvases[layer.uid] = {
947
+ displayName: layer.displayName,
948
+ layerDescription: layer.layerDescription,
949
+ attributions: layer.attributions,
950
+ canvas: [],
951
+ widths: [],
952
+ heights: [],
953
+ };
954
+ if (layer.src) {
955
+ let img = new Image();
956
+ img.addEventListener(
957
+ "load",
958
+ function () {
959
+ let canvas = document.createElement("canvas");
960
+ let ctx = canvas.getContext("2d");
961
+
962
+ //set canvas width & height
963
+ canvas.width = Number(img.width) + 2;
964
+ canvas.height = img.height;
965
+
966
+ //store width & height for larger canvas calculation
967
+ legendCanvases[layer.uid].widths.push(canvas.width);
968
+ legendCanvases[layer.uid].heights.push(canvas.height);
969
+
970
+ //set background
971
+ ctx.fillStyle = "white";
972
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
973
+
974
+ ctx.drawImage(img, 0, 0); //add image to canvas
975
+
976
+ legendCanvases[layer.uid].canvas.push(canvas);
977
+
978
+ dispatch({
979
+ type: "LEGEND_CANVAS_ADDED",
980
+ payload: {
981
+ legendCanvases: legendCanvases,
982
+ loading: false,
983
+ },
984
+ });
985
+ },
986
+ false
987
+ );
988
+ img.src = layer.src;
989
+ img.alt = `Style for ${layer.displayName}`;
990
+ img.crossOrigin = "anonymous";
991
+ legendLayers[layer.uid] = [img];
992
+ dispatch({
993
+ type: "LEGEND_LAYERS_UPDATED",
994
+ payload: {
995
+ legendLayers: legendLayers,
996
+ },
997
+ });
998
+ } else {
999
+ legendLayers[layer.uid] = ["Legend not available!"];
1000
+ dispatch({
1001
+ type: "LEGEND_LAYERS_UPDATE_ERROR",
1002
+ payload: {
1003
+ legendLayers: legendLayers,
1004
+ legendCanvases: legendCanvases,
1005
+ loading: false,
1006
+ },
1007
+ });
1008
+ }
1009
+ break;
1010
+ }
1011
+ } else {
1012
+ dispatch({
1013
+ type: "LEGEND_LOADED",
1014
+ payload: {
1015
+ loading: false,
1016
+ },
1017
+ });
987
1018
  }
988
- } else {
1019
+ });
1020
+
1021
+ if (queuedLayers.length) store.doFetchLegendInfo(queuedLayers);
1022
+ if (!visibleLayers.length) {
989
1023
  dispatch({
990
- type: "LEGEND_LOADED",
1024
+ type: "LEGEND_HAS_NO_VISIBLE_LAYERS",
991
1025
  payload: {
992
1026
  loading: false,
993
1027
  },
994
1028
  });
995
1029
  }
996
- });
997
-
998
- if (queuedLayers.length) store.doFetchLegendInfo(queuedLayers);
999
- if (!visibleLayers.length) {
1000
- dispatch({
1001
- type: "LEGEND_HAS_NO_VISIBLE_LAYERS",
1002
- payload: {
1003
- loading: false,
1004
- },
1005
- });
1006
- }
1007
- },
1030
+ },
1008
1031
  selectLegendLayers: (state) => {
1009
1032
  return state.legend.legendLayers;
1010
1033
  },