ol-stac 0.0.0

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 (107) hide show
  1. package/.eslintignore +2 -0
  2. package/.github/workflows/deploy.yml +67 -0
  3. package/.github/workflows/publish.yml +32 -0
  4. package/.github/workflows/release.yml +21 -0
  5. package/.github/workflows/test.yml +85 -0
  6. package/CHANGELOG.md +14 -0
  7. package/DEVELOPING.md +104 -0
  8. package/LICENSE.md +201 -0
  9. package/README.md +43 -0
  10. package/config/jsdoc/api/conf.json +38 -0
  11. package/config/jsdoc/api/index.md +1 -0
  12. package/config/jsdoc/api/readme.md +65 -0
  13. package/config/jsdoc/api/template/README.md +3 -0
  14. package/config/jsdoc/api/template/publish.js +743 -0
  15. package/config/jsdoc/api/template/static/scripts/linenumber.js +11 -0
  16. package/config/jsdoc/api/template/static/scripts/main.js +305 -0
  17. package/config/jsdoc/api/template/static/scripts/prettify/Apache-License-2.0.txt +202 -0
  18. package/config/jsdoc/api/template/static/scripts/prettify/lang-css.js +2 -0
  19. package/config/jsdoc/api/template/static/scripts/prettify/prettify.js +28 -0
  20. package/config/jsdoc/api/template/static/styles/carbon.css +65 -0
  21. package/config/jsdoc/api/template/static/styles/jaguar.css +512 -0
  22. package/config/jsdoc/api/template/static/styles/prettify-jsdoc.css +111 -0
  23. package/config/jsdoc/api/template/static/styles/prettify-tomorrow.css +132 -0
  24. package/config/jsdoc/api/template/static/theme +1 -0
  25. package/config/jsdoc/api/template/tmpl/container.tmpl +205 -0
  26. package/config/jsdoc/api/template/tmpl/details.tmpl +84 -0
  27. package/config/jsdoc/api/template/tmpl/example.tmpl +2 -0
  28. package/config/jsdoc/api/template/tmpl/examples.tmpl +16 -0
  29. package/config/jsdoc/api/template/tmpl/exceptions.tmpl +30 -0
  30. package/config/jsdoc/api/template/tmpl/layout.tmpl +92 -0
  31. package/config/jsdoc/api/template/tmpl/mainpage.tmpl +14 -0
  32. package/config/jsdoc/api/template/tmpl/members.tmpl +38 -0
  33. package/config/jsdoc/api/template/tmpl/method.tmpl +132 -0
  34. package/config/jsdoc/api/template/tmpl/navigation.tmpl +59 -0
  35. package/config/jsdoc/api/template/tmpl/observables.tmpl +39 -0
  36. package/config/jsdoc/api/template/tmpl/params.tmpl +109 -0
  37. package/config/jsdoc/api/template/tmpl/properties.tmpl +85 -0
  38. package/config/jsdoc/api/template/tmpl/returns.tmpl +72 -0
  39. package/config/jsdoc/api/template/tmpl/source.tmpl +8 -0
  40. package/config/jsdoc/api/template/tmpl/stability.tmpl +7 -0
  41. package/config/jsdoc/api/template/tmpl/tutorial.tmpl +19 -0
  42. package/config/jsdoc/api/template/tmpl/type.tmpl +7 -0
  43. package/config/jsdoc/info/conf.json +22 -0
  44. package/config/jsdoc/info/publish.js +175 -0
  45. package/config/jsdoc/package.json +4 -0
  46. package/config/jsdoc/plugins/api.cjs +181 -0
  47. package/config/jsdoc/plugins/default-export.cjs +35 -0
  48. package/config/jsdoc/plugins/define-plugin.cjs +33 -0
  49. package/config/jsdoc/plugins/events.cjs +39 -0
  50. package/config/jsdoc/plugins/inline-options.cjs +102 -0
  51. package/config/jsdoc/plugins/markdown.cjs +119 -0
  52. package/config/jsdoc/plugins/observable.cjs +69 -0
  53. package/config/jsdoc/plugins/virtual-plugin.cjs +16 -0
  54. package/config/rollup-full-build.js +24 -0
  55. package/config/tsconfig-build.json +25 -0
  56. package/examples/.eslintrc +29 -0
  57. package/examples/index.html +100 -0
  58. package/examples/index.js +109 -0
  59. package/examples/planetary-computer.html +14 -0
  60. package/examples/planetary-computer.js +53 -0
  61. package/examples/resources/Jugl.js +15 -0
  62. package/examples/resources/common.js +111 -0
  63. package/examples/stac-collection-webmaplinks.html +9 -0
  64. package/examples/stac-collection-webmaplinks.js +55 -0
  65. package/examples/stac-item-from-object.html +9 -0
  66. package/examples/stac-item-from-object.js +102 -0
  67. package/examples/stac-item-tileserver.html +9 -0
  68. package/examples/stac-item-tileserver.js +34 -0
  69. package/examples/stac-item.html +9 -0
  70. package/examples/stac-item.js +45 -0
  71. package/examples/stac-itemcollection.html +11 -0
  72. package/examples/stac-itemcollection.js +39 -0
  73. package/examples/templates/example.html +206 -0
  74. package/examples/templates/readme.md +3 -0
  75. package/examples/webpack/config.mjs +69 -0
  76. package/examples/webpack/example-builder.js +410 -0
  77. package/package.json +107 -0
  78. package/site/build.js +26 -0
  79. package/site/layouts/default.hbs +78 -0
  80. package/site/src/doc/faq.md +8 -0
  81. package/site/src/doc/index.md +22 -0
  82. package/site/src/doc/quickstart.md +121 -0
  83. package/site/src/doc/tutorials/index.md +8 -0
  84. package/site/src/download/index.hbs +62 -0
  85. package/site/src/favicon.ico +0 -0
  86. package/site/src/index.hbs +71 -0
  87. package/site/src/theme/index.css +26 -0
  88. package/site/src/theme/site.css +531 -0
  89. package/src/ol/events/ErrorEvent.js +25 -0
  90. package/src/ol/layer/STAC.js +780 -0
  91. package/src/ol/layer/stacUtil.js +169 -0
  92. package/src/ol/source/GeoTIFF2.js +47 -0
  93. package/tasks/.eslintrc +5 -0
  94. package/tasks/build-website.sh +90 -0
  95. package/tasks/create-release.js +107 -0
  96. package/tasks/generate-index.js +125 -0
  97. package/tasks/generate-info.js +189 -0
  98. package/tasks/get-latest-release.js +36 -0
  99. package/tasks/newest-tag.js +52 -0
  100. package/tasks/prepare-package.js +46 -0
  101. package/tasks/publish.sh +90 -0
  102. package/test/README.md +56 -0
  103. package/test/browser/.eslintrc +14 -0
  104. package/test/browser/karma.config.cjs +94 -0
  105. package/test/browser/spec/ol/layer/STAC.test.js +18 -0
  106. package/test/browser/test-extensions.js +419 -0
  107. package/tsconfig.json +62 -0
