react-spatial 1.2.2 → 1.2.3-beta.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 (186) hide show
  1. package/LayerService.js +128 -184
  2. package/LayerService.js.map +7 -1
  3. package/components/BaseLayerSwitcher/BaseLayerSwitcher.js +163 -221
  4. package/components/BaseLayerSwitcher/BaseLayerSwitcher.js.map +7 -1
  5. package/components/BaseLayerSwitcher/index.js +1 -3
  6. package/components/BaseLayerSwitcher/index.js.map +7 -1
  7. package/components/BasicMap/BasicMap.js +147 -285
  8. package/components/BasicMap/BasicMap.js.map +7 -1
  9. package/components/BasicMap/index.js +1 -3
  10. package/components/BasicMap/index.js.map +7 -1
  11. package/components/CanvasSaveButton/CanvasSaveButton.js +165 -419
  12. package/components/CanvasSaveButton/CanvasSaveButton.js.map +7 -1
  13. package/components/CanvasSaveButton/index.js +1 -3
  14. package/components/CanvasSaveButton/index.js.map +7 -1
  15. package/components/Copyright/Copyright.js +29 -70
  16. package/components/Copyright/Copyright.js.map +7 -1
  17. package/components/Copyright/index.js +1 -3
  18. package/components/Copyright/index.js.map +7 -1
  19. package/components/FeatureExportButton/FeatureExportButton.js +40 -106
  20. package/components/FeatureExportButton/FeatureExportButton.js.map +7 -1
  21. package/components/FeatureExportButton/index.js +1 -3
  22. package/components/FeatureExportButton/index.js.map +7 -1
  23. package/components/FilterButton/FilterButton.js +41 -106
  24. package/components/FilterButton/FilterButton.js.map +7 -1
  25. package/components/FilterButton/index.js +1 -3
  26. package/components/FilterButton/index.js.map +7 -1
  27. package/components/FitExtent/FitExtent.js +17 -50
  28. package/components/FitExtent/FitExtent.js.map +7 -1
  29. package/components/FitExtent/index.js +1 -3
  30. package/components/FitExtent/index.js.map +7 -1
  31. package/components/FollowButton/FollowButton.js +41 -111
  32. package/components/FollowButton/FollowButton.js.map +7 -1
  33. package/components/FollowButton/index.js +1 -3
  34. package/components/FollowButton/index.js.map +7 -1
  35. package/components/Geolocation/Geolocation.js +104 -213
  36. package/components/Geolocation/Geolocation.js.map +7 -1
  37. package/components/Geolocation/index.js +1 -3
  38. package/components/Geolocation/index.js.map +7 -1
  39. package/components/LayerTree/LayerTree.js +204 -410
  40. package/components/LayerTree/LayerTree.js.map +7 -1
  41. package/components/LayerTree/index.js +1 -3
  42. package/components/LayerTree/index.js.map +7 -1
  43. package/components/MousePosition/MousePosition.js +61 -130
  44. package/components/MousePosition/MousePosition.js.map +7 -1
  45. package/components/MousePosition/index.js +1 -3
  46. package/components/MousePosition/index.js.map +7 -1
  47. package/components/NorthArrow/NorthArrow.js +22 -62
  48. package/components/NorthArrow/NorthArrow.js.map +7 -1
  49. package/components/NorthArrow/index.js +1 -3
  50. package/components/NorthArrow/index.js.map +7 -1
  51. package/components/Overlay/Overlay.js +83 -130
  52. package/components/Overlay/Overlay.js.map +7 -1
  53. package/components/Overlay/index.js +1 -3
  54. package/components/Overlay/index.js.map +7 -1
  55. package/components/Permalink/Permalink.js +150 -244
  56. package/components/Permalink/Permalink.js.map +7 -1
  57. package/components/Permalink/index.js +1 -3
  58. package/components/Permalink/index.js.map +7 -1
  59. package/components/Popup/Popup.js +106 -233
  60. package/components/Popup/Popup.js.map +7 -1
  61. package/components/Popup/index.js +1 -3
  62. package/components/Popup/index.js.map +7 -1
  63. package/components/ResizeHandler/ResizeHandler.js +58 -113
  64. package/components/ResizeHandler/ResizeHandler.js.map +7 -1
  65. package/components/ResizeHandler/index.js +1 -3
  66. package/components/ResizeHandler/index.js.map +7 -1
  67. package/components/RouteSchedule/RouteSchedule.js +150 -283
  68. package/components/RouteSchedule/RouteSchedule.js.map +7 -1
  69. package/components/RouteSchedule/index.js +1 -3
  70. package/components/RouteSchedule/index.js.map +7 -1
  71. package/components/ScaleLine/ScaleLine.js +21 -45
  72. package/components/ScaleLine/ScaleLine.js.map +7 -1
  73. package/components/ScaleLine/index.js +1 -3
  74. package/components/ScaleLine/index.js.map +7 -1
  75. package/components/Search/Search.js +122 -186
  76. package/components/Search/Search.js.map +7 -1
  77. package/components/Search/SearchService.js +45 -69
  78. package/components/Search/SearchService.js.map +7 -1
  79. package/components/Search/engines/Engine.js +18 -25
  80. package/components/Search/engines/Engine.js.map +7 -1
  81. package/components/Search/engines/StopFinder.js +21 -38
  82. package/components/Search/engines/StopFinder.js.map +7 -1
  83. package/components/Search/index.js +3 -6
  84. package/components/Search/index.js.map +7 -1
  85. package/components/StopsFinder/StopsFinder.js +123 -174
  86. package/components/StopsFinder/StopsFinder.js.map +7 -1
  87. package/components/StopsFinder/StopsFinderOption.js +37 -54
  88. package/components/StopsFinder/StopsFinderOption.js.map +7 -1
  89. package/components/StopsFinder/index.js +1 -3
  90. package/components/StopsFinder/index.js.map +7 -1
  91. package/components/TrackerControl/TrackerControl.js +73 -128
  92. package/components/TrackerControl/TrackerControl.js.map +7 -1
  93. package/components/TrackerControl/index.js +1 -3
  94. package/components/TrackerControl/index.js.map +7 -1
  95. package/components/Zoom/Zoom.js +69 -112
  96. package/components/Zoom/Zoom.js.map +7 -1
  97. package/components/Zoom/index.js +1 -3
  98. package/components/Zoom/index.js.map +7 -1
  99. package/package.json +10 -5
  100. package/propTypes.js +17 -23
  101. package/propTypes.js.map +7 -1
  102. package/setupTests.js +2 -4
  103. package/setupTests.js.map +7 -1
  104. package/themes/README.md +26 -0
  105. package/themes/default/components.scss +0 -1
  106. package/themes/default/examples.scss +0 -1
  107. package/utils/GlobalsForOle.js +63 -64
  108. package/utils/GlobalsForOle.js.map +7 -1
  109. package/utils/KML.js +178 -364
  110. package/utils/KML.js.map +7 -1
  111. package/utils/KMLFormat.js +37 -73
  112. package/utils/KMLFormat.js.map +7 -1
  113. package/utils/Styles.js +24 -32
  114. package/utils/Styles.js.map +7 -1
  115. package/utils/getPolygonPattern.js +11 -44
  116. package/utils/getPolygonPattern.js.map +7 -1
  117. package/utils/timeUtils.js +16 -35
  118. package/utils/timeUtils.js.map +7 -1
  119. package/LayerService.test.js +0 -160
  120. package/LayerService.test.js.map +0 -1
  121. package/Projections.js +0 -16
  122. package/Projections.js.map +0 -1
  123. package/components/BaseLayerSwitcher/BaseLayerSwitcher.test.js +0 -88
  124. package/components/BaseLayerSwitcher/BaseLayerSwitcher.test.js.map +0 -1
  125. package/components/BaseLayerToggler/BaseLayerToggler.js +0 -490
  126. package/components/BaseLayerToggler/BaseLayerToggler.js.map +0 -1
  127. package/components/BaseLayerToggler/BaseLayerToggler.md.scss +0 -9
  128. package/components/BaseLayerToggler/BaseLayerToggler.scss +0 -49
  129. package/components/BaseLayerToggler/BaseLayerToggler.test.js +0 -127
  130. package/components/BaseLayerToggler/BaseLayerToggler.test.js.map +0 -1
  131. package/components/BaseLayerToggler/index.js +0 -3
  132. package/components/BaseLayerToggler/index.js.map +0 -1
  133. package/components/BasicMap/BasicMap.test.js +0 -288
  134. package/components/BasicMap/BasicMap.test.js.map +0 -1
  135. package/components/CanvasSaveButton/CanvasSaveButton.test.js +0 -173
  136. package/components/CanvasSaveButton/CanvasSaveButton.test.js.map +0 -1
  137. package/components/Copyright/Copyright.test.js +0 -133
  138. package/components/Copyright/Copyright.test.js.map +0 -1
  139. package/components/FeatureExportButton/FeatureExportButton.test.js +0 -407
  140. package/components/FeatureExportButton/FeatureExportButton.test.js.map +0 -1
  141. package/components/FilterButton/FilterButton.test.js +0 -48
  142. package/components/FilterButton/FilterButton.test.js.map +0 -1
  143. package/components/FitExtent/FitExtent.test.js +0 -44
  144. package/components/FitExtent/FitExtent.test.js.map +0 -1
  145. package/components/FollowButton/FollowButton.test.js +0 -57
  146. package/components/FollowButton/FollowButton.test.js.map +0 -1
  147. package/components/Geolocation/Geolocation.test.js +0 -263
  148. package/components/Geolocation/Geolocation.test.js.map +0 -1
  149. package/components/LayerTree/LayerTree.test.js +0 -323
  150. package/components/LayerTree/LayerTree.test.js.map +0 -1
  151. package/components/MousePosition/MousePosition.test.js +0 -125
  152. package/components/MousePosition/MousePosition.test.js.map +0 -1
  153. package/components/NorthArrow/NorthArrow.test.js +0 -106
  154. package/components/NorthArrow/NorthArrow.test.js.map +0 -1
  155. package/components/Overlay/Overlay.test.js +0 -145
  156. package/components/Overlay/Overlay.test.js.map +0 -1
  157. package/components/Permalink/Permalink.test.js +0 -267
  158. package/components/Permalink/Permalink.test.js.map +0 -1
  159. package/components/Popup/Popup.test.js +0 -291
  160. package/components/Popup/Popup.test.js.map +0 -1
  161. package/components/ResizeHandler/ResizeHandler.test.js +0 -410
  162. package/components/ResizeHandler/ResizeHandler.test.js.map +0 -1
  163. package/components/RouteSchedule/RouteSchedule.test.js +0 -102
  164. package/components/RouteSchedule/RouteSchedule.test.js.map +0 -1
  165. package/components/ScaleLine/ScaleLine.test.js +0 -32
  166. package/components/ScaleLine/ScaleLine.test.js.map +0 -1
  167. package/components/Search/Search.test.js +0 -15
  168. package/components/Search/Search.test.js.map +0 -1
  169. package/components/StopsFinder/StopsFinder.test.js +0 -19
  170. package/components/StopsFinder/StopsFinder.test.js.map +0 -1
  171. package/components/TrackerControl/TrackerControl.test.js +0 -17
  172. package/components/TrackerControl/TrackerControl.test.js.map +0 -1
  173. package/components/Zoom/Zoom.test.js +0 -150
  174. package/components/Zoom/Zoom.test.js.map +0 -1
  175. package/styleguidist/ComponentsList.js +0 -52
  176. package/styleguidist/ComponentsList.js.map +0 -1
  177. package/styleguidist/StyleGuide.js +0 -253
  178. package/styleguidist/StyleGuide.js.map +0 -1
  179. package/utils/KML.test.js +0 -163
  180. package/utils/KML.test.js.map +0 -1
  181. package/utils/KMLFormat.test.js +0 -22
  182. package/utils/KMLFormat.test.js.map +0 -1
  183. package/utils/getPolygonPattern.test.js +0 -66
  184. package/utils/getPolygonPattern.test.js.map +0 -1
  185. package/utils/timeUtils.test.js +0 -32
  186. package/utils/timeUtils.test.js.map +0 -1
