@josephinumresearch/swagger-ui-map-plugin 1.0.4 → 1.0.5

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.
@@ -0,0 +1,75 @@
1
+ import GeoTIFF from "ol/source/GeoTIFF";
2
+ import WebGLTileLayer from "ol/layer/WebGLTile";
3
+ import Overlay from "ol/Overlay";
4
+ import {transformExtent} from "ol/proj";
5
+
6
+ export default async (olMap, content, config) => {
7
+
8
+
9
+ const visualSource = new GeoTIFF({
10
+ sources: [{blob: content}],
11
+ convertToRGB: config.convertToRGB ?? 'auto',
12
+ interpolate: false,
13
+ });
14
+
15
+ const visualLayer = new WebGLTileLayer({
16
+ source: visualSource,
17
+ });
18
+ olMap.addLayer(visualLayer);
19
+
20
+ const srcView = await visualSource.getView();
21
+ const dstView = await olMap.getView();
22
+
23
+ dstView.fit(
24
+ transformExtent(srcView.extent, srcView.projection, dstView.getProjection()),
25
+ {padding: [10, 10, 10, 10]}
26
+ );
27
+
28
+ // show value of pixel on mouse hover
29
+ if (config.showValuesOnHover) {
30
+ // this is a bit inefficient, but it's WebGL... maybe fix that in the future
31
+ const dataLayer = new WebGLTileLayer({
32
+ source: new GeoTIFF({
33
+ sources: [{blob: content}],
34
+ convertToRGB: false,
35
+ interpolate: false,
36
+ normalize: false
37
+ }),
38
+ opacity: 0
39
+ });
40
+ olMap.addLayer(dataLayer);
41
+
42
+ const tooltipEl = document.createElement('div');
43
+ tooltipEl.style.cssText = `
44
+ background: rgba(0, 0, 0, 0.8);
45
+ color: white;
46
+ padding: 4px 8px;
47
+ border-radius: 4px;
48
+ font-family: sans-serif;
49
+ font-size: 12px;
50
+ pointer-events: none;
51
+ white-space: nowrap;
52
+ z-index: 1000;
53
+ `;
54
+
55
+ const overlay = new Overlay({
56
+ element: tooltipEl,
57
+ offset: [10, 0],
58
+ positioning: 'bottom-left',
59
+ });
60
+ olMap.addOverlay(overlay);
61
+
62
+ olMap.on("pointermove", (event) => {
63
+ const data = dataLayer.getData(event.pixel);
64
+
65
+ if (data) {
66
+ tooltipEl.innerText = data.join ? `Value: ${data.join(', ')}` : `Value: ${data}`;
67
+ overlay.setPosition(event.coordinate);
68
+ tooltipEl.style.display = 'block';
69
+ } else {
70
+ tooltipEl.style.display = 'none';
71
+ }
72
+ });
73
+
74
+ }
75
+ };
package/src/index.html CHANGED
@@ -24,6 +24,14 @@
24
24
  config: {
25
25
  defaultStrokeWidth: '4'
26
26
  }
27
+ },
28
+ geotiff: {
29
+ activationFnc: props => ['image/tiff', 'image/tif'].includes(props.contentType),
30
+ format: 'GeoTiff',
31
+ config: {
32
+ convertToRGB: 'auto',
33
+ showValuesOnHover: true
34
+ }
27
35
  }
28
36
  }
29
37
  })
package/webpack.config.js CHANGED
@@ -31,7 +31,11 @@ module.exports = (env, argv) => ({
31
31
  react: 'react',
32
32
  },
33
33
  ({ context, request }, callback) => {
34
- if (/^ol\/|^ol$/i.test(request)) {
34
+ if (/^ol\//i.test(request)) {
35
+ const path = request.replace(/^ol\//, '');
36
+ if (path.startsWith('source/GeoTIFF') || path.startsWith('layer/WebGLTile')) {
37
+ return callback();
38
+ }
35
39
  return callback(null, request.split('/'));
36
40
  }
37
41
  callback();
@@ -42,4 +46,4 @@ module.exports = (env, argv) => ({
42
46
  template: "src/index.html",
43
47
  })
44
48
  ] : []
45
- });
49
+ });