@map-colonies/react-components 3.12.2 → 3.12.3

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 (375) hide show
  1. package/.eslintignore +1 -1
  2. package/.storybook/main.js +13 -13
  3. package/.storybook/manager.js +6 -6
  4. package/.storybook/preview-head.html +21 -21
  5. package/.storybook/preview.js +18 -18
  6. package/.storybook/theme.js +9 -9
  7. package/CHANGELOG.md +828 -819
  8. package/README.md +53 -53
  9. package/dist/autocomplete/autocomplete.css +25 -25
  10. package/dist/autocomplete/autocomplete.d.ts +33 -33
  11. package/dist/autocomplete/autocomplete.js +478 -478
  12. package/dist/autocomplete/index.d.ts +1 -1
  13. package/dist/autocomplete/index.js +5 -5
  14. package/dist/box/box.d.ts +3 -3
  15. package/dist/box/box.js +35 -35
  16. package/dist/box/index.d.ts +1 -1
  17. package/dist/box/index.js +5 -5
  18. package/dist/cesium-map/data-sources/custom.data-source.d.ts +5 -5
  19. package/dist/cesium-map/data-sources/custom.data-source.js +23 -23
  20. package/dist/cesium-map/data-sources/drawings.data-source.d.ts +34 -34
  21. package/dist/cesium-map/data-sources/drawings.data-source.js +187 -187
  22. package/dist/cesium-map/data-sources/index.d.ts +2 -2
  23. package/dist/cesium-map/data-sources/index.js +14 -14
  24. package/dist/cesium-map/entities/entity.d.ts +5 -5
  25. package/dist/cesium-map/entities/entity.description.d.ts +6 -6
  26. package/dist/cesium-map/entities/entity.description.js +27 -27
  27. package/dist/cesium-map/entities/entity.js +23 -23
  28. package/dist/cesium-map/entities/graphics/polygon.graphics.d.ts +5 -5
  29. package/dist/cesium-map/entities/graphics/polygon.graphics.js +23 -23
  30. package/dist/cesium-map/entities/graphics/polyline.graphics.d.ts +5 -5
  31. package/dist/cesium-map/entities/graphics/polyline.graphics.js +23 -23
  32. package/dist/cesium-map/entities/graphics/rectangle.graphics.d.ts +5 -5
  33. package/dist/cesium-map/entities/graphics/rectangle.graphics.js +23 -23
  34. package/dist/cesium-map/entities/index.d.ts +4 -4
  35. package/dist/cesium-map/entities/index.js +16 -16
  36. package/dist/cesium-map/index.d.ts +8 -8
  37. package/dist/cesium-map/index.js +20 -20
  38. package/dist/cesium-map/layers/3d.tileset.d.ts +7 -7
  39. package/dist/cesium-map/layers/3d.tileset.js +43 -43
  40. package/dist/cesium-map/layers/3d.tileset.with.update.d.ts +6 -6
  41. package/dist/cesium-map/layers/3d.tileset.with.update.js +115 -115
  42. package/dist/cesium-map/layers/geojson.layer.d.ts +5 -5
  43. package/dist/cesium-map/layers/geojson.layer.js +23 -23
  44. package/dist/cesium-map/layers/imagery.layer.d.ts +6 -6
  45. package/dist/cesium-map/layers/imagery.layer.js +68 -68
  46. package/dist/cesium-map/layers/index.d.ts +7 -7
  47. package/dist/cesium-map/layers/index.js +19 -19
  48. package/dist/cesium-map/layers/osm.layer.d.ts +9 -9
  49. package/dist/cesium-map/layers/osm.layer.js +36 -36
  50. package/dist/cesium-map/layers/wms.layer.d.ts +9 -9
  51. package/dist/cesium-map/layers/wms.layer.js +36 -36
  52. package/dist/cesium-map/layers/wmts.layer.d.ts +9 -9
  53. package/dist/cesium-map/layers/wmts.layer.js +36 -36
  54. package/dist/cesium-map/layers/xyz.layer.d.ts +9 -9
  55. package/dist/cesium-map/layers/xyz.layer.js +36 -36
  56. package/dist/cesium-map/layers-manager.d.ts +55 -55
  57. package/dist/cesium-map/layers-manager.js +246 -246
  58. package/dist/cesium-map/map-legend/MapLegend.css +135 -135
  59. package/dist/cesium-map/map-legend/MapLegend.d.ts +15 -15
  60. package/dist/cesium-map/map-legend/MapLegend.js +57 -57
  61. package/dist/cesium-map/map-legend/MapLegendList.d.ts +13 -13
  62. package/dist/cesium-map/map-legend/MapLegendList.js +43 -43
  63. package/dist/cesium-map/map-legend/MapLegendSidebar.d.ts +16 -16
  64. package/dist/cesium-map/map-legend/MapLegendSidebar.js +20 -20
  65. package/dist/cesium-map/map-legend/MapLegendToggle.d.ts +7 -7
  66. package/dist/cesium-map/map-legend/MapLegendToggle.js +20 -20
  67. package/dist/cesium-map/map-legend/index.d.ts +3 -3
  68. package/dist/cesium-map/map-legend/index.js +14 -14
  69. package/dist/cesium-map/map.css +59 -59
  70. package/dist/cesium-map/map.d.ts +59 -59
  71. package/dist/cesium-map/map.js +305 -305
  72. package/dist/cesium-map/map.types.d.ts +8 -8
  73. package/dist/cesium-map/map.types.js +12 -12
  74. package/dist/cesium-map/proxied.types.d.ts +30 -30
  75. package/dist/cesium-map/proxied.types.js +132 -132
  76. package/dist/cesium-map/settings/base-maps.css +37 -37
  77. package/dist/cesium-map/settings/base-maps.d.ts +7 -7
  78. package/dist/cesium-map/settings/base-maps.js +78 -78
  79. package/dist/cesium-map/settings/scene-modes.css +19 -19
  80. package/dist/cesium-map/settings/scene-modes.d.ts +7 -7
  81. package/dist/cesium-map/settings/scene-modes.js +65 -65
  82. package/dist/cesium-map/settings/settings.css +52 -52
  83. package/dist/cesium-map/settings/settings.d.ts +23 -23
  84. package/dist/cesium-map/settings/settings.js +79 -79
  85. package/dist/cesium-map/terrain-providers/custom/dummy-quantized-mesh-tile.d.ts +3 -3
  86. package/dist/cesium-map/terrain-providers/custom/dummy-quantized-mesh-tile.js +245 -245
  87. package/dist/cesium-map/terrain-providers/custom/quantized-mesh-decoder.d.ts +9 -9
  88. package/dist/cesium-map/terrain-providers/custom/quantized-mesh-decoder.js +202 -202
  89. package/dist/cesium-map/terrain-providers/custom/quantized-mesh-terrain-provider.d.ts +50 -50
  90. package/dist/cesium-map/terrain-providers/custom/quantized-mesh-terrain-provider.js +136 -136
  91. package/dist/cesium-map/tools/cesium/primitives-conversions.cesium.d.ts +2 -2
  92. package/dist/cesium-map/tools/cesium/primitives-conversions.cesium.js +38 -38
  93. package/dist/cesium-map/tools/coordinates-tracker.tool.css +11 -11
  94. package/dist/cesium-map/tools/coordinates-tracker.tool.d.ts +7 -7
  95. package/dist/cesium-map/tools/coordinates-tracker.tool.js +78 -78
  96. package/dist/cesium-map/tools/draw/drawHelper.css +101 -101
  97. package/dist/cesium-map/tools/draw/drawHelper.d.ts +28 -28
  98. package/dist/cesium-map/tools/draw/drawHelper.js +1694 -1694
  99. package/dist/cesium-map/tools/geojson/geojson-to-primitive.d.ts +4 -4
  100. package/dist/cesium-map/tools/geojson/geojson-to-primitive.js +41 -41
  101. package/dist/cesium-map/tools/geojson/index.d.ts +2 -2
  102. package/dist/cesium-map/tools/geojson/index.js +14 -14
  103. package/dist/cesium-map/tools/geojson/point.geojson.d.ts +3 -3
  104. package/dist/cesium-map/tools/geojson/point.geojson.js +21 -21
  105. package/dist/cesium-map/tools/geojson/polygon.geojson.d.ts +3 -3
  106. package/dist/cesium-map/tools/geojson/polygon.geojson.js +24 -24
  107. package/dist/cesium-map/tools/geojson/rectangle.geojson.d.ts +3 -3
  108. package/dist/cesium-map/tools/geojson/rectangle.geojson.js +44 -44
  109. package/dist/cesium-map/tools/inspector.tool.d.ts +4 -4
  110. package/dist/cesium-map/tools/inspector.tool.js +33 -33
  111. package/dist/cesium-map/tools/scale-tracker.tool.css +16 -16
  112. package/dist/cesium-map/tools/scale-tracker.tool.d.ts +8 -8
  113. package/dist/cesium-map/tools/scale-tracker.tool.js +158 -158
  114. package/dist/cesium-map/tools/terranian-height.tool.d.ts +4 -4
  115. package/dist/cesium-map/tools/terranian-height.tool.js +114 -114
  116. package/dist/cssbaseline/cssbaseline.d.ts +5 -5
  117. package/dist/cssbaseline/cssbaseline.js +41 -41
  118. package/dist/cssbaseline/index.d.ts +1 -1
  119. package/dist/cssbaseline/index.js +6 -6
  120. package/dist/date-picker/date-picker.css +9 -9
  121. package/dist/date-picker/date-picker.d.ts +14 -14
  122. package/dist/date-picker/date-picker.js +78 -78
  123. package/dist/date-picker/index.d.ts +1 -1
  124. package/dist/date-picker/index.js +13 -13
  125. package/dist/date-range-picker/date-range-picker.css +9 -9
  126. package/dist/date-range-picker/date-range-picker.d.ts +26 -26
  127. package/dist/date-range-picker/date-range-picker.form-control.css +3 -3
  128. package/dist/date-range-picker/date-range-picker.form-control.d.ts +28 -28
  129. package/dist/date-range-picker/date-range-picker.form-control.js +95 -95
  130. package/dist/date-range-picker/date-range-picker.js +104 -104
  131. package/dist/date-range-picker/index.d.ts +2 -2
  132. package/dist/date-range-picker/index.js +14 -14
  133. package/dist/file-picker/file-picker.css +63 -63
  134. package/dist/file-picker/file-picker.d.ts +276 -276
  135. package/dist/file-picker/file-picker.js +151 -151
  136. package/dist/file-picker/fs-map.json +1556 -1556
  137. package/dist/file-picker/index.d.ts +2 -2
  138. package/dist/file-picker/index.js +14 -14
  139. package/dist/file-picker/localization.d.ts +11 -11
  140. package/dist/file-picker/localization.js +124 -124
  141. package/dist/index.d.ts +13 -13
  142. package/dist/index.js +25 -25
  143. package/dist/map-filter-container/container-map.css +5 -5
  144. package/dist/map-filter-container/container-map.d.ts +11 -11
  145. package/dist/map-filter-container/container-map.js +31 -31
  146. package/dist/map-filter-container/index.d.ts +1 -1
  147. package/dist/map-filter-container/index.js +13 -13
  148. package/dist/map-filter-container/map-filter-container.d.ts +9 -9
  149. package/dist/map-filter-container/map-filter-container.js +78 -78
  150. package/dist/map-filter-container/polygon-selection-ui.d.ts +12 -12
  151. package/dist/map-filter-container/polygon-selection-ui.js +62 -62
  152. package/dist/models/defaults.d.ts +28 -28
  153. package/dist/models/defaults.js +32 -32
  154. package/dist/models/enums.d.ts +14 -14
  155. package/dist/models/enums.js +20 -20
  156. package/dist/models/index.d.ts +1 -1
  157. package/dist/models/index.js +13 -13
  158. package/dist/ol-map/feature.d.ts +6 -6
  159. package/dist/ol-map/feature.js +20 -20
  160. package/dist/ol-map/index.d.ts +6 -6
  161. package/dist/ol-map/index.js +18 -18
  162. package/dist/ol-map/interactions/draw.d.ts +8 -8
  163. package/dist/ol-map/interactions/draw.js +44 -44
  164. package/dist/ol-map/interactions/index.d.ts +1 -1
  165. package/dist/ol-map/interactions/index.js +13 -13
  166. package/dist/ol-map/layers/index.d.ts +3 -3
  167. package/dist/ol-map/layers/index.js +15 -15
  168. package/dist/ol-map/layers/tile-layer.d.ts +9 -9
  169. package/dist/ol-map/layers/tile-layer.js +48 -48
  170. package/dist/ol-map/layers/vector-layer.d.ts +4 -4
  171. package/dist/ol-map/layers/vector-layer.js +48 -48
  172. package/dist/ol-map/layers/vector-tile-layer.d.ts +10 -10
  173. package/dist/ol-map/layers/vector-tile-layer.js +66 -66
  174. package/dist/ol-map/map.css +17 -17
  175. package/dist/ol-map/map.d.ts +14 -14
  176. package/dist/ol-map/map.js +117 -117
  177. package/dist/ol-map/source/index.d.ts +6 -6
  178. package/dist/ol-map/source/index.js +18 -18
  179. package/dist/ol-map/source/mvt.d.ts +11 -11
  180. package/dist/ol-map/source/mvt.js +37 -37
  181. package/dist/ol-map/source/osm.d.ts +2 -2
  182. package/dist/ol-map/source/osm.js +14 -14
  183. package/dist/ol-map/source/vector-source.d.ts +4 -4
  184. package/dist/ol-map/source/vector-source.js +45 -45
  185. package/dist/ol-map/source/wms.d.ts +17 -17
  186. package/dist/ol-map/source/wms.js +30 -30
  187. package/dist/ol-map/source/wmts.d.ts +21 -21
  188. package/dist/ol-map/source/wmts.js +59 -59
  189. package/dist/ol-map/source/xyz.d.ts +12 -12
  190. package/dist/ol-map/source/xyz.js +27 -27
  191. package/dist/ol-map/style.d.ts +4 -4
  192. package/dist/ol-map/style.js +22 -22
  193. package/dist/popover/index.d.ts +1 -1
  194. package/dist/popover/index.js +5 -5
  195. package/dist/popover/popover.d.ts +3 -3
  196. package/dist/popover/popover.js +35 -35
  197. package/dist/smart-table/__mock-data__/smartTableMocks.d.ts +7 -7
  198. package/dist/smart-table/__mock-data__/smartTableMocks.js +17 -17
  199. package/dist/smart-table/index.d.ts +2 -2
  200. package/dist/smart-table/index.js +14 -14
  201. package/dist/smart-table/smart-table-head.d.ts +11 -11
  202. package/dist/smart-table/smart-table-head.js +22 -22
  203. package/dist/smart-table/smart-table-row.d.ts +12 -12
  204. package/dist/smart-table/smart-table-row.js +46 -46
  205. package/dist/smart-table/smart-table-types.d.ts +9 -9
  206. package/dist/smart-table/smart-table-types.js +2 -2
  207. package/dist/smart-table/smart-table.d.ts +17 -17
  208. package/dist/smart-table/smart-table.js +51 -51
  209. package/dist/theme/index.d.ts +1 -1
  210. package/dist/theme/index.js +13 -13
  211. package/dist/theme/theme.d.ts +8 -8
  212. package/dist/theme/theme.js +124 -124
  213. package/dist/utils/map.d.ts +3 -3
  214. package/dist/utils/map.js +21 -21
  215. package/dist/utils/projections.d.ts +6 -6
  216. package/dist/utils/projections.js +10 -10
  217. package/dist/utils/story.d.ts +12 -12
  218. package/dist/utils/story.js +2 -2
  219. package/package.json +3 -3
  220. package/public/index.html +43 -43
  221. package/public/manifest.json +25 -25
  222. package/public/robots.txt +3 -3
  223. package/src/index.tsx +9 -9
  224. package/src/lib/autocomplete/autocomplete.css +25 -25
  225. package/src/lib/autocomplete/autocomplete.stories.tsx +101 -101
  226. package/src/lib/autocomplete/autocomplete.tsx +681 -681
  227. package/src/lib/autocomplete/index.ts +1 -1
  228. package/src/lib/box/box.tsx +7 -7
  229. package/src/lib/box/index.ts +1 -1
  230. package/src/lib/cesium-map/context-menu.stories.tsx +444 -444
  231. package/src/lib/cesium-map/data-sources/custom.data-source.tsx +12 -12
  232. package/src/lib/cesium-map/data-sources/drawings.data-source.stories.tsx +161 -161
  233. package/src/lib/cesium-map/data-sources/drawings.data-source.tsx +204 -204
  234. package/src/lib/cesium-map/data-sources/index.ts +2 -2
  235. package/src/lib/cesium-map/entities/entity.description.tsx +19 -19
  236. package/src/lib/cesium-map/entities/entity.graphics.stories.tsx +48 -48
  237. package/src/lib/cesium-map/entities/entity.stories.tsx +146 -146
  238. package/src/lib/cesium-map/entities/entity.tsx +10 -10
  239. package/src/lib/cesium-map/entities/graphics/polygon.graphics.tsx +12 -12
  240. package/src/lib/cesium-map/entities/graphics/polyline.graphics.tsx +12 -12
  241. package/src/lib/cesium-map/entities/graphics/rectangle.graphics.tsx +12 -12
  242. package/src/lib/cesium-map/entities/index.ts +4 -4
  243. package/src/lib/cesium-map/index.ts +8 -8
  244. package/src/lib/cesium-map/layers/3d.tileset.stories.tsx +164 -164
  245. package/src/lib/cesium-map/layers/3d.tileset.tsx +51 -51
  246. package/src/lib/cesium-map/layers/3d.tileset.with.update.tsx +120 -120
  247. package/src/lib/cesium-map/layers/geojson.layer.stories.tsx +119 -119
  248. package/src/lib/cesium-map/layers/geojson.layer.tsx +12 -12
  249. package/src/lib/cesium-map/layers/imagery.layer.stories.tsx +39 -39
  250. package/src/lib/cesium-map/layers/imagery.layer.tsx +37 -37
  251. package/src/lib/cesium-map/layers/index.ts +7 -7
  252. package/src/lib/cesium-map/layers/layers.rect.stories.tsx +171 -171
  253. package/src/lib/cesium-map/layers/osm.layer.stories.tsx +40 -40
  254. package/src/lib/cesium-map/layers/osm.layer.tsx +22 -22
  255. package/src/lib/cesium-map/layers/wms.layer.stories.tsx +38 -38
  256. package/src/lib/cesium-map/layers/wms.layer.tsx +22 -22
  257. package/src/lib/cesium-map/layers/wmts.layer.stories.tsx +53 -53
  258. package/src/lib/cesium-map/layers/wmts.layer.tsx +22 -22
  259. package/src/lib/cesium-map/layers/xyz.layer.stories.tsx +37 -37
  260. package/src/lib/cesium-map/layers/xyz.layer.tsx +22 -22
  261. package/src/lib/cesium-map/layers-manager.stories.tsx +286 -286
  262. package/src/lib/cesium-map/layers-manager.ts +354 -354
  263. package/src/lib/cesium-map/map-legend/MapLegend.css +135 -135
  264. package/src/lib/cesium-map/map-legend/MapLegend.tsx +92 -92
  265. package/src/lib/cesium-map/map-legend/MapLegendList.tsx +47 -47
  266. package/src/lib/cesium-map/map-legend/MapLegendSidebar.tsx +55 -55
  267. package/src/lib/cesium-map/map-legend/MapLegendToggle.tsx +31 -31
  268. package/src/lib/cesium-map/map-legend/index.tsx +3 -3
  269. package/src/lib/cesium-map/map-legend/legends-sidebar.stories.tsx +201 -201
  270. package/src/lib/cesium-map/map.css +59 -59
  271. package/src/lib/cesium-map/map.stories.tsx +143 -143
  272. package/src/lib/cesium-map/map.tsx +446 -446
  273. package/src/lib/cesium-map/map.types.ts +11 -11
  274. package/src/lib/cesium-map/proxied.types.ts +54 -54
  275. package/src/lib/cesium-map/settings/base-maps.css +37 -37
  276. package/src/lib/cesium-map/settings/base-maps.tsx +94 -94
  277. package/src/lib/cesium-map/settings/scene-modes.css +19 -19
  278. package/src/lib/cesium-map/settings/scene-modes.tsx +100 -100
  279. package/src/lib/cesium-map/settings/settings.css +52 -52
  280. package/src/lib/cesium-map/settings/settings.stories.tsx +182 -182
  281. package/src/lib/cesium-map/settings/settings.tsx +141 -141
  282. package/src/lib/cesium-map/terrain-providers/custom/dummy-quantized-mesh-tile.ts +243 -243
  283. package/src/lib/cesium-map/terrain-providers/custom/quantized-mesh-decoder.ts +321 -321
  284. package/src/lib/cesium-map/terrain-providers/custom/quantized-mesh-terrain-provider.ts +237 -237
  285. package/src/lib/cesium-map/terrain-providers/terrain-provider-heights-tool.stories.tsx +170 -170
  286. package/src/lib/cesium-map/terrain-providers/terrain-provider.stories.tsx +187 -187
  287. package/src/lib/cesium-map/tools/cesium/primitives-conversions.cesium.ts +15 -15
  288. package/src/lib/cesium-map/tools/coordinates-tracker.tool.css +11 -11
  289. package/src/lib/cesium-map/tools/coordinates-tracker.tool.tsx +79 -79
  290. package/src/lib/cesium-map/tools/draw/drawHelper.css +101 -101
  291. package/src/lib/cesium-map/tools/draw/drawHelper.ts +2116 -2116
  292. package/src/lib/cesium-map/tools/geojson/geojson-to-primitive.ts +54 -54
  293. package/src/lib/cesium-map/tools/geojson/index.ts +2 -2
  294. package/src/lib/cesium-map/tools/geojson/point.geojson.ts +29 -29
  295. package/src/lib/cesium-map/tools/geojson/polygon.geojson.ts +24 -24
  296. package/src/lib/cesium-map/tools/geojson/rectangle.geojson.ts +21 -21
  297. package/src/lib/cesium-map/tools/inspector.tool.tsx +15 -15
  298. package/src/lib/cesium-map/tools/scale-tracker.tool.css +16 -16
  299. package/src/lib/cesium-map/tools/scale-tracker.tool.tsx +192 -192
  300. package/src/lib/cesium-map/tools/terranian-height.tool.tsx +171 -171
  301. package/src/lib/cssbaseline/cssbaseline.tsx +19 -19
  302. package/src/lib/cssbaseline/index.ts +4 -4
  303. package/src/lib/date-picker/date-picker.css +9 -9
  304. package/src/lib/date-picker/date-picker.stories.tsx +130 -130
  305. package/src/lib/date-picker/date-picker.tsx +90 -90
  306. package/src/lib/date-picker/index.ts +1 -1
  307. package/src/lib/date-range-picker/date-range-picker.css +9 -9
  308. package/src/lib/date-range-picker/date-range-picker.form-control.css +3 -3
  309. package/src/lib/date-range-picker/date-range-picker.form-control.spec.tsx +58 -58
  310. package/src/lib/date-range-picker/date-range-picker.form-control.tsx +150 -150
  311. package/src/lib/date-range-picker/date-range-picker.stories.tsx +207 -207
  312. package/src/lib/date-range-picker/date-range-picker.tsx +156 -156
  313. package/src/lib/date-range-picker/index.ts +2 -2
  314. package/src/lib/file-picker/file-picker.css +63 -63
  315. package/src/lib/file-picker/file-picker.stories.tsx +447 -447
  316. package/src/lib/file-picker/file-picker.tsx +180 -180
  317. package/src/lib/file-picker/fs-map.json +1556 -1556
  318. package/src/lib/file-picker/index.ts +2 -2
  319. package/src/lib/file-picker/localization.ts +164 -164
  320. package/src/lib/index.ts +13 -13
  321. package/src/lib/map-filter-container/container-map.css +5 -5
  322. package/src/lib/map-filter-container/container-map.tsx +48 -48
  323. package/src/lib/map-filter-container/index.ts +1 -1
  324. package/src/lib/map-filter-container/map-filter-container.tsx +91 -91
  325. package/src/lib/map-filter-container/polygon-selection-ui.spec.tsx +119 -119
  326. package/src/lib/map-filter-container/polygon-selection-ui.tsx +111 -111
  327. package/src/lib/map-filter-container/stories/Map.stories.tsx +76 -76
  328. package/src/lib/models/defaults.ts +32 -32
  329. package/src/lib/models/enums.ts +16 -16
  330. package/src/lib/models/index.ts +1 -1
  331. package/src/lib/ol-map/feature.tsx +23 -23
  332. package/src/lib/ol-map/index.ts +6 -6
  333. package/src/lib/ol-map/interactions/draw.tsx +56 -56
  334. package/src/lib/ol-map/interactions/index.ts +1 -1
  335. package/src/lib/ol-map/layers/index.ts +3 -3
  336. package/src/lib/ol-map/layers/tile-layer.tsx +36 -36
  337. package/src/lib/ol-map/layers/vector-layer.tsx +32 -32
  338. package/src/lib/ol-map/layers/vector-tile-layer.tsx +56 -56
  339. package/src/lib/ol-map/map.css +17 -17
  340. package/src/lib/ol-map/map.tsx +137 -137
  341. package/src/lib/ol-map/source/index.ts +6 -6
  342. package/src/lib/ol-map/source/mvt.tsx +46 -46
  343. package/src/lib/ol-map/source/osm.tsx +13 -13
  344. package/src/lib/ol-map/source/stories/mvt.stories.tsx +68 -68
  345. package/src/lib/ol-map/source/stories/vector-source.stories.tsx +78 -78
  346. package/src/lib/ol-map/source/stories/wms.stories.tsx +51 -51
  347. package/src/lib/ol-map/source/stories/wmts.stories.tsx +72 -72
  348. package/src/lib/ol-map/source/stories/xyz.stories.tsx +53 -53
  349. package/src/lib/ol-map/source/vector-source.tsx +30 -30
  350. package/src/lib/ol-map/source/wms.tsx +40 -40
  351. package/src/lib/ol-map/source/wmts.tsx +82 -82
  352. package/src/lib/ol-map/source/xyz.tsx +33 -33
  353. package/src/lib/ol-map/stories/map.stories.tsx +60 -60
  354. package/src/lib/ol-map/style.ts +24 -24
  355. package/src/lib/popover/index.ts +1 -1
  356. package/src/lib/popover/popover.tsx +7 -7
  357. package/src/lib/smart-table/__mock-data__/smartTableMocks.ts +22 -22
  358. package/src/lib/smart-table/index.ts +2 -2
  359. package/src/lib/smart-table/smart-table-head.spec.tsx +116 -116
  360. package/src/lib/smart-table/smart-table-head.tsx +47 -47
  361. package/src/lib/smart-table/smart-table-row.spec.tsx +109 -109
  362. package/src/lib/smart-table/smart-table-row.tsx +78 -78
  363. package/src/lib/smart-table/smart-table-types.ts +10 -10
  364. package/src/lib/smart-table/smart-table.spec.tsx +116 -116
  365. package/src/lib/smart-table/smart-table.tsx +115 -115
  366. package/src/lib/smart-table/stories/SmartTable.stories.tsx +114 -114
  367. package/src/lib/theme/index.ts +1 -1
  368. package/src/lib/theme/theme.ts +123 -123
  369. package/src/lib/utils/map.ts +19 -19
  370. package/src/lib/utils/projections.ts +7 -7
  371. package/src/lib/utils/story.ts +11 -11
  372. package/src/react-app-env.d.ts +1 -1
  373. package/src/setupTests.ts +14 -14
  374. package/tsbuildconfig.json +37 -37
  375. package/tsconfig.json +26 -26