@@ -0,0 +1,102 @@
1
+ import Map from 'ol/Map.js';
2
+ import OSM from 'ol/source/OSM.js';
3
+ import STAC from '../src/ol/layer/STAC.js';
4
+ import TileLayer from 'ol/layer/WebGLTile.js';
5
+ import proj4 from 'proj4';
6
+ import {register} from 'ol/proj/proj4.js';
7
+
8
+ register(proj4); // required to support source reprojection
9
+
10
+ const layer = new STAC({
11
+ url: 'https://www.planet.com/data/stac/open-skysat-data/angkor-wat/dsm.json',
12
+ data: {
13
+ 'assets': {
14
+ 'dsm': {
15
+ 'href':
16
+ 'https://storage.googleapis.com/open-cogs/planet-stac/angkor-wat/3d-geofox.ai/angkor-wat-dsm.tif',
17
+ 'proj:epsg': 32648,
18
+ 'proj:shape': [8675, 36244],
19
+ 'proj:transform': [
20
+ 374283.8729316911, 0.699999988079071, 0, 1498553.1898692613, 0,
21
+ -0.699999988079071,
22
+ ],
23
+ 'raster:bands': [
24
+ {
25
+ 'data_type': 'float32',
26
+ 'statistics': {
27
+ 'maximum': 96.446,
28
+ 'mean': 26.839,
29
+ 'minimum': 2.095,
30
+ 'stddev': 10.117,
31
+ },
32
+ 'nodata': 'nan',
33
+ },
34
+ ],
35
+ 'roles': ['data', 'surface-model'],
36
+ 'title': 'Digital Surface Model',
37
+ 'type': 'image/tiff; application=geotiff; profile=cloud-optimized',
38
+ },
39
+ },
40
+ 'bbox': [103.8381461, 13.3233018, 103.8953104, 13.5529222],
41
+ 'collection': 'angkor-wat',
42
+ 'geometry': {
43
+ 'coordinates': [
44
+ [
45
+ [103.8381461, 13.5526676],
46
+ [103.83925, 13.3233018],
47
+ [103.8953104, 13.323552],
48
+ [103.8942598, 13.5529222],
49
+ [103.8381461, 13.5526676],
50
+ ],
51
+ ],
52
+ 'type': 'Polygon',
53
+ },
54
+ 'id': 'angkor-wat-3d-dsm',
55
+ 'links': [
56
+ {
57
+ 'href':
58
+ 'https://www.planet.com/data/stac/open-skysat-data/angkor-wat/item.json',
59
+ 'rel': 'self',
60
+ 'type': 'application/json',
61
+ },
62
+ ],
63
+ 'properties': {
64
+ 'datetime': null,
65
+ 'description':
66
+ 'Digital Surface Model (DSM) of Angkor Wat, Cambodia, created from stereo images captured by a [Planet](https://planet.com) SkySat satellite. It is distributed as a single band Cloud-optimized GeoTiff, with each pixel representing the height at that location.',
67
+ 'end_datetime': '2020-12-14T03:22:28.5Z',
68
+ 'providers': [
69
+ {
70
+ 'description':
71
+ 'Contact Planet at [planet.com/contact-sales](https://www.planet.com/contact-sales/)',
72
+ 'name': 'Planet Labs PBC',
73
+ 'roles': ['producer', 'licensor'],
74
+ 'url': 'https://www.planet.com',
75
+ },
76
+ {
77
+ 'name': 'Geofox.ai',
78
+ 'roles': ['processor'],
79
+ 'url': 'https://www.geofox.ai',
80
+ },
81
+ ],
82
+ 'start_datetime': '2020-12-14T03:21:56.5Z',
83
+ 'title': 'Digital Surface Model',
84
+ },
85
+ 'stac_extensions': [
86
+ 'https://stac-extensions.github.io/projection/v1.1.0/schema.json',
87
+ 'https://stac-extensions.github.io/raster/v1.1.0/schema.json',
88
+ ],
89
+ 'stac_version': '1.0.0',
90
+ 'type': 'Feature',
91
+ },
92
+ });
93
+
94
+ const background = new TileLayer({
95
+ source: new OSM(),
96
+ });
97
+
98
+ const map = new Map({
99
+ target: 'map',
100
+ layers: [background, layer],
101
+ });
102
+ map.getView().fit(layer.getExtent());
@@ -0,0 +1,9 @@
1
+ ---
2
+ layout: example.html
3
+ title: STAC Item with COG rendered by a tile server
4
+ shortdesc: Rendering a STAC Item as a layer, but uses a tile server instead of client-side GeoTiff rendering.
5
+ docs: >
6
+ Geometry and Assets from SpatioTemporal Asset Catalog (STAC) Items can be rendered as layer group using a tile server.
7
+ tags: "stac, stac item, geotiff, cog, layergroup, xyz, tilelayer"
8
+ ---
9
+ <div id="map" class="map"></div>
@@ -0,0 +1,34 @@
1
+ import Map from 'ol/Map.js';
2
+ import OSM from 'ol/source/OSM.js';
3
+ import STAC from '../src/ol/layer/STAC.js';
4
+ import TileLayer from 'ol/layer/WebGLTile.js';
5
+ import View from 'ol/View.js';
6
+ import proj4 from 'proj4';
7
+ import {register} from 'ol/proj/proj4.js';
8
+
9
+ register(proj4); // required to support source reprojection
10
+
11
+ const layer = new STAC({
12
+ url: 'https://s3.us-west-2.amazonaws.com/sentinel-cogs/sentinel-s2-l2a-cogs/10/T/ES/2022/7/S2A_10TES_20220726_0_L2A/S2A_10TES_20220726_0_L2A.json',
13
+ buildTileUrlTemplate: (asset) =>
14
+ 'https://tiles.rdnt.io/tiles/{z}/{x}/{y}@2x?url=' +
15
+ encodeURIComponent(asset.getAbsoluteUrl()),
16
+ });
17
+
18
+ const background = new TileLayer({
19
+ source: new OSM(),
20
+ });
21
+
22
+ const map = new Map({
23
+ target: 'map',
24
+ layers: [background, layer],
25
+ view: new View({
26
+ center: [0, 0],
27
+ zoom: 0,
28
+ }),
29
+ });
30
+
31
+ layer.on('sourceready', () => {
32
+ const view = map.getView();
33
+ view.fit(layer.getExtent());
34
+ });
@@ -0,0 +1,9 @@
1
+ ---
2
+ layout: example.html
3
+ title: STAC Item
4
+ shortdesc: Rendering a STAC Item as a layer.
5
+ docs: >
6
+ Geometry and Assets from SpatioTemporal Asset Catalog (STAC) Items can be rendered as layer group.
7
+ tags: "stac, stac item, geotiff, cog, layergroup"
8
+ ---
9
+ <div id="map" class="map"></div>
@@ -0,0 +1,45 @@
1
+ import Map from 'ol/Map.js';
2
+ import OSM from 'ol/source/OSM.js';
3
+ import STAC from '../src/ol/layer/STAC.js';
4
+ import TileLayer from 'ol/layer/WebGLTile.js';
5
+ import View from 'ol/View.js';
6
+ import proj4 from 'proj4';
7
+ import {register} from 'ol/proj/proj4.js';
8
+
9
+ register(proj4); // required to support source reprojection
10
+
11
+ const layer = new STAC({
12
+ url: 'https://s3.us-west-2.amazonaws.com/sentinel-cogs/sentinel-s2-l2a-cogs/10/T/ES/2022/7/S2A_10TES_20220726_0_L2A/S2A_10TES_20220726_0_L2A.json',
13
+ });
14
+
15
+ const background = new TileLayer({
16
+ source: new OSM(),
17
+ });
18
+
19
+ const map = new Map({
20
+ target: 'map',
21
+ layers: [background, layer],
22
+ view: new View({
23
+ center: [0, 0],
24
+ zoom: 0,
25
+ }),
26
+ });
27
+
28
+ layer.on('sourceready', () => {
29
+ const view = map.getView();
30
+ view.fit(layer.getExtent());
31
+ });
32
+
33
+ layer.on('assetsready', () => {
34
+ // Assign titles for e.g. a layerswitcher
35
+ for (const sublayer of layer.getLayersArray()) {
36
+ const stac = sublayer.get('stac');
37
+ let title;
38
+ if (stac.isAsset() || stac.isLink()) {
39
+ title = stac.getMetadata('title') || stac.getKey();
40
+ } else {
41
+ title = 'Footprint';
42
+ }
43
+ sublayer.set('title', title);
44
+ }
45
+ });
@@ -0,0 +1,11 @@
1
+ ---
2
+ layout: example.html
3
+ title: STAC Item Collection
4
+ shortdesc: Rendering a STAC Item Collection as a layer.
5
+ docs: >
6
+ Geometries and Thumbnails for various SpatioTemporal Asset Catalog (STAC) Items in an ItemCollection can be rendered as layer group.
7
+ Adds a click event to select individual items.
8
+ tags: "stac, stac api, staticimage, layergroup"
9
+ ---
10
+ <div id="map" class="map"></div>
11
+ <div><strong>Selected Product Identifier:</strong> <span id="ids"></span></div>
@@ -0,0 +1,39 @@
1
+ import Map from 'ol/Map.js';
2
+ import OSM from 'ol/source/OSM.js';
3
+ import STAC from '../src/ol/layer/STAC.js';
4
+ import TileLayer from 'ol/layer/WebGLTile.js';
5
+ import View from 'ol/View.js';
6
+ import proj4 from 'proj4';
7
+ import {getStacObjectsForEvent} from '../src/ol/layer/stacUtil.js';
8
+ import {register} from 'ol/proj/proj4.js';
9
+
10
+ register(proj4); // required to support source reprojection
11
+
12
+ const layer = new STAC({
13
+ url: 'https://tamn.snapplanet.io/search?bbox=125.727770,-29.514858,133.412707,-23.673395&collections=S2',
14
+ displayPreview: true,
15
+ });
16
+
17
+ const background = new TileLayer({
18
+ source: new OSM(),
19
+ });
20
+
21
+ const map = new Map({
22
+ target: 'map',
23
+ layers: [background, layer],
24
+ view: new View({
25
+ center: [0, 0],
26
+ zoom: 0,
27
+ }),
28
+ });
29
+ map.on('singleclick', async (event) => {
30
+ const objects = await getStacObjectsForEvent(event);
31
+ if (objects.length > 0) {
32
+ const ids = objects.map((obj) => obj.properties.productIdentifier);
33
+ document.getElementById('ids').innerText = ids.join(', ');
34
+ }
35
+ });
36
+ layer.on('sourceready', () => {
37
+ const view = map.getView();
38
+ view.fit(layer.getExtent());
39
+ });
@@ -0,0 +1,206 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
6
+ <title>{{ title }}</title>
7
+ <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" crossorigin="anonymous">
8
+ <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.1.2/css/fontawesome.min.css" crossorigin="anonymous">
9
+ <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.1.2/css/solid.css" crossorigin="anonymous">
10
+ <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.1.2/css/brands.css" crossorigin="anonymous">
11
+ <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/ol/ol.css">
12
+ <link rel="stylesheet" type="text/css" href="/ol-stac/theme/site.css">
13
+ {{#each css.local}}
14
+ <link rel="stylesheet" type="text/css" href="{{{ . }}}">
15
+ {{/each}}
16
+ </head>
17
+ <body>
18
+ <header class="navbar navbar-expand-md navbar-dark mb-3 px-3 py-0 fixed-top" role="navigation">
19
+ <a class="navbar-brand" href="/">OL STAC</a>
20
+ <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#olmenu" aria-controls="olmenu" aria-expanded="false" aria-label="Toggle navigation">
21
+ <span class="navbar-toggler-icon"></span>
22
+ </button>
23
+
24
+ <!-- menu items that get hidden below 768px width -->
25
+ <nav class="collapse navbar-collapse" id="olmenu">
26
+ <ul class="nav navbar-nav ms-auto">
27
+ <li class="nav-item dropdown">
28
+ <a class="nav-link dropdown-toggle" href="#" id="docdropdown" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Docs</a>
29
+ <div class="dropdown-menu dropdown-menu-end mb-3" aria-labelledby="docdropdown">
30
+ <a class="dropdown-item" href="/ol-stac/doc/">Docs</a>
31
+ <div class="dropdown-divider"></div>
32
+ <a class="dropdown-item" href="/ol-stac/doc/quickstart.html"><i class="fa fa-check fa-fw me-2 fa-lg"></i>Quick Start</a>
33
+ <a class="dropdown-item" href="/ol-stac/doc/faq.html"><i class="fa fa-question fa-fw me-2 fa-lg"></i>FAQ</a>
34
+ <a class="dropdown-item" href="/ol-stac/doc/tutorials/"><i class="fa fa-book fa-fw me-2 fa-lg"></i>Tutorials</a>
35
+ </div>
36
+ </li>
37
+ <li class="nav-item"><a class="nav-link" href="/ol-stac/examples/">Examples</a></li>
38
+ <li class="nav-item"><a class="nav-link" href="/ol-stac/apidoc/"><i class="fa fa-sitemap me-1"></i>API</a></li>
39
+ <li class="nav-item dropdown">
40
+ <a class="nav-link dropdown-toggle" href="#" id="codedropdown" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Code</a>
41
+ <div class="dropdown-menu dropdown-menu-end mb-3" aria-labelledby="codedropdown">
42
+ <a class="dropdown-item" href="https://github.com/m-mohr/ol-stac"><i class="fab fa-github fa-fw me-2 fa-lg"></i>Repository</a>
43
+ <a class="dropdown-item" href="/ol-stac/download/"><i class="fa fa-download fa-fw me-2 fa-lg"></i>Download</a>
44
+ </div>
45
+ </li>
46
+ </ul>
47
+ </nav>
48
+ </header>
49
+
50
+ <div class="container-fluid line-numbers">
51
+ <div id="latest-check" class="alert alert-warning alert-dismissible" role="alert" style="display:none">
52
+ <button id="latest-dismiss" type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
53
+ This example uses OL STAC v<span>{{ olVersion }}</span>. The <a id="latest-link" href="#" class="alert-link">latest</a> is v<span id="latest-version"></span>.
54
+ </div>
55
+
56
+ {{#if ./experimental}}
57
+ <div id="experimental-notice" class="alert alert-warning alert-dismissible" role="alert">
58
+ <button id="experimental-dismiss" type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
59
+ This example uses features that are not part of the stable API and subject to change between releases. Consult the <a href="/ol-stac/en/latest/apidoc/">API documentation</a>
60
+ to see what is supported in the latest release.
61
+ </div>
62
+ {{/if}}
63
+
64
+ <div class="row-fluid">
65
+ <a href="#" id="codepen-button" class="btn btn-link float-end">
66
+ <i class="fab fa-codepen fa-lg"></i> Edit
67
+ </a>
68
+ <div class="span12">
69
+ <h4 id="title">{{ title }}</h4>
70
+ <p class="tags">
71
+ {{#each tags}}
72
+ <span class="badge-group">
73
+ <a
74
+ href="./index.html?q={{ ./tag }}" class="badge badge-info">{{ ./tag }}</a
75
+ ><a
76
+ class="badge badge-info tag-modal-toggle"
77
+ data-bs-toggle="modal"
78
+ data-bs-target="#tag-example-list"
79
+ data-title="{{ ./tag }}"
80
+ data-content="&lt;ul class=&quot;list-group&quot;&gt;
81
+ {{#each ./examples}}
82
+ &lt;li&gt;&lt;a class=&quot;list-group-item list-group-item-action{{#if ./isCurrent}} active{{/if}}&quot; href=&quot;./{{ ./link }}&quot;&gt;{{escape ./title}}&lt;/a&gt;
83
+ {{/each}}
84
+ &lt;/ul&gt;"
85
+ tabindex="0"
86
+ >{{ ./examples.length }}</a>
87
+ </span>
88
+ {{/each}}
89
+ </p>
90
+ <div class="modal modal-tag-example" id="tag-example-list" tabindex="-1" role="dialog" aria-labelledby="tag-example-title" aria-hidden="true">
91
+ <div class="modal-dialog modal-dialog-scrollable" role="document">
92
+ <div class="modal-content">
93
+ <div class="modal-header">
94
+ <h5 class="modal-title" id="tag-example-title"></h5>
95
+ <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
96
+ </div>
97
+ <div class="modal-body">
98
+ <div class="list-group"></div>
99
+ </div>
100
+ </div>
101
+ </div>
102
+ </div>
103
+ {{{ contents }}}
104
+ </div>
105
+ <form method="POST" id="codepen-form" target="_blank" action="https://codesandbox.io/api/v1/sandboxes/define">
106
+ <input id="codesandbox-params" type="hidden" name="parameters">
107
+ </form>
108
+ </div>
109
+
110
+ <div class="row-fluid">
111
+ <div class="span12">
112
+ <p id="shortdesc">{{ shortdesc }}</p>
113
+ <div id="docs">{{ md docs }}</div>
114
+ </div>
115
+ </div>
116
+
117
+ <div class="row-fluid">
118
+ <h5 class="source-heading">main.js</h5>
119
+ <pre><code id="example-js-source" class="language-js">{{ js.source }}</code></pre>
120
+ </div>
121
+
122
+ <div class="row-fluid">
123
+ <h5 class="source-heading">index.html</h5>
124
+ <pre><code id="example-html-source" class="language-markup">&lt;!DOCTYPE html&gt;
125
+ &lt;html lang="en"&gt;
126
+ &lt;head&gt;
127
+ &lt;meta charset="UTF-8"&gt;
128
+ &lt;title&gt;{{ title }}&lt;/title&gt;
129
+ {{#each css.remote}}
130
+ &lt;link rel="stylesheet" href="{{ . }}"&gt;
131
+ {{/each}}
132
+ &lt;link rel="stylesheet" href="node_modules/ol/ol.css"&gt;
133
+ &lt;style&gt;
134
+ .map {
135
+ width: 100%;
136
+ height: 400px;
137
+ }
138
+ {{#if css.source}}{{ indent css.source spaces=6 }}{{/if}} &lt;/style&gt;
139
+ &lt;/head&gt;
140
+ &lt;body&gt;
141
+ {{ indent contents spaces=4 }}
142
+ {{#each js.remote}}
143
+ &lt;script src="{{ . }}"&gt;&lt;/script&gt;
144
+ {{/each}}
145
+ &lt;script type="module" src="main.js"&gt;&lt;/script&gt;
146
+ &lt;/body&gt;
147
+ &lt;/html&gt;</code></pre>
148
+ </div>
149
+
150
+ {{#each extraSources}}
151
+ <div class="row-fluid extra-source">
152
+ <h5 class="source-heading">{{./name}}</h5>
153
+ <pre><code class="language-{{./type}}">{{ ./source }}</code></pre>
154
+ </div>
155
+ {{/each}}
156
+ <div class="row-fluid">
157
+ <h5 class="source-heading">package.json</h5>
158
+ <pre><code id="example-pkg-source" class="language-json">{{ pkgJson }}</code></pre>
159
+ </div>
160
+ </div>
161
+
162
+ <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.bundle.min.js"></script>
163
+ {{#each js.local}}
164
+ <script src="{{{ . }}}"></script>
165
+ {{/each}}
166
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.28.0/components/prism-core.min.js"></script>
167
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.28.0/plugins/autoloader/prism-autoloader.min.js"></script>
168
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.28.0/plugins/toolbar/prism-toolbar.min.js"></script>
169
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.28.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.js"></script>
170
+ <script src="./resources/common.js"></script>
171
+ <script>
172
+ document.getElementById('tag-example-list')
173
+ .addEventListener('show.bs.modal', function (event) {
174
+ const button = event.relatedTarget; // Button that triggered the modal
175
+ this.querySelector('.modal-title').innerText = button.dataset.title;
176
+ this.querySelector('.modal-body').innerHTML = button.dataset.content;
177
+ });
178
+ </script>
179
+ <script>
180
+ const releaseUrl = 'https://cdn.jsdelivr.net/npm/ol-stac/package.json';
181
+ fetch(releaseUrl).then(function(response) {
182
+ return response.json();
183
+ }).then(function(json) {
184
+ const latestVersion = json.version;
185
+ document.getElementById('latest-version').innerHTML = latestVersion;
186
+ const url = window.location.href;
187
+ const branchSearch = url.match(/\/([^\/]*)\/examples\//);
188
+ const storageKey = 'ol-dismissed=-' + latestVersion;
189
+ const dismissed = localStorage.getItem(storageKey) === 'true';
190
+ if (branchSearch && !dismissed && /^v[0-9\.]*$/.test(branchSearch[1]) && '{{ olVersion }}' != latestVersion) {
191
+ const link = url.replace(branchSearch[0], '/latest/examples/');
192
+ fetch(link, {method: 'head'}).then(function(response) {
193
+ const a = document.getElementById('latest-link');
194
+ a.href = response.status == 200 ? link : '../../latest/examples/';
195
+ });
196
+ const latestCheck = document.getElementById('latest-check');
197
+ latestCheck.style.display = '';
198
+ document.getElementById('latest-dismiss').onclick = function() {
199
+ latestCheck.style.display = 'none';
200
+ localStorage.setItem(storageKey, 'true');
201
+ }
202
+ }
203
+ });
204
+ </script>
205
+ </body>
206
+ </html>
@@ -0,0 +1,3 @@
1
+ This folder contains example templates. These templates are used to build the examples in the `examples/` folder. The resulting examples are written to the `build/examples` folder.
2
+
3
+ At the bottom of each example generated in the `build/examples` folder, a modified version of its source code is shown. That modified version can be run standalone and is usually used as starting point for users to extend examples into their own application.
@@ -0,0 +1,69 @@
1
+ import CopyPlugin from 'copy-webpack-plugin';
2
+ import ExampleBuilder from './example-builder.js';
3
+ import TerserPlugin from 'terser-webpack-plugin';
4
+ import fs from 'fs';
5
+ import path, {dirname} from 'path';
6
+ import {fileURLToPath} from 'url';
7
+
8
+ const src = path.join(dirname(fileURLToPath(import.meta.url)), '..');
9
+ const root = path.join(src, '..');
10
+
11
+ export default {
12
+ context: src,
13
+ target: ['browserslist'],
14
+ entry: () => {
15
+ const entry = {};
16
+ fs.readdirSync(src)
17
+ .filter((name) => /^(?!index).*\.html$/.test(name))
18
+ .map((name) => name.replace(/\.html$/, ''))
19
+ .forEach((example) => {
20
+ entry[example] = `./${example}.js`;
21
+ });
22
+ return entry;
23
+ },
24
+ stats: 'minimal',
25
+ optimization: {
26
+ minimizer: [
27
+ new TerserPlugin({
28
+ extractComments: false,
29
+ }),
30
+ ],
31
+ runtimeChunk: {
32
+ name: 'common',
33
+ },
34
+ splitChunks: {
35
+ name: 'common',
36
+ chunks: 'initial',
37
+ minChunks: 2,
38
+ },
39
+ },
40
+ plugins: [
41
+ new ExampleBuilder({
42
+ templates: path.join(src, 'templates'),
43
+ common: 'common',
44
+ }),
45
+ new CopyPlugin({
46
+ patterns: [
47
+ {
48
+ from: path.join(root, 'site', 'src', 'theme'),
49
+ to: 'theme',
50
+ },
51
+ {from: 'resources', to: 'resources'},
52
+ {from: 'index.html', to: 'index.html'},
53
+ {from: 'index.js', to: 'index.js'},
54
+ ],
55
+ }),
56
+ ],
57
+ devtool: 'source-map',
58
+ output: {
59
+ filename: '[name].js',
60
+ path: path.join(root, 'build', 'examples'),
61
+ },
62
+ resolve: {
63
+ fallback: {
64
+ fs: false,
65
+ http: false,
66
+ https: false,
67
+ },
68
+ },
69
+ };