Skip to content

Commit 72964e2

Browse files
committed
Get a basic OSM renderer test to fire with some prepackaged data.
1 parent 6cab1a1 commit 72964e2

File tree

7 files changed

+143
-48
lines changed

7 files changed

+143
-48
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test/spec/renderer/PixiRenderer.js

data/languages.json

+6-44
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
"as": {"nativeName": "অসমীয়া"},
3535
"asa": {"nativeName": "Kipare"},
3636
"ast": {"nativeName": "asturianu"},
37-
"atj": {},
3837
"av": {},
3938
"avk": {},
4039
"awa": {},
@@ -51,7 +50,6 @@
5150
"bbc": {},
5251
"bbj": {},
5352
"be": {"nativeName": "беларуская"},
54-
"be-tarask": {},
5553
"bej": {},
5654
"bem": {"nativeName": "Ichibemba"},
5755
"bew": {},
@@ -67,7 +65,6 @@
6765
"bjn": {},
6866
"bkm": {},
6967
"bla": {},
70-
"blt": {},
7168
"bm": {"nativeName": "bamanakan"},
7269
"bn": {"nativeName": "বাংলা"},
7370
"bo": {"nativeName": "བོད་སྐད་"},
@@ -76,7 +73,7 @@
7673
"br": {"nativeName": "brezhoneg"},
7774
"bra": {},
7875
"brh": {},
79-
"brx": {"nativeName": "बर’"},
76+
"brx": {"nativeName": "बड़ो"},
8077
"bs": {"nativeName": "bosanski"},
8178
"bs-Cyrl": {"base": "bs", "script": "Cyrl"},
8279
"bs-Latn": {"base": "bs", "script": "Latn"},
@@ -107,25 +104,16 @@
107104
"chy": {},
108105
"cic": {},
109106
"ckb": {"nativeName": "کوردیی ناوەندی"},
110-
"clc": {},
111107
"co": {},
112108
"cop": {},
113109
"cps": {},
114110
"cr": {},
115-
"crg": {},
116111
"crh": {},
117-
"crj": {},
118-
"crk": {},
119-
"crl": {},
120-
"crm": {},
121-
"crr": {},
122112
"crs": {},
123113
"cs": {"nativeName": "čeština"},
124114
"csb": {},
125-
"csw": {},
126115
"cu": {},
127116
"cv": {},
128-
"cwd": {},
129117
"cy": {"nativeName": "Cymraeg"},
130118
"da": {"nativeName": "dansk"},
131119
"dak": {},
@@ -217,24 +205,19 @@
217205
"hai": {},
218206
"hak": {},
219207
"haw": {"nativeName": "ʻŌlelo Hawaiʻi"},
220-
"hax": {},
221-
"hdn": {},
222208
"he": {"nativeName": "עברית"},
223209
"hi": {"nativeName": "हिन्दी"},
224-
"hi-Latn": {"base": "en", "script": "Latn"},
225210
"hif": {},
226211
"hil": {},
227212
"hit": {},
228213
"hmn": {},
229-
"hnj": {},
230214
"ho": {},
231215
"hr": {"nativeName": "hrvatski"},
232216
"hsb": {"nativeName": "hornjoserbšćina"},
233217
"hsn": {},
234218
"ht": {},
235219
"hu": {"nativeName": "magyar"},
236220
"hup": {},
237-
"hur": {},
238221
"hy": {"nativeName": "հայերեն"},
239222
"hz": {},
240223
"ia": {"nativeName": "interlingua"},
@@ -245,8 +228,6 @@
245228
"ig": {"nativeName": "Igbo"},
246229
"ii": {"nativeName": "ꆈꌠꉙ"},
247230
"ik": {},
248-
"ike": {},
249-
"ikt": {},
250231
"ilo": {},
251232
"inh": {},
252233
"io": {},
@@ -280,7 +261,7 @@
280261
"ken": {},
281262
"kfo": {},
282263
"kg": {},
283-
"kgp": {"nativeName": "kanhgág"},
264+
"kgp": {},
284265
"kha": {},
285266
"kho": {},
286267
"khq": {"nativeName": "Koyra ciini"},
@@ -309,7 +290,6 @@
309290
"kru": {},
310291
"ks": {"nativeName": "کٲشُر"},
311292
"ks-Arab": {"base": "ks", "script": "Arab"},
312-
"ks-Deva": {"base": "ks", "script": "Deva"},
313293
"ksb": {"nativeName": "Kishambaa"},
314294
"ksf": {"nativeName": "rikpa"},
315295
"ksh": {"nativeName": "Kölsch"},
@@ -318,7 +298,6 @@
318298
"kut": {},
319299
"kv": {},
320300
"kw": {"nativeName": "kernewek"},
321-
"kwk": {},
322301
"ky": {"nativeName": "кыргызча"},
323302
"la": {},
324303
"lad": {},
@@ -331,7 +310,6 @@
331310
"lg": {"nativeName": "Luganda"},
332311
"li": {},
333312
"lij": {},
334-
"lil": {},
335313
"liv": {},
336314
"lkt": {"nativeName": "Lakȟólʼiyapi"},
337315
"lmo": {},
@@ -380,7 +358,6 @@
380358
"mnc": {},
381359
"mni": {"nativeName": "মৈতৈলোন্"},
382360
"mni-Beng": {"base": "mni", "script": "Beng"},
383-
"moe": {},
384361
"moh": {},
385362
"mos": {},
386363
"mr": {"nativeName": "मराठी"},
@@ -430,12 +407,6 @@
430407
"nzi": {},
431408
"oc": {"nativeName": "Occitan"},
432409
"oj": {},
433-
"ojb": {},
434-
"ojc": {},
435-
"ojg": {},
436-
"ojs": {},
437-
"ojw": {},
438-
"oka": {},
439410
"om": {"nativeName": "Oromoo"},
440411
"or": {"nativeName": "ଓଡ଼ିଆ"},
441412
"os": {"nativeName": "ирон"},
@@ -461,7 +432,6 @@
461432
"pms": {},
462433
"pnt": {},
463434
"pon": {},
464-
"pqm": {},
465435
"prg": {},
466436
"pro": {},
467437
"ps": {"nativeName": "پښتو"},
@@ -473,13 +443,13 @@
473443
"rap": {},
474444
"rar": {},
475445
"rgn": {},
476-
"rhg": {},
477446
"rif": {},
478447
"rm": {"nativeName": "rumantsch"},
479448
"rn": {"nativeName": "Ikirundi"},
480449
"ro": {"nativeName": "română"},
481450
"rof": {"nativeName": "Kihorombo"},
482451
"rom": {},
452+
"root": {},
483453
"rtm": {},
484454
"ru": {"nativeName": "русский"},
485455
"rue": {},
@@ -498,7 +468,7 @@
498468
"saz": {},
499469
"sba": {},
500470
"sbp": {"nativeName": "Ishisangu"},
501-
"sc": {"nativeName": "sardu"},
471+
"sc": {},
502472
"scn": {},
503473
"sco": {},
504474
"sd": {"nativeName": "سنڌي"},
@@ -525,7 +495,6 @@
525495
"sid": {},
526496
"sk": {"nativeName": "slovenčina"},
527497
"sl": {"nativeName": "slovenščina"},
528-
"slh": {},
529498
"sli": {},
530499
"sly": {},
531500
"sm": {},
@@ -547,7 +516,6 @@
547516
"ssy": {},
548517
"st": {},
549518
"stq": {},
550-
"str": {},
551519
"su": {"nativeName": "Basa Sunda"},
552520
"su-Latn": {"base": "su", "script": "Latn"},
553521
"suk": {},
@@ -560,18 +528,15 @@
560528
"syr": {},
561529
"szl": {},
562530
"ta": {"nativeName": "தமிழ்"},
563-
"tce": {},
564531
"tcy": {},
565532
"te": {"nativeName": "తెలుగు"},
566533
"tem": {},
567534
"teo": {"nativeName": "Kiteso"},
568535
"ter": {},
569536
"tet": {},
570537
"tg": {"nativeName": "тоҷикӣ"},
571-
"tgx": {},
572538
"th": {"nativeName": "ไทย"},
573-
"tht": {},
574-
"ti": {"nativeName": "ትግርኛ"},
539+
"ti": {"nativeName": "ትግር"},
575540
"tig": {},
576541
"tiv": {},
577542
"tk": {"nativeName": "türkmen dili"},
@@ -589,12 +554,10 @@
589554
"tr": {"nativeName": "Türkçe"},
590555
"tru": {},
591556
"trv": {},
592-
"trw": {},
593557
"ts": {},
594558
"tsd": {},
595559
"tsi": {},
596560
"tt": {"nativeName": "татар"},
597-
"ttm": {},
598561
"ttt": {},
599562
"tum": {},
600563
"tvl": {},
@@ -608,7 +571,6 @@
608571
"uga": {},
609572
"uk": {"nativeName": "українська"},
610573
"umb": {},
611-
"und": {"nativeName": "und"},
612574
"ur": {"nativeName": "اردو"},
613575
"uz": {"nativeName": "o‘zbek"},
614576
"uz-Arab": {"base": "uz", "script": "Arab"},
@@ -645,7 +607,7 @@
645607
"ybb": {},
646608
"yi": {"nativeName": "ייִדיש"},
647609
"yo": {"nativeName": "Èdè Yorùbá"},
648-
"yrl": {"nativeName": "nheẽgatu"},
610+
"yrl": {},
649611
"yue": {"nativeName": "粵語"},
650612
"yue-Hans": {"base": "yue", "script": "Hans"},
651613
"yue-Hant": {"base": "yue", "script": "Hant"},

