@geolonia/embed 6.0.0 → 6.1.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.
- package/CHANGELOG.md +24 -0
- package/README.md +54 -6
- package/dist/embed +1 -1
- package/dist/embed-chunks/1b101382794d13cd280c.js +2 -0
- package/dist/embed-chunks/856a68e16ab05c382e6f.js +2 -0
- package/dist/embed-chunks/9a1056aa012055998dc3.js +1 -0
- package/dist/embed-chunks/{5f80e0235f4b38778d0d.js → bf6d08239720e38dacd6.js} +1 -1
- package/dist/embed-core.js +1 -1
- package/dist/embed.js +1 -1
- package/dist/lib/util.d.ts +0 -5
- package/dist/types.d.ts +145 -7
- package/dist/version.d.ts +1 -1
- package/e2e/data-driven.spec.ts +9 -2
- package/e2e/iframe.spec.ts +37 -22
- package/e2e/mask.spec.ts +75 -0
- package/e2e/projection-raster-tiles.spec.ts +71 -0
- package/package.json +2 -2
- package/pnpm-workspace.yaml +6 -0
- package/src/lib/parse-atts.test.ts +531 -4
- package/src/lib/parse-atts.ts +261 -25
- package/src/lib/render.ts +99 -106
- package/src/lib/util.ts +0 -76
- package/src/types.ts +145 -7
- package/src/version.ts +1 -1
- package/dist/embed-chunks/9734b8bdf9fe84261b54.js +0 -2
- package/dist/embed-chunks/ae36f6b8e34f85ae3045.js +0 -2
- package/dist/embed-chunks/c83bb7c9a4a7ed9d5b23.js +0 -1
- /package/dist/embed-chunks/{9734b8bdf9fe84261b54.js.LICENSE.txt → 1b101382794d13cd280c.js.LICENSE.txt} +0 -0
- /package/dist/embed-chunks/{ae36f6b8e34f85ae3045.js.LICENSE.txt → 856a68e16ab05c382e6f.js.LICENSE.txt} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import { keyring, getStyle } from '@geolonia/maps-core';
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
2
|
+
import { keyring, getStyle, type ChoroplethOptions } from '@geolonia/maps-core';
|
|
3
3
|
import parseAtts, { attsToOptions } from './parse-atts';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -317,10 +317,124 @@ describe('attsToOptions のデータ駆動の描き方', () => {
|
|
|
317
317
|
});
|
|
318
318
|
});
|
|
319
319
|
|
|
320
|
+
describe('-colors の値と色の組 (ColorMap)', () => {
|
|
321
|
+
beforeEach(() => {
|
|
322
|
+
keyring.reset();
|
|
323
|
+
keyring.setApiKey('YOUR-API-KEY');
|
|
324
|
+
keyring.setStage('v1');
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
afterEach(() => {
|
|
328
|
+
keyring.reset();
|
|
329
|
+
vi.restoreAllMocks();
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
const toOptions = (dataset: Record<string, string>) => {
|
|
333
|
+
const container = document.createElement('div');
|
|
334
|
+
Object.assign(container.dataset, dataset);
|
|
335
|
+
return attsToOptions(container, parseAtts(container));
|
|
336
|
+
};
|
|
337
|
+
const choroplethColors = (value: string) =>
|
|
338
|
+
(
|
|
339
|
+
toOptions({ choropleth: 'status', choroplethColors: value })
|
|
340
|
+
.choropleth as ChoroplethOptions
|
|
341
|
+
).colors;
|
|
342
|
+
const circleColors = (value: string) =>
|
|
343
|
+
toOptions({ circleColor: 'status', circleColors: value }).circle?.colors;
|
|
344
|
+
|
|
345
|
+
it('値:色 の組を対応表にする (data-choropleth-colors と data-circle-colors)', () => {
|
|
346
|
+
const value = 'normal:#3b82f6, warning:#eab308, danger:#ef4444';
|
|
347
|
+
const expected = {
|
|
348
|
+
normal: '#3b82f6',
|
|
349
|
+
warning: '#eab308',
|
|
350
|
+
danger: '#ef4444',
|
|
351
|
+
};
|
|
352
|
+
expect(choroplethColors(value)).toEqual(expected);
|
|
353
|
+
expect(circleColors(value)).toEqual(expected);
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
it('値: の無い色だけなら、いまどおり色の並びにする', () => {
|
|
357
|
+
expect(circleColors('#f00, rgb(0, 0, 255)')).toEqual([
|
|
358
|
+
'#f00',
|
|
359
|
+
'rgb(0, 0, 255)',
|
|
360
|
+
]);
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
it('括弧の中のカンマは区切りとして扱わない', () => {
|
|
364
|
+
expect(circleColors('a:rgb(0, 0, 255), b:hsl(0 100% 50% / 0.5)')).toEqual({
|
|
365
|
+
a: 'rgb(0, 0, 255)',
|
|
366
|
+
b: 'hsl(0 100% 50% / 0.5)',
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it('値に : を含められる (最後の : で値と色を分ける)', () => {
|
|
371
|
+
expect(circleColors('10:30:#f00, 12:00:#00f')).toEqual({
|
|
372
|
+
'10:30': '#f00',
|
|
373
|
+
'12:00': '#00f',
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
it('値と色の前後の空白を除き、: の前が空なら空文字の値にする', () => {
|
|
378
|
+
expect(circleColors(' a : #f00 , : #00f ')).toEqual({
|
|
379
|
+
a: '#f00',
|
|
380
|
+
'': '#00f',
|
|
381
|
+
});
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
it('数字の値は文字列のキーにする', () => {
|
|
385
|
+
expect(circleColors('1:#f00, 2:#00f')).toEqual({ 1: '#f00', 2: '#00f' });
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
it('同じ値の組が複数あれば後のものを使う', () => {
|
|
389
|
+
expect(circleColors('a:#f00, a:#00f')).toEqual({ a: '#00f' });
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
it('__proto__ や constructor も値として対応表に入る', () => {
|
|
393
|
+
const colors = circleColors('__proto__:#f00, constructor:#00f');
|
|
394
|
+
expect(Object.keys(colors ?? {})).toEqual(['__proto__', 'constructor']);
|
|
395
|
+
expect(Object.entries(colors ?? {})).toEqual([
|
|
396
|
+
['__proto__', '#f00'],
|
|
397
|
+
['constructor', '#00f'],
|
|
398
|
+
]);
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
it('組と色だけの項目が混ざるときは、組だけを使い、ほかは警告して無視する', () => {
|
|
402
|
+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
403
|
+
expect(circleColors('a:#f00, #00f, b:')).toEqual({ a: '#f00' });
|
|
404
|
+
expect(warn).toHaveBeenCalledTimes(2);
|
|
405
|
+
expect(warn.mock.calls[0][0]).toContain('data-circle-colors');
|
|
406
|
+
expect(warn.mock.calls[0][0]).toContain('#00f');
|
|
407
|
+
expect(warn.mock.calls[1][0]).toContain('b:');
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
it('閉じていない ( より後ろのカンマと : は区切りとして読まない', () => {
|
|
411
|
+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
412
|
+
// `b(:#00f, c:#0f0` が 1 つの項目になり、括弧の外に : が無いので無視される
|
|
413
|
+
expect(circleColors('a:#f00, b(:#00f, c:#0f0')).toEqual({ a: '#f00' });
|
|
414
|
+
expect(warn).toHaveBeenCalledTimes(1);
|
|
415
|
+
expect(warn.mock.calls[0][0]).toContain('b(:#00f, c:#0f0');
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
it('使える組が 1 つも無ければ colors を渡さない (既定の色になる)', () => {
|
|
419
|
+
vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
420
|
+
const options = toOptions({
|
|
421
|
+
choropleth: 'status',
|
|
422
|
+
choroplethColors: 'a:, b:',
|
|
423
|
+
});
|
|
424
|
+
expect(options.choropleth).toEqual({ property: 'status' });
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
it('空の項目しか無ければ colors を渡さない', () => {
|
|
428
|
+
expect(
|
|
429
|
+
toOptions({ circleColor: 'status', circleColors: ' , ' }).circle,
|
|
430
|
+
).toEqual({ color: 'status' });
|
|
431
|
+
});
|
|
432
|
+
});
|
|
433
|
+
|
|
320
434
|
// data-lang の言語解決 (embed#462 / maps-core#50)。
|
|
321
435
|
// 正しい契約 (maps-core#50 のテストが基準):
|
|
322
|
-
// - `ja` / `ja-jp` のみ日本語スタイル、それ以外は英語スタイル
|
|
323
|
-
// - `auto`
|
|
436
|
+
// - `ja` / `ja-jp` のみ日本語スタイル、それ以外は英語スタイル (大文字と小文字を区別する)
|
|
437
|
+
// - `auto` と空文字はブラウザ言語に追従 (解決するのは maps-core の GeoloniaMap のコンストラクタ)
|
|
324
438
|
// embed の責務: `data-lang` を options.lang へ転送する (最終的な ja/en 判定は
|
|
325
439
|
// maps-core の getStyle が担う)。未指定時のみ embed が getLang() で具体値に解決する。
|
|
326
440
|
describe('data-lang 言語解決', () => {
|
|
@@ -376,4 +490,417 @@ describe('data-lang 言語解決', () => {
|
|
|
376
490
|
expect(optionsFor('auto', ['en']).lang).toBe('auto');
|
|
377
491
|
expect(optionsFor('auto', ['ja']).lang).toBe('auto');
|
|
378
492
|
});
|
|
493
|
+
|
|
494
|
+
it('data-lang の明示値は ja / en に解決せず、生の値のまま転送する', () => {
|
|
495
|
+
expect(optionsFor('', ['ja']).lang).toBe('');
|
|
496
|
+
expect(optionsFor('ja-JP', ['ja']).lang).toBe('ja-JP');
|
|
497
|
+
expect(optionsFor('fr', ['ja']).lang).toBe('fr');
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
// embed が生の値を転送することは直前のテストで見ている。ここでは転送先の
|
|
501
|
+
// maps-core が大文字を含む値を日本語として扱わないことを確かめる。
|
|
502
|
+
it('大文字を含む data-lang="ja-JP" は英語スタイルになる', () => {
|
|
503
|
+
expect(
|
|
504
|
+
getStyle('geolonia/basic-v2', { lang: 'ja-JP', apiKey: 'KEY' }),
|
|
505
|
+
).toContain('/en.json');
|
|
506
|
+
});
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
// 「そのまま返す」「例外を投げる」のテストは、現状の挙動を固定している。
|
|
510
|
+
// 対応外の値の扱いを変えるときは、これらのテストも書き換える
|
|
511
|
+
// (https://github.com/geolonia/embed/issues/570)。
|
|
512
|
+
describe('data-geojson の解決', () => {
|
|
513
|
+
const geojsonFor = (value: string) => {
|
|
514
|
+
const c = document.createElement('div');
|
|
515
|
+
c.dataset.geojson = value;
|
|
516
|
+
return attsToOptions(c, parseAtts(c)).geojson;
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
afterEach(() => {
|
|
520
|
+
document.body.innerHTML = '';
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
it('URL と相対パスは文字列のまま渡す', () => {
|
|
524
|
+
for (const value of [
|
|
525
|
+
'https://example.com/a.geojson',
|
|
526
|
+
'/a.geojson',
|
|
527
|
+
'./a.geojson',
|
|
528
|
+
'../a.geojson',
|
|
529
|
+
]) {
|
|
530
|
+
expect(geojsonFor(value)).toBe(value);
|
|
531
|
+
}
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
it('インライン要素を指すセレクタは中身を FeatureCollection にする', () => {
|
|
535
|
+
const fc = { type: 'FeatureCollection', features: [] };
|
|
536
|
+
const el = document.createElement('script');
|
|
537
|
+
el.type = 'application/json';
|
|
538
|
+
el.id = 'points';
|
|
539
|
+
el.textContent = JSON.stringify(fc);
|
|
540
|
+
document.body.appendChild(el);
|
|
541
|
+
expect(geojsonFor('#points')).toEqual(fc);
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
it('. で始まる値は、一致する要素があればセレクタ、無ければそのまま返す', () => {
|
|
545
|
+
const fc = { type: 'FeatureCollection', features: [] };
|
|
546
|
+
const el = document.createElement('script');
|
|
547
|
+
el.type = 'application/json';
|
|
548
|
+
el.className = 'points';
|
|
549
|
+
el.textContent = JSON.stringify(fc);
|
|
550
|
+
document.body.appendChild(el);
|
|
551
|
+
expect(geojsonFor('.points')).toEqual(fc);
|
|
552
|
+
expect(geojsonFor('.missing')).toBe('.missing');
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
it('何も指さないセレクタは、そのまま返す', () => {
|
|
556
|
+
expect(geojsonFor('#missing')).toBe('#missing');
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
it('要素の中身は検証せずに解析結果を返す (FeatureCollection 以外も通る)', () => {
|
|
560
|
+
const feature = {
|
|
561
|
+
type: 'Feature',
|
|
562
|
+
geometry: { type: 'Point', coordinates: [0, 0] },
|
|
563
|
+
properties: {},
|
|
564
|
+
};
|
|
565
|
+
const el = document.createElement('script');
|
|
566
|
+
el.type = 'application/json';
|
|
567
|
+
el.id = 'feature';
|
|
568
|
+
el.textContent = JSON.stringify(feature);
|
|
569
|
+
document.body.appendChild(el);
|
|
570
|
+
expect(geojsonFor('#feature')).toEqual(feature);
|
|
571
|
+
});
|
|
572
|
+
|
|
573
|
+
it('インラインの JSON 文字列と ./ の無い相対パスは、そのまま返す', () => {
|
|
574
|
+
const json = '{"type":"FeatureCollection","features":[]}';
|
|
575
|
+
expect(geojsonFor(json)).toBe(json);
|
|
576
|
+
expect(geojsonFor('data.geojson')).toBe('data.geojson');
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
it('中身が空の要素を指すセレクタは、そのまま返す', () => {
|
|
580
|
+
const el = document.createElement('script');
|
|
581
|
+
el.type = 'application/json';
|
|
582
|
+
el.id = 'empty';
|
|
583
|
+
document.body.appendChild(el);
|
|
584
|
+
expect(geojsonFor('#empty')).toBe('#empty');
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
it('要素の中身が JSON として読めないときは例外を投げる (空白だけの中身を含む)', () => {
|
|
588
|
+
for (const [id, text] of [
|
|
589
|
+
['broken', '{'],
|
|
590
|
+
['blank', '\n '],
|
|
591
|
+
]) {
|
|
592
|
+
const el = document.createElement('script');
|
|
593
|
+
el.type = 'application/json';
|
|
594
|
+
el.id = id;
|
|
595
|
+
el.textContent = text;
|
|
596
|
+
document.body.appendChild(el);
|
|
597
|
+
expect(() => geojsonFor(`#${id}`)).toThrow(SyntaxError);
|
|
598
|
+
}
|
|
599
|
+
});
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
describe('attsToOptions の投影と重ねるタイル', () => {
|
|
603
|
+
beforeEach(() => {
|
|
604
|
+
keyring.reset();
|
|
605
|
+
keyring.setApiKey('YOUR-API-KEY');
|
|
606
|
+
keyring.setStage('v1');
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
afterEach(() => {
|
|
610
|
+
keyring.reset();
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
const toOptions = (dataset: Record<string, string>) => {
|
|
614
|
+
const container = document.createElement('div');
|
|
615
|
+
Object.assign(container.dataset, dataset);
|
|
616
|
+
return attsToOptions(container, parseAtts(container));
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
it('属性が無ければ projection と rasterTiles を渡さない', () => {
|
|
620
|
+
const options = toOptions({});
|
|
621
|
+
|
|
622
|
+
expect('projection' in options).toBe(false);
|
|
623
|
+
expect('rasterTiles' in options).toBe(false);
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
it('data-projection の値を前後の空白を除いて渡す', () => {
|
|
627
|
+
expect(toOptions({ projection: 'globe' }).projection).toBe('globe');
|
|
628
|
+
expect(toOptions({ projection: ' mercator ' }).projection).toBe('mercator');
|
|
629
|
+
});
|
|
630
|
+
|
|
631
|
+
it('data-projection の値は検査せずに渡す (maps-core がエラーを出して無視する)', () => {
|
|
632
|
+
expect(toOptions({ projection: 'Globe' }).projection).toBe('Globe');
|
|
633
|
+
});
|
|
634
|
+
|
|
635
|
+
it('空の data-projection は渡さない', () => {
|
|
636
|
+
expect('projection' in toOptions({ projection: '' })).toBe(false);
|
|
637
|
+
expect('projection' in toOptions({ projection: ' ' })).toBe(false);
|
|
638
|
+
});
|
|
639
|
+
|
|
640
|
+
it('data-raster-tiles だけなら URL だけを渡す', () => {
|
|
641
|
+
expect(
|
|
642
|
+
toOptions({ rasterTiles: 'https://example.com/{z}/{x}/{y}.png' })
|
|
643
|
+
.rasterTiles,
|
|
644
|
+
).toEqual({ url: 'https://example.com/{z}/{x}/{y}.png' });
|
|
645
|
+
});
|
|
646
|
+
|
|
647
|
+
it('data-raster-tiles-* をすべて読む', () => {
|
|
648
|
+
expect(
|
|
649
|
+
toOptions({
|
|
650
|
+
rasterTiles: 'https://example.com/{z}/{x}/{y}.png',
|
|
651
|
+
rasterTilesAttribution: '<a href="https://example.com/">出典</a>',
|
|
652
|
+
rasterTilesOpacity: '0.7',
|
|
653
|
+
rasterTilesSize: '512',
|
|
654
|
+
rasterTilesMinZoom: '2',
|
|
655
|
+
rasterTilesMaxZoom: '17',
|
|
656
|
+
}).rasterTiles,
|
|
657
|
+
).toEqual({
|
|
658
|
+
url: 'https://example.com/{z}/{x}/{y}.png',
|
|
659
|
+
attribution: '<a href="https://example.com/">出典</a>',
|
|
660
|
+
opacity: 0.7,
|
|
661
|
+
tileSize: 512,
|
|
662
|
+
minZoom: 2,
|
|
663
|
+
maxZoom: 17,
|
|
664
|
+
});
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
it('0 は数値として渡す', () => {
|
|
668
|
+
expect(
|
|
669
|
+
toOptions({
|
|
670
|
+
rasterTiles: 'https://example.com/{z}/{x}/{y}.png',
|
|
671
|
+
rasterTilesOpacity: '0',
|
|
672
|
+
rasterTilesMinZoom: '0',
|
|
673
|
+
}).rasterTiles,
|
|
674
|
+
).toEqual({
|
|
675
|
+
url: 'https://example.com/{z}/{x}/{y}.png',
|
|
676
|
+
opacity: 0,
|
|
677
|
+
minZoom: 0,
|
|
678
|
+
});
|
|
679
|
+
});
|
|
680
|
+
|
|
681
|
+
it('数値として読めない値と空の値は渡さない', () => {
|
|
682
|
+
expect(
|
|
683
|
+
toOptions({
|
|
684
|
+
rasterTiles: 'https://example.com/{z}/{x}/{y}.png',
|
|
685
|
+
rasterTilesAttribution: ' ',
|
|
686
|
+
rasterTilesOpacity: 'half',
|
|
687
|
+
rasterTilesSize: '',
|
|
688
|
+
rasterTilesMinZoom: ' ',
|
|
689
|
+
rasterTilesMaxZoom: 'Infinity',
|
|
690
|
+
}).rasterTiles,
|
|
691
|
+
).toEqual({ url: 'https://example.com/{z}/{x}/{y}.png' });
|
|
692
|
+
});
|
|
693
|
+
|
|
694
|
+
it('範囲の外の数値は検査せずに渡す (maps-core が範囲内に収める)', () => {
|
|
695
|
+
expect(
|
|
696
|
+
toOptions({
|
|
697
|
+
rasterTiles: 'https://example.com/{z}/{x}/{y}.png',
|
|
698
|
+
rasterTilesOpacity: '1.5',
|
|
699
|
+
rasterTilesSize: '-1',
|
|
700
|
+
}).rasterTiles,
|
|
701
|
+
).toEqual({
|
|
702
|
+
url: 'https://example.com/{z}/{x}/{y}.png',
|
|
703
|
+
opacity: 1.5,
|
|
704
|
+
tileSize: -1,
|
|
705
|
+
});
|
|
706
|
+
});
|
|
707
|
+
|
|
708
|
+
it('data-raster-tiles が無いか空なら、ほかの data-raster-tiles-* は無視する', () => {
|
|
709
|
+
const others = {
|
|
710
|
+
rasterTilesAttribution: '出典',
|
|
711
|
+
rasterTilesOpacity: '0.5',
|
|
712
|
+
rasterTilesSize: '256',
|
|
713
|
+
rasterTilesMinZoom: '2',
|
|
714
|
+
rasterTilesMaxZoom: '17',
|
|
715
|
+
};
|
|
716
|
+
expect('rasterTiles' in toOptions(others)).toBe(false);
|
|
717
|
+
expect('rasterTiles' in toOptions({ ...others, rasterTiles: ' ' })).toBe(
|
|
718
|
+
false,
|
|
719
|
+
);
|
|
720
|
+
});
|
|
721
|
+
});
|
|
722
|
+
|
|
723
|
+
describe('attsToOptions の立体表示とマスク', () => {
|
|
724
|
+
beforeEach(() => {
|
|
725
|
+
keyring.reset();
|
|
726
|
+
keyring.setApiKey('YOUR-API-KEY');
|
|
727
|
+
keyring.setStage('v1');
|
|
728
|
+
});
|
|
729
|
+
|
|
730
|
+
afterEach(() => {
|
|
731
|
+
keyring.reset();
|
|
732
|
+
vi.restoreAllMocks();
|
|
733
|
+
});
|
|
734
|
+
|
|
735
|
+
const toOptions = (dataset: Record<string, string>) => {
|
|
736
|
+
const container = document.createElement('div');
|
|
737
|
+
Object.assign(container.dataset, dataset);
|
|
738
|
+
return attsToOptions(container, parseAtts(container));
|
|
739
|
+
};
|
|
740
|
+
|
|
741
|
+
it('属性が無ければ extrusion と mask を渡さない', () => {
|
|
742
|
+
const options = toOptions({});
|
|
743
|
+
expect('extrusion' in options).toBe(false);
|
|
744
|
+
expect('mask' in options).toBe(false);
|
|
745
|
+
});
|
|
746
|
+
|
|
747
|
+
it('data-extrusion だけならプロパティ名だけを渡す', () => {
|
|
748
|
+
expect(toOptions({ extrusion: ' population ' }).extrusion).toBe(
|
|
749
|
+
'population',
|
|
750
|
+
);
|
|
751
|
+
});
|
|
752
|
+
|
|
753
|
+
it('空の data-extrusion は渡さず、ほかの data-extrusion-* も無視する', () => {
|
|
754
|
+
const others = {
|
|
755
|
+
extrusionMaxHeight: '1000',
|
|
756
|
+
extrusionColor: 'kind',
|
|
757
|
+
extrusionColors: '#f00,#00f',
|
|
758
|
+
};
|
|
759
|
+
expect('extrusion' in toOptions(others)).toBe(false);
|
|
760
|
+
expect('extrusion' in toOptions({ ...others, extrusion: ' ' })).toBe(false);
|
|
761
|
+
});
|
|
762
|
+
|
|
763
|
+
it('data-extrusion-color だけを足すと、高さと色を別のプロパティにする', () => {
|
|
764
|
+
expect(
|
|
765
|
+
toOptions({ extrusion: 'population', extrusionColor: 'kind' }).extrusion,
|
|
766
|
+
).toEqual({ height: 'population', color: 'kind' });
|
|
767
|
+
});
|
|
768
|
+
|
|
769
|
+
it('data-extrusion-* をすべて読む', () => {
|
|
770
|
+
expect(
|
|
771
|
+
toOptions({
|
|
772
|
+
extrusion: 'population',
|
|
773
|
+
extrusionMaxHeight: '5000',
|
|
774
|
+
extrusionHeightScale: '0.5',
|
|
775
|
+
extrusionHeightRange: '0,100',
|
|
776
|
+
extrusionColor: 'density',
|
|
777
|
+
extrusionColors: '#fff, rgb(255, 0, 0)',
|
|
778
|
+
extrusionColorRange: '10,20',
|
|
779
|
+
}).extrusion,
|
|
780
|
+
).toEqual({
|
|
781
|
+
height: {
|
|
782
|
+
property: 'population',
|
|
783
|
+
maxHeight: 5000,
|
|
784
|
+
heightScale: 0.5,
|
|
785
|
+
range: [0, 100],
|
|
786
|
+
},
|
|
787
|
+
color: {
|
|
788
|
+
property: 'density',
|
|
789
|
+
colors: ['#fff', 'rgb(255, 0, 0)'],
|
|
790
|
+
range: [10, 20],
|
|
791
|
+
},
|
|
792
|
+
});
|
|
793
|
+
});
|
|
794
|
+
|
|
795
|
+
it('色のプロパティを省略して色を指定すると、高さと同じプロパティで色分けする', () => {
|
|
796
|
+
expect(
|
|
797
|
+
toOptions({ extrusion: 'population', extrusionColors: '#fff,#f00' })
|
|
798
|
+
.extrusion,
|
|
799
|
+
).toEqual({
|
|
800
|
+
height: { property: 'population' },
|
|
801
|
+
color: { property: 'population', colors: ['#fff', '#f00'] },
|
|
802
|
+
});
|
|
803
|
+
});
|
|
804
|
+
|
|
805
|
+
it('data-extrusion-colors は値と色の組を対応表として読む', () => {
|
|
806
|
+
expect(
|
|
807
|
+
toOptions({
|
|
808
|
+
extrusion: 'height',
|
|
809
|
+
extrusionColor: 'kind',
|
|
810
|
+
extrusionColors: 'house:#3b82f6, shop:#ef4444',
|
|
811
|
+
}).extrusion,
|
|
812
|
+
).toEqual({
|
|
813
|
+
height: { property: 'height' },
|
|
814
|
+
color: {
|
|
815
|
+
property: 'kind',
|
|
816
|
+
colors: { house: '#3b82f6', shop: '#ef4444' },
|
|
817
|
+
},
|
|
818
|
+
});
|
|
819
|
+
});
|
|
820
|
+
|
|
821
|
+
it('読めない数値と範囲は渡さない (0 は数値として渡す)', () => {
|
|
822
|
+
expect(
|
|
823
|
+
toOptions({
|
|
824
|
+
extrusion: 'population',
|
|
825
|
+
extrusionMaxHeight: 'high',
|
|
826
|
+
extrusionHeightScale: '0',
|
|
827
|
+
extrusionHeightRange: '100,0',
|
|
828
|
+
extrusionColorRange: '1',
|
|
829
|
+
}).extrusion,
|
|
830
|
+
).toEqual({
|
|
831
|
+
height: { property: 'population', heightScale: 0 },
|
|
832
|
+
color: { property: 'population' },
|
|
833
|
+
});
|
|
834
|
+
});
|
|
835
|
+
|
|
836
|
+
it('読めない値しか無ければ、プロパティ名だけを渡す', () => {
|
|
837
|
+
expect(
|
|
838
|
+
toOptions({
|
|
839
|
+
extrusion: 'population',
|
|
840
|
+
extrusionMaxHeight: '',
|
|
841
|
+
extrusionHeightRange: 'a,b',
|
|
842
|
+
}).extrusion,
|
|
843
|
+
).toBe('population');
|
|
844
|
+
});
|
|
845
|
+
|
|
846
|
+
it('data-mask だけなら URL だけを渡す', () => {
|
|
847
|
+
expect(toOptions({ mask: ' https://example.com/area.geojson ' }).mask).toBe(
|
|
848
|
+
'https://example.com/area.geojson',
|
|
849
|
+
);
|
|
850
|
+
});
|
|
851
|
+
|
|
852
|
+
it('data-mask-* をすべて読む', () => {
|
|
853
|
+
expect(
|
|
854
|
+
toOptions({
|
|
855
|
+
mask: '/area.geojson',
|
|
856
|
+
maskColor: '#123456',
|
|
857
|
+
maskOpacity: '0.5',
|
|
858
|
+
maskOutline: 'on',
|
|
859
|
+
}).mask,
|
|
860
|
+
).toEqual({
|
|
861
|
+
geojson: '/area.geojson',
|
|
862
|
+
color: '#123456',
|
|
863
|
+
opacity: 0.5,
|
|
864
|
+
outline: true,
|
|
865
|
+
});
|
|
866
|
+
});
|
|
867
|
+
|
|
868
|
+
it('data-mask-outline は on のときだけ線を引く (大文字小文字と空白を区別しない)', () => {
|
|
869
|
+
expect(toOptions({ mask: '/a.geojson', maskOutline: ' ON ' }).mask).toEqual(
|
|
870
|
+
{
|
|
871
|
+
geojson: '/a.geojson',
|
|
872
|
+
outline: true,
|
|
873
|
+
},
|
|
874
|
+
);
|
|
875
|
+
expect(toOptions({ mask: '/a.geojson', maskOutline: 'off' }).mask).toBe(
|
|
876
|
+
'/a.geojson',
|
|
877
|
+
);
|
|
878
|
+
expect(toOptions({ mask: '/a.geojson', maskOutline: '' }).mask).toBe(
|
|
879
|
+
'/a.geojson',
|
|
880
|
+
);
|
|
881
|
+
});
|
|
882
|
+
|
|
883
|
+
it('読めない data-mask-opacity と空の data-mask-color は渡さない (0 は渡す)', () => {
|
|
884
|
+
expect(
|
|
885
|
+
toOptions({ mask: '/a.geojson', maskOpacity: 'half', maskColor: ' ' })
|
|
886
|
+
.mask,
|
|
887
|
+
).toBe('/a.geojson');
|
|
888
|
+
expect(toOptions({ mask: '/a.geojson', maskOpacity: '0' }).mask).toEqual({
|
|
889
|
+
geojson: '/a.geojson',
|
|
890
|
+
opacity: 0,
|
|
891
|
+
});
|
|
892
|
+
});
|
|
893
|
+
|
|
894
|
+
it('範囲の外の data-mask-opacity は検査せずに渡す (maps-core がエラーを出して既定値にする)', () => {
|
|
895
|
+
expect(toOptions({ mask: '/a.geojson', maskOpacity: '2' }).mask).toEqual({
|
|
896
|
+
geojson: '/a.geojson',
|
|
897
|
+
opacity: 2,
|
|
898
|
+
});
|
|
899
|
+
});
|
|
900
|
+
|
|
901
|
+
it('data-mask が無いか空なら、ほかの data-mask-* は無視する', () => {
|
|
902
|
+
const others = { maskColor: '#000', maskOpacity: '0.5', maskOutline: 'on' };
|
|
903
|
+
expect('mask' in toOptions(others)).toBe(false);
|
|
904
|
+
expect('mask' in toOptions({ ...others, mask: ' ' })).toBe(false);
|
|
905
|
+
});
|
|
379
906
|
});
|