Configure additional sources displayed below map

This commit is contained in:
Maximilian Krög
2021-11-02 00:12:57 +01:00
parent ca9fc92f70
commit a10bc713f2
4 changed files with 35 additions and 28 deletions

View File

@@ -5,7 +5,9 @@ shortdesc: Move a map to a seperate window.
docs: > docs: >
Move a map to a seperate window. Move a map to a seperate window.
tags: "external, window" tags: "external, window"
sources:
- resources/external-map-map.html
--- ---
<div id="map" class="map"></div> <div id="map" class="map"></div>
<input id="external-map-button" type="button" value="Open external map"></input> <input id="external-map-button" type="button" value="Open external map"></input>
<span id="blocker-notice" hidden>Could not open map in external window. If you are using an popup or ad blocker you may need to disable it for this example.</span> <span id="blocker-notice" hidden>Could not open map in external window. If you are using a popup or ad blocker you may need to disable it for this example.</span>

View File

@@ -6,10 +6,11 @@ docs: >
The map in this example is rendered in a web worker, using `OffscreenCanvas`. **Note:** This is currently only supported in Chrome and Edge. The map in this example is rendered in a web worker, using `OffscreenCanvas`. **Note:** This is currently only supported in Chrome and Edge.
tags: "worker, offscreencanvas, vector-tiles" tags: "worker, offscreencanvas, vector-tiles"
experimental: true experimental: true
sources:
- offscreen-canvas.worker.js as worker.js
cloak: cloak:
- key: get_your_own_D6rA4zTHduk6KOKTXzGB - key: get_your_own_D6rA4zTHduk6KOKTXzGB
value: Get your own API key at https://www.maptiler.com/cloud/ value: Get your own API key at https://www.maptiler.com/cloud/
--- ---
<div id="map" class="map"> <div id="map" class="map">
<pre id="info" class="info"/> <pre id="info" class="info"/>

View File

@@ -211,13 +211,12 @@
&lt;/html&gt;</code></pre> &lt;/html&gt;</code></pre>
</div> </div>
{{#if worker.source}} {{#each extraSources}}
<div class="row-fluid"> <div class="row-fluid extra-source">
<h5 class="source-heading">worker.js</h5> <h5 class="source-heading">{{./name}}</h5>
<pre><code id="example-worker-source" class="language-js">{{ worker.source }}</code></pre> <pre><code class="language-{{./type}}">{{ ./source }}</code></pre>
</div> </div>
{{/if}} {{/each}}
<div class="row-fluid"> <div class="row-fluid">
<h5 class="source-heading">package.json</h5> <h5 class="source-heading">package.json</h5>
<pre><code id="example-pkg-source" class="language-json">{{ pkgJson }}</code></pre> <pre><code id="example-pkg-source" class="language-json">{{ pkgJson }}</code></pre>

View File

@@ -311,33 +311,38 @@ export default class ExampleBuilder {
source: jsSource, source: jsSource,
}; };
// check for worker js let jsSources = jsSource;
const workerName = `${data.name}.worker.js`; if (data.sources) {
const workerPath = path.join(data.dir, workerName); data.extraSources = await Promise.all(
let workerSource; data.sources.map(async (fileName) => {
try { const as = fileName.split(/ +as +/);
workerSource = await fse.readFile(workerPath, readOptions); fileName = as[0];
} catch (err) { const extraSourcePath = path.join(data.dir, fileName);
// pass let source = await fse.readFile(extraSourcePath, readOptions);
} let ext = fileName.match(/\.(\w+)$/)[1];
if (workerSource) { if (ext === 'mjs') {
workerSource = this.transformJsSource( ext = 'js';
this.cloakSource(workerSource, data.cloak) }
if (ext === 'js') {
source = this.transformJsSource(source);
jsSources += '\n' + source;
}
source = this.cloakSource(source, data.cloak);
assets[fileName] = source;
return {
name: as[1] || fileName,
source: source,
type: ext,
};
})
); );
data.worker = {
source: workerSource,
};
assets[workerName] = workerSource;
} }
const pkg = await getPackageInfo(); const pkg = await getPackageInfo();
data.pkgJson = JSON.stringify( data.pkgJson = JSON.stringify(
{ {
name: data.name, name: data.name,
dependencies: getDependencies( dependencies: getDependencies(jsSources, pkg),
jsSource + (workerSource ? `\n${workerSource}` : ''),
pkg
),
devDependencies: { devDependencies: {
parcel: '^2.0.0', parcel: '^2.0.0',
}, },