@geolonia/embed 2.1.1 → 2.1.4

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geolonia/embed",
3
- "version": "2.1.1",
3
+ "version": "2.1.4",
4
4
  "description": "Geolonia embed JS API",
5
5
  "main": "dist/embed.js",
6
6
  "types": "src/embed.d.ts",
@@ -10,8 +10,7 @@
10
10
  "analyze": "ANALYZE=true webpack --mode production",
11
11
  "format": "prettier-eslint \"./src/**/*.js\" --write",
12
12
  "lint": "eslint \"src/**/*.js\"",
13
- "test": "npm run lint && mocha ./src/**/*.test.js --recursive -r jsdom-global/register -r @babel/register",
14
- "test:snapshot": "mkdir -p snapshots && mocha test/snapshot.test.js --timeout 30000"
13
+ "test": "npm run lint && mocha ./src/**/*.test.js --recursive -r jsdom-global/register -r @babel/register"
15
14
  },
16
15
  "author": "Geolonia (https://geolonia.com)",
17
16
  "repository": {
@@ -38,10 +37,8 @@
38
37
  "jsdom-global": "^3.0.2",
39
38
  "mocha": "^5.2.0",
40
39
  "node-fetch": "2",
41
- "pngjs": "^6.0.0",
42
40
  "prettier-eslint": "^12.0.0",
43
41
  "prettier-eslint-cli": "^5.0.0",
44
- "puppeteer": "^9.1.1",
45
42
  "style-loader": "^0.23.1",
46
43
  "svg-inline-loader": "^0.8.2",
47
44
  "webpack": "^5.59.1",
@@ -50,7 +47,7 @@
50
47
  "webpack-dev-server": "^4.3.1"
51
48
  },
52
49
  "dependencies": {
53
- "@geolonia/mbgl-geolonia-control": "^0.4.0",
50
+ "@geolonia/mbgl-geolonia-control": "^0.4.2",
54
51
  "@geolonia/mbgl-gesture-handling": "^1.0.15",
55
52
  "@mapbox/geojson-extent": "^0.3.2",
56
53
  "@turf/center": "^6.0.1",
@@ -84,15 +84,27 @@ export default class GeoloniaMap extends maplibregl.Map {
84
84
  }
85
85
  }
86
86
 
87
+ const transformedUrlObj = new URL(transformedUrl);
88
+
87
89
  if (resourceType === 'Source' && transformedUrl.startsWith('https://tileserver.geolonia.com')) {
88
- const tileserverSourcesUrl = new URL(transformedUrl);
89
90
  if (atts.stage !== 'v1') {
90
- tileserverSourcesUrl.hostname = `tileserver-${atts.stage}.geolonia.com`;
91
+ transformedUrlObj.hostname = `tileserver-${atts.stage}.geolonia.com`;
91
92
  }
92
- tileserverSourcesUrl.searchParams.set('sessionId', sessionId);
93
- tileserverSourcesUrl.searchParams.set('key', atts.key);
93
+ transformedUrlObj.searchParams.set('sessionId', sessionId);
94
+ transformedUrlObj.searchParams.set('key', atts.key);
95
+ return {
96
+ url: transformedUrlObj.toString(),
97
+ };
98
+ } else if (
99
+ (resourceType === 'SpriteJSON' || resourceType === 'SpriteImage') &&
100
+ transformedUrl.match(/^https:\/\/api\.geolonia\.com\/(dev|v1)\/sprites\//)
101
+ ) {
102
+ const pathParts = transformedUrlObj.pathname.split('/');
103
+ pathParts[1] = atts.stage;
104
+ transformedUrlObj.pathname = pathParts.join('/');
105
+ transformedUrlObj.searchParams.set('key', atts.key);
94
106
  return {
95
- url: tileserverSourcesUrl.toString(),
107
+ url: transformedUrlObj.toString(),
96
108
  };
97
109
  }
98
110
 
@@ -280,4 +292,10 @@ export default class GeoloniaMap extends maplibregl.Map {
280
292
  // Calls `maplibregl.Map.setStyle()`.
281
293
  super.setStyle.call(this, style, options);
282
294
  }
295
+
296
+ remove() {
297
+ const container = this.getContainer();
298
+ super.remove.call(this);
299
+ delete container.geoloniaMap;
300
+ }
283
301
  }