karma.conf.cjs

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = function (config) {
66
// base path that will be used to resolve all patterns (eg. files, exclude)
77
basePath: '',
88

9-
plugins: ['karma-coverage', 'karma-mocha', 'karma-chrome-launcher'],
9+
plugins: ['karma-coverage', 'karma-mocha', 'karma-chrome-launcher', 'karma-json-fixtures-preprocessor'],
1010

1111
// frameworks to use
1212
// available frameworks: https://www.npmjs.com/search?q=keywords:karma-adapter
@@ -22,8 +22,10 @@ module.exports = function (config) {
2222
{ pattern: 'dist/iD.js', included: true },
2323
{ pattern: 'dist/iD.css', included: true },
2424
{ pattern: 'dist/**/*', included: false },
25+
{ pattern: 'test/spec/renderer/*.json', included: true, served: true},
2526
'test/spec/spec_helpers.js',
26-
'test/spec/**/*.js',
27+
// 'test/spec/**/*.js',
28+
'test/spec/renderer/*.js',
2729
],
2830

2931
// list of files / patterns to exclude
@@ -42,7 +44,8 @@ module.exports = function (config) {
4244
// preprocess matching files before serving them to the browser
4345
// available preprocessors: https://www.npmjs.com/search?q=keywords:karma-preprocessor
4446
preprocessors: {
45-
'dist/iD.js': ['coverage']
47+
'dist/iD.js': ['coverage'],
48+
'test/spec/renderer/*.json': ['json_fixtures']
4649
},
4750

4851
// test results reporter to use

modules/pixi/PixiLayerOsm.js

+36
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import geojsonRewind from '@mapbox/geojson-rewind';
33

44
import { services } from '../services';
55
import { presetManager } from '../presets';
6+
import { JXON } from '../util/jxon';
67

78
import { PixiLayer } from './PixiLayer';
89
import { PixiFeatureLine } from './PixiFeatureLine';
@@ -35,6 +36,9 @@ export class PixiLayerOsm extends PixiLayer {
3536
this._service = null;
3637
this.getService();
3738

39+
this._alreadyDownloaded = false;
40+
this._saveCannedData = false;
41+
3842
// Setup Scene
3943
//
4044
// A few definitions:
@@ -90,6 +94,24 @@ export class PixiLayerOsm extends PixiLayer {
9094
return this._service;
9195
}
9296

97+
downloadFile(data, fileName) {
98+
let a = document.createElement('a'); // Create an invisible A element
99+
a.style.display = 'none';
100+
document.body.appendChild(a);
101+
102+
// Set the HREF to a Blob representation of the data to be downloaded
103+
a.href = window.URL.createObjectURL(new Blob([data]));
104+
105+
// Use download attribute to set set desired file name
106+
a.setAttribute('download', fileName);
107+
108+
// Trigger the download by simulating click
109+
a.click();
110+
111+
// Cleanup
112+
window.URL.revokeObjectURL(a.href);
113+
document.body.removeChild(a);
114+
}
93115

94116
/**
95117
* render
@@ -128,6 +150,20 @@ export class PixiLayerOsm extends PixiLayer {
128150
}
129151
});
130152

153+
154+
//Instructions to save 'canned' entity data for use in the renderer test suite:
155+
//Set a breakpoint at the next line, then modify `this._saveCannedData` to be 'true'
156+
//continuing will fire off the download of the data into a file called 'canned_data.json'.
157+
//move the data into the test/spec/renderer directory.
158+
if (this._saveCannedData && !this._alreadyDownloaded) {
159+
let viewData = { 'zoom': zoom, 'projection': projection, 'data': data , 'entities': context.graph().base().entities};
160+
let cannedData = JSON.stringify(viewData);
161+
this.downloadFile(cannedData,'canned_osm_data.json');
162+
163+
this._alreadyDownloaded = true;
164+
}
165+
166+
131167
// // Gather all child nodes of visible lines
132168
// data.lines.forEach(line => {
133169
// graph.childNodes(line).forEach(node => data.vertices.add(node));

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"esbuild": "^0.14.38",
5858
"fast-deep-equal": "~3.1.1",
5959
"fast-json-stable-stringify": "2.1.0",
60+
"karma-json-fixtures-preprocessor": "^0.0.6",
6061
"lodash-es": "~4.17.15",
6162
"marked": "~4.0.15",
6263
"node-diff3": "~3.1.0",
@@ -126,4 +127,4 @@
126127
"browserslist": [
127128
"> 0.2%, last 3 major versions, Firefox ESR, maintained node versions"
128129
]
129-
}
130+
}

0 commit comments

Comments
 (0)