@@ -1 +1,7 @@
1
- {"version":3,"file":"CanvasSaveButton.js","sources":["../../../src/components/CanvasSaveButton/CanvasSaveButton.js"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport React, { PureComponent } from 'react';\nimport PropTypes from 'prop-types';\nimport OLMap from 'ol/Map';\nimport { getTopLeft, getBottomRight } from 'ol/extent';\nimport NorthArrowSimple from '../../images/northArrow.url.svg';\nimport NorthArrowCircle from '../../images/northArrowCircle.url.svg';\n\nconst propTypes = {\n /**\n * Automatically download the image saved.\n */\n autoDownload: PropTypes.bool,\n\n /**\n * Children content of the button.\n */\n children: PropTypes.node,\n\n /**\n * Output format of the image.\n */\n format: PropTypes.oneOf(['image/jpeg', 'image/png']),\n\n /** An [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html). */\n map: PropTypes.instanceOf(OLMap),\n\n /**\n * Extent for the export. If no extent is given, the whole map is exported.\n */\n extent: PropTypes.arrayOf(PropTypes.number),\n\n /**\n * Array of 4 [ol/Coordinate](https://openlayers.org/en/latest/apidoc/module-ol_coordinate.html#~Coordinate).\n * If no coordinates and no extent are given, the whole map is exported.\n * This property must be used to export rotated map.\n * If you don't need to export rotated map the extent property can be used as well.\n * If extent is specified, coordinates property is ignored.\n */\n coordinates: PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.number)),\n\n /**\n * Scale the map for better quality. Possible values: 1, 2 or 3.\n * WARNING: The tiled layer with a WMTS or XYZ source must provides an url\n * for each scale in the config file.\n */\n scale: PropTypes.number,\n\n /**\n * Function called before the dowload process begins.\n */\n onSaveStart: PropTypes.func,\n\n /**\n * Function called after the dowload process ends.\n *\n * @param {object} error Error message the process fails.\n */\n onSaveEnd: PropTypes.func,\n\n /**\n * Extra data, such as copyright, north arrow configuration.\n * All extra data is optional.\n *\n * Example 1:\n *\n {\n copyright: {\n text: 'Example copyright', // Copyright text or function\n font: '10px Arial', // Font, default is '12px Arial'\n fillStyle: 'blue', // Fill style, default is 'black'\n },\n northArrow, // True if the north arrow\n // should be placed with default configuration\n // (default image, rotation=0, circled=False)\n }\n * Example 2:\n *\n {\n northArrow: {\n src: NorthArrowCustom,\n width: 60, // Width in px, default is 80\n height: 100, // Height in px, default is 80\n rotation: 25, // Absolute rotation in degrees as number or function\n\n }\n }\n * Example 3:\n *\n {\n copyright: {\n text: () => { // Copyright as function\n return this.copyright;\n },\n },\n northArrow: {\n rotation: () => { // Rotation as function\n return NorthArrow.radToDeg(this.map.getView().getRotation());\n },\n circled, // Display circle around the north arrow (Does not work for custom src)\n },\n }\n */\n extraData: PropTypes.object,\n};\n\nconst defaultProps = {\n autoDownload: true,\n children: null,\n map: null,\n format: 'image/png',\n extent: null,\n extraData: null,\n coordinates: null,\n scale: 1,\n onSaveStart: (map) => {\n return Promise.resolve(map);\n },\n onSaveEnd: () => {},\n};\n\n/**\n * The CanvasSaveButton component creates a button to save\n * an [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html)\n * canvas as an image.\n */\nclass CanvasSaveButton extends PureComponent {\n constructor(props) {\n super(props);\n const { format } = this.props;\n this.fileExt = format === 'image/jpeg' ? 'jpg' : 'png';\n this.padding = 5;\n }\n\n onClick(evt) {\n const { map, onSaveStart, onSaveEnd, autoDownload } = this.props;\n if (window.navigator.msSaveBlob) {\n // ie only\n evt.preventDefault();\n evt.stopPropagation();\n }\n onSaveStart(map).then((mapToExport) => {\n return this.createCanvasImage(mapToExport || map)\n .then((canvas) => {\n if (autoDownload) {\n this.downloadCanvasImage(canvas).then((blob) => {\n onSaveEnd(mapToExport, canvas, blob);\n });\n } else {\n onSaveEnd(mapToExport, canvas);\n }\n })\n .catch((err) => {\n if (err) {\n // eslint-disable-next-line no-console\n console.error(err);\n }\n onSaveEnd(mapToExport, err);\n });\n });\n }\n\n getDownloadImageName() {\n return (\n `${window.document.title.replace(/ /g, '_').toLowerCase()}` +\n `.${this.fileExt}`\n );\n }\n\n // Ensure the font size fita with the image width.\n decreaseFontSize(destContext, maxWidth, copyright, scale) {\n const minFontSize = 8;\n let sizeMatch;\n let fontSize;\n do {\n sizeMatch = destContext.font.match(/[0-9]+(?:\\.[0-9]+)?(px)/i);\n fontSize = parseInt(sizeMatch[0].replace(sizeMatch[1], ''), 10);\n\n // eslint-disable-next-line no-param-reassign\n destContext.font = destContext.font.replace(fontSize, fontSize - 1);\n\n if (fontSize - 1 === minFontSize) {\n this.multilineCopyright = true;\n }\n } while (\n fontSize - 1 > minFontSize &&\n destContext.measureText(copyright).width * scale > maxWidth\n );\n\n return destContext.font;\n }\n\n // eslint-disable-next-line class-methods-use-this\n drawTextBackground(\n destContext,\n textMeasure,\n textX,\n textY,\n padding,\n styleOptions = {},\n ) {\n /// get width of text\n const { width, height, actualBoundingBoxAscent } = textMeasure;\n destContext.save();\n // Dflt is a white background\n destContext.fillStyle = 'rgba(255,255,255,.8)';\n\n // To simplify usability the user could pass a boolean to use only default values.\n if (typeof styleOptions === 'object') {\n Object.entries(styleOptions).forEach(([key, value]) => {\n destContext[key] = value;\n });\n }\n\n /// draw background rect assuming height of font\n destContext.fillRect(\n textX - padding,\n textY - actualBoundingBoxAscent - padding,\n width + padding * 2,\n height + padding * 2,\n );\n destContext.restore();\n }\n\n drawCopyright(destContext, destCanvas, maxWidth) {\n const { extraData, scale } = this.props;\n const { text, font, fillStyle, background } = extraData.copyright;\n let copyright = typeof text === 'function' ? text() : text;\n\n if (Array.isArray(copyright)) {\n copyright = copyright.join();\n }\n\n destContext.save();\n destContext.scale(scale, scale);\n destContext.font = font || '12px Arial';\n destContext.font = this.decreaseFontSize(\n destContext,\n maxWidth - this.padding,\n copyright,\n scale,\n );\n\n destContext.scale(scale, scale);\n destContext.fillStyle = fillStyle || 'black';\n\n // We search if the display on 2 line is necessary\n let firstLine = copyright;\n const wordNumber = copyright.split(' ').length;\n\n // If the text is bigger than the max width we split itinto 2 lines\n if (this.multilineCopyright) {\n for (let i = 0; i < wordNumber; i += 1) {\n firstLine = firstLine.substring(0, firstLine.lastIndexOf(' '));\n // Stop removing word when fits within one line.\n if (\n destContext.measureText(firstLine).width * scale <\n maxWidth - this.padding\n ) {\n break;\n }\n }\n }\n const secondLine = copyright.replace(firstLine, '');\n\n // Draw first line (line break isn't supported for fillText).\n const textX = this.padding;\n let textMeasure = destContext.measureText(firstLine);\n textMeasure.height =\n textMeasure.actualBoundingBoxAscent +\n textMeasure.actualBoundingBoxDescent;\n let firstLineY = destCanvas.height / scale - this.padding;\n const secondLineY = firstLineY;\n const paddingBetweenLines = 3;\n const paddingBackground = paddingBetweenLines / 2;\n\n if (secondLine) {\n firstLineY -= textMeasure.height + paddingBetweenLines;\n }\n if (background) {\n this.drawTextBackground(\n destContext,\n textMeasure,\n textX,\n firstLineY,\n paddingBackground,\n background,\n );\n }\n destContext.fillText(firstLine, textX, firstLineY);\n\n // Draw second line.\n if (secondLine) {\n textMeasure = destContext.measureText(secondLine);\n textMeasure.height =\n textMeasure.actualBoundingBoxAscent +\n textMeasure.actualBoundingBoxDescent;\n if (background) {\n this.drawTextBackground(\n destContext,\n textMeasure,\n textX,\n secondLineY,\n paddingBackground,\n background,\n );\n }\n destContext.fillText(secondLine, textX, secondLineY);\n }\n\n destContext.restore();\n }\n\n drawElement(data, destCanvas, previousItemSize = [0, 0]) {\n const destContext = destCanvas.getContext('2d');\n const { scale } = this.props;\n const { src, width, height, rotation } = data;\n\n return new Promise((resolve) => {\n const img = new Image();\n img.crossOrigin = 'Anonymous';\n img.src = src;\n img.onload = () => {\n destContext.save();\n const elementWidth = (width || 80) * scale;\n const elementHeight = (height || 80) * scale;\n destContext.translate(\n destCanvas.width - 2 * this.padding - elementWidth / 2,\n destCanvas.height -\n 2 * this.padding -\n elementHeight / 2 -\n previousItemSize[1],\n );\n\n if (rotation) {\n const angle = typeof rotation === 'function' ? rotation() : rotation;\n destContext.rotate(angle * (Math.PI / 180));\n }\n\n destContext.drawImage(\n img,\n -elementWidth / 2,\n -elementHeight / 2,\n elementWidth,\n elementHeight,\n );\n destContext.restore();\n\n // Return the pixels width of the arrow and the margin right,\n // that must not be occupied by the copyright.\n resolve([\n elementWidth + 2 * this.padding,\n elementHeight + 2 * this.padding,\n ]);\n };\n\n img.onerror = () => {\n resolve();\n };\n });\n }\n\n calculatePixelsToExport(mapToExport) {\n const { extent, coordinates } = this.props;\n let firstCoordinate;\n let oppositeCoordinate;\n\n if (extent) {\n firstCoordinate = getTopLeft(extent);\n oppositeCoordinate = getBottomRight(extent);\n } else if (coordinates) {\n // In case of coordinates coming from DragBox interaction:\n // firstCoordinate is the first coordinate drawn by the user.\n // oppositeCoordinate is the coordinate of the point dragged by the user.\n [firstCoordinate, , oppositeCoordinate] = coordinates;\n }\n\n if (firstCoordinate && oppositeCoordinate) {\n const firstPixel = mapToExport.getPixelFromCoordinate(firstCoordinate);\n const oppositePixel =\n mapToExport.getPixelFromCoordinate(oppositeCoordinate);\n const pixelTopLeft = [\n firstPixel[0] <= oppositePixel[0] ? firstPixel[0] : oppositePixel[0],\n firstPixel[1] <= oppositePixel[1] ? firstPixel[1] : oppositePixel[1],\n ];\n const pixelBottomRight = [\n firstPixel[0] > oppositePixel[0] ? firstPixel[0] : oppositePixel[0],\n firstPixel[1] > oppositePixel[1] ? firstPixel[1] : oppositePixel[1],\n ];\n\n return {\n x: pixelTopLeft[0],\n y: pixelTopLeft[1],\n w: pixelBottomRight[0] - pixelTopLeft[0],\n h: pixelBottomRight[1] - pixelTopLeft[1],\n };\n }\n return null;\n }\n\n createCanvasImage(mapToExport) {\n const { extraData } = this.props;\n\n return new Promise((resolve) => {\n mapToExport.once('rendercomplete', () => {\n // Find all layer canvases and add it to dest canvas.\n const canvases = mapToExport\n .getTargetElement()\n .getElementsByTagName('canvas');\n\n // Create the canvas to export with the good size.\n let destCanvas;\n let destContext;\n\n // canvases is an HTMLCollection, we don't try to transform to array because some compilers like cra doesn't translate it right.\n for (let i = 0; i < canvases.length; i += 1) {\n const canvas = canvases[i];\n if (!canvas.width || !canvas.height) {\n // eslint-disable-next-line no-continue\n continue;\n }\n const clip = this.calculatePixelsToExport(mapToExport) || {\n x: 0,\n y: 0,\n w: canvas.width,\n h: canvas.height,\n };\n\n if (!destCanvas) {\n destCanvas = document.createElement('canvas');\n destCanvas.width = clip.w;\n destCanvas.height = clip.h;\n destContext = destCanvas.getContext('2d');\n }\n\n // Draw canvas to the canvas to export.\n destContext.drawImage(\n canvas,\n clip.x,\n clip.y,\n clip.w,\n clip.h,\n 0,\n 0,\n destCanvas.width,\n destCanvas.height,\n );\n }\n\n // Custom info\n let logoPromise = Promise.resolve();\n if (destContext && extraData && extraData.logo) {\n logoPromise = this.drawElement(extraData.logo, destCanvas);\n }\n\n logoPromise.then((logoSize = [0, 0]) => {\n // North arrow\n let arrowPromise = Promise.resolve();\n if (destContext && extraData && extraData.northArrow) {\n arrowPromise = this.drawElement(\n {\n src: extraData.northArrow.circled\n ? NorthArrowCircle\n : NorthArrowSimple,\n ...extraData.northArrow,\n },\n destCanvas,\n logoSize,\n );\n }\n\n // Copyright\n arrowPromise.then((arrowSize = [0, 0]) => {\n const widestElement = Math.max(logoSize[0], arrowSize[0]);\n if (\n destContext &&\n extraData &&\n extraData.copyright &&\n extraData.copyright.text\n ) {\n const maxWidth = widestElement\n ? destContext.canvas.width - widestElement\n : destContext.canvas.width;\n this.drawCopyright(destContext, destCanvas, maxWidth);\n }\n resolve(destCanvas);\n });\n });\n });\n mapToExport.renderSync();\n });\n }\n\n downloadCanvasImage(canvas) {\n // Use blob for large images\n const promise = new Promise((resolve) => {\n const { format } = this.props;\n if (/msie (9|10)/gi.test(window.navigator.userAgent.toLowerCase())) {\n // ie 9 and 10\n const url = canvas.toDataURL(format);\n const w = window.open('about:blank', '');\n w.document.write(`<img src=\"${url}\" alt=\"from canvas\"/>`);\n resolve(url);\n }\n if (window.navigator.msSaveBlob) {\n // ie 11 and higher\n let image;\n try {\n image = canvas.msToBlob();\n } catch (e) {\n // eslint-disable-next-line no-console\n console.log(e);\n }\n const blob = new Blob([image], {\n type: format,\n });\n resolve(blob);\n window.navigator.msSaveBlob(blob, this.getDownloadImageName());\n } else {\n canvas.toBlob((blob) => {\n const link = document.createElement('a');\n link.download = this.getDownloadImageName();\n link.href = URL.createObjectURL(blob);\n // append child to document for firefox to be able to download.\n document.body.appendChild(link);\n link.click();\n resolve(blob);\n }, format);\n }\n });\n return promise;\n }\n\n render() {\n const { children, ...other } = this.props;\n\n delete other.onSaveStart;\n delete other.onSaveEnd;\n delete other.extraData;\n delete other.extent;\n delete other.format;\n delete other.map;\n delete other.coordinates;\n delete other.autoDownload;\n delete other.scale;\n\n return (\n <div\n role=\"button\"\n className=\"rs-canvas-save-button\"\n tabIndex={0}\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...other}\n onClick={(e) => {\n return this.onClick(e);\n }}\n onKeyPress={(e) => {\n return e.which === 13 && this.onClick(e);\n }}\n >\n {children}\n </div>\n );\n }\n}\n\nCanvasSaveButton.propTypes = propTypes;\nCanvasSaveButton.defaultProps = defaultProps;\n\nexport default CanvasSaveButton;\n"],"names":["const","super","this","let"],"mappings":"AAAA;;AACA,OAAO,KAAK,IAAI,aAAa,QAAQ,OAAO,CAAC;AAC7C,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,MAAM,QAAQ,CAAC;AAC3B,SAAS,UAAU,EAAE,cAAc,QAAQ,WAAW,CAAC;AACvD,OAAO,gBAAgB,MAAM,iCAAiC,CAAC;AAC/D,OAAO,gBAAgB,MAAM,uCAAuC,CAAC;AACrE;AACAA,GAAK,CAAC,SAAS,GAAG;AAClB;AACA;AACA;AACA,EAAE,YAAY,EAAE,SAAS,CAAC,IAAI;AAC9B;AACA;AACA;AACA;AACA,EAAE,QAAQ,EAAE,SAAS,CAAC,IAAI;AAC1B;AACA;AACA;AACA;AACA,EAAE,MAAM,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;AACtD;AACA;AACA,EAAE,GAAG,EAAE,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC;AAClC;AACA;AACA;AACA;AACA,EAAE,MAAM,EAAE,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC;AAC7C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,E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,KAAK,CAAC,MAAM,CAAC;AACxB,IAAI,OAAO,KAAK,CAAC,MAAM,CAAC;AACxB,IAAI,OAAO,KAAK,CAAC,GAAG,CAAC;AACrB,IAAI,OAAO,KAAK,CAAC,WAAW,CAAC;AAC7B,IAAI,OAAO,KAAK,CAAC,YAAY,CAAC;AAC9B,IAAI,OAAO,KAAK,CAAC,KAAK,CAAC;AACvB;AACA,IAAI,OAAO;AACX,MAAM,sBAAC,uBAAG;AACV,UAAQ,MAAK,QAAQ,EACb,WAAU,uBAAuB,EACjC,UAAU,GAAE,EAER,KAAM,IACV,kBAAS,CAAC,CAAC,EAAK;AACxB,UAAU,OAAOA,MAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACjC,SAAU,EACF,qBAAY,CAAC,CAAC,EAAK;AAC3B,UAAU,OAAO,CAAC,CAAC,KAAK,KAAK,EAAE,IAAIA,MAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACnD,aACO;AACP,QAAS,QAAS;AAClB,MAAM,CAAM;AACZ,KAAK,CAAC;AACN;;;EArb+B,gBAsb9B;AACD;AACA,gBAAgB,CAAC,SAAS,GAAG,SAAS,CAAC;AACvC,gBAAgB,CAAC,YAAY,GAAG,YAAY,CAAC;AAC7C;AACA,eAAe,gBAAgB,CAAC;"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/CanvasSaveButton/CanvasSaveButton.js"],
4
+ "sourcesContent": ["/* eslint-disable no-param-reassign */\nimport React, { PureComponent } from 'react';\nimport PropTypes from 'prop-types';\nimport OLMap from 'ol/Map';\nimport { getTopLeft, getBottomRight } from 'ol/extent';\nimport NorthArrowSimple from '../../images/northArrow.url.svg';\nimport NorthArrowCircle from '../../images/northArrowCircle.url.svg';\n\nconst propTypes = {\n /**\n * Automatically download the image saved.\n */\n autoDownload: PropTypes.bool,\n\n /**\n * Children content of the button.\n */\n children: PropTypes.node,\n\n /**\n * Output format of the image.\n */\n format: PropTypes.oneOf(['image/jpeg', 'image/png']),\n\n /** An [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html). */\n map: PropTypes.instanceOf(OLMap),\n\n /**\n * Extent for the export. If no extent is given, the whole map is exported.\n */\n extent: PropTypes.arrayOf(PropTypes.number),\n\n /**\n * Array of 4 [ol/Coordinate](https://openlayers.org/en/latest/apidoc/module-ol_coordinate.html#~Coordinate).\n * If no coordinates and no extent are given, the whole map is exported.\n * This property must be used to export rotated map.\n * If you don't need to export rotated map the extent property can be used as well.\n * If extent is specified, coordinates property is ignored.\n */\n coordinates: PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.number)),\n\n /**\n * Scale the map for better quality. Possible values: 1, 2 or 3.\n * WARNING: The tiled layer with a WMTS or XYZ source must provides an url\n * for each scale in the config file.\n */\n scale: PropTypes.number,\n\n /**\n * Function called before the dowload process begins.\n */\n onSaveStart: PropTypes.func,\n\n /**\n * Function called after the dowload process ends.\n *\n * @param {object} error Error message the process fails.\n */\n onSaveEnd: PropTypes.func,\n\n /**\n * Extra data, such as copyright, north arrow configuration.\n * All extra data is optional.\n *\n * Example 1:\n *\n {\n copyright: {\n text: 'Example copyright', // Copyright text or function\n font: '10px Arial', // Font, default is '12px Arial'\n fillStyle: 'blue', // Fill style, default is 'black'\n },\n northArrow, // True if the north arrow\n // should be placed with default configuration\n // (default image, rotation=0, circled=False)\n }\n * Example 2:\n *\n {\n northArrow: {\n src: NorthArrowCustom,\n width: 60, // Width in px, default is 80\n height: 100, // Height in px, default is 80\n rotation: 25, // Absolute rotation in degrees as number or function\n\n }\n }\n * Example 3:\n *\n {\n copyright: {\n text: () => { // Copyright as function\n return this.copyright;\n },\n },\n northArrow: {\n rotation: () => { // Rotation as function\n return NorthArrow.radToDeg(this.map.getView().getRotation());\n },\n circled, // Display circle around the north arrow (Does not work for custom src)\n },\n }\n */\n extraData: PropTypes.object,\n};\n\nconst defaultProps = {\n autoDownload: true,\n children: null,\n map: null,\n format: 'image/png',\n extent: null,\n extraData: null,\n coordinates: null,\n scale: 1,\n onSaveStart: (map) => {\n return Promise.resolve(map);\n },\n onSaveEnd: () => {},\n};\n\n/**\n * The CanvasSaveButton component creates a button to save\n * an [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html)\n * canvas as an image.\n */\nclass CanvasSaveButton extends PureComponent {\n constructor(props) {\n super(props);\n const { format } = this.props;\n this.fileExt = format === 'image/jpeg' ? 'jpg' : 'png';\n this.padding = 5;\n }\n\n onClick(evt) {\n const { map, onSaveStart, onSaveEnd, autoDownload } = this.props;\n if (window.navigator.msSaveBlob) {\n // ie only\n evt.preventDefault();\n evt.stopPropagation();\n }\n onSaveStart(map).then((mapToExport) => {\n return this.createCanvasImage(mapToExport || map)\n .then((canvas) => {\n if (autoDownload) {\n this.downloadCanvasImage(canvas).then((blob) => {\n onSaveEnd(mapToExport, canvas, blob);\n });\n } else {\n onSaveEnd(mapToExport, canvas);\n }\n })\n .catch((err) => {\n if (err) {\n // eslint-disable-next-line no-console\n console.error(err);\n }\n onSaveEnd(mapToExport, err);\n });\n });\n }\n\n getDownloadImageName() {\n return (\n `${window.document.title.replace(/ /g, '_').toLowerCase()}` +\n `.${this.fileExt}`\n );\n }\n\n // Ensure the font size fita with the image width.\n decreaseFontSize(destContext, maxWidth, copyright, scale) {\n const minFontSize = 8;\n let sizeMatch;\n let fontSize;\n do {\n sizeMatch = destContext.font.match(/[0-9]+(?:\\.[0-9]+)?(px)/i);\n fontSize = parseInt(sizeMatch[0].replace(sizeMatch[1], ''), 10);\n\n // eslint-disable-next-line no-param-reassign\n destContext.font = destContext.font.replace(fontSize, fontSize - 1);\n\n if (fontSize - 1 === minFontSize) {\n this.multilineCopyright = true;\n }\n } while (\n fontSize - 1 > minFontSize &&\n destContext.measureText(copyright).width * scale > maxWidth\n );\n\n return destContext.font;\n }\n\n // eslint-disable-next-line class-methods-use-this\n drawTextBackground(\n destContext,\n textMeasure,\n textX,\n textY,\n padding,\n styleOptions = {},\n ) {\n /// get width of text\n const { width, height, actualBoundingBoxAscent } = textMeasure;\n destContext.save();\n // Dflt is a white background\n destContext.fillStyle = 'rgba(255,255,255,.8)';\n\n // To simplify usability the user could pass a boolean to use only default values.\n if (typeof styleOptions === 'object') {\n Object.entries(styleOptions).forEach(([key, value]) => {\n destContext[key] = value;\n });\n }\n\n /// draw background rect assuming height of font\n destContext.fillRect(\n textX - padding,\n textY - actualBoundingBoxAscent - padding,\n width + padding * 2,\n height + padding * 2,\n );\n destContext.restore();\n }\n\n drawCopyright(destContext, destCanvas, maxWidth) {\n const { extraData, scale } = this.props;\n const { text, font, fillStyle, background } = extraData.copyright;\n let copyright = typeof text === 'function' ? text() : text;\n\n if (Array.isArray(copyright)) {\n copyright = copyright.join();\n }\n\n destContext.save();\n destContext.scale(scale, scale);\n destContext.font = font || '12px Arial';\n destContext.font = this.decreaseFontSize(\n destContext,\n maxWidth - this.padding,\n copyright,\n scale,\n );\n\n destContext.scale(scale, scale);\n destContext.fillStyle = fillStyle || 'black';\n\n // We search if the display on 2 line is necessary\n let firstLine = copyright;\n const wordNumber = copyright.split(' ').length;\n\n // If the text is bigger than the max width we split itinto 2 lines\n if (this.multilineCopyright) {\n for (let i = 0; i < wordNumber; i += 1) {\n firstLine = firstLine.substring(0, firstLine.lastIndexOf(' '));\n // Stop removing word when fits within one line.\n if (\n destContext.measureText(firstLine).width * scale <\n maxWidth - this.padding\n ) {\n break;\n }\n }\n }\n const secondLine = copyright.replace(firstLine, '');\n\n // Draw first line (line break isn't supported for fillText).\n const textX = this.padding;\n let textMeasure = destContext.measureText(firstLine);\n textMeasure.height =\n textMeasure.actualBoundingBoxAscent +\n textMeasure.actualBoundingBoxDescent;\n let firstLineY = destCanvas.height / scale - this.padding;\n const secondLineY = firstLineY;\n const paddingBetweenLines = 3;\n const paddingBackground = paddingBetweenLines / 2;\n\n if (secondLine) {\n firstLineY -= textMeasure.height + paddingBetweenLines;\n }\n if (background) {\n this.drawTextBackground(\n destContext,\n textMeasure,\n textX,\n firstLineY,\n paddingBackground,\n background,\n );\n }\n destContext.fillText(firstLine, textX, firstLineY);\n\n // Draw second line.\n if (secondLine) {\n textMeasure = destContext.measureText(secondLine);\n textMeasure.height =\n textMeasure.actualBoundingBoxAscent +\n textMeasure.actualBoundingBoxDescent;\n if (background) {\n this.drawTextBackground(\n destContext,\n textMeasure,\n textX,\n secondLineY,\n paddingBackground,\n background,\n );\n }\n destContext.fillText(secondLine, textX, secondLineY);\n }\n\n destContext.restore();\n }\n\n drawElement(data, destCanvas, previousItemSize = [0, 0]) {\n const destContext = destCanvas.getContext('2d');\n const { scale } = this.props;\n const { src, width, height, rotation } = data;\n\n return new Promise((resolve) => {\n const img = new Image();\n img.crossOrigin = 'Anonymous';\n img.src = src;\n img.onload = () => {\n destContext.save();\n const elementWidth = (width || 80) * scale;\n const elementHeight = (height || 80) * scale;\n destContext.translate(\n destCanvas.width - 2 * this.padding - elementWidth / 2,\n destCanvas.height -\n 2 * this.padding -\n elementHeight / 2 -\n previousItemSize[1],\n );\n\n if (rotation) {\n const angle = typeof rotation === 'function' ? rotation() : rotation;\n destContext.rotate(angle * (Math.PI / 180));\n }\n\n destContext.drawImage(\n img,\n -elementWidth / 2,\n -elementHeight / 2,\n elementWidth,\n elementHeight,\n );\n destContext.restore();\n\n // Return the pixels width of the arrow and the margin right,\n // that must not be occupied by the copyright.\n resolve([\n elementWidth + 2 * this.padding,\n elementHeight + 2 * this.padding,\n ]);\n };\n\n img.onerror = () => {\n resolve();\n };\n });\n }\n\n calculatePixelsToExport(mapToExport) {\n const { extent, coordinates } = this.props;\n let firstCoordinate;\n let oppositeCoordinate;\n\n if (extent) {\n firstCoordinate = getTopLeft(extent);\n oppositeCoordinate = getBottomRight(extent);\n } else if (coordinates) {\n // In case of coordinates coming from DragBox interaction:\n // firstCoordinate is the first coordinate drawn by the user.\n // oppositeCoordinate is the coordinate of the point dragged by the user.\n [firstCoordinate, , oppositeCoordinate] = coordinates;\n }\n\n if (firstCoordinate && oppositeCoordinate) {\n const firstPixel = mapToExport.getPixelFromCoordinate(firstCoordinate);\n const oppositePixel =\n mapToExport.getPixelFromCoordinate(oppositeCoordinate);\n const pixelTopLeft = [\n firstPixel[0] <= oppositePixel[0] ? firstPixel[0] : oppositePixel[0],\n firstPixel[1] <= oppositePixel[1] ? firstPixel[1] : oppositePixel[1],\n ];\n const pixelBottomRight = [\n firstPixel[0] > oppositePixel[0] ? firstPixel[0] : oppositePixel[0],\n firstPixel[1] > oppositePixel[1] ? firstPixel[1] : oppositePixel[1],\n ];\n\n return {\n x: pixelTopLeft[0],\n y: pixelTopLeft[1],\n w: pixelBottomRight[0] - pixelTopLeft[0],\n h: pixelBottomRight[1] - pixelTopLeft[1],\n };\n }\n return null;\n }\n\n createCanvasImage(mapToExport) {\n const { extraData } = this.props;\n\n return new Promise((resolve) => {\n mapToExport.once('rendercomplete', () => {\n // Find all layer canvases and add it to dest canvas.\n const canvases = mapToExport\n .getTargetElement()\n .getElementsByTagName('canvas');\n\n // Create the canvas to export with the good size.\n let destCanvas;\n let destContext;\n\n // canvases is an HTMLCollection, we don't try to transform to array because some compilers like cra doesn't translate it right.\n for (let i = 0; i < canvases.length; i += 1) {\n const canvas = canvases[i];\n if (!canvas.width || !canvas.height) {\n // eslint-disable-next-line no-continue\n continue;\n }\n const clip = this.calculatePixelsToExport(mapToExport) || {\n x: 0,\n y: 0,\n w: canvas.width,\n h: canvas.height,\n };\n\n if (!destCanvas) {\n destCanvas = document.createElement('canvas');\n destCanvas.width = clip.w;\n destCanvas.height = clip.h;\n destContext = destCanvas.getContext('2d');\n }\n\n // Draw canvas to the canvas to export.\n destContext.drawImage(\n canvas,\n clip.x,\n clip.y,\n clip.w,\n clip.h,\n 0,\n 0,\n destCanvas.width,\n destCanvas.height,\n );\n }\n\n // Custom info\n let logoPromise = Promise.resolve();\n if (destContext && extraData && extraData.logo) {\n logoPromise = this.drawElement(extraData.logo, destCanvas);\n }\n\n logoPromise.then((logoSize = [0, 0]) => {\n // North arrow\n let arrowPromise = Promise.resolve();\n if (destContext && extraData && extraData.northArrow) {\n arrowPromise = this.drawElement(\n {\n src: extraData.northArrow.circled\n ? NorthArrowCircle\n : NorthArrowSimple,\n ...extraData.northArrow,\n },\n destCanvas,\n logoSize,\n );\n }\n\n // Copyright\n arrowPromise.then((arrowSize = [0, 0]) => {\n const widestElement = Math.max(logoSize[0], arrowSize[0]);\n if (\n destContext &&\n extraData &&\n extraData.copyright &&\n extraData.copyright.text\n ) {\n const maxWidth = widestElement\n ? destContext.canvas.width - widestElement\n : destContext.canvas.width;\n this.drawCopyright(destContext, destCanvas, maxWidth);\n }\n resolve(destCanvas);\n });\n });\n });\n mapToExport.renderSync();\n });\n }\n\n downloadCanvasImage(canvas) {\n // Use blob for large images\n const promise = new Promise((resolve) => {\n const { format } = this.props;\n if (/msie (9|10)/gi.test(window.navigator.userAgent.toLowerCase())) {\n // ie 9 and 10\n const url = canvas.toDataURL(format);\n const w = window.open('about:blank', '');\n w.document.write(`<img src=\"${url}\" alt=\"from canvas\"/>`);\n resolve(url);\n }\n if (window.navigator.msSaveBlob) {\n // ie 11 and higher\n let image;\n try {\n image = canvas.msToBlob();\n } catch (e) {\n // eslint-disable-next-line no-console\n console.log(e);\n }\n const blob = new Blob([image], {\n type: format,\n });\n resolve(blob);\n window.navigator.msSaveBlob(blob, this.getDownloadImageName());\n } else {\n canvas.toBlob((blob) => {\n const link = document.createElement('a');\n link.download = this.getDownloadImageName();\n link.href = URL.createObjectURL(blob);\n // append child to document for firefox to be able to download.\n document.body.appendChild(link);\n link.click();\n resolve(blob);\n }, format);\n }\n });\n return promise;\n }\n\n render() {\n const { children, ...other } = this.props;\n\n delete other.onSaveStart;\n delete other.onSaveEnd;\n delete other.extraData;\n delete other.extent;\n delete other.format;\n delete other.map;\n delete other.coordinates;\n delete other.autoDownload;\n delete other.scale;\n\n return (\n <div\n role=\"button\"\n className=\"rs-canvas-save-button\"\n tabIndex={0}\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...other}\n onClick={(e) => {\n return this.onClick(e);\n }}\n onKeyPress={(e) => {\n return e.which === 13 && this.onClick(e);\n }}\n >\n {children}\n </div>\n );\n }\n}\n\nCanvasSaveButton.propTypes = propTypes;\nCanvasSaveButton.defaultProps = defaultProps;\n\nexport default CanvasSaveButton;\n"],
5
+ "mappings": "AACA,OAAO,SAAS,qBAAqB;AACrC,OAAO,eAAe;AACtB,OAAO,WAAW;AAClB,SAAS,YAAY,sBAAsB;AAC3C,OAAO,sBAAsB;AAC7B,OAAO,sBAAsB;AAE7B,MAAM,YAAY;AAAA,EAIhB,cAAc,UAAU;AAAA,EAKxB,UAAU,UAAU;AAAA,EAKpB,QAAQ,UAAU,MAAM,CAAC,cAAc,WAAW,CAAC;AAAA,EAGnD,KAAK,UAAU,WAAW,KAAK;AAAA,EAK/B,QAAQ,UAAU,QAAQ,UAAU,MAAM;AAAA,EAS1C,aAAa,UAAU,QAAQ,UAAU,QAAQ,UAAU,MAAM,CAAC;AAAA,EAOlE,OAAO,UAAU;AAAA,EAKjB,aAAa,UAAU;AAAA,EAOvB,WAAW,UAAU;AAAA,EA6CrB,WAAW,UAAU;AACvB;AAEA,MAAM,eAAe;AAAA,EACnB,cAAc;AAAA,EACd,UAAU;AAAA,EACV,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,aAAa;AAAA,EACb,OAAO;AAAA,EACP,aAAa,CAAC,QAAQ;AACpB,WAAO,QAAQ,QAAQ,GAAG;AAAA,EAC5B;AAAA,EACA,WAAW,MAAM;AAAA,EAAC;AACpB;AAOA,MAAM,yBAAyB,cAAc;AAAA,EAC3C,YAAY,OAAO;AACjB,UAAM,KAAK;AACX,UAAM,EAAE,OAAO,IAAI,KAAK;AACxB,SAAK,UAAU,WAAW,eAAe,QAAQ;AACjD,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,QAAQ,KAAK;AACX,UAAM,EAAE,KAAK,aAAa,WAAW,aAAa,IAAI,KAAK;A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;AACP,UAAM,EAAE,aAAa,MAAM,IAAI,KAAK;AAEpC,WAAO,MAAM;AACb,WAAO,MAAM;AACb,WAAO,MAAM;AACb,WAAO,MAAM;AACb,WAAO,MAAM;AACb,WAAO,MAAM;AACb,WAAO,MAAM;AACb,WAAO,MAAM;AACb,WAAO,MAAM;AAEb,WACE,oCAAC;AAAA,MACC,MAAK;AAAA,MACL,WAAU;AAAA,MACV,UAAU;AAAA,MAET,GAAG;AAAA,MACJ,SAAS,CAAC,MAAM;AACd,eAAO,KAAK,QAAQ,CAAC;AAAA,MACvB;AAAA,MACA,YAAY,CAAC,MAAM;AACjB,eAAO,EAAE,UAAU,MAAM,KAAK,QAAQ,CAAC;AAAA,MACzC;AAAA,OAEC,QACH;AAAA,EAEJ;AACF;AAEA,iBAAiB,YAAY;AAC7B,iBAAiB,eAAe;AAEhC,eAAe;",
6
+ "names": []
7
+ }
@@ -1,3 +1 @@
1
- export { default } from './CanvasSaveButton';
2
-
3
- //# sourceMappingURL=index.js.map
1
+ export { default } from "./CanvasSaveButton";
@@ -1 +1,7 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/components/CanvasSaveButton/index.js"],"sourcesContent":["export { default } from './CanvasSaveButton';\n"],"names":[],"mappings":"AAAA,SAAS,OAAO,QAAQ,oBAAoB,CAAC;"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/CanvasSaveButton/index.js"],
4
+ "sourcesContent": ["export { default } from './CanvasSaveButton';\n"],
5
+ "mappings": "AAAA,wBAAwB;",
6
+ "names": []
7
+ }
@@ -1,96 +1,55 @@
1
- function objectWithoutProperties (obj, exclude) { var target = {}; for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k) && exclude.indexOf(k) === -1) target[k] = obj[k]; return target; }
2
- import React, { useMemo, useEffect, useState } from 'react';
3
- import PropTypes from 'prop-types';
4
- import { Map } from 'ol';
5
- import { CopyrightControl } from 'mobility-toolbox-js/ol';
6
-
7
- var propTypes = {
8
- /**
9
- * A map.
10
- */
1
+ import React, { useMemo, useEffect, useState } from "react";
2
+ import PropTypes from "prop-types";
3
+ import { Map } from "ol";
4
+ import { CopyrightControl } from "mobility-toolbox-js/ol";
5
+ const propTypes = {
11
6
  map: PropTypes.instanceOf(Map).isRequired,
12
-
13
- /**
14
- * Format function. Called with an array of copyrights from visible layers
15
- * and returns the copyright.
16
- */
17
7
  format: PropTypes.func,
18
-
19
- /**
20
- * CSS class of th root element
21
- */
22
- className: PropTypes.string,
8
+ className: PropTypes.string
23
9
  };
24
-
25
- var defaultProps = {
26
- format: function (copyrights) {
27
- return copyrights.join(' | ');
10
+ const defaultProps = {
11
+ format: (copyrights) => {
12
+ return copyrights.join(" | ");
28
13
  },
29
- className: 'rs-copyright',
14
+ className: "rs-copyright"
30
15
  };
31
-
32
- /**
33
- * The Copyright component uses the
34
- * [mobility-toolbox-js CopyrightControl](https://mobility-toolbox-js.geops.io/api/class/src/mapbox/controls/CopyrightControl%20js~CopyrightControl%20html-offset-anchor)
35
- * to render the layer copyrights.
36
- */
37
- function Copyright(ref) {
38
- var map = ref.map;
39
- var format = ref.format;
40
- var rest = objectWithoutProperties( ref, ["map", "format"] );
41
- var other = rest;
42
-
43
- var ref$1 = useState([]);
44
- var copyrights = ref$1[0];
45
- var setCopyrights = ref$1[1];
46
-
47
- var control = useMemo(
48
- function () {
16
+ function Copyright({ map, format, ...other }) {
17
+ const [copyrights, setCopyrights] = useState([]);
18
+ const control = useMemo(
19
+ () => {
49
20
  return new CopyrightControl({
50
- target: document.createElement('div'),
51
- element: document.createElement('div'),
52
- render: function render() {
53
- // eslint-disable-next-line react/no-this-in-sfc
54
- var newCopyrights = this.getCopyrights();
21
+ target: document.createElement("div"),
22
+ element: document.createElement("div"),
23
+ render() {
24
+ const newCopyrights = this.getCopyrights();
55
25
  if (copyrights.toString() !== newCopyrights.toString()) {
56
26
  setCopyrights(newCopyrights);
57
27
  }
58
- },
28
+ }
59
29
  });
60
30
  },
61
- // eslint-disable-next-line react-hooks/exhaustive-deps
62
31
  []
63
32
  );
64
-
65
- // Ensure the control is not associated to the wrong map
66
- useEffect(function () {
33
+ useEffect(() => {
67
34
  if (!control) {
68
- return function () {};
35
+ return () => {
36
+ };
69
37
  }
70
-
71
38
  control.map = map;
72
-
73
- return function () {
39
+ return () => {
74
40
  control.map = null;
75
41
  };
76
42
  }, [map, control]);
77
-
78
43
  if (!control || !control.getCopyrights().length) {
79
44
  return null;
80
45
  }
81
-
82
- return (
83
- React.createElement( 'div', Object.assign({},
84
- // eslint-disable-next-line react/jsx-props-no-spreading
85
- other, { dangerouslySetInnerHTML: {
86
- __html: format(copyrights) || '',
87
- } }))
88
- );
46
+ return /* @__PURE__ */ React.createElement("div", {
47
+ ...other,
48
+ dangerouslySetInnerHTML: {
49
+ __html: format(copyrights) || ""
50
+ }
51
+ });
89
52
  }
90
-
91
53
  Copyright.propTypes = propTypes;
92
54
  Copyright.defaultProps = defaultProps;
93
-
94
55
  export default React.memo(Copyright);
95
-
96
- //# sourceMappingURL=Copyright.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"Copyright.js","sources":["../../../src/components/Copyright/Copyright.js"],"sourcesContent":["import React, { useMemo, useEffect, useState } from 'react';\nimport PropTypes from 'prop-types';\nimport { Map } from 'ol';\nimport { CopyrightControl } from 'mobility-toolbox-js/ol';\n\nconst propTypes = {\n /**\n * A map.\n */\n map: PropTypes.instanceOf(Map).isRequired,\n\n /**\n * Format function. Called with an array of copyrights from visible layers\n * and returns the copyright.\n */\n format: PropTypes.func,\n\n /**\n * CSS class of th root element\n */\n className: PropTypes.string,\n};\n\nconst defaultProps = {\n format: (copyrights) => {\n return copyrights.join(' | ');\n },\n className: 'rs-copyright',\n};\n\n/**\n * The Copyright component uses the\n * [mobility-toolbox-js CopyrightControl](https://mobility-toolbox-js.geops.io/api/class/src/mapbox/controls/CopyrightControl%20js~CopyrightControl%20html-offset-anchor)\n * to render the layer copyrights.\n */\nfunction Copyright({ map, format, ...other }) {\n const [copyrights, setCopyrights] = useState([]);\n\n const control = useMemo(\n () => {\n return new CopyrightControl({\n target: document.createElement('div'),\n element: document.createElement('div'),\n render() {\n // eslint-disable-next-line react/no-this-in-sfc\n const newCopyrights = this.getCopyrights();\n if (copyrights.toString() !== newCopyrights.toString()) {\n setCopyrights(newCopyrights);\n }\n },\n });\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [],\n );\n\n // Ensure the control is not associated to the wrong map\n useEffect(() => {\n if (!control) {\n return () => {};\n }\n\n control.map = map;\n\n return () => {\n control.map = null;\n };\n }, [map, control]);\n\n if (!control || !control.getCopyrights().length) {\n return null;\n }\n\n return (\n <div\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...other}\n // eslint-disable-next-line react/no-danger\n dangerouslySetInnerHTML={{\n __html: format(copyrights) || '',\n }}\n />\n );\n}\n\nCopyright.propTypes = propTypes;\nCopyright.defaultProps = defaultProps;\n\nexport default React.memo(Copyright);\n"],"names":["const"],"mappings":";AAAA,OAAO,KAAK,IAAI,OAAO,EAAE,SAAS,EAAE,QAAQ,QAAQ,OAAO,CAAC;AAC5D,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,SAAS,GAAG,QAAQ,IAAI,CAAC;AACzB,SAAS,gBAAgB,QAAQ,wBAAwB,CAAC;AAC1D;AACAA,GAAK,CAAC,SAAS,GAAG;AAClB;AACA;AACA;AACA,EAAE,GAAG,EAAE,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,UAAU;AAC3C;AACA;AACA;AACA;AACA;AACA,EAAE,MAAM,EAAE,SAAS,CAAC,IAAI;AACxB;AACA;AACA;AACA;AACA,EAAE,SAAS,EAAE,SAAS,CAAC,MAAM;AAC7B,CAAC,CAAC;AACF;AACAA,GAAK,CAAC,YAAY,GAAG;AACrB,EAAE,MAAM,WAAE,CAAC,UAAU,EAAK;AAC1B,IAAI,OAAO,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAClC,GAAG;AACH,EAAE,SAAS,EA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AAC,uBAAG;AACR;AACA,MAAU,KAAM,IAEV,yBAAyB;AAC/B,QAAQ,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE;AACxC,UAAQ,CACF;AACN,GAAG,CAAC;AACJ,CAAC;AACD;AACA,SAAS,CAAC,SAAS,GAAG,SAAS,CAAC;AAChC,SAAS,CAAC,YAAY,GAAG,YAAY,CAAC;AACtC;AACA,eAAe,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/Copyright/Copyright.js"],
4
+ "sourcesContent": ["import React, { useMemo, useEffect, useState } from 'react';\nimport PropTypes from 'prop-types';\nimport { Map } from 'ol';\nimport { CopyrightControl } from 'mobility-toolbox-js/ol';\n\nconst propTypes = {\n /**\n * A map.\n */\n map: PropTypes.instanceOf(Map).isRequired,\n\n /**\n * Format function. Called with an array of copyrights from visible layers\n * and returns the copyright.\n */\n format: PropTypes.func,\n\n /**\n * CSS class of th root element\n */\n className: PropTypes.string,\n};\n\nconst defaultProps = {\n format: (copyrights) => {\n return copyrights.join(' | ');\n },\n className: 'rs-copyright',\n};\n\n/**\n * The Copyright component uses the\n * [mobility-toolbox-js CopyrightControl](https://mobility-toolbox-js.geops.io/api/class/src/mapbox/controls/CopyrightControl%20js~CopyrightControl%20html-offset-anchor)\n * to render the layer copyrights.\n */\nfunction Copyright({ map, format, ...other }) {\n const [copyrights, setCopyrights] = useState([]);\n\n const control = useMemo(\n () => {\n return new CopyrightControl({\n target: document.createElement('div'),\n element: document.createElement('div'),\n render() {\n // eslint-disable-next-line react/no-this-in-sfc\n const newCopyrights = this.getCopyrights();\n if (copyrights.toString() !== newCopyrights.toString()) {\n setCopyrights(newCopyrights);\n }\n },\n });\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [],\n );\n\n // Ensure the control is not associated to the wrong map\n useEffect(() => {\n if (!control) {\n return () => {};\n }\n\n control.map = map;\n\n return () => {\n control.map = null;\n };\n }, [map, control]);\n\n if (!control || !control.getCopyrights().length) {\n return null;\n }\n\n return (\n <div\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...other}\n // eslint-disable-next-line react/no-danger\n dangerouslySetInnerHTML={{\n __html: format(copyrights) || '',\n }}\n />\n );\n}\n\nCopyright.propTypes = propTypes;\nCopyright.defaultProps = defaultProps;\n\nexport default React.memo(Copyright);\n"],
5
+ "mappings": "AAAA,OAAO,SAAS,SAAS,WAAW,gBAAgB;AACpD,OAAO,eAAe;AACtB,SAAS,WAAW;AACpB,SAAS,wBAAwB;AAEjC,MAAM,YAAY;AAAA,EAIhB,KAAK,UAAU,WAAW,GAAG,EAAE;AAAA,EAM/B,QAAQ,UAAU;AAAA,EAKlB,WAAW,UAAU;AACvB;AAEA,MAAM,eAAe;AAAA,EACnB,QAAQ,CAAC,eAAe;AACtB,WAAO,WAAW,KAAK,KAAK;AAAA,EAC9B;AAAA,EACA,WAAW;AACb;AAOA,SAAS,UAAU,EAAE,KAAK,WAAW,MAAM,GAAG;AAC5C,QAAM,CAAC,YAAY,aAAa,IAAI,SAAS,CAAC,CAAC;AAE/C,QAAM,UAAU;AAAA,IACd,MAAM;AACJ,aAAO,IAAI,iBAAiB;AAAA,QAC1B,QAAQ,SAAS,cAAc,KAAK;AAAA,QACpC,SAAS,SAAS,cAAc,KAAK;AAAA,QACrC,SAAS;AAEP,gBAAM,gBAAgB,KAAK,cAAc;AACzC,cAAI,WAAW,SAAS,MAAM,cAAc,SAAS,GAAG;AACtD,0BAAc,aAAa;AAAA,UAC7B;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,IAEA,CAAC;AAAA,EACH;AAGA,YAAU,MAAM;AACd,QAAI,CAAC,SAAS;AACZ,aAAO,MAAM;AAAA,MAAC;AAAA,IAChB;AAEA,YAAQ,MAAM;AAEd,WAAO,MAAM;AACX,cAAQ,MAAM;AAAA,IAChB;AAAA,EACF,GAAG,CAAC,KAAK,OAAO,CAAC;AAEjB,MAAI,CAAC,WAAW,CAAC,QAAQ,cAAc,EAAE,QAAQ;AAC/C,WAAO;AAAA,EACT;AAEA,SACE,oCAAC;AAAA,IAEE,GAAG;AAAA,IAEJ,yBAAyB;AAAA,MACvB,QAAQ,OAAO,UAAU,KAAK;AAAA,IAChC;AAAA,GACF;AAEJ;AAEA,UAAU,YAAY;AACtB,UAAU,eAAe;AAEzB,eAAe,MAAM,KAAK,SAAS;",
6
+ "names": []
7
+ }
@@ -1,3 +1 @@
1
- export { default } from './Copyright';
2
-
3
- //# sourceMappingURL=index.js.map
1
+ export { default } from "./Copyright";
@@ -1 +1,7 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/components/Copyright/index.js"],"sourcesContent":["export { default } from './Copyright';\n"],"names":[],"mappings":"AAAA,SAAS,OAAO,QAAQ,aAAa,CAAC;"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/Copyright/index.js"],
4
+ "sourcesContent": ["export { default } from './Copyright';\n"],
5
+ "mappings": "AAAA,wBAAwB;",
6
+ "names": []
7
+ }
@@ -1,128 +1,62 @@
1
- function objectWithoutProperties (obj, exclude) { var target = {}; for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k) && exclude.indexOf(k) === -1) target[k] = obj[k]; return target; }
2
- import React, { PureComponent } from 'react';
3
- import PropTypes from 'prop-types';
4
- import KMLFormat from 'ol/format/KML';
5
- import { Layer } from 'mobility-toolbox-js/ol';
6
- import KML from '../../utils/KML';
7
-
8
- var propTypes = {
9
- /**
10
- * Children content of the Feature export button.
11
- */
1
+ import React, { PureComponent } from "react";
2
+ import PropTypes from "prop-types";
3
+ import KMLFormat from "ol/format/KML";
4
+ import { Layer } from "mobility-toolbox-js/ol";
5
+ import KML from "../../utils/KML";
6
+ const propTypes = {
12
7
  children: PropTypes.node,
13
-
14
- /**
15
- * Format to export features (function).
16
- * Supported formats: https://openlayers.org/en/latest/apidoc/module-ol_format_Feature-FeatureFormat.html
17
- */
18
8
  format: PropTypes.func,
19
-
20
- /**
21
- * An existing [mobility-toolbox-js Layer](https://mobility-toolbox-js.geops.io/api/identifiers%20html#ol-layers),
22
- * using a valid [ol/source/Vector](https://openlayers.org/en/latest/apidoc/module-ol_source_Vector.html)
23
- */
24
9
  layer: PropTypes.instanceOf(Layer).isRequired,
25
-
26
- /**
27
- * Map projection.
28
- */
29
- projection: PropTypes.string,
10
+ projection: PropTypes.string
30
11
  };
31
-
32
- var defaultProps = {
12
+ const defaultProps = {
33
13
  children: null,
34
14
  format: KMLFormat,
35
- projection: 'EPSG:3857',
15
+ projection: "EPSG:3857"
36
16
  };
37
-
38
- /**
39
- * The FeatureExportButton component creates a button that exports feature geometries
40
- * from a [[mobility-toolbox-js Layer](https://mobility-toolbox-js.geops.io/api/identifiers%20html#ol-layers)]
41
- * containing an [ol/layer/Vector](https://openlayers.org/en/latest/apidoc/module-ol_layer_Vector-VectorLayer.html)
42
- * with a [ol/source/Vector](https://openlayers.org/en/latest/apidoc/module-ol_source_Vector.html) on click.<br>
43
- * The default export format is KML, which supports the features' style export.<br>
44
- * Other formats do not always support style export (See specific format specs).
45
- */
46
- var FeatureExportButton = /*@__PURE__*/(function (PureComponent) {
47
- function FeatureExportButton () {
48
- PureComponent.apply(this, arguments);
49
- }
50
-
51
- if ( PureComponent ) FeatureExportButton.__proto__ = PureComponent;
52
- FeatureExportButton.prototype = Object.create( PureComponent && PureComponent.prototype );
53
- FeatureExportButton.prototype.constructor = FeatureExportButton;
54
-
55
- FeatureExportButton.createFeatureString = function createFeatureString (layer, projection, format) {
17
+ class FeatureExportButton extends PureComponent {
18
+ static createFeatureString(layer, projection, format) {
56
19
  if (format === KMLFormat) {
57
20
  return KML.writeFeatures(layer, projection);
58
21
  }
59
-
60
- // eslint-disable-next-line new-cap
61
22
  return new format().writeFeatures(layer.olLayer.getSource().getFeatures(), {
62
- featureProjection: projection,
23
+ featureProjection: projection
63
24
  });
64
- };
65
-
66
- FeatureExportButton.exportFeatures = function exportFeatures (layer, projection, format) {
67
- var now = new Date()
68
- .toJSON()
69
- .slice(0, 20)
70
- .replace(/[.:T-]+/g, '');
71
- var featString = this.createFeatureString(layer, projection, format);
72
-
73
- var formatString = featString
74
- ? featString.match(/<(\w+)\s+\w+.*?>/)[1]
75
- : 'xml';
76
-
77
- var fileName = "exported_features_" + now + "." + formatString;
78
- var charset = document.characterSet || 'UTF-8';
79
- var type = (formatString === 'kml'
80
- ? 'data:application/vnd.google-earth.kml+xml'
81
- : 'data:text/xml') + ";charset=" + charset;
82
-
25
+ }
26
+ static exportFeatures(layer, projection, format) {
27
+ const now = new Date().toJSON().slice(0, 20).replace(/[.:T-]+/g, "");
28
+ const featString = this.createFeatureString(layer, projection, format);
29
+ const formatString = featString ? featString.match(/<(\w+)\s+\w+.*?>/)[1] : "xml";
30
+ const fileName = `exported_features_${now}.${formatString}`;
31
+ const charset = document.characterSet || "UTF-8";
32
+ const type = `${formatString === "kml" ? "data:application/vnd.google-earth.kml+xml" : "data:text/xml"};charset=${charset}`;
83
33
  if (featString) {
84
34
  if (window.navigator.msSaveBlob) {
85
- // ie 11 and higher
86
- window.navigator.msSaveBlob(new Blob([featString], { type: type }), fileName);
35
+ window.navigator.msSaveBlob(new Blob([featString], { type }), fileName);
87
36
  } else {
88
- var link = document.createElement('a');
37
+ const link = document.createElement("a");
89
38
  link.download = fileName;
90
- link.href = type + "," + (encodeURIComponent(featString));
39
+ link.href = `${type},${encodeURIComponent(featString)}`;
91
40
  link.click();
92
41
  }
93
42
  }
94
- };
95
-
96
- FeatureExportButton.prototype.render = function render () {
97
- var ref = this.props;
98
- var children = ref.children;
99
- var layer = ref.layer;
100
- var projection = ref.projection;
101
- var format = ref.format;
102
- var rest = objectWithoutProperties( ref, ["children", "layer", "projection", "format"] );
103
- var other = rest;
104
-
105
- return (
106
- React.createElement( 'div', Object.assign({},
107
- { role: "button", className: "rs-feature-export-button", tabIndex: 0 }, other, { onClick: function () {
108
- return FeatureExportButton.exportFeatures(layer, projection, format);
109
- }, onKeyPress: function (evt) {
110
- return (
111
- evt.which === 13 &&
112
- FeatureExportButton.exportFeatures(layer, projection, format)
113
- );
114
- } }),
115
- children
116
- )
117
- );
118
- };
119
-
120
- return FeatureExportButton;
121
- }(PureComponent));
122
-
43
+ }
44
+ render() {
45
+ const { children, layer, projection, format, ...other } = this.props;
46
+ return /* @__PURE__ */ React.createElement("div", {
47
+ role: "button",
48
+ className: "rs-feature-export-button",
49
+ tabIndex: 0,
50
+ ...other,
51
+ onClick: () => {
52
+ return FeatureExportButton.exportFeatures(layer, projection, format);
53
+ },
54
+ onKeyPress: (evt) => {
55
+ return evt.which === 13 && FeatureExportButton.exportFeatures(layer, projection, format);
56
+ }
57
+ }, children);
58
+ }
59
+ }
123
60
  FeatureExportButton.propTypes = propTypes;
124
61
  FeatureExportButton.defaultProps = defaultProps;
125
-
126
62
  export default FeatureExportButton;
127
-
128
- //# sourceMappingURL=FeatureExportButton.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"FeatureExportButton.js","sources":["../../../src/components/FeatureExportButton/FeatureExportButton.js"],"sourcesContent":["import React, { PureComponent } from 'react';\nimport PropTypes from 'prop-types';\nimport KMLFormat from 'ol/format/KML';\nimport { Layer } from 'mobility-toolbox-js/ol';\nimport KML from '../../utils/KML';\n\nconst propTypes = {\n /**\n * Children content of the Feature export button.\n */\n children: PropTypes.node,\n\n /**\n * Format to export features (function).\n * Supported formats: https://openlayers.org/en/latest/apidoc/module-ol_format_Feature-FeatureFormat.html\n */\n format: PropTypes.func,\n\n /**\n * An existing [mobility-toolbox-js Layer](https://mobility-toolbox-js.geops.io/api/identifiers%20html#ol-layers),\n * using a valid [ol/source/Vector](https://openlayers.org/en/latest/apidoc/module-ol_source_Vector.html)\n */\n layer: PropTypes.instanceOf(Layer).isRequired,\n\n /**\n * Map projection.\n */\n projection: PropTypes.string,\n};\n\nconst defaultProps = {\n children: null,\n format: KMLFormat,\n projection: 'EPSG:3857',\n};\n\n/**\n * The FeatureExportButton component creates a button that exports feature geometries\n * from a [[mobility-toolbox-js Layer](https://mobility-toolbox-js.geops.io/api/identifiers%20html#ol-layers)]\n * containing an [ol/layer/Vector](https://openlayers.org/en/latest/apidoc/module-ol_layer_Vector-VectorLayer.html)\n * with a [ol/source/Vector](https://openlayers.org/en/latest/apidoc/module-ol_source_Vector.html) on click.<br>\n * The default export format is KML, which supports the features' style export.<br>\n * Other formats do not always support style export (See specific format specs).\n */\nclass FeatureExportButton extends PureComponent {\n static createFeatureString(layer, projection, format) {\n if (format === KMLFormat) {\n return KML.writeFeatures(layer, projection);\n }\n\n // eslint-disable-next-line new-cap\n return new format().writeFeatures(layer.olLayer.getSource().getFeatures(), {\n featureProjection: projection,\n });\n }\n\n static exportFeatures(layer, projection, format) {\n const now = new Date()\n .toJSON()\n .slice(0, 20)\n .replace(/[.:T-]+/g, '');\n const featString = this.createFeatureString(layer, projection, format);\n\n const formatString = featString\n ? featString.match(/<(\\w+)\\s+\\w+.*?>/)[1]\n : 'xml';\n\n const fileName = `exported_features_${now}.${formatString}`;\n const charset = document.characterSet || 'UTF-8';\n const type = `${\n formatString === 'kml'\n ? 'data:application/vnd.google-earth.kml+xml'\n : 'data:text/xml'\n };charset=${charset}`;\n\n if (featString) {\n if (window.navigator.msSaveBlob) {\n // ie 11 and higher\n window.navigator.msSaveBlob(new Blob([featString], { type }), fileName);\n } else {\n const link = document.createElement('a');\n link.download = fileName;\n link.href = `${type},${encodeURIComponent(featString)}`;\n link.click();\n }\n }\n }\n\n render() {\n const { children, layer, projection, format, ...other } = this.props;\n\n return (\n <div\n role=\"button\"\n className=\"rs-feature-export-button\"\n tabIndex={0}\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...other}\n onClick={() => {\n return FeatureExportButton.exportFeatures(layer, projection, format);\n }}\n onKeyPress={(evt) => {\n return (\n evt.which === 13 &&\n FeatureExportButton.exportFeatures(layer, projection, format)\n );\n }}\n >\n {children}\n </div>\n );\n }\n}\n\nFeatureExportButton.propTypes = propTypes;\nFeatureExportButton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,KAAK,EAAE,CAAC;AACrB,OAAO;AACP,KAAK;AACL,IAAG;AACH;AACA,gCAAE,yBAAM,GAAG;AACX,WAA2D,GAAG,IAAI,CAAC;IAAvD;IAAU;IAAO;IAAY;IAAQ;IAAG,iBAAqB;AACzE;AACA,IAAI,OAAO;AACX,MAAM,sBAAC,uBAAG;AACV,UAAQ,MAAK,QAAQ,EACb,WAAU,0BAA0B,EACpC,UAAU,GAAE,EAER,KAAM,IACV,kBAAS,GAAM;AACvB,UAAU,OAAO,mBAAmB,CAAC,cAAc,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;AAC/E,SAAU,EACF,qBAAY,CAAC,GAAG,EAAK;AAC7B,UAAU,OAAO;AACjB,YAAY,GAAG,CAAC,KAAK,KAAK,EAAE;AAC5B,YAAY,mBAAmB,CAAC,cAAc,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC;AACzE,WAAW,CAAC;AACZ,aACO;AACP,QAAS,QAAS;AAClB,MAAM,CAAM;AACZ,KAAK,CAAC;AACN;;;EAnEkC,gBAoEjC;AACD;AACA,mBAAmB,CAAC,SAAS,GAAG,SAAS,CAAC;AAC1C,mBAAmB,CAAC,YAAY,GAAG,YAAY,CAAC;AAChD;AACA,eAAe,mBAAmB,CAAC;"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/FeatureExportButton/FeatureExportButton.js"],
4
+ "sourcesContent": ["import React, { PureComponent } from 'react';\nimport PropTypes from 'prop-types';\nimport KMLFormat from 'ol/format/KML';\nimport { Layer } from 'mobility-toolbox-js/ol';\nimport KML from '../../utils/KML';\n\nconst propTypes = {\n /**\n * Children content of the Feature export button.\n */\n children: PropTypes.node,\n\n /**\n * Format to export features (function).\n * Supported formats: https://openlayers.org/en/latest/apidoc/module-ol_format_Feature-FeatureFormat.html\n */\n format: PropTypes.func,\n\n /**\n * An existing [mobility-toolbox-js Layer](https://mobility-toolbox-js.geops.io/api/identifiers%20html#ol-layers),\n * using a valid [ol/source/Vector](https://openlayers.org/en/latest/apidoc/module-ol_source_Vector.html)\n */\n layer: PropTypes.instanceOf(Layer).isRequired,\n\n /**\n * Map projection.\n */\n projection: PropTypes.string,\n};\n\nconst defaultProps = {\n children: null,\n format: KMLFormat,\n projection: 'EPSG:3857',\n};\n\n/**\n * The FeatureExportButton component creates a button that exports feature geometries\n * from a [[mobility-toolbox-js Layer](https://mobility-toolbox-js.geops.io/api/identifiers%20html#ol-layers)]\n * containing an [ol/layer/Vector](https://openlayers.org/en/latest/apidoc/module-ol_layer_Vector-VectorLayer.html)\n * with a [ol/source/Vector](https://openlayers.org/en/latest/apidoc/module-ol_source_Vector.html) on click.<br>\n * The default export format is KML, which supports the features' style export.<br>\n * Other formats do not always support style export (See specific format specs).\n */\nclass FeatureExportButton extends PureComponent {\n static createFeatureString(layer, projection, format) {\n if (format === KMLFormat) {\n return KML.writeFeatures(layer, projection);\n }\n\n // eslint-disable-next-line new-cap\n return new format().writeFeatures(layer.olLayer.getSource().getFeatures(), {\n featureProjection: projection,\n });\n }\n\n static exportFeatures(layer, projection, format) {\n const now = new Date()\n .toJSON()\n .slice(0, 20)\n .replace(/[.:T-]+/g, '');\n const featString = this.createFeatureString(layer, projection, format);\n\n const formatString = featString\n ? featString.match(/<(\\w+)\\s+\\w+.*?>/)[1]\n : 'xml';\n\n const fileName = `exported_features_${now}.${formatString}`;\n const charset = document.characterSet || 'UTF-8';\n const type = `${\n formatString === 'kml'\n ? 'data:application/vnd.google-earth.kml+xml'\n : 'data:text/xml'\n };charset=${charset}`;\n\n if (featString) {\n if (window.navigator.msSaveBlob) {\n // ie 11 and higher\n window.navigator.msSaveBlob(new Blob([featString], { type }), fileName);\n } else {\n const link = document.createElement('a');\n link.download = fileName;\n link.href = `${type},${encodeURIComponent(featString)}`;\n link.click();\n }\n }\n }\n\n render() {\n const { children, layer, projection, format, ...other } = this.props;\n\n return (\n <div\n role=\"button\"\n className=\"rs-feature-export-button\"\n tabIndex={0}\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...other}\n onClick={() => {\n return FeatureExportButton.exportFeatures(layer, projection, format);\n }}\n onKeyPress={(evt) => {\n return (\n evt.which === 13 &&\n FeatureExportButton.exportFeatures(layer, projection, format)\n );\n }}\n >\n {children}\n </div>\n );\n }\n}\n\nFeatureExportButton.propTypes = propTypes;\nFeatureExportButton.defaultProps = defaultProps;\n\nexport default FeatureExportButton;\n"],
5
+ "mappings": "AAAA,OAAO,SAAS,qBAAqB;AACrC,OAAO,eAAe;AACtB,OAAO,eAAe;AACtB,SAAS,aAAa;AACtB,OAAO,SAAS;AAEhB,MAAM,YAAY;AAAA,EAIhB,UAAU,UAAU;AAAA,EAMpB,QAAQ,UAAU;AAAA,EAMlB,OAAO,UAAU,WAAW,KAAK,EAAE;AAAA,EAKnC,YAAY,UAAU;AACxB;AAEA,MAAM,eAAe;AAAA,EACnB,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,YAAY;AACd;AAUA,MAAM,4BAA4B,cAAc;AAAA,EAC9C,OAAO,oBAAoB,OAAO,YAAY,QAAQ;AACpD,QAAI,WAAW,WAAW;AACxB,aAAO,IAAI,cAAc,OAAO,UAAU;AAAA,IAC5C;AAGA,WAAO,IAAI,OAAO,EAAE,cAAc,MAAM,QAAQ,UAAU,EAAE,YAAY,GAAG;AAAA,MACzE,mBAAmB;AAAA,IACrB,CAAC;AAAA,EACH;AAAA,EAEA,OAAO,eAAe,OAAO,YAAY,QAAQ;AAC/C,UAAM,MAAM,IAAI,KAAK,EAClB,OAAO,EACP,MAAM,GAAG,EAAE,EACX,QAAQ,YAAY,EAAE;AACzB,UAAM,aAAa,KAAK,oBAAoB,OAAO,YAAY,MAAM;AAErE,UAAM,eAAe,aACjB,WAAW,MAAM,kBAAkB,EAAE,KACrC;AAEJ,UAAM,WAAW,qBAAqB,OAAO;AAC7C,UAAM,UAAU,SAAS,gBAAgB;AACzC,UAAM,OAAO,GACX,iBAAiB,QACb,8CACA,2BACM;AAEZ,QAAI,YAAY;AACd,UAAI,OAAO,UAAU,YAAY;AAE/B,eAAO,UAAU,WAAW,IAAI,KAAK,CAAC,UAAU,GAAG,EAAE,KAAK,CAAC,GAAG,QAAQ;AAAA,MACxE,OAAO;AACL,cAAM,OAAO,SAAS,cAAc,GAAG;AACvC,aAAK,WAAW;AAChB,aAAK,OAAO,GAAG,QAAQ,mBAAmB,UAAU;AACpD,aAAK,MAAM;AAAA,MACb;AAAA,IACF;AAAA,EACF;AAAA,EAEA,SAAS;AACP,UAAM,EAAE,UAAU,OAAO,YAAY,WAAW,MAAM,IAAI,KAAK;AAE/D,WACE,oCAAC;AAAA,MACC,MAAK;AAAA,MACL,WAAU;AAAA,MACV,UAAU;AAAA,MAET,GAAG;AAAA,MACJ,SAAS,MAAM;AACb,eAAO,oBAAoB,eAAe,OAAO,YAAY,MAAM;AAAA,MACrE;AAAA,MACA,YAAY,CAAC,QAAQ;AACnB,eACE,IAAI,UAAU,MACd,oBAAoB,eAAe,OAAO,YAAY,MAAM;AAAA,MAEhE;AAAA,OAEC,QACH;AAAA,EAEJ;AACF;AAEA,oBAAoB,YAAY;AAChC,oBAAoB,eAAe;AAEnC,eAAe;",
6
+ "names": []
7
+ }
@@ -1,3 +1 @@
1
- export { default } from './FeatureExportButton';
2
-
3
- //# sourceMappingURL=index.js.map
1
+ export { default } from "./FeatureExportButton";
@@ -1 +1,7 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/components/FeatureExportButton/index.js"],"sourcesContent":["export { default } from './FeatureExportButton';\n"],"names":[],"mappings":"AAAA,SAAS,OAAO,QAAQ,uBAAuB,CAAC;"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/FeatureExportButton/index.js"],
4
+ "sourcesContent": ["export { default } from './FeatureExportButton';\n"],
5
+ "mappings": "AAAA,wBAAwB;",
6
+ "names": []
7
+ }