@@ -6,7 +6,7 @@ import markerSVG from './marker.svg';
6
6
  import * as util from './util';
7
7
 
8
8
  /**
9
- * Render the map
9
+ * Geolonia default marker
10
10
  *
11
11
  * @param container
12
12
  */
package/src/style.css CHANGED
@@ -109,3 +109,27 @@
109
109
  background-position: center center;
110
110
  background-size: cover;
111
111
  }
112
+
113
+ /* CSS for Attribution */
114
+ /* Fix: https://github.com/geolonia/embed/issues/291 */
115
+ .mapboxgl-map,
116
+ .maplibregl-map {
117
+ display: block!important;
118
+ }
119
+
120
+ .maplibregl-ctrl-attrib-inner.mapboxgl-ctrl-attrib-inner {
121
+ display: block!important;
122
+ }
123
+
124
+ .mapboxgl-ctrl-attrib.mapboxgl-compact .mapboxgl-ctrl-attrib-inner,
125
+ .maplibregl-ctrl-attrib.maplibregl-compact .maplibregl-ctrl-attrib-inner {
126
+ display: none!important;
127
+ }
128
+
129
+ .mapboxgl-ctrl-attrib.mapboxgl-compact-show .mapboxgl-ctrl-attrib-inner,
130
+ .mapboxgl-ctrl-attrib.mapboxgl-compact .mapboxgl-ctrl-attrib-button,
131
+ .maplibregl-ctrl-attrib.maplibregl-compact-show .maplibregl-ctrl-attrib-inner,
132
+ .maplibregl-ctrl-attrib.maplibregl-compact .maplibregl-ctrl-attrib-button {
133
+ display: block!important;
134
+ }
135
+ /* End: CSS for Attribution */
package/.dockerignore DELETED
@@ -1,5 +0,0 @@
1
- /dist
2
- node_modules
3
- *.log
4
- snapshots
5
- .git
package/Dockerfile DELETED
@@ -1,48 +0,0 @@
1
- FROM node:14
2
- WORKDIR /app
3
- RUN apt-get update && apt-get install -y \
4
- gconf-service \
5
- libasound2 \
6
- libatk1.0-0 \
7
- libc6 \
8
- libcairo2 \
9
- libcups2 \
10
- libdbus-1-3 \
11
- libexpat1 \
12
- libfontconfig1 \
13
- libgcc1 \
14
- libgconf-2-4 \
15
- libgdk-pixbuf2.0-0 \
16
- libglib2.0-0 \
17
- libgtk-3-0 \
18
- libnspr4 \
19
- libpango-1.0-0 \
20
- libpangocairo-1.0-0 \
21
- libstdc++6 \
22
- libx11-6 \
23
- libx11-xcb1 \
24
- libxcb1 \
25
- libxcomposite1 \
26
- libxcursor1 \
27
- libxdamage1 \
28
- libxext6 \
29
- libxfixes3 \
30
- libxi6 \
31
- libxrandr2 \
32
- libxrender1 \
33
- libxss1 \
34
- libxtst6 \
35
- ca-certificates \
36
- fonts-liberation \
37
- libappindicator1 \
38
- libnss3 \
39
- lsb-release \
40
- xdg-utils \
41
- wget \
42
- fonts-ipafont-mincho \
43
- fonts-ipafont-gothic
44
- COPY . .
45
- RUN yarn install
46
- ENV GEOLONIA_API_KEY=YOUR-API-KEY
47
- ENV NO_SANDBOX=true
48
- ENTRYPOINT ["yarn", "test:snapshot"]
@@ -1,97 +0,0 @@
1
- const assert = require('assert')
2
- const puppeteer = require('puppeteer')
3
- const fs = require('fs').promises
4
- const path = require('path')
5
- const http = require('http')
6
- const { pngDiff, niceDiff } = require('./util')
7
-
8
- const sleep = msec => new Promise(resolve => setTimeout(resolve, msec))
9
-
10
- describe('Tests for Maps.', () => {
11
- let browser
12
- let page
13
- let embedServer
14
- const capturedErrors = []
15
- const reports = []
16
-
17
- before(async () => {
18
- const embed = (
19
- await fs.readFile(path.resolve(__dirname, '..', 'dist', 'embed.js'))
20
- ).toString()
21
- embedServer = http.createServer((request, response) => {
22
- response.writeHead(200, { 'Content-Type': 'text/javascirpt' })
23
- response.write(embed)
24
- response.end()
25
- })
26
- embedServer.listen(8080)
27
-
28
- // prepare pupeteer
29
- browser = await puppeteer.launch({
30
- headless: true,
31
- args:
32
- process.env.NO_SANDBOX === 'true'
33
- ? ['--no-sandbox', '--disable-setuid-sandbox'] // for Docker env
34
- : [],
35
- })
36
- page = await browser.newPage()
37
-
38
- // navigation
39
- const template = await (
40
- await fs.readFile(path.resolve(__dirname, 'assets', 'map.html.template'))
41
- ).toString()
42
- const content = template
43
- .replace(/%ORIGIN%/g, 'http://127.0.0.1:8080')
44
- .replace(/%API_KEY%/g, process.env.GEOLONIA_API_KEY || 'YOUR-API-KEY')
45
- await page.goto('https://geoloniamaps.github.io/basic/')
46
- page.on('pageerror', error => capturedErrors.push(error))
47
- await page.setContent(content)
48
- await sleep(15000)
49
- })
50
-
51
- after(async () => {
52
- reports.forEach(report => process.stdout.write(`[report] ${report}\n`))
53
- await browser.close()
54
- embedServer.close()
55
- })
56
-
57
- it('should not emit JS errors', () => {
58
- assert.strictEqual(capturedErrors.length, 0)
59
- })
60
-
61
- it('should build DOM as expected', async () => {
62
- const map = await page.$('#map div:first-child')
63
- const className = await (await map.getProperty('className')).jsonValue()
64
- console.log(className)
65
- assert.strictEqual(className.includes('maplibregl-canvas-container'), true)
66
- })
67
-
68
- it('should match the snapshot at >95.00%', async () => {
69
- const basePath = path.resolve('__dirname', '..', 'snapshots')
70
- const snapshotPath = path.resolve(basePath, 'map.png.snapshot')
71
- const tmpSnapshotPath = path.resolve(basePath, 'map.png')
72
- const diffSnapshotPath = path.resolve(basePath, 'diff.png')
73
- const [nextImage, prevImage] = await Promise.all([
74
- page.screenshot(),
75
- fs.readFile(snapshotPath).catch(() => null),
76
- ])
77
- await fs.writeFile(tmpSnapshotPath, nextImage)
78
-
79
- if (process.env.UPDATE_SNAPSHOT === 'true' || !prevImage) {
80
- // Store snapshot
81
- reports.push('A snapshot has been updated.')
82
- await fs.writeFile(snapshotPath, nextImage)
83
- } else {
84
- const [matchRate, diffImage] = await Promise.all([
85
- pngDiff(prevImage, nextImage),
86
- niceDiff(prevImage, nextImage),
87
- ])
88
- await fs.writeFile(diffSnapshotPath, diffImage)
89
-
90
- const matchRateLabel =
91
- ((Math.round(10000 * matchRate) + 0.1) / 100).toString().slice(0, 5) +
92
- '%'
93
- reports.push(`Snapshot matching rate: ${matchRateLabel}`)
94
- assert.strictEqual(matchRate > 0.95, true)
95
- }
96
- })
97
- })
package/test/util.js DELETED
@@ -1,96 +0,0 @@
1
- const { PNG } = require('pngjs')
2
-
3
- const pngDiff = (prevImage, nextImage) => {
4
- return new Promise(resolve => {
5
- const prev = PNG.sync.read(prevImage)
6
- const next = PNG.sync.read(nextImage)
7
- let totalDelta = 0
8
- if (prev.data.length !== next.data.length) {
9
- throw new Error(
10
- `image size mismatch: ${prev.width}x${prev.height} vs. ${next.width}x${next.height}`,
11
- )
12
- }
13
- const byteCount = prev.data.length
14
- const pixelCount = byteCount / 4
15
- for (let index = 0; index < byteCount; index += 4) {
16
- const prevA = prev.data[index + 3] / 255
17
- const nextA = next.data[index + 3] / 255
18
- let delta = 0
19
- delta += Math.abs(
20
- (prev.data[index] * prevA - next.data[index] * nextA) / 255,
21
- )
22
- delta += Math.abs(
23
- (prev.data[index + 1] * prevA - next.data[index + 1] * nextA) / 255,
24
- )
25
- delta += Math.abs(
26
- (prev.data[index + 2] * prevA - next.data[index + 2] * nextA) / 255,
27
- )
28
- totalDelta += delta / 3
29
- }
30
- const matchRate = (pixelCount - totalDelta) / pixelCount
31
- resolve(matchRate)
32
- })
33
- }
34
-
35
- const niceDiff = (img1, img2) => {
36
- return new Promise(resolve => {
37
- const png1 = PNG.sync.read(img1)
38
- const png2 = PNG.sync.read(img2)
39
- if (png1.data.length !== png2.data.length) {
40
- throw new Error(
41
- `image size mismatch: ${png1.width}x${png1.height} vs. ${png2.width}x${png2.height}`,
42
- )
43
- }
44
- const byteCount = png1.data.length
45
- const diff = {
46
- data: [],
47
- width: png1.width,
48
- height: png1.height,
49
- }
50
- for (let index = 0; index < byteCount; index += 4) {
51
- if (
52
- png1.data[index] !== png2.data[index] ||
53
- png1.data[index + 1] !== png2.data[index + 1] ||
54
- png1.data[index + 2] !== png2.data[index + 2]
55
- ) {
56
- // a bright marker
57
- diff.data.push(...[255, 120, 255, 255])
58
- } else {
59
- const darker = [png1.data[index], png1.data[index + 1], png1.data[index + 2]].map(p => Math.floor(p / 5))
60
- diff.data.push(...darker, 255)
61
- }
62
- }
63
- resolve(PNG.sync.write(diff))
64
- })
65
- }
66
-
67
- // eslint-disable-next-line no-unused-vars
68
- const _test = async () => {
69
- const alfa = 255
70
- const img1 = PNG.sync.write({
71
- width: 2,
72
- height: 2,
73
- data: [
74
- [0, 0, 0],
75
- [0, 0, 0],
76
- [0, 0, 0],
77
- [0, 0, 0],
78
- ].flatMap(rgb => [...rgb, alfa]),
79
- })
80
- const img2 = PNG.sync.write({
81
- width: 2,
82
- height: 2,
83
- data: [
84
- [255, 255, 255],
85
- [255, 255, 255],
86
- [255, 255, 255],
87
- [255, 255, 255],
88
- ].flatMap(rgb => [...rgb, alfa]),
89
- })
90
- const matchRate = await pngDiff(img1, img2)
91
- if (matchRate > 0) {
92
- throw new Error(`invalid match rate: ${matchRate}`)
93
- }
94
- }
95
-
96
- module.exports = { pngDiff, niceDiff }