|
1 | 1 | <!DOCTYPE html>
|
2 | 2 | <html lang="en">
|
3 |
| - <head> |
4 |
| - <meta charset="UTF-8"> |
5 |
| - <title>Extensions</title> |
6 |
| - <script src="https://unpkg.com/d3@4"></script> |
7 |
| - <script src="https://unpkg.com/d3-geo-projection@4"></script> |
8 |
| - <script src="https://unpkg.com/topojson-client@3"></script> |
9 |
| - <script type="module" src="https://unpkg.com/@material/mwc-circular-progress?module"></script> |
10 |
| - </head> |
11 |
| - <body> |
12 |
| - <pre style="text-align:center; width: 100%; margin-top: 20px;"> |
13 |
| - Wait for loading & creating <mwc-circular-progress id="progress" style="vertical-align: middle;" density=-8 indeterminate></mwc-circular-progress> TopoJSON from a GeoJSON file inside the worker extension. |
14 |
| - </pre> |
15 |
| - <canvas width="800" height="600"></canvas> |
16 |
| - <script type="module"> |
| 3 | + <head> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <title>Extensions</title> |
| 6 | + <style> |
| 7 | + canvas { |
| 8 | + display: block; |
| 9 | + margin: 0 auto; |
| 10 | + } |
| 11 | + </style> |
| 12 | + </head> |
| 13 | + <body> |
| 14 | + <pre style="text-align:center; width: 100%; margin-top: 20px;"> |
| 15 | + Wait for loading & creating <mwc-circular-progress id="progress" style="vertical-align: middle;" density=-8 indeterminate></mwc-circular-progress> TopoJSON from a GeoJSON file inside the worker extension. |
| 16 | + </pre> |
| 17 | + <canvas width="800" height="600"></canvas> |
| 18 | + <script type="module"> |
17 | 19 |
|
18 |
| - import SPL from '../dist/index.js'; |
| 20 | + import { d3, geoAitoff, topojson } from './lib/lib.js'; |
| 21 | + import SPL from '../dist/index.js'; |
19 | 22 |
|
20 |
| - const extention = { |
21 |
| - extends: 'db', |
22 |
| - fns: { |
23 |
| - 'toTopoJSON': async (db, table, column='geometry') => { |
24 |
| - if (typeof(topojson) === 'undefined') { |
25 |
| - await import('https://unpkg.com/topojson-server@3'); |
| 23 | + const extention = { |
| 24 | + extends: 'db', |
| 25 | + fns: { |
| 26 | + 'toTopoJSON': async (db, table, column='geometry') => { |
| 27 | + if (typeof(topojson) === 'undefined') { |
| 28 | + await import('https://unpkg.com/topojson-server@3'); |
| 29 | + } |
| 30 | + return topojson.topology(db.exec(`SELECT ${column} FROM ${table}`).get.flat); |
| 31 | + }, |
| 32 | + 'timeout': async (_, delay) => { |
| 33 | + return new Promise(resolve => setTimeout(resolve, delay)); |
26 | 34 | }
|
27 |
| - return topojson.topology(db.exec(`SELECT ${column} FROM ${table}`).get.flat); |
28 |
| - }, |
29 |
| - 'timeout': async (_, delay) => { |
30 |
| - return new Promise(resolve => setTimeout(resolve, delay)); |
31 | 35 | }
|
32 |
| - } |
33 |
| - }; |
| 36 | + }; |
34 | 37 |
|
35 |
| - const spl = await SPL([extention]); |
36 |
| - const db = await spl.mount('data', [{ |
37 |
| - name: 'world.geojson', |
38 |
| - data: await fetch('world.json').then(res => res.arrayBuffer()) |
39 |
| - }]).db().read(` |
40 |
| - SELECT InitSpatialMetaDataFull(1); |
41 |
| - SELECT ImportGeoJSON('/data/world.geojson', 'world'); |
42 |
| - `); |
| 38 | + const spl = await SPL([extention]); |
| 39 | + const db = await spl.mount('data', [{ |
| 40 | + name: 'world.geojson', |
| 41 | + data: await fetch('data/world.json').then(res => res.arrayBuffer()) |
| 42 | + }]).db().read(` |
| 43 | + SELECT InitSpatialMetaDataFull(1); |
| 44 | + SELECT ImportGeoJSON('/data/world.geojson', 'world'); |
| 45 | + `); |
43 | 46 |
|
44 |
| - const context = d3.select('canvas').node().getContext('2d'); |
45 |
| - const path = d3.geoPath().projection(d3.geoAitoff()).context(context); |
| 47 | + const context = d3.select('canvas').node().getContext('2d'); |
| 48 | + const path = d3.geoPath().projection(geoAitoff()).context(context); |
46 | 49 |
|
47 |
| - db.toTopoJSON('world').then(topology => { |
48 |
| - context.beginPath(); |
49 |
| - document.querySelector('#progress').remove(); |
50 |
| - path(topojson.mesh(topology)); |
51 |
| - context.stroke(); |
52 |
| - }); |
| 50 | + db.toTopoJSON('world').then(topology => { |
| 51 | + context.beginPath(); |
| 52 | + document.querySelector('#progress').remove(); |
| 53 | + path(topojson.mesh(topology)); |
| 54 | + context.stroke(); |
| 55 | + }); |
53 | 56 |
|
54 |
| - </script> |
55 |
| - </body> |
| 57 | + </script> |
| 58 | + </body> |
56 | 59 | </html>
|
0 commit comments