@@ -1,2116 +1,2116 @@
1
- // inspired by https://github.com/leforthomas/cesium-drawhelper
2
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3
- // @ts-nocheck
4
- import * as Cesium from 'cesium';
5
- import './drawHelper.css';
6
- /* eslint-disable */
7
- var DrawHelper = (function () {
8
- // static variables
9
- var ellipsoid = Cesium.Ellipsoid.WGS84;
10
- var drawingVertexColor;
11
- var material = Cesium.Material.fromType(Cesium.Material.ColorType);
12
-
13
- // constructor
14
- function _(
15
- cesiumWidget,
16
- materialClr = new Cesium.Color(1.0, 1.0, 0.0, 0.5),
17
- drawingVertexClr = new Cesium.Color(1.0, 1.0, 1.0, 1.0)
18
- ) {
19
- this._scene = cesiumWidget.scene;
20
-
21
- // UPDATE scoped varibles
22
- material.uniforms.color = materialClr;
23
- drawingVertexColor = drawingVertexClr;
24
-
25
- //MC_CHANGE disable/override tooltip
26
- this._tooltip = {
27
- setVisible: () => {},
28
- showAt: () => {},
29
- };
30
- // this._tooltip = createTooltip(cesiumWidget.container);
31
- this._surfaces = [];
32
-
33
- this.initialiseHandlers();
34
-
35
- this.enhancePrimitives();
36
- }
37
-
38
- _.prototype.initialiseHandlers = function () {
39
- var scene = this._scene;
40
- var _self = this;
41
- // scene events
42
- var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
43
- function callPrimitiveCallback(name, position) {
44
- if (_self._handlersMuted == true) return;
45
- var pickedObject = scene.pick(position);
46
- if (
47
- pickedObject &&
48
- pickedObject.primitive &&
49
- pickedObject.primitive[name]
50
- ) {
51
- pickedObject.primitive[name](position);
52
- }
53
- }
54
- handler.setInputAction(function (movement) {
55
- callPrimitiveCallback('leftClick', movement.position);
56
- }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
57
- handler.setInputAction(function (movement) {
58
- callPrimitiveCallback('leftDoubleClick', movement.position);
59
- }, Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
60
- var mouseOutObject;
61
- handler.setInputAction(function (movement) {
62
- if (_self._handlersMuted == true) return;
63
- var pickedObject = scene.pick(movement.endPosition);
64
- if (
65
- mouseOutObject &&
66
- (!pickedObject || mouseOutObject != pickedObject.primitive)
67
- ) {
68
- !(mouseOutObject.isDestroyed && mouseOutObject.isDestroyed()) &&
69
- mouseOutObject.mouseOut(movement.endPosition);
70
- mouseOutObject = null;
71
- }
72
- if (pickedObject && pickedObject.primitive) {
73
- pickedObject = pickedObject.primitive;
74
- if (pickedObject.mouseOut) {
75
- mouseOutObject = pickedObject;
76
- }
77
- if (pickedObject.mouseMove) {
78
- pickedObject.mouseMove(movement.endPosition);
79
- }
80
- }
81
- }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
82
- handler.setInputAction(function (movement) {
83
- callPrimitiveCallback('leftUp', movement.position);
84
- }, Cesium.ScreenSpaceEventType.LEFT_UP);
85
- handler.setInputAction(function (movement) {
86
- callPrimitiveCallback('leftDown', movement.position);
87
- }, Cesium.ScreenSpaceEventType.LEFT_DOWN);
88
- };
89
-
90
- _.prototype.setListener = function (primitive, type, callback) {
91
- primitive[type] = callback;
92
- };
93
-
94
- _.prototype.muteHandlers = function (muted) {
95
- this._handlersMuted = muted;
96
- };
97
-
98
- // register event handling for an editable shape
99
- // shape should implement setEditMode and setHighlighted
100
- _.prototype.registerEditableShape = function (surface) {
101
- var _self = this;
102
-
103
- // handlers for interactions
104
- // highlight polygon when mouse is entering
105
- setListener(surface, 'mouseMove', function (position) {
106
- surface.setHighlighted(true);
107
- if (!surface._editMode) {
108
- _self._tooltip.showAt(position, 'Click to edit this shape');
109
- }
110
- });
111
- // hide the highlighting when mouse is leaving the polygon
112
- setListener(surface, 'mouseOut', function (position) {
113
- surface.setHighlighted(false);
114
- _self._tooltip.setVisible(false);
115
- });
116
- setListener(surface, 'leftClick', function (position) {
117
- surface.setEditMode(true);
118
- });
119
- };
120
-
121
- _.prototype.startDrawing = function (cleanUp) {
122
- // undo any current edit of shapes
123
- this.disableAllEditMode();
124
- // check for cleanUp first
125
- if (this.editCleanUp) {
126
- this.editCleanUp();
127
- }
128
- this.editCleanUp = cleanUp;
129
- this.muteHandlers(true);
130
- };
131
-
132
- _.prototype.stopDrawing = function () {
133
- // check for cleanUp first
134
- if (this.editCleanUp) {
135
- this.editCleanUp();
136
- this.editCleanUp = null;
137
- }
138
- this.muteHandlers(false);
139
- };
140
-
141
- // make sure only one shape is highlighted at a time
142
- _.prototype.disableAllHighlights = function () {
143
- this.setHighlighted(undefined);
144
- };
145
-
146
- _.prototype.setHighlighted = function (surface) {
147
- if (
148
- this._highlightedSurface &&
149
- !this._highlightedSurface.isDestroyed() &&
150
- this._highlightedSurface != surface
151
- ) {
152
- this._highlightedSurface.setHighlighted(false);
153
- }
154
- this._highlightedSurface = surface;
155
- };
156
-
157
- _.prototype.disableAllEditMode = function () {
158
- this.setEdited(undefined);
159
- };
160
-
161
- _.prototype.setEdited = function (surface) {
162
- if (this._editedSurface && !this._editedSurface.isDestroyed()) {
163
- this._editedSurface.setEditMode(false);
164
- }
165
- this._editedSurface = surface;
166
- };
167
-
168
- var defaultShapeOptions = {
169
- ellipsoid: Cesium.Ellipsoid.WGS84,
170
- textureRotationAngle: 0.0,
171
- height: 0.0,
172
- asynchronous: true,
173
- show: true,
174
- debugShowBoundingVolume: false,
175
- };
176
-
177
- var defaultSurfaceOptions = copyOptions(defaultShapeOptions, {
178
- appearance: new Cesium.EllipsoidSurfaceAppearance({
179
- aboveGround: false,
180
- }),
181
- material: material,
182
- granularity: Math.PI / 180.0,
183
- });
184
-
185
- var defaultPolygonOptions = copyOptions(defaultShapeOptions, {});
186
- var defaultExtentOptions = copyOptions(defaultShapeOptions, {});
187
- var defaultCircleOptions = copyOptions(defaultShapeOptions, {});
188
- var defaultEllipseOptions = copyOptions(defaultSurfaceOptions, {
189
- rotation: 0,
190
- });
191
-
192
- var defaultPolylineOptions = copyOptions(defaultShapeOptions, {
193
- width: 5,
194
- geodesic: true,
195
- granularity: 10000,
196
- appearance: new Cesium.PolylineMaterialAppearance({
197
- aboveGround: false,
198
- }),
199
- material: material,
200
- });
201
-
202
- // Cesium.Polygon.prototype.setStrokeStyle = setStrokeStyle;
203
- //
204
- // Cesium.Polygon.prototype.drawOutline = drawOutline;
205
- //
206
-
207
- var ChangeablePrimitive = (function () {
208
- function _() {}
209
-
210
- _.prototype.initialiseOptions = function (options) {
211
- fillOptions(this, options);
212
-
213
- this._ellipsoid = undefined;
214
- this._granularity = undefined;
215
- this._height = undefined;
216
- this._textureRotationAngle = undefined;
217
- this._id = undefined;
218
-
219
- // set the flags to initiate a first drawing
220
- this._createPrimitive = true;
221
- this._primitive = undefined;
222
- this._outlinePolygon = undefined;
223
- };
224
-
225
- _.prototype.setAttribute = function (name, value) {
226
- this[name] = value;
227
- this._createPrimitive = true;
228
- };
229
-
230
- _.prototype.getAttribute = function (name) {
231
- return this[name];
232
- };
233
-
234
- /**
235
- * @private
236
- */
237
- _.prototype.update = function (context, frameState, commandList) {
238
- if (!Cesium.defined(this.ellipsoid)) {
239
- throw new Cesium.DeveloperError('this.ellipsoid must be defined.');
240
- }
241
-
242
- if (!Cesium.defined(this.appearance)) {
243
- throw new Cesium.DeveloperError('this.material must be defined.');
244
- }
245
-
246
- if (this.granularity < 0.0) {
247
- throw new Cesium.DeveloperError(
248
- 'this.granularity and scene2D/scene3D overrides must be greater than zero.'
249
- );
250
- }
251
-
252
- if (!this.show) {
253
- return;
254
- }
255
-
256
- if (!this._createPrimitive && !Cesium.defined(this._primitive)) {
257
- // No positions/hierarchy to draw
258
- return;
259
- }
260
-
261
- if (
262
- this._createPrimitive ||
263
- this._ellipsoid !== this.ellipsoid ||
264
- this._granularity !== this.granularity ||
265
- this._height !== this.height ||
266
- this._textureRotationAngle !== this.textureRotationAngle ||
267
- this._id !== this.id
268
- ) {
269
- var geometry = this.getGeometry();
270
- if (!geometry) {
271
- return;
272
- }
273
-
274
- this._createPrimitive = false;
275
- this._ellipsoid = this.ellipsoid;
276
- this._granularity = this.granularity;
277
- this._height = this.height;
278
- this._textureRotationAngle = this.textureRotationAngle;
279
- this._id = this.id;
280
-
281
- this._primitive = this._primitive && this._primitive.destroy();
282
-
283
- this._primitive = new Cesium.Primitive({
284
- geometryInstances: new Cesium.GeometryInstance({
285
- geometry: geometry,
286
- id: this.id,
287
- pickPrimitive: this,
288
- }),
289
- appearance: this.appearance,
290
- asynchronous: this.asynchronous,
291
- });
292
-
293
- this._outlinePolygon =
294
- this._outlinePolygon && this._outlinePolygon.destroy();
295
- if (this.strokeColor && this.getOutlineGeometry) {
296
- // create the highlighting frame
297
- this._outlinePolygon = new Cesium.Primitive({
298
- geometryInstances: new Cesium.GeometryInstance({
299
- geometry: this.getOutlineGeometry(),
300
- attributes: {
301
- color: Cesium.ColorGeometryInstanceAttribute.fromColor(
302
- this.strokeColor
303
- ),
304
- },
305
- }),
306
- appearance: new Cesium.PerInstanceColorAppearance({
307
- flat: true,
308
- renderState: {
309
- depthTest: {
310
- enabled: true,
311
- },
312
- //MC_CHANGE
313
- lineWidth: this.strokeWidth || 4.0,
314
- // lineWidth : Math.min(this.strokeWidth || 4.0, context._aliasedLineWidthRange[1])
315
- },
316
- }),
317
- });
318
- }
319
- }
320
-
321
- var primitive = this._primitive;
322
- primitive.appearance.material = this.material;
323
- primitive.debugShowBoundingVolume = this.debugShowBoundingVolume;
324
-
325
- primitive.update(context, frameState, commandList);
326
-
327
- this._outlinePolygon &&
328
- this._outlinePolygon.update(context, frameState, commandList);
329
- };
330
-
331
- _.prototype.isDestroyed = function () {
332
- return false;
333
- };
334
-
335
- _.prototype.destroy = function () {
336
- this._primitive = this._primitive && this._primitive.destroy();
337
- return Cesium.destroyObject(this);
338
- };
339
-
340
- _.prototype.setStrokeStyle = function (strokeColor, strokeWidth) {
341
- if (
342
- !this.strokeColor ||
343
- !this.strokeColor.equals(strokeColor) ||
344
- this.strokeWidth != strokeWidth
345
- ) {
346
- this._createPrimitive = true;
347
- this.strokeColor = strokeColor;
348
- this.strokeWidth = strokeWidth;
349
- }
350
- };
351
-
352
- return _;
353
- })();
354
-
355
- _.ExtentPrimitive = (function () {
356
- function _(options) {
357
- if (!Cesium.defined(options.extent)) {
358
- throw new Cesium.DeveloperError('Extent is required');
359
- }
360
-
361
- options = copyOptions(options, defaultSurfaceOptions);
362
-
363
- this.initialiseOptions(options);
364
-
365
- this.setExtent(options.extent);
366
- }
367
-
368
- _.prototype = new ChangeablePrimitive();
369
-
370
- _.prototype.setExtent = function (extent) {
371
- this.setAttribute('extent', extent);
372
- };
373
-
374
- _.prototype.getExtent = function () {
375
- return this.getAttribute('extent');
376
- };
377
-
378
- _.prototype.getGeometry = function () {
379
- if (!Cesium.defined(this.extent)) {
380
- return;
381
- }
382
-
383
- return new Cesium.RectangleGeometry({
384
- rectangle: this.extent,
385
- height: this.height,
386
- vertexFormat: Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT,
387
- stRotation: this.textureRotationAngle,
388
- ellipsoid: this.ellipsoid,
389
- granularity: this.granularity,
390
- });
391
- };
392
-
393
- _.prototype.getOutlineGeometry = function () {
394
- return new Cesium.RectangleOutlineGeometry({
395
- rectangle: this.extent,
396
- });
397
- };
398
-
399
- return _;
400
- })();
401
-
402
- _.PolygonPrimitive = (function () {
403
- function _(options) {
404
- options = copyOptions(options, defaultSurfaceOptions);
405
-
406
- this.initialiseOptions(options);
407
-
408
- this.isPolygon = true;
409
- }
410
-
411
- _.prototype = new ChangeablePrimitive();
412
-
413
- _.prototype.setPositions = function (positions) {
414
- this.setAttribute('positions', positions);
415
- };
416
-
417
- _.prototype.getPositions = function () {
418
- return this.getAttribute('positions');
419
- };
420
-
421
- _.prototype.getGeometry = function () {
422
- if (!Cesium.defined(this.positions) || this.positions.length < 3) {
423
- return;
424
- }
425
-
426
- return Cesium.PolygonGeometry.fromPositions({
427
- positions: this.positions,
428
- height: this.height,
429
- vertexFormat: Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT,
430
- stRotation: this.textureRotationAngle,
431
- ellipsoid: this.ellipsoid,
432
- granularity: this.granularity,
433
- });
434
- };
435
-
436
- _.prototype.getOutlineGeometry = function () {
437
- return Cesium.PolygonOutlineGeometry.fromPositions({
438
- positions: this.getPositions(),
439
- });
440
- };
441
-
442
- return _;
443
- })();
444
-
445
- _.CirclePrimitive = (function () {
446
- function _(options) {
447
- if (!(Cesium.defined(options.center) && Cesium.defined(options.radius))) {
448
- throw new Cesium.DeveloperError('Center and radius are required');
449
- }
450
-
451
- options = copyOptions(options, defaultSurfaceOptions);
452
-
453
- this.initialiseOptions(options);
454
-
455
- this.setRadius(options.radius);
456
- }
457
-
458
- _.prototype = new ChangeablePrimitive();
459
-
460
- _.prototype.setCenter = function (center) {
461
- this.setAttribute('center', center);
462
- };
463
-
464
- _.prototype.setRadius = function (radius) {
465
- this.setAttribute('radius', Math.max(0.1, radius));
466
- };
467
-
468
- _.prototype.getCenter = function () {
469
- return this.getAttribute('center');
470
- };
471
-
472
- _.prototype.getRadius = function () {
473
- return this.getAttribute('radius');
474
- };
475
-
476
- _.prototype.getGeometry = function () {
477
- if (!(Cesium.defined(this.center) && Cesium.defined(this.radius))) {
478
- return;
479
- }
480
-
481
- return new Cesium.CircleGeometry({
482
- center: this.center,
483
- radius: this.radius,
484
- height: this.height,
485
- vertexFormat: Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT,
486
- stRotation: this.textureRotationAngle,
487
- ellipsoid: this.ellipsoid,
488
- granularity: this.granularity,
489
- });
490
- };
491
-
492
- _.prototype.getOutlineGeometry = function () {
493
- return new Cesium.CircleOutlineGeometry({
494
- center: this.getCenter(),
495
- radius: this.getRadius(),
496
- });
497
- };
498
-
499
- return _;
500
- })();
501
-
502
- _.EllipsePrimitive = (function () {
503
- function _(options) {
504
- if (
505
- !(
506
- Cesium.defined(options.center) &&
507
- Cesium.defined(options.semiMajorAxis) &&
508
- Cesium.defined(options.semiMinorAxis)
509
- )
510
- ) {
511
- throw new Cesium.DeveloperError(
512
- 'Center and semi major and semi minor axis are required'
513
- );
514
- }
515
-
516
- options = copyOptions(options, defaultEllipseOptions);
517
-
518
- this.initialiseOptions(options);
519
- }
520
-
521
- _.prototype = new ChangeablePrimitive();
522
-
523
- _.prototype.setCenter = function (center) {
524
- this.setAttribute('center', center);
525
- };
526
-
527
- _.prototype.setSemiMajorAxis = function (semiMajorAxis) {
528
- if (semiMajorAxis < this.getSemiMinorAxis()) return;
529
- this.setAttribute('semiMajorAxis', semiMajorAxis);
530
- };
531
-
532
- _.prototype.setSemiMinorAxis = function (semiMinorAxis) {
533
- if (semiMinorAxis > this.getSemiMajorAxis()) return;
534
- this.setAttribute('semiMinorAxis', semiMinorAxis);
535
- };
536
-
537
- _.prototype.setRotation = function (rotation) {
538
- return this.setAttribute('rotation', rotation);
539
- };
540
-
541
- _.prototype.getCenter = function () {
542
- return this.getAttribute('center');
543
- };
544
-
545
- _.prototype.getSemiMajorAxis = function () {
546
- return this.getAttribute('semiMajorAxis');
547
- };
548
-
549
- _.prototype.getSemiMinorAxis = function () {
550
- return this.getAttribute('semiMinorAxis');
551
- };
552
-
553
- _.prototype.getRotation = function () {
554
- return this.getAttribute('rotation');
555
- };
556
-
557
- _.prototype.getGeometry = function () {
558
- if (
559
- !(
560
- Cesium.defined(this.center) &&
561
- Cesium.defined(this.semiMajorAxis) &&
562
- Cesium.defined(this.semiMinorAxis)
563
- )
564
- ) {
565
- return;
566
- }
567
-
568
- return new Cesium.EllipseGeometry({
569
- ellipsoid: this.ellipsoid,
570
- center: this.center,
571
- semiMajorAxis: this.semiMajorAxis,
572
- semiMinorAxis: this.semiMinorAxis,
573
- rotation: this.rotation,
574
- height: this.height,
575
- vertexFormat: Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT,
576
- stRotation: this.textureRotationAngle,
577
- ellipsoid: this.ellipsoid,
578
- granularity: this.granularity,
579
- });
580
- };
581
-
582
- _.prototype.getOutlineGeometry = function () {
583
- return new Cesium.EllipseOutlineGeometry({
584
- center: this.getCenter(),
585
- semiMajorAxis: this.getSemiMajorAxis(),
586
- semiMinorAxis: this.getSemiMinorAxis(),
587
- rotation: this.getRotation(),
588
- });
589
- };
590
-
591
- return _;
592
- })();
593
-
594
- _.PolylinePrimitive = (function () {
595
- function _(options) {
596
- options = copyOptions(options, defaultPolylineOptions);
597
-
598
- this.initialiseOptions(options);
599
- }
600
-
601
- _.prototype = new ChangeablePrimitive();
602
-
603
- _.prototype.setPositions = function (positions) {
604
- this.setAttribute('positions', positions);
605
- };
606
-
607
- _.prototype.setWidth = function (width) {
608
- this.setAttribute('width', width);
609
- };
610
-
611
- _.prototype.setGeodesic = function (geodesic) {
612
- this.setAttribute('geodesic', geodesic);
613
- };
614
-
615
- _.prototype.getPositions = function () {
616
- return this.getAttribute('positions');
617
- };
618
-
619
- _.prototype.getWidth = function () {
620
- return this.getAttribute('width');
621
- };
622
-
623
- _.prototype.getGeodesic = function (geodesic) {
624
- return this.getAttribute('geodesic');
625
- };
626
-
627
- _.prototype.getGeometry = function () {
628
- if (!Cesium.defined(this.positions) || this.positions.length < 2) {
629
- return;
630
- }
631
-
632
- return new Cesium.PolylineGeometry({
633
- positions: this.positions,
634
- height: this.height,
635
- width: this.width < 1 ? 1 : this.width,
636
- vertexFormat: Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT,
637
- ellipsoid: this.ellipsoid,
638
- });
639
- };
640
-
641
- return _;
642
- })();
643
-
644
- var defaultBillboard = {
645
- iconUrl: './assets/img/dragIcon.png',
646
- shiftX: 0,
647
- shiftY: 0,
648
- };
649
-
650
- var dragBillboard = {
651
- iconUrl: './assets/img/dragIcon.png',
652
- shiftX: 0,
653
- shiftY: 0,
654
- };
655
-
656
- var dragHalfBillboard = {
657
- iconUrl: './assets/img/dragIconLight.png',
658
- shiftX: 0,
659
- shiftY: 0,
660
- };
661
-
662
- _.prototype.createBillboardGroup = function (points, options, callbacks) {
663
- var markers = new _.BillboardGroup(this, options);
664
- markers.addBillboards(points, callbacks);
665
- return markers;
666
- };
667
-
668
- _.BillboardGroup = function (drawHelper, options) {
669
- this._drawHelper = drawHelper;
670
- this._scene = drawHelper._scene;
671
-
672
- this._options = copyOptions(options, defaultBillboard);
673
-
674
- // create one common billboard collection for all billboards
675
- var b = new Cesium.BillboardCollection();
676
- this._scene.primitives.add(b);
677
- this._billboards = b;
678
- // keep an ordered list of billboards
679
- this._orderedBillboards = [];
680
- };
681
-
682
- _.BillboardGroup.prototype.createBillboard = function (position, callbacks) {
683
- var billboard = this._billboards.add({
684
- show: true,
685
- position: position,
686
- pixelOffset: new Cesium.Cartesian2(
687
- this._options.shiftX,
688
- this._options.shiftY
689
- ),
690
- eyeOffset: new Cesium.Cartesian3(0.0, 0.0, 0.0),
691
- horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
692
- verticalOrigin: Cesium.VerticalOrigin.CENTER,
693
- scale: 1.0,
694
- image: this._options.iconUrl,
695
- color: drawingVertexColor,
696
- });
697
-
698
- // if editable
699
- if (callbacks) {
700
- var _self = this;
701
- var screenSpaceCameraController = this._scene.screenSpaceCameraController;
702
- function enableRotation(enable) {
703
- screenSpaceCameraController.enableRotate = enable;
704
- }
705
- function getIndex() {
706
- // find index
707
- for (
708
- var i = 0, I = _self._orderedBillboards.length;
709
- i < I && _self._orderedBillboards[i] != billboard;
710
- ++i
711
- );
712
- return i;
713
- }
714
- if (callbacks.dragHandlers) {
715
- var _self = this;
716
- setListener(billboard, 'leftDown', function (position) {
717
- // TODO - start the drag handlers here
718
- // create handlers for mouseOut and leftUp for the billboard and a mouseMove
719
- function onDrag(position) {
720
- billboard.position = position;
721
- // find index
722
- for (
723
- var i = 0, I = _self._orderedBillboards.length;
724
- i < I && _self._orderedBillboards[i] != billboard;
725
- ++i
726
- );
727
- callbacks.dragHandlers.onDrag &&
728
- callbacks.dragHandlers.onDrag(getIndex(), position);
729
- }
730
- function onDragEnd(position) {
731
- handler.destroy();
732
- enableRotation(true);
733
- callbacks.dragHandlers.onDragEnd &&
734
- callbacks.dragHandlers.onDragEnd(getIndex(), position);
735
- }
736
-
737
- var handler = new Cesium.ScreenSpaceEventHandler(_self._scene.canvas);
738
-
739
- handler.setInputAction(function (movement) {
740
- var cartesian = _self._scene.camera.pickEllipsoid(
741
- movement.endPosition,
742
- ellipsoid
743
- );
744
- if (cartesian) {
745
- onDrag(cartesian);
746
- } else {
747
- onDragEnd(cartesian);
748
- }
749
- }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
750
-
751
- handler.setInputAction(function (movement) {
752
- onDragEnd(
753
- _self._scene.camera.pickEllipsoid(movement.position, ellipsoid)
754
- );
755
- }, Cesium.ScreenSpaceEventType.LEFT_UP);
756
-
757
- enableRotation(false);
758
-
759
- callbacks.dragHandlers.onDragStart &&
760
- callbacks.dragHandlers.onDragStart(
761
- getIndex(),
762
- _self._scene.camera.pickEllipsoid(position, ellipsoid)
763
- );
764
- });
765
- }
766
- if (callbacks.onDoubleClick) {
767
- setListener(billboard, 'leftDoubleClick', function (position) {
768
- callbacks.onDoubleClick(getIndex());
769
- });
770
- }
771
- if (callbacks.onClick) {
772
- setListener(billboard, 'leftClick', function (position) {
773
- callbacks.onClick(getIndex());
774
- });
775
- }
776
- if (callbacks.tooltip) {
777
- setListener(billboard, 'mouseMove', function (position) {
778
- _self._drawHelper._tooltip.showAt(position, callbacks.tooltip());
779
- });
780
- setListener(billboard, 'mouseOut', function (position) {
781
- _self._drawHelper._tooltip.setVisible(false);
782
- });
783
- }
784
- }
785
-
786
- return billboard;
787
- };
788
-
789
- _.BillboardGroup.prototype.insertBillboard = function (
790
- index,
791
- position,
792
- callbacks
793
- ) {
794
- this._orderedBillboards.splice(
795
- index,
796
- 0,
797
- this.createBillboard(position, callbacks)
798
- );
799
- };
800
-
801
- _.BillboardGroup.prototype.addBillboard = function (position, callbacks) {
802
- this._orderedBillboards.push(this.createBillboard(position, callbacks));
803
- };
804
-
805
- _.BillboardGroup.prototype.addBillboards = function (positions, callbacks) {
806
- var index = 0;
807
- for (; index < positions.length; index++) {
808
- this.addBillboard(positions[index], callbacks);
809
- }
810
- };
811
-
812
- _.BillboardGroup.prototype.updateBillboardsPositions = function (positions) {
813
- var index = 0;
814
- for (; index < positions.length; index++) {
815
- this.getBillboard(index).position = positions[index];
816
- }
817
- };
818
-
819
- _.BillboardGroup.prototype.countBillboards = function () {
820
- return this._orderedBillboards.length;
821
- };
822
-
823
- _.BillboardGroup.prototype.getBillboard = function (index) {
824
- return this._orderedBillboards[index];
825
- };
826
-
827
- _.BillboardGroup.prototype.removeBillboard = function (index) {
828
- this._billboards.remove(this.getBillboard(index));
829
- this._orderedBillboards.splice(index, 1);
830
- };
831
-
832
- _.BillboardGroup.prototype.remove = function () {
833
- this._billboards =
834
- this._billboards &&
835
- this._billboards.removeAll() &&
836
- this._billboards.destroy();
837
- };
838
-
839
- _.BillboardGroup.prototype.setOnTop = function () {
840
- this._scene.primitives.raiseToTop(this._billboards);
841
- };
842
-
843
- _.prototype.startDrawingMarker = function (options) {
844
- var options = copyOptions(options, defaultBillboard);
845
-
846
- this.startDrawing(function () {
847
- markers.remove();
848
- mouseHandler.destroy();
849
- tooltip.setVisible(false);
850
- });
851
-
852
- var _self = this;
853
- var scene = this._scene;
854
- var primitives = scene.primitives;
855
- var tooltip = this._tooltip;
856
-
857
- var markers = new _.BillboardGroup(this, options);
858
-
859
- var mouseHandler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
860
-
861
- // Now wait for start
862
- mouseHandler.setInputAction(function (movement) {
863
- if (movement.position != null) {
864
- var cartesian = scene.camera.pickEllipsoid(
865
- movement.position,
866
- ellipsoid
867
- );
868
- if (cartesian) {
869
- markers.addBillboard(cartesian);
870
- _self.stopDrawing();
871
- options.callback(cartesian);
872
- }
873
- }
874
- }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
875
-
876
- mouseHandler.setInputAction(function (movement) {
877
- var position = movement.endPosition;
878
- if (position != null) {
879
- var cartesian = scene.camera.pickEllipsoid(position, ellipsoid);
880
- if (cartesian) {
881
- tooltip.showAt(
882
- position,
883
- '<p>Click to add your marker. Position is: </p>' +
884
- getDisplayLatLngString(
885
- ellipsoid.cartesianToCartographic(cartesian)
886
- )
887
- );
888
- } else {
889
- tooltip.showAt(
890
- position,
891
- '<p>Click on the globe to add your marker.</p>'
892
- );
893
- }
894
- }
895
- }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
896
- };
897
-
898
- _.prototype.startDrawingPolygon = function (options) {
899
- var options = copyOptions(options, defaultSurfaceOptions);
900
- this.startDrawingPolyshape(true, options);
901
- };
902
-
903
- _.prototype.startDrawingPolyline = function (options) {
904
- var options = copyOptions(options, defaultPolylineOptions);
905
- this.startDrawingPolyshape(false, options);
906
- };
907
-
908
- _.prototype.startDrawingPolyshape = function (isPolygon, options) {
909
- this.startDrawing(function () {
910
- primitives.remove(poly);
911
- markers.remove();
912
- mouseHandler.destroy();
913
- tooltip.setVisible(false);
914
- unsetDrawCursor(scene);
915
- });
916
-
917
- var _self = this;
918
- var scene = this._scene;
919
- var primitives = scene.primitives;
920
- var tooltip = this._tooltip;
921
-
922
- var minPoints = isPolygon ? 3 : 2;
923
- var poly;
924
- if (isPolygon) {
925
- poly = new DrawHelper.PolygonPrimitive(options);
926
- } else {
927
- poly = new DrawHelper.PolylinePrimitive(options);
928
- }
929
- poly.asynchronous = false;
930
- primitives.add(poly);
931
-
932
- var positions = [];
933
- var markers = new _.BillboardGroup(this, defaultBillboard);
934
-
935
- var mouseHandler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
936
- setDrawCursor(scene);
937
-
938
- // Now wait for start
939
- mouseHandler.setInputAction(function (movement) {
940
- if (movement.position != null) {
941
- var cartesian = scene.camera.pickEllipsoid(
942
- movement.position,
943
- ellipsoid
944
- );
945
- if (cartesian) {
946
- // first click
947
- if (positions.length == 0) {
948
- positions.push(cartesian.clone());
949
- markers.addBillboard(positions[0]);
950
- }
951
- if (positions.length >= minPoints) {
952
- poly.positions = positions;
953
- poly._createPrimitive = true;
954
- }
955
- // add new point to polygon
956
- // this one will move with the mouse
957
- positions.push(cartesian);
958
- // add marker at the new position
959
- markers.addBillboard(cartesian);
960
- }
961
- }
962
- }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
963
-
964
- mouseHandler.setInputAction(function (movement) {
965
- var position = movement.endPosition;
966
- if (position != null) {
967
- if (positions.length == 0) {
968
- tooltip.showAt(position, '<p>Click to add first point</p>');
969
- } else {
970
- var cartesian = scene.camera.pickEllipsoid(position, ellipsoid);
971
- if (cartesian) {
972
- positions.pop();
973
- // make sure it is slightly different
974
- cartesian.y += 1 + Math.random();
975
- positions.push(cartesian);
976
- if (positions.length >= minPoints) {
977
- poly.positions = positions;
978
- poly._createPrimitive = true;
979
- }
980
- // update marker
981
- markers.getBillboard(positions.length - 1).position = cartesian;
982
- // show tooltip
983
- tooltip.showAt(
984
- position,
985
- '<p>Click to add new point (' +
986
- positions.length +
987
- ')</p>' +
988
- (positions.length > minPoints
989
- ? '<p>Double click to finish drawing</p>'
990
- : '')
991
- );
992
- }
993
- }
994
- }
995
- }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
996
-
997
- mouseHandler.setInputAction(function (movement) {
998
- var position = movement.position;
999
- if (position != null) {
1000
- if (positions.length < minPoints + 2) {
1001
- return;
1002
- } else {
1003
- var cartesian = scene.camera.pickEllipsoid(position, ellipsoid);
1004
- if (cartesian) {
1005
- unsetDrawCursor(scene);
1006
- _self.stopDrawing();
1007
- if (typeof options.callback == 'function') {
1008
- // remove overlapping ones
1009
- var index = positions.length - 1;
1010
- options.callback(positions);
1011
- }
1012
- }
1013
- }
1014
- }
1015
- }, Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
1016
- };
1017
-
1018
- function getExtentCorners(value) {
1019
- return ellipsoid.cartographicArrayToCartesianArray([
1020
- Cesium.Rectangle.northwest(value),
1021
- Cesium.Rectangle.northeast(value),
1022
- Cesium.Rectangle.southeast(value),
1023
- Cesium.Rectangle.southwest(value),
1024
- ]);
1025
- }
1026
-
1027
- // MC_CHANGE add to change draw mode cursor
1028
- function setDrawCursor(scene) {
1029
- if (scene) {
1030
- scene.canvas.style.cursor = 'crosshair';
1031
- }
1032
- }
1033
-
1034
- // MC_CHANGE add to restore regular mode
1035
- function unsetDrawCursor(scene) {
1036
- if (scene) {
1037
- scene.canvas.style.cursor = '';
1038
- }
1039
- }
1040
-
1041
- _.prototype.startDrawingExtent = function (options) {
1042
- var options = copyOptions(options, defaultSurfaceOptions);
1043
-
1044
- this.startDrawing(function () {
1045
- if (extent != null) {
1046
- primitives.remove(extent);
1047
- }
1048
- //MC_CHANGE if added
1049
- if (markers != null) {
1050
- markers.remove();
1051
- }
1052
- mouseHandler.destroy();
1053
- tooltip.setVisible(false);
1054
- unsetDrawCursor(scene);
1055
- });
1056
-
1057
- var _self = this;
1058
- var scene = this._scene;
1059
- var primitives = this._scene.primitives;
1060
- var tooltip = this._tooltip;
1061
-
1062
- var firstPoint = null;
1063
- var extent = null;
1064
- var markers = null;
1065
-
1066
- var mouseHandler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
1067
- setDrawCursor(scene);
1068
-
1069
- function updateExtent(value) {
1070
- if (extent == null) {
1071
- //MC_CHANGE
1072
- extent = new DrawHelper.ExtentPrimitive({
1073
- extent: value,
1074
- material: options.material,
1075
- });
1076
- //extent = new Cesium.RectanglePrimitive();
1077
- extent.asynchronous = false;
1078
- primitives.add(extent);
1079
- }
1080
- extent.setExtent(value);
1081
- // update the markers
1082
- var corners = getExtentCorners(value);
1083
- // create if they do not yet exist
1084
- if (markers == null) {
1085
- markers = new _.BillboardGroup(_self, defaultBillboard);
1086
- markers.addBillboards(corners);
1087
- } else {
1088
- markers.updateBillboardsPositions(corners);
1089
- }
1090
- }
1091
-
1092
- // Now wait for start
1093
- mouseHandler.setInputAction(function (movement) {
1094
- if (movement.position != null) {
1095
- var cartesian = scene.camera.pickEllipsoid(
1096
- movement.position,
1097
- ellipsoid
1098
- );
1099
- if (cartesian) {
1100
- if (extent == null) {
1101
- // create the rectangle
1102
- firstPoint = ellipsoid.cartesianToCartographic(cartesian);
1103
- var value = getExtent(firstPoint, firstPoint);
1104
- updateExtent(value);
1105
- } else {
1106
- _self.stopDrawing();
1107
- if (typeof options.callback == 'function') {
1108
- options.callback(
1109
- getExtent(
1110
- firstPoint,
1111
- ellipsoid.cartesianToCartographic(cartesian)
1112
- )
1113
- );
1114
- }
1115
- }
1116
- }
1117
- }
1118
- }, Cesium.ScreenSpaceEventType.LEFT_DOWN);
1119
-
1120
- mouseHandler.setInputAction(function (movement) {
1121
- var position = movement.endPosition;
1122
- if (position != null) {
1123
- if (extent == null) {
1124
- tooltip.showAt(position, '<p>Click to start drawing rectangle</p>');
1125
- } else {
1126
- var cartesian = scene.camera.pickEllipsoid(position, ellipsoid);
1127
- if (cartesian) {
1128
- var value = getExtent(
1129
- firstPoint,
1130
- ellipsoid.cartesianToCartographic(cartesian)
1131
- );
1132
- updateExtent(value);
1133
- tooltip.showAt(
1134
- position,
1135
- '<p>Drag to change rectangle extent</p><p>Click again to finish drawing</p>'
1136
- );
1137
- }
1138
- }
1139
- }
1140
- }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
1141
- };
1142
-
1143
- _.prototype.startDrawingCircle = function (options) {
1144
- var options = copyOptions(options, defaultSurfaceOptions);
1145
-
1146
- this.startDrawing(function cleanUp() {
1147
- if (circle != null) {
1148
- primitives.remove(circle);
1149
- }
1150
- markers.remove();
1151
- mouseHandler.destroy();
1152
- tooltip.setVisible(false);
1153
- });
1154
-
1155
- var _self = this;
1156
- var scene = this._scene;
1157
- var primitives = this._scene.primitives;
1158
- var tooltip = this._tooltip;
1159
-
1160
- var circle = null;
1161
- var markers = null;
1162
-
1163
- var mouseHandler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
1164
-
1165
- // Now wait for start
1166
- mouseHandler.setInputAction(function (movement) {
1167
- if (movement.position != null) {
1168
- var cartesian = scene.camera.pickEllipsoid(
1169
- movement.position,
1170
- ellipsoid
1171
- );
1172
- if (cartesian) {
1173
- if (circle == null) {
1174
- // create the circle
1175
- circle = new _.CirclePrimitive({
1176
- center: cartesian,
1177
- radius: 0,
1178
- asynchronous: false,
1179
- material: options.material,
1180
- });
1181
- primitives.add(circle);
1182
- markers = new _.BillboardGroup(_self, defaultBillboard);
1183
- markers.addBillboards([cartesian]);
1184
- } else {
1185
- if (typeof options.callback == 'function') {
1186
- options.callback(circle.getCenter(), circle.getRadius());
1187
- }
1188
- _self.stopDrawing();
1189
- }
1190
- }
1191
- }
1192
- }, Cesium.ScreenSpaceEventType.LEFT_DOWN);
1193
-
1194
- mouseHandler.setInputAction(function (movement) {
1195
- var position = movement.endPosition;
1196
- if (position != null) {
1197
- if (circle == null) {
1198
- tooltip.showAt(position, '<p>Click to start drawing the circle</p>');
1199
- } else {
1200
- var cartesian = scene.camera.pickEllipsoid(position, ellipsoid);
1201
- if (cartesian) {
1202
- circle.setRadius(
1203
- Cesium.Cartesian3.distance(circle.getCenter(), cartesian)
1204
- );
1205
- markers.updateBillboardsPositions(cartesian);
1206
- tooltip.showAt(
1207
- position,
1208
- '<p>Move mouse to change circle radius</p><p>Click again to finish drawing</p>'
1209
- );
1210
- }
1211
- }
1212
- }
1213
- }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
1214
- };
1215
-
1216
- _.prototype.enhancePrimitives = function () {
1217
- var drawHelper = this;
1218
-
1219
- Cesium.Billboard.prototype.setEditable = function () {
1220
- if (this._editable) {
1221
- return;
1222
- }
1223
-
1224
- this._editable = true;
1225
-
1226
- var billboard = this;
1227
-
1228
- var _self = this;
1229
-
1230
- function enableRotation(enable) {
1231
- drawHelper._scene.screenSpaceCameraController.enableRotate = enable;
1232
- }
1233
-
1234
- setListener(billboard, 'leftDown', function (position) {
1235
- // TODO - start the drag handlers here
1236
- // create handlers for mouseOut and leftUp for the billboard and a mouseMove
1237
- function onDrag(position) {
1238
- billboard.position = position;
1239
- _self.executeListeners({ name: 'drag', positions: position });
1240
- }
1241
- function onDragEnd(position) {
1242
- handler.destroy();
1243
- enableRotation(true);
1244
- _self.executeListeners({ name: 'dragEnd', positions: position });
1245
- }
1246
-
1247
- var handler = new Cesium.ScreenSpaceEventHandler(
1248
- drawHelper._scene.canvas
1249
- );
1250
-
1251
- handler.setInputAction(function (movement) {
1252
- var cartesian = drawHelper._scene.camera.pickEllipsoid(
1253
- movement.endPosition,
1254
- ellipsoid
1255
- );
1256
- if (cartesian) {
1257
- onDrag(cartesian);
1258
- } else {
1259
- onDragEnd(cartesian);
1260
- }
1261
- }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
1262
-
1263
- handler.setInputAction(function (movement) {
1264
- onDragEnd(
1265
- drawHelper._scene.camera.pickEllipsoid(movement.position, ellipsoid)
1266
- );
1267
- }, Cesium.ScreenSpaceEventType.LEFT_UP);
1268
-
1269
- enableRotation(false);
1270
- });
1271
-
1272
- enhanceWithListeners(billboard);
1273
- };
1274
-
1275
- function setHighlighted(highlighted) {
1276
- var scene = drawHelper._scene;
1277
-
1278
- // if no change
1279
- // if already highlighted, the outline polygon will be available
1280
- if (this._highlighted && this._highlighted == highlighted) {
1281
- return;
1282
- }
1283
- // disable if already in edit mode
1284
- if (this._editMode === true) {
1285
- return;
1286
- }
1287
- this._highlighted = highlighted;
1288
- // highlight by creating an outline polygon matching the polygon points
1289
- if (highlighted) {
1290
- // make sure all other shapes are not highlighted
1291
- drawHelper.setHighlighted(this);
1292
- this._strokeColor = this.strokeColor;
1293
- this.setStrokeStyle(
1294
- Cesium.Color.fromCssColorString('white'),
1295
- this.strokeWidth
1296
- );
1297
- } else {
1298
- if (this._strokeColor) {
1299
- this.setStrokeStyle(this._strokeColor, this.strokeWidth);
1300
- } else {
1301
- this.setStrokeStyle(undefined, undefined);
1302
- }
1303
- }
1304
- }
1305
-
1306
- function setEditMode(editMode) {
1307
- // if no change
1308
- if (this._editMode == editMode) {
1309
- return;
1310
- }
1311
- // make sure all other shapes are not in edit mode before starting the editing of this shape
1312
- drawHelper.disableAllHighlights();
1313
- // display markers
1314
- if (editMode) {
1315
- drawHelper.setEdited(this);
1316
- var scene = drawHelper._scene;
1317
- var _self = this;
1318
- // create the markers and handlers for the editing
1319
- if (this._markers == null) {
1320
- var markers = new _.BillboardGroup(drawHelper, dragBillboard);
1321
- var editMarkers = new _.BillboardGroup(drawHelper, dragHalfBillboard);
1322
- // function for updating the edit markers around a certain point
1323
- function updateHalfMarkers(index, positions) {
1324
- // update the half markers before and after the index
1325
- var editIndex = index - 1 < 0 ? positions.length - 1 : index - 1;
1326
- if (editIndex < editMarkers.countBillboards()) {
1327
- editMarkers.getBillboard(
1328
- editIndex
1329
- ).position = calculateHalfMarkerPosition(editIndex);
1330
- }
1331
- editIndex = index;
1332
- if (editIndex < editMarkers.countBillboards()) {
1333
- editMarkers.getBillboard(
1334
- editIndex
1335
- ).position = calculateHalfMarkerPosition(editIndex);
1336
- }
1337
- }
1338
- function onEdited() {
1339
- _self.executeListeners({
1340
- name: 'onEdited',
1341
- positions: _self.positions,
1342
- });
1343
- }
1344
- var handleMarkerChanges = {
1345
- dragHandlers: {
1346
- onDrag: function (index, position) {
1347
- _self.positions[index] = position;
1348
- updateHalfMarkers(index, _self.positions);
1349
- _self._createPrimitive = true;
1350
- },
1351
- onDragEnd: function (index, position) {
1352
- _self._createPrimitive = true;
1353
- onEdited();
1354
- },
1355
- },
1356
- onDoubleClick: function (index) {
1357
- if (_self.positions.length < 4) {
1358
- return;
1359
- }
1360
- // remove the point and the corresponding markers
1361
- _self.positions.splice(index, 1);
1362
- _self._createPrimitive = true;
1363
- markers.removeBillboard(index);
1364
- editMarkers.removeBillboard(index);
1365
- updateHalfMarkers(index, _self.positions);
1366
- onEdited();
1367
- },
1368
- tooltip: function () {
1369
- if (_self.positions.length > 3) {
1370
- return 'Double click to remove this point';
1371
- }
1372
- },
1373
- };
1374
- // add billboards and keep an ordered list of them for the polygon edges
1375
- markers.addBillboards(_self.positions, handleMarkerChanges);
1376
- this._markers = markers;
1377
- function calculateHalfMarkerPosition(index) {
1378
- var positions = _self.positions;
1379
- return ellipsoid.cartographicToCartesian(
1380
- new Cesium.EllipsoidGeodesic(
1381
- ellipsoid.cartesianToCartographic(positions[index]),
1382
- ellipsoid.cartesianToCartographic(
1383
- positions[index < positions.length - 1 ? index + 1 : 0]
1384
- )
1385
- ).interpolateUsingFraction(0.5)
1386
- );
1387
- }
1388
- var halfPositions = [];
1389
- var index = 0;
1390
- var length = _self.positions.length + (this.isPolygon ? 0 : -1);
1391
- for (; index < length; index++) {
1392
- halfPositions.push(calculateHalfMarkerPosition(index));
1393
- }
1394
- var handleEditMarkerChanges = {
1395
- dragHandlers: {
1396
- onDragStart: function (index, position) {
1397
- // add a new position to the polygon but not a new marker yet
1398
- this.index = index + 1;
1399
- _self.positions.splice(this.index, 0, position);
1400
- _self._createPrimitive = true;
1401
- },
1402
- onDrag: function (index, position) {
1403
- _self.positions[this.index] = position;
1404
- _self._createPrimitive = true;
1405
- },
1406
- onDragEnd: function (index, position) {
1407
- // create new sets of makers for editing
1408
- markers.insertBillboard(
1409
- this.index,
1410
- position,
1411
- handleMarkerChanges
1412
- );
1413
- editMarkers.getBillboard(
1414
- this.index - 1
1415
- ).position = calculateHalfMarkerPosition(this.index - 1);
1416
- editMarkers.insertBillboard(
1417
- this.index,
1418
- calculateHalfMarkerPosition(this.index),
1419
- handleEditMarkerChanges
1420
- );
1421
- _self._createPrimitive = true;
1422
- onEdited();
1423
- },
1424
- },
1425
- tooltip: function () {
1426
- return 'Drag to create a new point';
1427
- },
1428
- };
1429
- editMarkers.addBillboards(halfPositions, handleEditMarkerChanges);
1430
- this._editMarkers = editMarkers;
1431
- // add a handler for clicking in the globe
1432
- this._globeClickhandler = new Cesium.ScreenSpaceEventHandler(
1433
- scene.canvas
1434
- );
1435
- this._globeClickhandler.setInputAction(function (movement) {
1436
- var pickedObject = scene.pick(movement.position);
1437
- if (!(pickedObject && pickedObject.primitive)) {
1438
- _self.setEditMode(false);
1439
- }
1440
- }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
1441
-
1442
- // set on top of the polygon
1443
- markers.setOnTop();
1444
- editMarkers.setOnTop();
1445
- }
1446
- this._editMode = true;
1447
- } else {
1448
- if (this._markers != null) {
1449
- this._markers.remove();
1450
- this._editMarkers.remove();
1451
- this._markers = null;
1452
- this._editMarkers = null;
1453
- this._globeClickhandler.destroy();
1454
- }
1455
- this._editMode = false;
1456
- }
1457
- }
1458
-
1459
- DrawHelper.PolylinePrimitive.prototype.setEditable = function () {
1460
- if (this.setEditMode) {
1461
- return;
1462
- }
1463
-
1464
- var polyline = this;
1465
- polyline.isPolygon = false;
1466
- polyline.asynchronous = false;
1467
-
1468
- drawHelper.registerEditableShape(polyline);
1469
-
1470
- polyline.setEditMode = setEditMode;
1471
-
1472
- var originalWidth = this.width;
1473
-
1474
- polyline.setHighlighted = function (highlighted) {
1475
- // disable if already in edit mode
1476
- if (this._editMode === true) {
1477
- return;
1478
- }
1479
- if (highlighted) {
1480
- drawHelper.setHighlighted(this);
1481
- this.setWidth(originalWidth * 2);
1482
- } else {
1483
- this.setWidth(originalWidth);
1484
- }
1485
- };
1486
-
1487
- polyline.getExtent = function () {
1488
- return Cesium.Extent.fromCartographicArray(
1489
- ellipsoid.cartesianArrayToCartographicArray(this.positions)
1490
- );
1491
- };
1492
-
1493
- enhanceWithListeners(polyline);
1494
-
1495
- polyline.setEditMode(false);
1496
- };
1497
-
1498
- DrawHelper.PolygonPrimitive.prototype.setEditable = function () {
1499
- var polygon = this;
1500
- polygon.asynchronous = false;
1501
-
1502
- var scene = drawHelper._scene;
1503
-
1504
- drawHelper.registerEditableShape(polygon);
1505
-
1506
- polygon.setEditMode = setEditMode;
1507
-
1508
- polygon.setHighlighted = setHighlighted;
1509
-
1510
- enhanceWithListeners(polygon);
1511
-
1512
- polygon.setEditMode(false);
1513
- };
1514
-
1515
- DrawHelper.ExtentPrimitive.prototype.setEditable = function () {
1516
- if (this.setEditMode) {
1517
- return;
1518
- }
1519
-
1520
- var extent = this;
1521
- var scene = drawHelper._scene;
1522
-
1523
- drawHelper.registerEditableShape(extent);
1524
- extent.asynchronous = false;
1525
-
1526
- extent.setEditMode = function (editMode) {
1527
- // if no change
1528
- if (this._editMode == editMode) {
1529
- return;
1530
- }
1531
- drawHelper.disableAllHighlights();
1532
- // display markers
1533
- if (editMode) {
1534
- // make sure all other shapes are not in edit mode before starting the editing of this shape
1535
- drawHelper.setEdited(this);
1536
- // create the markers and handlers for the editing
1537
- if (this._markers == null) {
1538
- var markers = new _.BillboardGroup(drawHelper, dragBillboard);
1539
- function onEdited() {
1540
- extent.executeListeners({
1541
- name: 'onEdited',
1542
- extent: extent.extent,
1543
- });
1544
- }
1545
- var handleMarkerChanges = {
1546
- dragHandlers: {
1547
- onDrag: function (index, position) {
1548
- var corner = markers.getBillboard((index + 2) % 4).position;
1549
- extent.setExtent(
1550
- getExtent(
1551
- ellipsoid.cartesianToCartographic(corner),
1552
- ellipsoid.cartesianToCartographic(position)
1553
- )
1554
- );
1555
- markers.updateBillboardsPositions(
1556
- getExtentCorners(extent.extent)
1557
- );
1558
- },
1559
- onDragEnd: function (index, position) {
1560
- onEdited();
1561
- },
1562
- },
1563
- tooltip: function () {
1564
- return 'Drag to change the corners of this extent';
1565
- },
1566
- };
1567
- markers.addBillboards(
1568
- getExtentCorners(extent.extent),
1569
- handleMarkerChanges
1570
- );
1571
- this._markers = markers;
1572
- // add a handler for clicking in the globe
1573
- this._globeClickhandler = new Cesium.ScreenSpaceEventHandler(
1574
- scene.canvas
1575
- );
1576
- this._globeClickhandler.setInputAction(function (movement) {
1577
- var pickedObject = scene.pick(movement.position);
1578
- // disable edit if pickedobject is different or not an object
1579
- if (
1580
- !(
1581
- pickedObject &&
1582
- !pickedObject.isDestroyed() &&
1583
- pickedObject.primitive
1584
- )
1585
- ) {
1586
- extent.setEditMode(false);
1587
- }
1588
- }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
1589
-
1590
- // set on top of the polygon
1591
- markers.setOnTop();
1592
- }
1593
- this._editMode = true;
1594
- } else {
1595
- if (this._markers != null) {
1596
- this._markers.remove();
1597
- this._markers = null;
1598
- this._globeClickhandler.destroy();
1599
- }
1600
- this._editMode = false;
1601
- }
1602
- };
1603
-
1604
- extent.setHighlighted = setHighlighted;
1605
-
1606
- enhanceWithListeners(extent);
1607
-
1608
- extent.setEditMode(false);
1609
- };
1610
-
1611
- _.EllipsePrimitive.prototype.setEditable = function () {
1612
- if (this.setEditMode) {
1613
- return;
1614
- }
1615
-
1616
- var ellipse = this;
1617
- var scene = drawHelper._scene;
1618
-
1619
- ellipse.asynchronous = false;
1620
-
1621
- drawHelper.registerEditableShape(ellipse);
1622
-
1623
- ellipse.setEditMode = function (editMode) {
1624
- // if no change
1625
- if (this._editMode == editMode) {
1626
- return;
1627
- }
1628
- drawHelper.disableAllHighlights();
1629
- // display markers
1630
- if (editMode) {
1631
- // make sure all other shapes are not in edit mode before starting the editing of this shape
1632
- drawHelper.setEdited(this);
1633
- var _self = this;
1634
- // create the markers and handlers for the editing
1635
- if (this._markers == null) {
1636
- var markers = new _.BillboardGroup(drawHelper, dragBillboard);
1637
- function getMarkerPositions() {
1638
- return Cesium.Shapes.computeEllipseBoundary(
1639
- ellipsoid,
1640
- ellipse.getCenter(),
1641
- ellipse.getSemiMajorAxis(),
1642
- ellipse.getSemiMinorAxis(),
1643
- ellipse.getRotation() + Math.PI / 2,
1644
- Math.PI / 2.0
1645
- ).splice(0, 4);
1646
- }
1647
- function onEdited() {
1648
- ellipse.executeListeners({
1649
- name: 'onEdited',
1650
- center: ellipse.getCenter(),
1651
- semiMajorAxis: ellipse.getSemiMajorAxis(),
1652
- semiMinorAxis: ellipse.getSemiMinorAxis(),
1653
- rotation: 0,
1654
- });
1655
- }
1656
- var handleMarkerChanges = {
1657
- dragHandlers: {
1658
- onDrag: function (index, position) {
1659
- var distance = Cesium.Cartesian3.distance(
1660
- ellipse.getCenter(),
1661
- position
1662
- );
1663
- if (index % 2 == 0) {
1664
- ellipse.setSemiMajorAxis(distance);
1665
- } else {
1666
- ellipse.setSemiMinorAxis(distance);
1667
- }
1668
- markers.updateBillboardsPositions(getMarkerPositions());
1669
- },
1670
- onDragEnd: function (index, position) {
1671
- onEdited();
1672
- },
1673
- },
1674
- tooltip: function () {
1675
- return 'Drag to change the excentricity and radius';
1676
- },
1677
- };
1678
- markers.addBillboards(getMarkerPositions(), handleMarkerChanges);
1679
- this._markers = markers;
1680
- // add a handler for clicking in the globe
1681
- this._globeClickhandler = new Cesium.ScreenSpaceEventHandler(
1682
- scene.canvas
1683
- );
1684
- this._globeClickhandler.setInputAction(function (movement) {
1685
- var pickedObject = scene.pick(movement.position);
1686
- if (!(pickedObject && pickedObject.primitive)) {
1687
- _self.setEditMode(false);
1688
- }
1689
- }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
1690
-
1691
- // set on top of the polygon
1692
- markers.setOnTop();
1693
- }
1694
- this._editMode = true;
1695
- } else {
1696
- if (this._markers != null) {
1697
- this._markers.remove();
1698
- this._markers = null;
1699
- this._globeClickhandler.destroy();
1700
- }
1701
- this._editMode = false;
1702
- }
1703
- };
1704
-
1705
- ellipse.setHighlighted = setHighlighted;
1706
-
1707
- enhanceWithListeners(ellipse);
1708
-
1709
- ellipse.setEditMode(false);
1710
- };
1711
-
1712
- _.CirclePrimitive.prototype.getCircleCartesianCoordinates = function (
1713
- granularity
1714
- ) {
1715
- var geometry = Cesium.CircleOutlineGeometry.createGeometry(
1716
- new Cesium.CircleOutlineGeometry({
1717
- ellipsoid: ellipsoid,
1718
- center: this.getCenter(),
1719
- radius: this.getRadius(),
1720
- granularity: granularity,
1721
- })
1722
- );
1723
- var count = 0,
1724
- value,
1725
- values = [];
1726
- for (; count < geometry.attributes.position.values.length; count += 3) {
1727
- value = geometry.attributes.position.values;
1728
- values.push(
1729
- new Cesium.Cartesian3(
1730
- value[count],
1731
- value[count + 1],
1732
- value[count + 2]
1733
- )
1734
- );
1735
- }
1736
- return values;
1737
- };
1738
-
1739
- _.CirclePrimitive.prototype.setEditable = function () {
1740
- if (this.setEditMode) {
1741
- return;
1742
- }
1743
-
1744
- var circle = this;
1745
- var scene = drawHelper._scene;
1746
-
1747
- circle.asynchronous = false;
1748
-
1749
- drawHelper.registerEditableShape(circle);
1750
-
1751
- circle.setEditMode = function (editMode) {
1752
- // if no change
1753
- if (this._editMode == editMode) {
1754
- return;
1755
- }
1756
- drawHelper.disableAllHighlights();
1757
- // display markers
1758
- if (editMode) {
1759
- // make sure all other shapes are not in edit mode before starting the editing of this shape
1760
- drawHelper.setEdited(this);
1761
- var _self = this;
1762
- // create the markers and handlers for the editing
1763
- if (this._markers == null) {
1764
- var markers = new _.BillboardGroup(drawHelper, dragBillboard);
1765
- function getMarkerPositions() {
1766
- return _self.getCircleCartesianCoordinates(
1767
- Cesium.Math.PI_OVER_TWO
1768
- );
1769
- }
1770
- function onEdited() {
1771
- circle.executeListeners({
1772
- name: 'onEdited',
1773
- center: circle.getCenter(),
1774
- radius: circle.getRadius(),
1775
- });
1776
- }
1777
- var handleMarkerChanges = {
1778
- dragHandlers: {
1779
- onDrag: function (index, position) {
1780
- circle.setRadius(
1781
- Cesium.Cartesian3.distance(circle.getCenter(), position)
1782
- );
1783
- markers.updateBillboardsPositions(getMarkerPositions());
1784
- },
1785
- onDragEnd: function (index, position) {
1786
- onEdited();
1787
- },
1788
- },
1789
- tooltip: function () {
1790
- return 'Drag to change the radius';
1791
- },
1792
- };
1793
- markers.addBillboards(getMarkerPositions(), handleMarkerChanges);
1794
- this._markers = markers;
1795
- // add a handler for clicking in the globe
1796
- this._globeClickhandler = new Cesium.ScreenSpaceEventHandler(
1797
- scene.canvas
1798
- );
1799
- this._globeClickhandler.setInputAction(function (movement) {
1800
- var pickedObject = scene.pick(movement.position);
1801
- if (!(pickedObject && pickedObject.primitive)) {
1802
- _self.setEditMode(false);
1803
- }
1804
- }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
1805
-
1806
- // set on top of the polygon
1807
- markers.setOnTop();
1808
- }
1809
- this._editMode = true;
1810
- } else {
1811
- if (this._markers != null) {
1812
- this._markers.remove();
1813
- this._markers = null;
1814
- this._globeClickhandler.destroy();
1815
- }
1816
- this._editMode = false;
1817
- }
1818
- };
1819
-
1820
- circle.setHighlighted = setHighlighted;
1821
-
1822
- enhanceWithListeners(circle);
1823
-
1824
- circle.setEditMode(false);
1825
- };
1826
- };
1827
-
1828
- _.DrawHelperWidget = (function () {
1829
- // constructor
1830
- function _(drawHelper, options) {
1831
- // container must be specified
1832
- if (!Cesium.defined(options.container)) {
1833
- throw new Cesium.DeveloperError('Container is required');
1834
- }
1835
-
1836
- var drawOptions = {
1837
- markerIcon: './assets/img/glyphicons_242_google_maps.png',
1838
- polylineIcon: './assets/img/glyphicons_097_vector_path_line.png',
1839
- polygonIcon: './assets/img/glyphicons_096_vector_path_polygon.png',
1840
- circleIcon: './assets/img/glyphicons_095_vector_path_circle.png',
1841
- extentIcon: './assets/img/glyphicons_094_vector_path_square.png',
1842
- clearIcon: './assets/img/glyphicons_067_cleaning.png',
1843
- polylineDrawingOptions: defaultPolylineOptions,
1844
- polygonDrawingOptions: defaultPolygonOptions,
1845
- extentDrawingOptions: defaultExtentOptions,
1846
- circleDrawingOptions: defaultCircleOptions,
1847
- };
1848
-
1849
- fillOptions(options, drawOptions);
1850
-
1851
- var _self = this;
1852
-
1853
- var toolbar = document.createElement('DIV');
1854
- toolbar.className = 'toolbar';
1855
- options.container.appendChild(toolbar);
1856
-
1857
- function addIcon(id, url, title, callback) {
1858
- var div = document.createElement('DIV');
1859
- div.className = 'button';
1860
- div.title = title;
1861
- toolbar.appendChild(div);
1862
- div.onclick = callback;
1863
- var span = document.createElement('SPAN');
1864
- div.appendChild(span);
1865
- var image = document.createElement('IMG');
1866
- image.src = url;
1867
- span.appendChild(image);
1868
- return div;
1869
- }
1870
-
1871
- var scene = drawHelper._scene;
1872
-
1873
- addIcon(
1874
- 'marker',
1875
- options.markerIcon,
1876
- 'Click to start drawing a 2D marker',
1877
- function () {
1878
- drawHelper.startDrawingMarker({
1879
- callback: function (position) {
1880
- _self.executeListeners({
1881
- name: 'markerCreated',
1882
- position: position,
1883
- });
1884
- },
1885
- });
1886
- }
1887
- );
1888
-
1889
- addIcon(
1890
- 'polyline',
1891
- options.polylineIcon,
1892
- 'Click to start drawing a 2D polyline',
1893
- function () {
1894
- drawHelper.startDrawingPolyline({
1895
- callback: function (positions) {
1896
- _self.executeListeners({
1897
- name: 'polylineCreated',
1898
- positions: positions,
1899
- });
1900
- },
1901
- });
1902
- }
1903
- );
1904
-
1905
- addIcon(
1906
- 'polygon',
1907
- options.polygonIcon,
1908
- 'Click to start drawing a 2D polygon',
1909
- function () {
1910
- drawHelper.startDrawingPolygon({
1911
- callback: function (positions) {
1912
- _self.executeListeners({
1913
- name: 'polygonCreated',
1914
- positions: positions,
1915
- });
1916
- },
1917
- });
1918
- }
1919
- );
1920
-
1921
- addIcon(
1922
- 'extent',
1923
- options.extentIcon,
1924
- 'Click to start drawing an Extent',
1925
- function () {
1926
- drawHelper.startDrawingExtent({
1927
- callback: function (extent) {
1928
- _self.executeListeners({ name: 'extentCreated', extent: extent });
1929
- },
1930
- });
1931
- }
1932
- );
1933
-
1934
- addIcon(
1935
- 'circle',
1936
- options.circleIcon,
1937
- 'Click to start drawing a Circle',
1938
- function () {
1939
- drawHelper.startDrawingCircle({
1940
- callback: function (center, radius) {
1941
- _self.executeListeners({
1942
- name: 'circleCreated',
1943
- center: center,
1944
- radius: radius,
1945
- });
1946
- },
1947
- });
1948
- }
1949
- );
1950
-
1951
- // add a clear button at the end
1952
- // add a divider first
1953
- var div = document.createElement('DIV');
1954
- div.className = 'divider';
1955
- toolbar.appendChild(div);
1956
- addIcon('clear', options.clearIcon, 'Remove all primitives', function () {
1957
- scene.primitives.removeAll();
1958
- });
1959
-
1960
- enhanceWithListeners(this);
1961
- }
1962
-
1963
- return _;
1964
- })();
1965
-
1966
- _.prototype.addToolbar = function (container, options) {
1967
- options = copyOptions(options, { container: container });
1968
- return new _.DrawHelperWidget(this, options);
1969
- };
1970
-
1971
- function getExtent(mn, mx) {
1972
- var e = new Cesium.Rectangle();
1973
-
1974
- // Re-order so west < east and south < north
1975
- e.west = Math.min(mn.longitude, mx.longitude);
1976
- e.east = Math.max(mn.longitude, mx.longitude);
1977
- e.south = Math.min(mn.latitude, mx.latitude);
1978
- e.north = Math.max(mn.latitude, mx.latitude);
1979
-
1980
- // Check for approx equal (shouldn't require abs due to re-order)
1981
- var epsilon = Cesium.Math.EPSILON7;
1982
-
1983
- if (e.east - e.west < epsilon) {
1984
- e.east += epsilon * 2.0;
1985
- }
1986
-
1987
- if (e.north - e.south < epsilon) {
1988
- e.north += epsilon * 2.0;
1989
- }
1990
-
1991
- return e;
1992
- }
1993
-
1994
- function createTooltip(frameDiv) {
1995
- var tooltip = function (frameDiv) {
1996
- var div = document.createElement('DIV');
1997
- div.className = 'twipsy right';
1998
-
1999
- var arrow = document.createElement('DIV');
2000
- arrow.className = 'twipsy-arrow';
2001
- div.appendChild(arrow);
2002
-
2003
- var title = document.createElement('DIV');
2004
- title.className = 'twipsy-inner';
2005
- div.appendChild(title);
2006
-
2007
- this._div = div;
2008
- this._title = title;
2009
-
2010
- // add to frame div and display coordinates
2011
- frameDiv.appendChild(div);
2012
- };
2013
-
2014
- tooltip.prototype.setVisible = function (visible) {
2015
- this._div.style.display = visible ? 'block' : 'none';
2016
- };
2017
-
2018
- tooltip.prototype.showAt = function (position, message) {
2019
- if (position && message) {
2020
- this.setVisible(true);
2021
- this._title.innerHTML = message;
2022
- this._div.style.left = position.x + 10 + 'px';
2023
- this._div.style.top = position.y - this._div.clientHeight / 2 + 'px';
2024
- }
2025
- };
2026
-
2027
- return new tooltip(frameDiv);
2028
- }
2029
-
2030
- function getDisplayLatLngString(cartographic, precision) {
2031
- return (
2032
- cartographic.longitude.toFixed(precision || 3) +
2033
- ', ' +
2034
- cartographic.latitude.toFixed(precision || 3)
2035
- );
2036
- }
2037
-
2038
- function clone(from, to) {
2039
- if (from == null || typeof from != 'object') return from;
2040
- if (from.constructor != Object && from.constructor != Array) return from;
2041
- if (
2042
- from.constructor == Date ||
2043
- from.constructor == RegExp ||
2044
- from.constructor == Function ||
2045
- from.constructor == String ||
2046
- from.constructor == Number ||
2047
- from.constructor == Boolean
2048
- )
2049
- return new from.constructor(from);
2050
-
2051
- to = to || new from.constructor();
2052
-
2053
- for (var name in from) {
2054
- to[name] =
2055
- typeof to[name] == 'undefined' ? clone(from[name], null) : to[name];
2056
- }
2057
-
2058
- return to;
2059
- }
2060
-
2061
- function fillOptions(options, defaultOptions) {
2062
- options = options || {};
2063
- var option;
2064
- for (option in defaultOptions) {
2065
- if (options[option] === undefined) {
2066
- options[option] = clone(defaultOptions[option]);
2067
- }
2068
- }
2069
- }
2070
-
2071
- // shallow copy
2072
- function copyOptions(options, defaultOptions) {
2073
- var newOptions = clone(options),
2074
- option;
2075
- for (option in defaultOptions) {
2076
- if (newOptions[option] === undefined) {
2077
- newOptions[option] = clone(defaultOptions[option]);
2078
- }
2079
- }
2080
- return newOptions;
2081
- }
2082
-
2083
- function setListener(primitive, type, callback) {
2084
- primitive[type] = callback;
2085
- }
2086
-
2087
- function enhanceWithListeners(element) {
2088
- element._listeners = {};
2089
-
2090
- element.addListener = function (name, callback) {
2091
- this._listeners[name] = this._listeners[name] || [];
2092
- this._listeners[name].push(callback);
2093
- return this._listeners[name].length;
2094
- };
2095
-
2096
- element.executeListeners = function (event, defaultCallback) {
2097
- if (
2098
- this._listeners[event.name] &&
2099
- this._listeners[event.name].length > 0
2100
- ) {
2101
- var index = 0;
2102
- for (; index < this._listeners[event.name].length; index++) {
2103
- this._listeners[event.name][index](event);
2104
- }
2105
- } else {
2106
- if (defaultCallback) {
2107
- defaultCallback(event);
2108
- }
2109
- }
2110
- };
2111
- }
2112
-
2113
- return _;
2114
- })();
2115
-
2116
- export { DrawHelper };
1
+ // inspired by https://github.com/leforthomas/cesium-drawhelper
2
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3
+ // @ts-nocheck
4
+ import * as Cesium from 'cesium';
5
+ import './drawHelper.css';
6
+ /* eslint-disable */
7
+ var DrawHelper = (function () {
8
+ // static variables
9
+ var ellipsoid = Cesium.Ellipsoid.WGS84;
10
+ var drawingVertexColor;
11
+ var material = Cesium.Material.fromType(Cesium.Material.ColorType);
12
+
13
+ // constructor
14
+ function _(
15
+ cesiumWidget,
16
+ materialClr = new Cesium.Color(1.0, 1.0, 0.0, 0.5),
17
+ drawingVertexClr = new Cesium.Color(1.0, 1.0, 1.0, 1.0)
18
+ ) {
19
+ this._scene = cesiumWidget.scene;
20
+
21
+ // UPDATE scoped varibles
22
+ material.uniforms.color = materialClr;
23
+ drawingVertexColor = drawingVertexClr;
24
+
25
+ //MC_CHANGE disable/override tooltip
26
+ this._tooltip = {
27
+ setVisible: () => {},
28
+ showAt: () => {},
29
+ };
30
+ // this._tooltip = createTooltip(cesiumWidget.container);
31
+ this._surfaces = [];
32
+
33
+ this.initialiseHandlers();
34
+
35
+ this.enhancePrimitives();
36
+ }
37
+
38
+ _.prototype.initialiseHandlers = function () {
39
+ var scene = this._scene;
40
+ var _self = this;
41
+ // scene events
42
+ var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
43
+ function callPrimitiveCallback(name, position) {
44
+ if (_self._handlersMuted == true) return;
45
+ var pickedObject = scene.pick(position);
46
+ if (
47
+ pickedObject &&
48
+ pickedObject.primitive &&
49
+ pickedObject.primitive[name]
50
+ ) {
51
+ pickedObject.primitive[name](position);
52
+ }
53
+ }
54
+ handler.setInputAction(function (movement) {
55
+ callPrimitiveCallback('leftClick', movement.position);
56
+ }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
57
+ handler.setInputAction(function (movement) {
58
+ callPrimitiveCallback('leftDoubleClick', movement.position);
59
+ }, Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
60
+ var mouseOutObject;
61
+ handler.setInputAction(function (movement) {
62
+ if (_self._handlersMuted == true) return;
63
+ var pickedObject = scene.pick(movement.endPosition);
64
+ if (
65
+ mouseOutObject &&
66
+ (!pickedObject || mouseOutObject != pickedObject.primitive)
67
+ ) {
68
+ !(mouseOutObject.isDestroyed && mouseOutObject.isDestroyed()) &&
69
+ mouseOutObject.mouseOut(movement.endPosition);
70
+ mouseOutObject = null;
71
+ }
72
+ if (pickedObject && pickedObject.primitive) {
73
+ pickedObject = pickedObject.primitive;
74
+ if (pickedObject.mouseOut) {
75
+ mouseOutObject = pickedObject;
76
+ }
77
+ if (pickedObject.mouseMove) {
78
+ pickedObject.mouseMove(movement.endPosition);
79
+ }
80
+ }
81
+ }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
82
+ handler.setInputAction(function (movement) {
83
+ callPrimitiveCallback('leftUp', movement.position);
84
+ }, Cesium.ScreenSpaceEventType.LEFT_UP);
85
+ handler.setInputAction(function (movement) {
86
+ callPrimitiveCallback('leftDown', movement.position);
87
+ }, Cesium.ScreenSpaceEventType.LEFT_DOWN);
88
+ };
89
+
90
+ _.prototype.setListener = function (primitive, type, callback) {
91
+ primitive[type] = callback;
92
+ };
93
+
94
+ _.prototype.muteHandlers = function (muted) {
95
+ this._handlersMuted = muted;
96
+ };
97
+
98
+ // register event handling for an editable shape
99
+ // shape should implement setEditMode and setHighlighted
100
+ _.prototype.registerEditableShape = function (surface) {
101
+ var _self = this;
102
+
103
+ // handlers for interactions
104
+ // highlight polygon when mouse is entering
105
+ setListener(surface, 'mouseMove', function (position) {
106
+ surface.setHighlighted(true);
107
+ if (!surface._editMode) {
108
+ _self._tooltip.showAt(position, 'Click to edit this shape');
109
+ }
110
+ });
111
+ // hide the highlighting when mouse is leaving the polygon
112
+ setListener(surface, 'mouseOut', function (position) {
113
+ surface.setHighlighted(false);
114
+ _self._tooltip.setVisible(false);
115
+ });
116
+ setListener(surface, 'leftClick', function (position) {
117
+ surface.setEditMode(true);
118
+ });
119
+ };
120
+
121
+ _.prototype.startDrawing = function (cleanUp) {
122
+ // undo any current edit of shapes
123
+ this.disableAllEditMode();
124
+ // check for cleanUp first
125
+ if (this.editCleanUp) {
126
+ this.editCleanUp();
127
+ }
128
+ this.editCleanUp = cleanUp;
129
+ this.muteHandlers(true);
130
+ };
131
+
132
+ _.prototype.stopDrawing = function () {
133
+ // check for cleanUp first
134
+ if (this.editCleanUp) {
135
+ this.editCleanUp();
136
+ this.editCleanUp = null;
137
+ }
138
+ this.muteHandlers(false);
139
+ };
140
+
141
+ // make sure only one shape is highlighted at a time
142
+ _.prototype.disableAllHighlights = function () {
143
+ this.setHighlighted(undefined);
144
+ };
145
+
146
+ _.prototype.setHighlighted = function (surface) {
147
+ if (
148
+ this._highlightedSurface &&
149
+ !this._highlightedSurface.isDestroyed() &&
150
+ this._highlightedSurface != surface
151
+ ) {
152
+ this._highlightedSurface.setHighlighted(false);
153
+ }
154
+ this._highlightedSurface = surface;
155
+ };
156
+
157
+ _.prototype.disableAllEditMode = function () {
158
+ this.setEdited(undefined);
159
+ };
160
+
161
+ _.prototype.setEdited = function (surface) {
162
+ if (this._editedSurface && !this._editedSurface.isDestroyed()) {
163
+ this._editedSurface.setEditMode(false);
164
+ }
165
+ this._editedSurface = surface;
166
+ };
167
+
168
+ var defaultShapeOptions = {
169
+ ellipsoid: Cesium.Ellipsoid.WGS84,
170
+ textureRotationAngle: 0.0,
171
+ height: 0.0,
172
+ asynchronous: true,
173
+ show: true,
174
+ debugShowBoundingVolume: false,
175
+ };
176
+
177
+ var defaultSurfaceOptions = copyOptions(defaultShapeOptions, {
178
+ appearance: new Cesium.EllipsoidSurfaceAppearance({
179
+ aboveGround: false,
180
+ }),
181
+ material: material,
182
+ granularity: Math.PI / 180.0,
183
+ });
184
+
185
+ var defaultPolygonOptions = copyOptions(defaultShapeOptions, {});
186
+ var defaultExtentOptions = copyOptions(defaultShapeOptions, {});
187
+ var defaultCircleOptions = copyOptions(defaultShapeOptions, {});
188
+ var defaultEllipseOptions = copyOptions(defaultSurfaceOptions, {
189
+ rotation: 0,
190
+ });
191
+
192
+ var defaultPolylineOptions = copyOptions(defaultShapeOptions, {
193
+ width: 5,
194
+ geodesic: true,
195
+ granularity: 10000,
196
+ appearance: new Cesium.PolylineMaterialAppearance({
197
+ aboveGround: false,
198
+ }),
199
+ material: material,
200
+ });
201
+
202
+ // Cesium.Polygon.prototype.setStrokeStyle = setStrokeStyle;
203
+ //
204
+ // Cesium.Polygon.prototype.drawOutline = drawOutline;
205
+ //
206
+
207
+ var ChangeablePrimitive = (function () {
208
+ function _() {}
209
+
210
+ _.prototype.initialiseOptions = function (options) {
211
+ fillOptions(this, options);
212
+
213
+ this._ellipsoid = undefined;
214
+ this._granularity = undefined;
215
+ this._height = undefined;
216
+ this._textureRotationAngle = undefined;
217
+ this._id = undefined;
218
+
219
+ // set the flags to initiate a first drawing
220
+ this._createPrimitive = true;
221
+ this._primitive = undefined;
222
+ this._outlinePolygon = undefined;
223
+ };
224
+
225
+ _.prototype.setAttribute = function (name, value) {
226
+ this[name] = value;
227
+ this._createPrimitive = true;
228
+ };
229
+
230
+ _.prototype.getAttribute = function (name) {
231
+ return this[name];
232
+ };
233
+
234
+ /**
235
+ * @private
236
+ */
237
+ _.prototype.update = function (context, frameState, commandList) {
238
+ if (!Cesium.defined(this.ellipsoid)) {
239
+ throw new Cesium.DeveloperError('this.ellipsoid must be defined.');
240
+ }
241
+
242
+ if (!Cesium.defined(this.appearance)) {
243
+ throw new Cesium.DeveloperError('this.material must be defined.');
244
+ }
245
+
246
+ if (this.granularity < 0.0) {
247
+ throw new Cesium.DeveloperError(
248
+ 'this.granularity and scene2D/scene3D overrides must be greater than zero.'
249
+ );
250
+ }
251
+
252
+ if (!this.show) {
253
+ return;
254
+ }
255
+
256
+ if (!this._createPrimitive && !Cesium.defined(this._primitive)) {
257
+ // No positions/hierarchy to draw
258
+ return;
259
+ }
260
+
261
+ if (
262
+ this._createPrimitive ||
263
+ this._ellipsoid !== this.ellipsoid ||
264
+ this._granularity !== this.granularity ||
265
+ this._height !== this.height ||
266
+ this._textureRotationAngle !== this.textureRotationAngle ||
267
+ this._id !== this.id
268
+ ) {
269
+ var geometry = this.getGeometry();
270
+ if (!geometry) {
271
+ return;
272
+ }
273
+
274
+ this._createPrimitive = false;
275
+ this._ellipsoid = this.ellipsoid;
276
+ this._granularity = this.granularity;
277
+ this._height = this.height;
278
+ this._textureRotationAngle = this.textureRotationAngle;
279
+ this._id = this.id;
280
+
281
+ this._primitive = this._primitive && this._primitive.destroy();
282
+
283
+ this._primitive = new Cesium.Primitive({
284
+ geometryInstances: new Cesium.GeometryInstance({
285
+ geometry: geometry,
286
+ id: this.id,
287
+ pickPrimitive: this,
288
+ }),
289
+ appearance: this.appearance,
290
+ asynchronous: this.asynchronous,
291
+ });
292
+
293
+ this._outlinePolygon =
294
+ this._outlinePolygon && this._outlinePolygon.destroy();
295
+ if (this.strokeColor && this.getOutlineGeometry) {
296
+ // create the highlighting frame
297
+ this._outlinePolygon = new Cesium.Primitive({
298
+ geometryInstances: new Cesium.GeometryInstance({
299
+ geometry: this.getOutlineGeometry(),
300
+ attributes: {
301
+ color: Cesium.ColorGeometryInstanceAttribute.fromColor(
302
+ this.strokeColor
303
+ ),
304
+ },
305
+ }),
306
+ appearance: new Cesium.PerInstanceColorAppearance({
307
+ flat: true,
308
+ renderState: {
309
+ depthTest: {
310
+ enabled: true,
311
+ },
312
+ //MC_CHANGE
313
+ lineWidth: this.strokeWidth || 4.0,
314
+ // lineWidth : Math.min(this.strokeWidth || 4.0, context._aliasedLineWidthRange[1])
315
+ },
316
+ }),
317
+ });
318
+ }
319
+ }
320
+
321
+ var primitive = this._primitive;
322
+ primitive.appearance.material = this.material;
323
+ primitive.debugShowBoundingVolume = this.debugShowBoundingVolume;
324
+
325
+ primitive.update(context, frameState, commandList);
326
+
327
+ this._outlinePolygon &&
328
+ this._outlinePolygon.update(context, frameState, commandList);
329
+ };
330
+
331
+ _.prototype.isDestroyed = function () {
332
+ return false;
333
+ };
334
+
335
+ _.prototype.destroy = function () {
336
+ this._primitive = this._primitive && this._primitive.destroy();
337
+ return Cesium.destroyObject(this);
338
+ };
339
+
340
+ _.prototype.setStrokeStyle = function (strokeColor, strokeWidth) {
341
+ if (
342
+ !this.strokeColor ||
343
+ !this.strokeColor.equals(strokeColor) ||
344
+ this.strokeWidth != strokeWidth
345
+ ) {
346
+ this._createPrimitive = true;
347
+ this.strokeColor = strokeColor;
348
+ this.strokeWidth = strokeWidth;
349
+ }
350
+ };
351
+
352
+ return _;
353
+ })();
354
+
355
+ _.ExtentPrimitive = (function () {
356
+ function _(options) {
357
+ if (!Cesium.defined(options.extent)) {
358
+ throw new Cesium.DeveloperError('Extent is required');
359
+ }
360
+
361
+ options = copyOptions(options, defaultSurfaceOptions);
362
+
363
+ this.initialiseOptions(options);
364
+
365
+ this.setExtent(options.extent);
366
+ }
367
+
368
+ _.prototype = new ChangeablePrimitive();
369
+
370
+ _.prototype.setExtent = function (extent) {
371
+ this.setAttribute('extent', extent);
372
+ };
373
+
374
+ _.prototype.getExtent = function () {
375
+ return this.getAttribute('extent');
376
+ };
377
+
378
+ _.prototype.getGeometry = function () {
379
+ if (!Cesium.defined(this.extent)) {
380
+ return;
381
+ }
382
+
383
+ return new Cesium.RectangleGeometry({
384
+ rectangle: this.extent,
385
+ height: this.height,
386
+ vertexFormat: Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT,
387
+ stRotation: this.textureRotationAngle,
388
+ ellipsoid: this.ellipsoid,
389
+ granularity: this.granularity,
390
+ });
391
+ };
392
+
393
+ _.prototype.getOutlineGeometry = function () {
394
+ return new Cesium.RectangleOutlineGeometry({
395
+ rectangle: this.extent,
396
+ });
397
+ };
398
+
399
+ return _;
400
+ })();
401
+
402
+ _.PolygonPrimitive = (function () {
403
+ function _(options) {
404
+ options = copyOptions(options, defaultSurfaceOptions);
405
+
406
+ this.initialiseOptions(options);
407
+
408
+ this.isPolygon = true;
409
+ }
410
+
411
+ _.prototype = new ChangeablePrimitive();
412
+
413
+ _.prototype.setPositions = function (positions) {
414
+ this.setAttribute('positions', positions);
415
+ };
416
+
417
+ _.prototype.getPositions = function () {
418
+ return this.getAttribute('positions');
419
+ };
420
+
421
+ _.prototype.getGeometry = function () {
422
+ if (!Cesium.defined(this.positions) || this.positions.length < 3) {
423
+ return;
424
+ }
425
+
426
+ return Cesium.PolygonGeometry.fromPositions({
427
+ positions: this.positions,
428
+ height: this.height,
429
+ vertexFormat: Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT,
430
+ stRotation: this.textureRotationAngle,
431
+ ellipsoid: this.ellipsoid,
432
+ granularity: this.granularity,
433
+ });
434
+ };
435
+
436
+ _.prototype.getOutlineGeometry = function () {
437
+ return Cesium.PolygonOutlineGeometry.fromPositions({
438
+ positions: this.getPositions(),
439
+ });
440
+ };
441
+
442
+ return _;
443
+ })();
444
+
445
+ _.CirclePrimitive = (function () {
446
+ function _(options) {
447
+ if (!(Cesium.defined(options.center) && Cesium.defined(options.radius))) {
448
+ throw new Cesium.DeveloperError('Center and radius are required');
449
+ }
450
+
451
+ options = copyOptions(options, defaultSurfaceOptions);
452
+
453
+ this.initialiseOptions(options);
454
+
455
+ this.setRadius(options.radius);
456
+ }
457
+
458
+ _.prototype = new ChangeablePrimitive();
459
+
460
+ _.prototype.setCenter = function (center) {
461
+ this.setAttribute('center', center);
462
+ };
463
+
464
+ _.prototype.setRadius = function (radius) {
465
+ this.setAttribute('radius', Math.max(0.1, radius));
466
+ };
467
+
468
+ _.prototype.getCenter = function () {
469
+ return this.getAttribute('center');
470
+ };
471
+
472
+ _.prototype.getRadius = function () {
473
+ return this.getAttribute('radius');
474
+ };
475
+
476
+ _.prototype.getGeometry = function () {
477
+ if (!(Cesium.defined(this.center) && Cesium.defined(this.radius))) {
478
+ return;
479
+ }
480
+
481
+ return new Cesium.CircleGeometry({
482
+ center: this.center,
483
+ radius: this.radius,
484
+ height: this.height,
485
+ vertexFormat: Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT,
486
+ stRotation: this.textureRotationAngle,
487
+ ellipsoid: this.ellipsoid,
488
+ granularity: this.granularity,
489
+ });
490
+ };
491
+
492
+ _.prototype.getOutlineGeometry = function () {
493
+ return new Cesium.CircleOutlineGeometry({
494
+ center: this.getCenter(),
495
+ radius: this.getRadius(),
496
+ });
497
+ };
498
+
499
+ return _;
500
+ })();
501
+
502
+ _.EllipsePrimitive = (function () {
503
+ function _(options) {
504
+ if (
505
+ !(
506
+ Cesium.defined(options.center) &&
507
+ Cesium.defined(options.semiMajorAxis) &&
508
+ Cesium.defined(options.semiMinorAxis)
509
+ )
510
+ ) {
511
+ throw new Cesium.DeveloperError(
512
+ 'Center and semi major and semi minor axis are required'
513
+ );
514
+ }
515
+
516
+ options = copyOptions(options, defaultEllipseOptions);
517
+
518
+ this.initialiseOptions(options);
519
+ }
520
+
521
+ _.prototype = new ChangeablePrimitive();
522
+
523
+ _.prototype.setCenter = function (center) {
524
+ this.setAttribute('center', center);
525
+ };
526
+
527
+ _.prototype.setSemiMajorAxis = function (semiMajorAxis) {
528
+ if (semiMajorAxis < this.getSemiMinorAxis()) return;
529
+ this.setAttribute('semiMajorAxis', semiMajorAxis);
530
+ };
531
+
532
+ _.prototype.setSemiMinorAxis = function (semiMinorAxis) {
533
+ if (semiMinorAxis > this.getSemiMajorAxis()) return;
534
+ this.setAttribute('semiMinorAxis', semiMinorAxis);
535
+ };
536
+
537
+ _.prototype.setRotation = function (rotation) {
538
+ return this.setAttribute('rotation', rotation);
539
+ };
540
+
541
+ _.prototype.getCenter = function () {
542
+ return this.getAttribute('center');
543
+ };
544
+
545
+ _.prototype.getSemiMajorAxis = function () {
546
+ return this.getAttribute('semiMajorAxis');
547
+ };
548
+
549
+ _.prototype.getSemiMinorAxis = function () {
550
+ return this.getAttribute('semiMinorAxis');
551
+ };
552
+
553
+ _.prototype.getRotation = function () {
554
+ return this.getAttribute('rotation');
555
+ };
556
+
557
+ _.prototype.getGeometry = function () {
558
+ if (
559
+ !(
560
+ Cesium.defined(this.center) &&
561
+ Cesium.defined(this.semiMajorAxis) &&
562
+ Cesium.defined(this.semiMinorAxis)
563
+ )
564
+ ) {
565
+ return;
566
+ }
567
+
568
+ return new Cesium.EllipseGeometry({
569
+ ellipsoid: this.ellipsoid,
570
+ center: this.center,
571
+ semiMajorAxis: this.semiMajorAxis,
572
+ semiMinorAxis: this.semiMinorAxis,
573
+ rotation: this.rotation,
574
+ height: this.height,
575
+ vertexFormat: Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT,
576
+ stRotation: this.textureRotationAngle,
577
+ ellipsoid: this.ellipsoid,
578
+ granularity: this.granularity,
579
+ });
580
+ };
581
+
582
+ _.prototype.getOutlineGeometry = function () {
583
+ return new Cesium.EllipseOutlineGeometry({
584
+ center: this.getCenter(),
585
+ semiMajorAxis: this.getSemiMajorAxis(),
586
+ semiMinorAxis: this.getSemiMinorAxis(),
587
+ rotation: this.getRotation(),
588
+ });
589
+ };
590
+
591
+ return _;
592
+ })();
593
+
594
+ _.PolylinePrimitive = (function () {
595
+ function _(options) {
596
+ options = copyOptions(options, defaultPolylineOptions);
597
+
598
+ this.initialiseOptions(options);
599
+ }
600
+
601
+ _.prototype = new ChangeablePrimitive();
602
+
603
+ _.prototype.setPositions = function (positions) {
604
+ this.setAttribute('positions', positions);
605
+ };
606
+
607
+ _.prototype.setWidth = function (width) {
608
+ this.setAttribute('width', width);
609
+ };
610
+
611
+ _.prototype.setGeodesic = function (geodesic) {
612
+ this.setAttribute('geodesic', geodesic);
613
+ };
614
+
615
+ _.prototype.getPositions = function () {
616
+ return this.getAttribute('positions');
617
+ };
618
+
619
+ _.prototype.getWidth = function () {
620
+ return this.getAttribute('width');
621
+ };
622
+
623
+ _.prototype.getGeodesic = function (geodesic) {
624
+ return this.getAttribute('geodesic');
625
+ };
626
+
627
+ _.prototype.getGeometry = function () {
628
+ if (!Cesium.defined(this.positions) || this.positions.length < 2) {
629
+ return;
630
+ }
631
+
632
+ return new Cesium.PolylineGeometry({
633
+ positions: this.positions,
634
+ height: this.height,
635
+ width: this.width < 1 ? 1 : this.width,
636
+ vertexFormat: Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT,
637
+ ellipsoid: this.ellipsoid,
638
+ });
639
+ };
640
+
641
+ return _;
642
+ })();
643
+
644
+ var defaultBillboard = {
645
+ iconUrl: './assets/img/dragIcon.png',
646
+ shiftX: 0,
647
+ shiftY: 0,
648
+ };
649
+
650
+ var dragBillboard = {
651
+ iconUrl: './assets/img/dragIcon.png',
652
+ shiftX: 0,
653
+ shiftY: 0,
654
+ };
655
+
656
+ var dragHalfBillboard = {
657
+ iconUrl: './assets/img/dragIconLight.png',
658
+ shiftX: 0,
659
+ shiftY: 0,
660
+ };
661
+
662
+ _.prototype.createBillboardGroup = function (points, options, callbacks) {
663
+ var markers = new _.BillboardGroup(this, options);
664
+ markers.addBillboards(points, callbacks);
665
+ return markers;
666
+ };
667
+
668
+ _.BillboardGroup = function (drawHelper, options) {
669
+ this._drawHelper = drawHelper;
670
+ this._scene = drawHelper._scene;
671
+
672
+ this._options = copyOptions(options, defaultBillboard);
673
+
674
+ // create one common billboard collection for all billboards
675
+ var b = new Cesium.BillboardCollection();
676
+ this._scene.primitives.add(b);
677
+ this._billboards = b;
678
+ // keep an ordered list of billboards
679
+ this._orderedBillboards = [];
680
+ };
681
+
682
+ _.BillboardGroup.prototype.createBillboard = function (position, callbacks) {
683
+ var billboard = this._billboards.add({
684
+ show: true,
685
+ position: position,
686
+ pixelOffset: new Cesium.Cartesian2(
687
+ this._options.shiftX,
688
+ this._options.shiftY
689
+ ),
690
+ eyeOffset: new Cesium.Cartesian3(0.0, 0.0, 0.0),
691
+ horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
692
+ verticalOrigin: Cesium.VerticalOrigin.CENTER,
693
+ scale: 1.0,
694
+ image: this._options.iconUrl,
695
+ color: drawingVertexColor,
696
+ });
697
+
698
+ // if editable
699
+ if (callbacks) {
700
+ var _self = this;
701
+ var screenSpaceCameraController = this._scene.screenSpaceCameraController;
702
+ function enableRotation(enable) {
703
+ screenSpaceCameraController.enableRotate = enable;
704
+ }
705
+ function getIndex() {
706
+ // find index
707
+ for (
708
+ var i = 0, I = _self._orderedBillboards.length;
709
+ i < I && _self._orderedBillboards[i] != billboard;
710
+ ++i
711
+ );
712
+ return i;
713
+ }
714
+ if (callbacks.dragHandlers) {
715
+ var _self = this;
716
+ setListener(billboard, 'leftDown', function (position) {
717
+ // TODO - start the drag handlers here
718
+ // create handlers for mouseOut and leftUp for the billboard and a mouseMove
719
+ function onDrag(position) {
720
+ billboard.position = position;
721
+ // find index
722
+ for (
723
+ var i = 0, I = _self._orderedBillboards.length;
724
+ i < I && _self._orderedBillboards[i] != billboard;
725
+ ++i
726
+ );
727
+ callbacks.dragHandlers.onDrag &&
728
+ callbacks.dragHandlers.onDrag(getIndex(), position);
729
+ }
730
+ function onDragEnd(position) {
731
+ handler.destroy();
732
+ enableRotation(true);
733
+ callbacks.dragHandlers.onDragEnd &&
734
+ callbacks.dragHandlers.onDragEnd(getIndex(), position);
735
+ }
736
+
737
+ var handler = new Cesium.ScreenSpaceEventHandler(_self._scene.canvas);
738
+
739
+ handler.setInputAction(function (movement) {
740
+ var cartesian = _self._scene.camera.pickEllipsoid(
741
+ movement.endPosition,
742
+ ellipsoid
743
+ );
744
+ if (cartesian) {
745
+ onDrag(cartesian);
746
+ } else {
747
+ onDragEnd(cartesian);
748
+ }
749
+ }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
750
+
751
+ handler.setInputAction(function (movement) {
752
+ onDragEnd(
753
+ _self._scene.camera.pickEllipsoid(movement.position, ellipsoid)
754
+ );
755
+ }, Cesium.ScreenSpaceEventType.LEFT_UP);
756
+
757
+ enableRotation(false);
758
+
759
+ callbacks.dragHandlers.onDragStart &&
760
+ callbacks.dragHandlers.onDragStart(
761
+ getIndex(),
762
+ _self._scene.camera.pickEllipsoid(position, ellipsoid)
763
+ );
764
+ });
765
+ }
766
+ if (callbacks.onDoubleClick) {
767
+ setListener(billboard, 'leftDoubleClick', function (position) {
768
+ callbacks.onDoubleClick(getIndex());
769
+ });
770
+ }
771
+ if (callbacks.onClick) {
772
+ setListener(billboard, 'leftClick', function (position) {
773
+ callbacks.onClick(getIndex());
774
+ });
775
+ }
776
+ if (callbacks.tooltip) {
777
+ setListener(billboard, 'mouseMove', function (position) {
778
+ _self._drawHelper._tooltip.showAt(position, callbacks.tooltip());
779
+ });
780
+ setListener(billboard, 'mouseOut', function (position) {
781
+ _self._drawHelper._tooltip.setVisible(false);
782
+ });
783
+ }
784
+ }
785
+
786
+ return billboard;
787
+ };
788
+
789
+ _.BillboardGroup.prototype.insertBillboard = function (
790
+ index,
791
+ position,
792
+ callbacks
793
+ ) {
794
+ this._orderedBillboards.splice(
795
+ index,
796
+ 0,
797
+ this.createBillboard(position, callbacks)
798
+ );
799
+ };
800
+
801
+ _.BillboardGroup.prototype.addBillboard = function (position, callbacks) {
802
+ this._orderedBillboards.push(this.createBillboard(position, callbacks));
803
+ };
804
+
805
+ _.BillboardGroup.prototype.addBillboards = function (positions, callbacks) {
806
+ var index = 0;
807
+ for (; index < positions.length; index++) {
808
+ this.addBillboard(positions[index], callbacks);
809
+ }
810
+ };
811
+
812
+ _.BillboardGroup.prototype.updateBillboardsPositions = function (positions) {
813
+ var index = 0;
814
+ for (; index < positions.length; index++) {
815
+ this.getBillboard(index).position = positions[index];
816
+ }
817
+ };
818
+
819
+ _.BillboardGroup.prototype.countBillboards = function () {
820
+ return this._orderedBillboards.length;
821
+ };
822
+
823
+ _.BillboardGroup.prototype.getBillboard = function (index) {
824
+ return this._orderedBillboards[index];
825
+ };
826
+
827
+ _.BillboardGroup.prototype.removeBillboard = function (index) {
828
+ this._billboards.remove(this.getBillboard(index));
829
+ this._orderedBillboards.splice(index, 1);
830
+ };
831
+
832
+ _.BillboardGroup.prototype.remove = function () {
833
+ this._billboards =
834
+ this._billboards &&
835
+ this._billboards.removeAll() &&
836
+ this._billboards.destroy();
837
+ };
838
+
839
+ _.BillboardGroup.prototype.setOnTop = function () {
840
+ this._scene.primitives.raiseToTop(this._billboards);
841
+ };
842
+
843
+ _.prototype.startDrawingMarker = function (options) {
844
+ var options = copyOptions(options, defaultBillboard);
845
+
846
+ this.startDrawing(function () {
847
+ markers.remove();
848
+ mouseHandler.destroy();
849
+ tooltip.setVisible(false);
850
+ });
851
+
852
+ var _self = this;
853
+ var scene = this._scene;
854
+ var primitives = scene.primitives;
855
+ var tooltip = this._tooltip;
856
+
857
+ var markers = new _.BillboardGroup(this, options);
858
+
859
+ var mouseHandler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
860
+
861
+ // Now wait for start
862
+ mouseHandler.setInputAction(function (movement) {
863
+ if (movement.position != null) {
864
+ var cartesian = scene.camera.pickEllipsoid(
865
+ movement.position,
866
+ ellipsoid
867
+ );
868
+ if (cartesian) {
869
+ markers.addBillboard(cartesian);
870
+ _self.stopDrawing();
871
+ options.callback(cartesian);
872
+ }
873
+ }
874
+ }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
875
+
876
+ mouseHandler.setInputAction(function (movement) {
877
+ var position = movement.endPosition;
878
+ if (position != null) {
879
+ var cartesian = scene.camera.pickEllipsoid(position, ellipsoid);
880
+ if (cartesian) {
881
+ tooltip.showAt(
882
+ position,
883
+ '<p>Click to add your marker. Position is: </p>' +
884
+ getDisplayLatLngString(
885
+ ellipsoid.cartesianToCartographic(cartesian)
886
+ )
887
+ );
888
+ } else {
889
+ tooltip.showAt(
890
+ position,
891
+ '<p>Click on the globe to add your marker.</p>'
892
+ );
893
+ }
894
+ }
895
+ }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
896
+ };
897
+
898
+ _.prototype.startDrawingPolygon = function (options) {
899
+ var options = copyOptions(options, defaultSurfaceOptions);
900
+ this.startDrawingPolyshape(true, options);
901
+ };
902
+
903
+ _.prototype.startDrawingPolyline = function (options) {
904
+ var options = copyOptions(options, defaultPolylineOptions);
905
+ this.startDrawingPolyshape(false, options);
906
+ };
907
+
908
+ _.prototype.startDrawingPolyshape = function (isPolygon, options) {
909
+ this.startDrawing(function () {
910
+ primitives.remove(poly);
911
+ markers.remove();
912
+ mouseHandler.destroy();
913
+ tooltip.setVisible(false);
914
+ unsetDrawCursor(scene);
915
+ });
916
+
917
+ var _self = this;
918
+ var scene = this._scene;
919
+ var primitives = scene.primitives;
920
+ var tooltip = this._tooltip;
921
+
922
+ var minPoints = isPolygon ? 3 : 2;
923
+ var poly;
924
+ if (isPolygon) {
925
+ poly = new DrawHelper.PolygonPrimitive(options);
926
+ } else {
927
+ poly = new DrawHelper.PolylinePrimitive(options);
928
+ }
929
+ poly.asynchronous = false;
930
+ primitives.add(poly);
931
+
932
+ var positions = [];
933
+ var markers = new _.BillboardGroup(this, defaultBillboard);
934
+
935
+ var mouseHandler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
936
+ setDrawCursor(scene);
937
+
938
+ // Now wait for start
939
+ mouseHandler.setInputAction(function (movement) {
940
+ if (movement.position != null) {
941
+ var cartesian = scene.camera.pickEllipsoid(
942
+ movement.position,
943
+ ellipsoid
944
+ );
945
+ if (cartesian) {
946
+ // first click
947
+ if (positions.length == 0) {
948
+ positions.push(cartesian.clone());
949
+ markers.addBillboard(positions[0]);
950
+ }
951
+ if (positions.length >= minPoints) {
952
+ poly.positions = positions;
953
+ poly._createPrimitive = true;
954
+ }
955
+ // add new point to polygon
956
+ // this one will move with the mouse
957
+ positions.push(cartesian);
958
+ // add marker at the new position
959
+ markers.addBillboard(cartesian);
960
+ }
961
+ }
962
+ }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
963
+
964
+ mouseHandler.setInputAction(function (movement) {
965
+ var position = movement.endPosition;
966
+ if (position != null) {
967
+ if (positions.length == 0) {
968
+ tooltip.showAt(position, '<p>Click to add first point</p>');
969
+ } else {
970
+ var cartesian = scene.camera.pickEllipsoid(position, ellipsoid);
971
+ if (cartesian) {
972
+ positions.pop();
973
+ // make sure it is slightly different
974
+ cartesian.y += 1 + Math.random();
975
+ positions.push(cartesian);
976
+ if (positions.length >= minPoints) {
977
+ poly.positions = positions;
978
+ poly._createPrimitive = true;
979
+ }
980
+ // update marker
981
+ markers.getBillboard(positions.length - 1).position = cartesian;
982
+ // show tooltip
983
+ tooltip.showAt(
984
+ position,
985
+ '<p>Click to add new point (' +
986
+ positions.length +
987
+ ')</p>' +
988
+ (positions.length > minPoints
989
+ ? '<p>Double click to finish drawing</p>'
990
+ : '')
991
+ );
992
+ }
993
+ }
994
+ }
995
+ }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
996
+
997
+ mouseHandler.setInputAction(function (movement) {
998
+ var position = movement.position;
999
+ if (position != null) {
1000
+ if (positions.length < minPoints + 2) {
1001
+ return;
1002
+ } else {
1003
+ var cartesian = scene.camera.pickEllipsoid(position, ellipsoid);
1004
+ if (cartesian) {
1005
+ unsetDrawCursor(scene);
1006
+ _self.stopDrawing();
1007
+ if (typeof options.callback == 'function') {
1008
+ // remove overlapping ones
1009
+ var index = positions.length - 1;
1010
+ options.callback(positions);
1011
+ }
1012
+ }
1013
+ }
1014
+ }
1015
+ }, Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
1016
+ };
1017
+
1018
+ function getExtentCorners(value) {
1019
+ return ellipsoid.cartographicArrayToCartesianArray([
1020
+ Cesium.Rectangle.northwest(value),
1021
+ Cesium.Rectangle.northeast(value),
1022
+ Cesium.Rectangle.southeast(value),
1023
+ Cesium.Rectangle.southwest(value),
1024
+ ]);
1025
+ }
1026
+
1027
+ // MC_CHANGE add to change draw mode cursor
1028
+ function setDrawCursor(scene) {
1029
+ if (scene) {
1030
+ scene.canvas.style.cursor = 'crosshair';
1031
+ }
1032
+ }
1033
+
1034
+ // MC_CHANGE add to restore regular mode
1035
+ function unsetDrawCursor(scene) {
1036
+ if (scene) {
1037
+ scene.canvas.style.cursor = '';
1038
+ }
1039
+ }
1040
+
1041
+ _.prototype.startDrawingExtent = function (options) {
1042
+ var options = copyOptions(options, defaultSurfaceOptions);
1043
+
1044
+ this.startDrawing(function () {
1045
+ if (extent != null) {
1046
+ primitives.remove(extent);
1047
+ }
1048
+ //MC_CHANGE if added
1049
+ if (markers != null) {
1050
+ markers.remove();
1051
+ }
1052
+ mouseHandler.destroy();
1053
+ tooltip.setVisible(false);
1054
+ unsetDrawCursor(scene);
1055
+ });
1056
+
1057
+ var _self = this;
1058
+ var scene = this._scene;
1059
+ var primitives = this._scene.primitives;
1060
+ var tooltip = this._tooltip;
1061
+
1062
+ var firstPoint = null;
1063
+ var extent = null;
1064
+ var markers = null;
1065
+
1066
+ var mouseHandler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
1067
+ setDrawCursor(scene);
1068
+
1069
+ function updateExtent(value) {
1070
+ if (extent == null) {
1071
+ //MC_CHANGE
1072
+ extent = new DrawHelper.ExtentPrimitive({
1073
+ extent: value,
1074
+ material: options.material,
1075
+ });
1076
+ //extent = new Cesium.RectanglePrimitive();
1077
+ extent.asynchronous = false;
1078
+ primitives.add(extent);
1079
+ }
1080
+ extent.setExtent(value);
1081
+ // update the markers
1082
+ var corners = getExtentCorners(value);
1083
+ // create if they do not yet exist
1084
+ if (markers == null) {
1085
+ markers = new _.BillboardGroup(_self, defaultBillboard);
1086
+ markers.addBillboards(corners);
1087
+ } else {
1088
+ markers.updateBillboardsPositions(corners);
1089
+ }
1090
+ }
1091
+
1092
+ // Now wait for start
1093
+ mouseHandler.setInputAction(function (movement) {
1094
+ if (movement.position != null) {
1095
+ var cartesian = scene.camera.pickEllipsoid(
1096
+ movement.position,
1097
+ ellipsoid
1098
+ );
1099
+ if (cartesian) {
1100
+ if (extent == null) {
1101
+ // create the rectangle
1102
+ firstPoint = ellipsoid.cartesianToCartographic(cartesian);
1103
+ var value = getExtent(firstPoint, firstPoint);
1104
+ updateExtent(value);
1105
+ } else {
1106
+ _self.stopDrawing();
1107
+ if (typeof options.callback == 'function') {
1108
+ options.callback(
1109
+ getExtent(
1110
+ firstPoint,
1111
+ ellipsoid.cartesianToCartographic(cartesian)
1112
+ )
1113
+ );
1114
+ }
1115
+ }
1116
+ }
1117
+ }
1118
+ }, Cesium.ScreenSpaceEventType.LEFT_DOWN);
1119
+
1120
+ mouseHandler.setInputAction(function (movement) {
1121
+ var position = movement.endPosition;
1122
+ if (position != null) {
1123
+ if (extent == null) {
1124
+ tooltip.showAt(position, '<p>Click to start drawing rectangle</p>');
1125
+ } else {
1126
+ var cartesian = scene.camera.pickEllipsoid(position, ellipsoid);
1127
+ if (cartesian) {
1128
+ var value = getExtent(
1129
+ firstPoint,
1130
+ ellipsoid.cartesianToCartographic(cartesian)
1131
+ );
1132
+ updateExtent(value);
1133
+ tooltip.showAt(
1134
+ position,
1135
+ '<p>Drag to change rectangle extent</p><p>Click again to finish drawing</p>'
1136
+ );
1137
+ }
1138
+ }
1139
+ }
1140
+ }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
1141
+ };
1142
+
1143
+ _.prototype.startDrawingCircle = function (options) {
1144
+ var options = copyOptions(options, defaultSurfaceOptions);
1145
+
1146
+ this.startDrawing(function cleanUp() {
1147
+ if (circle != null) {
1148
+ primitives.remove(circle);
1149
+ }
1150
+ markers.remove();
1151
+ mouseHandler.destroy();
1152
+ tooltip.setVisible(false);
1153
+ });
1154
+
1155
+ var _self = this;
1156
+ var scene = this._scene;
1157
+ var primitives = this._scene.primitives;
1158
+ var tooltip = this._tooltip;
1159
+
1160
+ var circle = null;
1161
+ var markers = null;
1162
+
1163
+ var mouseHandler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
1164
+
1165
+ // Now wait for start
1166
+ mouseHandler.setInputAction(function (movement) {
1167
+ if (movement.position != null) {
1168
+ var cartesian = scene.camera.pickEllipsoid(
1169
+ movement.position,
1170
+ ellipsoid
1171
+ );
1172
+ if (cartesian) {
1173
+ if (circle == null) {
1174
+ // create the circle
1175
+ circle = new _.CirclePrimitive({
1176
+ center: cartesian,
1177
+ radius: 0,
1178
+ asynchronous: false,
1179
+ material: options.material,
1180
+ });
1181
+ primitives.add(circle);
1182
+ markers = new _.BillboardGroup(_self, defaultBillboard);
1183
+ markers.addBillboards([cartesian]);
1184
+ } else {
1185
+ if (typeof options.callback == 'function') {
1186
+ options.callback(circle.getCenter(), circle.getRadius());
1187
+ }
1188
+ _self.stopDrawing();
1189
+ }
1190
+ }
1191
+ }
1192
+ }, Cesium.ScreenSpaceEventType.LEFT_DOWN);
1193
+
1194
+ mouseHandler.setInputAction(function (movement) {
1195
+ var position = movement.endPosition;
1196
+ if (position != null) {
1197
+ if (circle == null) {
1198
+ tooltip.showAt(position, '<p>Click to start drawing the circle</p>');
1199
+ } else {
1200
+ var cartesian = scene.camera.pickEllipsoid(position, ellipsoid);
1201
+ if (cartesian) {
1202
+ circle.setRadius(
1203
+ Cesium.Cartesian3.distance(circle.getCenter(), cartesian)
1204
+ );
1205
+ markers.updateBillboardsPositions(cartesian);
1206
+ tooltip.showAt(
1207
+ position,
1208
+ '<p>Move mouse to change circle radius</p><p>Click again to finish drawing</p>'
1209
+ );
1210
+ }
1211
+ }
1212
+ }
1213
+ }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
1214
+ };
1215
+
1216
+ _.prototype.enhancePrimitives = function () {
1217
+ var drawHelper = this;
1218
+
1219
+ Cesium.Billboard.prototype.setEditable = function () {
1220
+ if (this._editable) {
1221
+ return;
1222
+ }
1223
+
1224
+ this._editable = true;
1225
+
1226
+ var billboard = this;
1227
+
1228
+ var _self = this;
1229
+
1230
+ function enableRotation(enable) {
1231
+ drawHelper._scene.screenSpaceCameraController.enableRotate = enable;
1232
+ }
1233
+
1234
+ setListener(billboard, 'leftDown', function (position) {
1235
+ // TODO - start the drag handlers here
1236
+ // create handlers for mouseOut and leftUp for the billboard and a mouseMove
1237
+ function onDrag(position) {
1238
+ billboard.position = position;
1239
+ _self.executeListeners({ name: 'drag', positions: position });
1240
+ }
1241
+ function onDragEnd(position) {
1242
+ handler.destroy();
1243
+ enableRotation(true);
1244
+ _self.executeListeners({ name: 'dragEnd', positions: position });
1245
+ }
1246
+
1247
+ var handler = new Cesium.ScreenSpaceEventHandler(
1248
+ drawHelper._scene.canvas
1249
+ );
1250
+
1251
+ handler.setInputAction(function (movement) {
1252
+ var cartesian = drawHelper._scene.camera.pickEllipsoid(
1253
+ movement.endPosition,
1254
+ ellipsoid
1255
+ );
1256
+ if (cartesian) {
1257
+ onDrag(cartesian);
1258
+ } else {
1259
+ onDragEnd(cartesian);
1260
+ }
1261
+ }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
1262
+
1263
+ handler.setInputAction(function (movement) {
1264
+ onDragEnd(
1265
+ drawHelper._scene.camera.pickEllipsoid(movement.position, ellipsoid)
1266
+ );
1267
+ }, Cesium.ScreenSpaceEventType.LEFT_UP);
1268
+
1269
+ enableRotation(false);
1270
+ });
1271
+
1272
+ enhanceWithListeners(billboard);
1273
+ };
1274
+
1275
+ function setHighlighted(highlighted) {
1276
+ var scene = drawHelper._scene;
1277
+
1278
+ // if no change
1279
+ // if already highlighted, the outline polygon will be available
1280
+ if (this._highlighted && this._highlighted == highlighted) {
1281
+ return;
1282
+ }
1283
+ // disable if already in edit mode
1284
+ if (this._editMode === true) {
1285
+ return;
1286
+ }
1287
+ this._highlighted = highlighted;
1288
+ // highlight by creating an outline polygon matching the polygon points
1289
+ if (highlighted) {
1290
+ // make sure all other shapes are not highlighted
1291
+ drawHelper.setHighlighted(this);
1292
+ this._strokeColor = this.strokeColor;
1293
+ this.setStrokeStyle(
1294
+ Cesium.Color.fromCssColorString('white'),
1295
+ this.strokeWidth
1296
+ );
1297
+ } else {
1298
+ if (this._strokeColor) {
1299
+ this.setStrokeStyle(this._strokeColor, this.strokeWidth);
1300
+ } else {
1301
+ this.setStrokeStyle(undefined, undefined);
1302
+ }
1303
+ }
1304
+ }
1305
+
1306
+ function setEditMode(editMode) {
1307
+ // if no change
1308
+ if (this._editMode == editMode) {
1309
+ return;
1310
+ }
1311
+ // make sure all other shapes are not in edit mode before starting the editing of this shape
1312
+ drawHelper.disableAllHighlights();
1313
+ // display markers
1314
+ if (editMode) {
1315
+ drawHelper.setEdited(this);
1316
+ var scene = drawHelper._scene;
1317
+ var _self = this;
1318
+ // create the markers and handlers for the editing
1319
+ if (this._markers == null) {
1320
+ var markers = new _.BillboardGroup(drawHelper, dragBillboard);
1321
+ var editMarkers = new _.BillboardGroup(drawHelper, dragHalfBillboard);
1322
+ // function for updating the edit markers around a certain point
1323
+ function updateHalfMarkers(index, positions) {
1324
+ // update the half markers before and after the index
1325
+ var editIndex = index - 1 < 0 ? positions.length - 1 : index - 1;
1326
+ if (editIndex < editMarkers.countBillboards()) {
1327
+ editMarkers.getBillboard(
1328
+ editIndex
1329
+ ).position = calculateHalfMarkerPosition(editIndex);
1330
+ }
1331
+ editIndex = index;
1332
+ if (editIndex < editMarkers.countBillboards()) {
1333
+ editMarkers.getBillboard(
1334
+ editIndex
1335
+ ).position = calculateHalfMarkerPosition(editIndex);
1336
+ }
1337
+ }
1338
+ function onEdited() {
1339
+ _self.executeListeners({
1340
+ name: 'onEdited',
1341
+ positions: _self.positions,
1342
+ });
1343
+ }
1344
+ var handleMarkerChanges = {
1345
+ dragHandlers: {
1346
+ onDrag: function (index, position) {
1347
+ _self.positions[index] = position;
1348
+ updateHalfMarkers(index, _self.positions);
1349
+ _self._createPrimitive = true;
1350
+ },
1351
+ onDragEnd: function (index, position) {
1352
+ _self._createPrimitive = true;
1353
+ onEdited();
1354
+ },
1355
+ },
1356
+ onDoubleClick: function (index) {
1357
+ if (_self.positions.length < 4) {
1358
+ return;
1359
+ }
1360
+ // remove the point and the corresponding markers
1361
+ _self.positions.splice(index, 1);
1362
+ _self._createPrimitive = true;
1363
+ markers.removeBillboard(index);
1364
+ editMarkers.removeBillboard(index);
1365
+ updateHalfMarkers(index, _self.positions);
1366
+ onEdited();
1367
+ },
1368
+ tooltip: function () {
1369
+ if (_self.positions.length > 3) {
1370
+ return 'Double click to remove this point';
1371
+ }
1372
+ },
1373
+ };
1374
+ // add billboards and keep an ordered list of them for the polygon edges
1375
+ markers.addBillboards(_self.positions, handleMarkerChanges);
1376
+ this._markers = markers;
1377
+ function calculateHalfMarkerPosition(index) {
1378
+ var positions = _self.positions;
1379
+ return ellipsoid.cartographicToCartesian(
1380
+ new Cesium.EllipsoidGeodesic(
1381
+ ellipsoid.cartesianToCartographic(positions[index]),
1382
+ ellipsoid.cartesianToCartographic(
1383
+ positions[index < positions.length - 1 ? index + 1 : 0]
1384
+ )
1385
+ ).interpolateUsingFraction(0.5)
1386
+ );
1387
+ }
1388
+ var halfPositions = [];
1389
+ var index = 0;
1390
+ var length = _self.positions.length + (this.isPolygon ? 0 : -1);
1391
+ for (; index < length; index++) {
1392
+ halfPositions.push(calculateHalfMarkerPosition(index));
1393
+ }
1394
+ var handleEditMarkerChanges = {
1395
+ dragHandlers: {
1396
+ onDragStart: function (index, position) {
1397
+ // add a new position to the polygon but not a new marker yet
1398
+ this.index = index + 1;
1399
+ _self.positions.splice(this.index, 0, position);
1400
+ _self._createPrimitive = true;
1401
+ },
1402
+ onDrag: function (index, position) {
1403
+ _self.positions[this.index] = position;
1404
+ _self._createPrimitive = true;
1405
+ },
1406
+ onDragEnd: function (index, position) {
1407
+ // create new sets of makers for editing
1408
+ markers.insertBillboard(
1409
+ this.index,
1410
+ position,
1411
+ handleMarkerChanges
1412
+ );
1413
+ editMarkers.getBillboard(
1414
+ this.index - 1
1415
+ ).position = calculateHalfMarkerPosition(this.index - 1);
1416
+ editMarkers.insertBillboard(
1417
+ this.index,
1418
+ calculateHalfMarkerPosition(this.index),
1419
+ handleEditMarkerChanges
1420
+ );
1421
+ _self._createPrimitive = true;
1422
+ onEdited();
1423
+ },
1424
+ },
1425
+ tooltip: function () {
1426
+ return 'Drag to create a new point';
1427
+ },
1428
+ };
1429
+ editMarkers.addBillboards(halfPositions, handleEditMarkerChanges);
1430
+ this._editMarkers = editMarkers;
1431
+ // add a handler for clicking in the globe
1432
+ this._globeClickhandler = new Cesium.ScreenSpaceEventHandler(
1433
+ scene.canvas
1434
+ );
1435
+ this._globeClickhandler.setInputAction(function (movement) {
1436
+ var pickedObject = scene.pick(movement.position);
1437
+ if (!(pickedObject && pickedObject.primitive)) {
1438
+ _self.setEditMode(false);
1439
+ }
1440
+ }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
1441
+
1442
+ // set on top of the polygon
1443
+ markers.setOnTop();
1444
+ editMarkers.setOnTop();
1445
+ }
1446
+ this._editMode = true;
1447
+ } else {
1448
+ if (this._markers != null) {
1449
+ this._markers.remove();
1450
+ this._editMarkers.remove();
1451
+ this._markers = null;
1452
+ this._editMarkers = null;
1453
+ this._globeClickhandler.destroy();
1454
+ }
1455
+ this._editMode = false;
1456
+ }
1457
+ }
1458
+
1459
+ DrawHelper.PolylinePrimitive.prototype.setEditable = function () {
1460
+ if (this.setEditMode) {
1461
+ return;
1462
+ }
1463
+
1464
+ var polyline = this;
1465
+ polyline.isPolygon = false;
1466
+ polyline.asynchronous = false;
1467
+
1468
+ drawHelper.registerEditableShape(polyline);
1469
+
1470
+ polyline.setEditMode = setEditMode;
1471
+
1472
+ var originalWidth = this.width;
1473
+
1474
+ polyline.setHighlighted = function (highlighted) {
1475
+ // disable if already in edit mode
1476
+ if (this._editMode === true) {
1477
+ return;
1478
+ }
1479
+ if (highlighted) {
1480
+ drawHelper.setHighlighted(this);
1481
+ this.setWidth(originalWidth * 2);
1482
+ } else {
1483
+ this.setWidth(originalWidth);
1484
+ }
1485
+ };
1486
+
1487
+ polyline.getExtent = function () {
1488
+ return Cesium.Extent.fromCartographicArray(
1489
+ ellipsoid.cartesianArrayToCartographicArray(this.positions)
1490
+ );
1491
+ };
1492
+
1493
+ enhanceWithListeners(polyline);
1494
+
1495
+ polyline.setEditMode(false);
1496
+ };
1497
+
1498
+ DrawHelper.PolygonPrimitive.prototype.setEditable = function () {
1499
+ var polygon = this;
1500
+ polygon.asynchronous = false;
1501
+
1502
+ var scene = drawHelper._scene;
1503
+
1504
+ drawHelper.registerEditableShape(polygon);
1505
+
1506
+ polygon.setEditMode = setEditMode;
1507
+
1508
+ polygon.setHighlighted = setHighlighted;
1509
+
1510
+ enhanceWithListeners(polygon);
1511
+
1512
+ polygon.setEditMode(false);
1513
+ };
1514
+
1515
+ DrawHelper.ExtentPrimitive.prototype.setEditable = function () {
1516
+ if (this.setEditMode) {
1517
+ return;
1518
+ }
1519
+
1520
+ var extent = this;
1521
+ var scene = drawHelper._scene;
1522
+
1523
+ drawHelper.registerEditableShape(extent);
1524
+ extent.asynchronous = false;
1525
+
1526
+ extent.setEditMode = function (editMode) {
1527
+ // if no change
1528
+ if (this._editMode == editMode) {
1529
+ return;
1530
+ }
1531
+ drawHelper.disableAllHighlights();
1532
+ // display markers
1533
+ if (editMode) {
1534
+ // make sure all other shapes are not in edit mode before starting the editing of this shape
1535
+ drawHelper.setEdited(this);
1536
+ // create the markers and handlers for the editing
1537
+ if (this._markers == null) {
1538
+ var markers = new _.BillboardGroup(drawHelper, dragBillboard);
1539
+ function onEdited() {
1540
+ extent.executeListeners({
1541
+ name: 'onEdited',
1542
+ extent: extent.extent,
1543
+ });
1544
+ }
1545
+ var handleMarkerChanges = {
1546
+ dragHandlers: {
1547
+ onDrag: function (index, position) {
1548
+ var corner = markers.getBillboard((index + 2) % 4).position;
1549
+ extent.setExtent(
1550
+ getExtent(
1551
+ ellipsoid.cartesianToCartographic(corner),
1552
+ ellipsoid.cartesianToCartographic(position)
1553
+ )
1554
+ );
1555
+ markers.updateBillboardsPositions(
1556
+ getExtentCorners(extent.extent)
1557
+ );
1558
+ },
1559
+ onDragEnd: function (index, position) {
1560
+ onEdited();
1561
+ },
1562
+ },
1563
+ tooltip: function () {
1564
+ return 'Drag to change the corners of this extent';
1565
+ },
1566
+ };
1567
+ markers.addBillboards(
1568
+ getExtentCorners(extent.extent),
1569
+ handleMarkerChanges
1570
+ );
1571
+ this._markers = markers;
1572
+ // add a handler for clicking in the globe
1573
+ this._globeClickhandler = new Cesium.ScreenSpaceEventHandler(
1574
+ scene.canvas
1575
+ );
1576
+ this._globeClickhandler.setInputAction(function (movement) {
1577
+ var pickedObject = scene.pick(movement.position);
1578
+ // disable edit if pickedobject is different or not an object
1579
+ if (
1580
+ !(
1581
+ pickedObject &&
1582
+ !pickedObject.isDestroyed() &&
1583
+ pickedObject.primitive
1584
+ )
1585
+ ) {
1586
+ extent.setEditMode(false);
1587
+ }
1588
+ }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
1589
+
1590
+ // set on top of the polygon
1591
+ markers.setOnTop();
1592
+ }
1593
+ this._editMode = true;
1594
+ } else {
1595
+ if (this._markers != null) {
1596
+ this._markers.remove();
1597
+ this._markers = null;
1598
+ this._globeClickhandler.destroy();
1599
+ }
1600
+ this._editMode = false;
1601
+ }
1602
+ };
1603
+
1604
+ extent.setHighlighted = setHighlighted;
1605
+
1606
+ enhanceWithListeners(extent);
1607
+
1608
+ extent.setEditMode(false);
1609
+ };
1610
+
1611
+ _.EllipsePrimitive.prototype.setEditable = function () {
1612
+ if (this.setEditMode) {
1613
+ return;
1614
+ }
1615
+
1616
+ var ellipse = this;
1617
+ var scene = drawHelper._scene;
1618
+
1619
+ ellipse.asynchronous = false;
1620
+
1621
+ drawHelper.registerEditableShape(ellipse);
1622
+
1623
+ ellipse.setEditMode = function (editMode) {
1624
+ // if no change
1625
+ if (this._editMode == editMode) {
1626
+ return;
1627
+ }
1628
+ drawHelper.disableAllHighlights();
1629
+ // display markers
1630
+ if (editMode) {
1631
+ // make sure all other shapes are not in edit mode before starting the editing of this shape
1632
+ drawHelper.setEdited(this);
1633
+ var _self = this;
1634
+ // create the markers and handlers for the editing
1635
+ if (this._markers == null) {
1636
+ var markers = new _.BillboardGroup(drawHelper, dragBillboard);
1637
+ function getMarkerPositions() {
1638
+ return Cesium.Shapes.computeEllipseBoundary(
1639
+ ellipsoid,
1640
+ ellipse.getCenter(),
1641
+ ellipse.getSemiMajorAxis(),
1642
+ ellipse.getSemiMinorAxis(),
1643
+ ellipse.getRotation() + Math.PI / 2,
1644
+ Math.PI / 2.0
1645
+ ).splice(0, 4);
1646
+ }
1647
+ function onEdited() {
1648
+ ellipse.executeListeners({
1649
+ name: 'onEdited',
1650
+ center: ellipse.getCenter(),
1651
+ semiMajorAxis: ellipse.getSemiMajorAxis(),
1652
+ semiMinorAxis: ellipse.getSemiMinorAxis(),
1653
+ rotation: 0,
1654
+ });
1655
+ }
1656
+ var handleMarkerChanges = {
1657
+ dragHandlers: {
1658
+ onDrag: function (index, position) {
1659
+ var distance = Cesium.Cartesian3.distance(
1660
+ ellipse.getCenter(),
1661
+ position
1662
+ );
1663
+ if (index % 2 == 0) {
1664
+ ellipse.setSemiMajorAxis(distance);
1665
+ } else {
1666
+ ellipse.setSemiMinorAxis(distance);
1667
+ }
1668
+ markers.updateBillboardsPositions(getMarkerPositions());
1669
+ },
1670
+ onDragEnd: function (index, position) {
1671
+ onEdited();
1672
+ },
1673
+ },
1674
+ tooltip: function () {
1675
+ return 'Drag to change the excentricity and radius';
1676
+ },
1677
+ };
1678
+ markers.addBillboards(getMarkerPositions(), handleMarkerChanges);
1679
+ this._markers = markers;
1680
+ // add a handler for clicking in the globe
1681
+ this._globeClickhandler = new Cesium.ScreenSpaceEventHandler(
1682
+ scene.canvas
1683
+ );
1684
+ this._globeClickhandler.setInputAction(function (movement) {
1685
+ var pickedObject = scene.pick(movement.position);
1686
+ if (!(pickedObject && pickedObject.primitive)) {
1687
+ _self.setEditMode(false);
1688
+ }
1689
+ }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
1690
+
1691
+ // set on top of the polygon
1692
+ markers.setOnTop();
1693
+ }
1694
+ this._editMode = true;
1695
+ } else {
1696
+ if (this._markers != null) {
1697
+ this._markers.remove();
1698
+ this._markers = null;
1699
+ this._globeClickhandler.destroy();
1700
+ }
1701
+ this._editMode = false;
1702
+ }
1703
+ };
1704
+
1705
+ ellipse.setHighlighted = setHighlighted;
1706
+
1707
+ enhanceWithListeners(ellipse);
1708
+
1709
+ ellipse.setEditMode(false);
1710
+ };
1711
+
1712
+ _.CirclePrimitive.prototype.getCircleCartesianCoordinates = function (
1713
+ granularity
1714
+ ) {
1715
+ var geometry = Cesium.CircleOutlineGeometry.createGeometry(
1716
+ new Cesium.CircleOutlineGeometry({
1717
+ ellipsoid: ellipsoid,
1718
+ center: this.getCenter(),
1719
+ radius: this.getRadius(),
1720
+ granularity: granularity,
1721
+ })
1722
+ );
1723
+ var count = 0,
1724
+ value,
1725
+ values = [];
1726
+ for (; count < geometry.attributes.position.values.length; count += 3) {
1727
+ value = geometry.attributes.position.values;
1728
+ values.push(
1729
+ new Cesium.Cartesian3(
1730
+ value[count],
1731
+ value[count + 1],
1732
+ value[count + 2]
1733
+ )
1734
+ );
1735
+ }
1736
+ return values;
1737
+ };
1738
+
1739
+ _.CirclePrimitive.prototype.setEditable = function () {
1740
+ if (this.setEditMode) {
1741
+ return;
1742
+ }
1743
+
1744
+ var circle = this;
1745
+ var scene = drawHelper._scene;
1746
+
1747
+ circle.asynchronous = false;
1748
+
1749
+ drawHelper.registerEditableShape(circle);
1750
+
1751
+ circle.setEditMode = function (editMode) {
1752
+ // if no change
1753
+ if (this._editMode == editMode) {
1754
+ return;
1755
+ }
1756
+ drawHelper.disableAllHighlights();
1757
+ // display markers
1758
+ if (editMode) {
1759
+ // make sure all other shapes are not in edit mode before starting the editing of this shape
1760
+ drawHelper.setEdited(this);
1761
+ var _self = this;
1762
+ // create the markers and handlers for the editing
1763
+ if (this._markers == null) {
1764
+ var markers = new _.BillboardGroup(drawHelper, dragBillboard);
1765
+ function getMarkerPositions() {
1766
+ return _self.getCircleCartesianCoordinates(
1767
+ Cesium.Math.PI_OVER_TWO
1768
+ );
1769
+ }
1770
+ function onEdited() {
1771
+ circle.executeListeners({
1772
+ name: 'onEdited',
1773
+ center: circle.getCenter(),
1774
+ radius: circle.getRadius(),
1775
+ });
1776
+ }
1777
+ var handleMarkerChanges = {
1778
+ dragHandlers: {
1779
+ onDrag: function (index, position) {
1780
+ circle.setRadius(
1781
+ Cesium.Cartesian3.distance(circle.getCenter(), position)
1782
+ );
1783
+ markers.updateBillboardsPositions(getMarkerPositions());
1784
+ },
1785
+ onDragEnd: function (index, position) {
1786
+ onEdited();
1787
+ },
1788
+ },
1789
+ tooltip: function () {
1790
+ return 'Drag to change the radius';
1791
+ },
1792
+ };
1793
+ markers.addBillboards(getMarkerPositions(), handleMarkerChanges);
1794
+ this._markers = markers;
1795
+ // add a handler for clicking in the globe
1796
+ this._globeClickhandler = new Cesium.ScreenSpaceEventHandler(
1797
+ scene.canvas
1798
+ );
1799
+ this._globeClickhandler.setInputAction(function (movement) {
1800
+ var pickedObject = scene.pick(movement.position);
1801
+ if (!(pickedObject && pickedObject.primitive)) {
1802
+ _self.setEditMode(false);
1803
+ }
1804
+ }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
1805
+
1806
+ // set on top of the polygon
1807
+ markers.setOnTop();
1808
+ }
1809
+ this._editMode = true;
1810
+ } else {
1811
+ if (this._markers != null) {
1812
+ this._markers.remove();
1813
+ this._markers = null;
1814
+ this._globeClickhandler.destroy();
1815
+ }
1816
+ this._editMode = false;
1817
+ }
1818
+ };
1819
+
1820
+ circle.setHighlighted = setHighlighted;
1821
+
1822
+ enhanceWithListeners(circle);
1823
+
1824
+ circle.setEditMode(false);
1825
+ };
1826
+ };
1827
+
1828
+ _.DrawHelperWidget = (function () {
1829
+ // constructor
1830
+ function _(drawHelper, options) {
1831
+ // container must be specified
1832
+ if (!Cesium.defined(options.container)) {
1833
+ throw new Cesium.DeveloperError('Container is required');
1834
+ }
1835
+
1836
+ var drawOptions = {
1837
+ markerIcon: './assets/img/glyphicons_242_google_maps.png',
1838
+ polylineIcon: './assets/img/glyphicons_097_vector_path_line.png',
1839
+ polygonIcon: './assets/img/glyphicons_096_vector_path_polygon.png',
1840
+ circleIcon: './assets/img/glyphicons_095_vector_path_circle.png',
1841
+ extentIcon: './assets/img/glyphicons_094_vector_path_square.png',
1842
+ clearIcon: './assets/img/glyphicons_067_cleaning.png',
1843
+ polylineDrawingOptions: defaultPolylineOptions,
1844
+ polygonDrawingOptions: defaultPolygonOptions,
1845
+ extentDrawingOptions: defaultExtentOptions,
1846
+ circleDrawingOptions: defaultCircleOptions,
1847
+ };
1848
+
1849
+ fillOptions(options, drawOptions);
1850
+
1851
+ var _self = this;
1852
+
1853
+ var toolbar = document.createElement('DIV');
1854
+ toolbar.className = 'toolbar';
1855
+ options.container.appendChild(toolbar);
1856
+
1857
+ function addIcon(id, url, title, callback) {
1858
+ var div = document.createElement('DIV');
1859
+ div.className = 'button';
1860
+ div.title = title;
1861
+ toolbar.appendChild(div);
1862
+ div.onclick = callback;
1863
+ var span = document.createElement('SPAN');
1864
+ div.appendChild(span);
1865
+ var image = document.createElement('IMG');
1866
+ image.src = url;
1867
+ span.appendChild(image);
1868
+ return div;
1869
+ }
1870
+
1871
+ var scene = drawHelper._scene;
1872
+
1873
+ addIcon(
1874
+ 'marker',
1875
+ options.markerIcon,
1876
+ 'Click to start drawing a 2D marker',
1877
+ function () {
1878
+ drawHelper.startDrawingMarker({
1879
+ callback: function (position) {
1880
+ _self.executeListeners({
1881
+ name: 'markerCreated',
1882
+ position: position,
1883
+ });
1884
+ },
1885
+ });
1886
+ }
1887
+ );
1888
+
1889
+ addIcon(
1890
+ 'polyline',
1891
+ options.polylineIcon,
1892
+ 'Click to start drawing a 2D polyline',
1893
+ function () {
1894
+ drawHelper.startDrawingPolyline({
1895
+ callback: function (positions) {
1896
+ _self.executeListeners({
1897
+ name: 'polylineCreated',
1898
+ positions: positions,
1899
+ });
1900
+ },
1901
+ });
1902
+ }
1903
+ );
1904
+
1905
+ addIcon(
1906
+ 'polygon',
1907
+ options.polygonIcon,
1908
+ 'Click to start drawing a 2D polygon',
1909
+ function () {
1910
+ drawHelper.startDrawingPolygon({
1911
+ callback: function (positions) {
1912
+ _self.executeListeners({
1913
+ name: 'polygonCreated',
1914
+ positions: positions,
1915
+ });
1916
+ },
1917
+ });
1918
+ }
1919
+ );
1920
+
1921
+ addIcon(
1922
+ 'extent',
1923
+ options.extentIcon,
1924
+ 'Click to start drawing an Extent',
1925
+ function () {
1926
+ drawHelper.startDrawingExtent({
1927
+ callback: function (extent) {
1928
+ _self.executeListeners({ name: 'extentCreated', extent: extent });
1929
+ },
1930
+ });
1931
+ }
1932
+ );
1933
+
1934
+ addIcon(
1935
+ 'circle',
1936
+ options.circleIcon,
1937
+ 'Click to start drawing a Circle',
1938
+ function () {
1939
+ drawHelper.startDrawingCircle({
1940
+ callback: function (center, radius) {
1941
+ _self.executeListeners({
1942
+ name: 'circleCreated',
1943
+ center: center,
1944
+ radius: radius,
1945
+ });
1946
+ },
1947
+ });
1948
+ }
1949
+ );
1950
+
1951
+ // add a clear button at the end
1952
+ // add a divider first
1953
+ var div = document.createElement('DIV');
1954
+ div.className = 'divider';
1955
+ toolbar.appendChild(div);
1956
+ addIcon('clear', options.clearIcon, 'Remove all primitives', function () {
1957
+ scene.primitives.removeAll();
1958
+ });
1959
+
1960
+ enhanceWithListeners(this);
1961
+ }
1962
+
1963
+ return _;
1964
+ })();
1965
+
1966
+ _.prototype.addToolbar = function (container, options) {
1967
+ options = copyOptions(options, { container: container });
1968
+ return new _.DrawHelperWidget(this, options);
1969
+ };
1970
+
1971
+ function getExtent(mn, mx) {
1972
+ var e = new Cesium.Rectangle();
1973
+
1974
+ // Re-order so west < east and south < north
1975
+ e.west = Math.min(mn.longitude, mx.longitude);
1976
+ e.east = Math.max(mn.longitude, mx.longitude);
1977
+ e.south = Math.min(mn.latitude, mx.latitude);
1978
+ e.north = Math.max(mn.latitude, mx.latitude);
1979
+
1980
+ // Check for approx equal (shouldn't require abs due to re-order)
1981
+ var epsilon = Cesium.Math.EPSILON7;
1982
+
1983
+ if (e.east - e.west < epsilon) {
1984
+ e.east += epsilon * 2.0;
1985
+ }
1986
+
1987
+ if (e.north - e.south < epsilon) {
1988
+ e.north += epsilon * 2.0;
1989
+ }
1990
+
1991
+ return e;
1992
+ }
1993
+
1994
+ function createTooltip(frameDiv) {
1995
+ var tooltip = function (frameDiv) {
1996
+ var div = document.createElement('DIV');
1997
+ div.className = 'twipsy right';
1998
+
1999
+ var arrow = document.createElement('DIV');
2000
+ arrow.className = 'twipsy-arrow';
2001
+ div.appendChild(arrow);
2002
+
2003
+ var title = document.createElement('DIV');
2004
+ title.className = 'twipsy-inner';
2005
+ div.appendChild(title);
2006
+
2007
+ this._div = div;
2008
+ this._title = title;
2009
+
2010
+ // add to frame div and display coordinates
2011
+ frameDiv.appendChild(div);
2012
+ };
2013
+
2014
+ tooltip.prototype.setVisible = function (visible) {
2015
+ this._div.style.display = visible ? 'block' : 'none';
2016
+ };
2017
+
2018
+ tooltip.prototype.showAt = function (position, message) {
2019
+ if (position && message) {
2020
+ this.setVisible(true);
2021
+ this._title.innerHTML = message;
2022
+ this._div.style.left = position.x + 10 + 'px';
2023
+ this._div.style.top = position.y - this._div.clientHeight / 2 + 'px';
2024
+ }
2025
+ };
2026
+
2027
+ return new tooltip(frameDiv);
2028
+ }
2029
+
2030
+ function getDisplayLatLngString(cartographic, precision) {
2031
+ return (
2032
+ cartographic.longitude.toFixed(precision || 3) +
2033
+ ', ' +
2034
+ cartographic.latitude.toFixed(precision || 3)
2035
+ );
2036
+ }
2037
+
2038
+ function clone(from, to) {
2039
+ if (from == null || typeof from != 'object') return from;
2040
+ if (from.constructor != Object && from.constructor != Array) return from;
2041
+ if (
2042
+ from.constructor == Date ||
2043
+ from.constructor == RegExp ||
2044
+ from.constructor == Function ||
2045
+ from.constructor == String ||
2046
+ from.constructor == Number ||
2047
+ from.constructor == Boolean
2048
+ )
2049
+ return new from.constructor(from);
2050
+
2051
+ to = to || new from.constructor();
2052
+
2053
+ for (var name in from) {
2054
+ to[name] =
2055
+ typeof to[name] == 'undefined' ? clone(from[name], null) : to[name];
2056
+ }
2057
+
2058
+ return to;
2059
+ }
2060
+
2061
+ function fillOptions(options, defaultOptions) {
2062
+ options = options || {};
2063
+ var option;
2064
+ for (option in defaultOptions) {
2065
+ if (options[option] === undefined) {
2066
+ options[option] = clone(defaultOptions[option]);
2067
+ }
2068
+ }
2069
+ }
2070
+
2071
+ // shallow copy
2072
+ function copyOptions(options, defaultOptions) {
2073
+ var newOptions = clone(options),
2074
+ option;
2075
+ for (option in defaultOptions) {
2076
+ if (newOptions[option] === undefined) {
2077
+ newOptions[option] = clone(defaultOptions[option]);
2078
+ }
2079
+ }
2080
+ return newOptions;
2081
+ }
2082
+
2083
+ function setListener(primitive, type, callback) {
2084
+ primitive[type] = callback;
2085
+ }
2086
+
2087
+ function enhanceWithListeners(element) {
2088
+ element._listeners = {};
2089
+
2090
+ element.addListener = function (name, callback) {
2091
+ this._listeners[name] = this._listeners[name] || [];
2092
+ this._listeners[name].push(callback);
2093
+ return this._listeners[name].length;
2094
+ };
2095
+
2096
+ element.executeListeners = function (event, defaultCallback) {
2097
+ if (
2098
+ this._listeners[event.name] &&
2099
+ this._listeners[event.name].length > 0
2100
+ ) {
2101
+ var index = 0;
2102
+ for (; index < this._listeners[event.name].length; index++) {
2103
+ this._listeners[event.name][index](event);
2104
+ }
2105
+ } else {
2106
+ if (defaultCallback) {
2107
+ defaultCallback(event);
2108
+ }
2109
+ }
2110
+ };
2111
+ }
2112
+
2113
+ return _;
2114
+ })();
2115
+
2116
+ export { DrawHelper };