forked from mapnik/node-mapnik
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunicode-loading.test.js
More file actions
173 lines (156 loc) · 6.79 KB
/
unicode-loading.test.js
File metadata and controls
173 lines (156 loc) · 6.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
"use strict";
var mapnik = require('../');
var assert = require('assert');
var path = require('path');
var fs = require('fs');
var existsSync = require('fs').existsSync || require('path').existsSync;
var map_pre = '\n<Map>\n <Layer name="test">\n <Datasource>';
var map_param = '\n <Parameter name="{{{key}}}">{{{value}}}</Parameter>';
var map_post = '\n </Datasource>\n </Layer>\n</Map>';
mapnik.register_default_input_plugins();
var available_ds = mapnik.datasources();
describe('Handling unicode paths, filenames, and data', function(){
// beware: folder storage can get messed up
// https://github.com/mapnik/node-mapnik/issues/142
/*
// not a valid test due to https://github.com/mapbox/tilemill/issues/1870
it('register font file with unicode directory and name', function(){
var filepath = './test/data/dir-区县级行政区划/你好_DejaVuSansMono-BoldOblique.ttf';
assert.ok(existsSync(filepath));
mapnik.register_fonts(filepath);
assert.deepEqual(mapnik.fontFiles()['DejaVu Sans Mono Bold Oblique'],filepath);
});
*/
it('render a map with unicode markers', function(done){
if (available_ds.indexOf('csv') == -1) {
console.log('skipping due to lack of csv plugin');
return done();
}
var filepath = './test/data/ünicode_symbols.xml';
assert.ok(existsSync(filepath));
var svg = './test/data/dir-区县级行政区划/你好-ellipses.svg';
assert.ok(existsSync(svg));
var map = new mapnik.Map(256,256);
map.load(filepath,function(err,map) {
if (err) throw err;
var im = new mapnik.Image(256,256);
map.zoomAll();
map.render(im,function(err,im) {
assert.ok(im);
//im.save('test.png')
done();
});
});
});
it('open csv file with unicode name', function(done){
if (available_ds.indexOf('csv') == -1) {
console.log('skipping due to lack of csv plugin');
return done();
}
var filepath = './test/data/你好_points.csv';
assert.ok(existsSync(filepath));
var ds = new mapnik.Datasource({type:'csv',file:filepath});
assert.ok(ds);
done();
});
it('open csv file with unicode name in XML', function(done){
if (available_ds.indexOf('csv') == -1) {
console.log('skipping due to lack of csv plugin');
return done();
}
var filepath = './test/data/你好_points.csv';
assert.ok(existsSync(filepath));
var map_string = map_pre;
map_string += map_param.replace('{{{key}}}','type').replace('{{{value}}}','csv');
map_string += map_param.replace('{{{key}}}','file').replace('{{{value}}}',filepath);
map_string += map_post;
var map = new mapnik.Map(256,256);
map.fromStringSync(map_string,{base:path.dirname(__dirname)});
fs.writeFileSync('./test/tmp/mapnik-tmp-map-load.xml',map_string,'utf-8');
map.loadSync('./test/tmp/mapnik-tmp-map-load.xml',{base:path.dirname(__dirname)});
assert.ok(true);
done();
});
it('open csv file with abs path and unicode name in XML', function(done){
if (available_ds.indexOf('csv') == -1) {
console.log('skipping due to lack of csv plugin');
return done();
}
var filepath = path.join(path.dirname(__dirname),'test/data/avlee-区县级行政区划.csv');
assert.ok(existsSync(filepath));
var map_string = map_pre;
map_string += map_param.replace('{{{key}}}','type').replace('{{{value}}}','csv');
map_string += map_param.replace('{{{key}}}','file').replace('{{{value}}}',filepath);
map_string += map_post;
var map = new mapnik.Map(256,256);
map.fromStringSync(map_string,{base:path.dirname(__dirname)});
fs.writeFileSync('./test/tmp/mapnik-tmp-map-load.xml',map_string,'utf-8');
map.loadSync('./test/tmp/mapnik-tmp-map-load.xml',{base:path.dirname(__dirname)});
assert.ok(true);
done();
});
it('open csv file with unicode directory name in XML', function(done){
if (available_ds.indexOf('csv') == -1) {
console.log('skipping due to lack of csv plugin');
return done();
}
var filepath = './test/data/dir-区县级行政区划/points.csv';
assert.ok(existsSync(filepath));
var map_string = map_pre;
map_string += map_param.replace('{{{key}}}','type').replace('{{{value}}}','csv');
map_string += map_param.replace('{{{key}}}','file').replace('{{{value}}}',filepath);
map_string += map_post;
var map = new mapnik.Map(256,256);
map.fromStringSync(map_string,{base:path.dirname(__dirname)});
var xml_path = './test/tmp/mapnik-tmp-map-load'+'区县级行政区划' +'.xml';
fs.writeFileSync(xml_path,map_string,'utf-8');
assert.ok(existsSync(xml_path));
map.loadSync(xml_path,{base:path.dirname(__dirname)});
assert.ok(true);
done();
});
it('open shape file with unicode name', function(done){
if (available_ds.indexOf('shape') == -1) {
console.log('skipping due to lack of shape plugin');
return done();
}
var filepath = './test/data/你好_points.shp';
assert.ok(existsSync(filepath));
var ds = new mapnik.Datasource({type:'shape',file:filepath});
assert.ok(ds);
done();
});
it('open shape file with ogr and unicode name', function(done){
if (available_ds.indexOf('ogr') == -1) {
console.log('skipping due to lack of ogr plugin');
return done();
}
var filepath = './test/data/你好_points.shp';
assert.ok(existsSync(filepath));
var ds = new mapnik.Datasource({type:'ogr',file:filepath, layer_by_index:0});
assert.ok(ds);
done();
});
it('open json with unicode name', function(done){
if (available_ds.indexOf('geojson') == -1) {
console.log('skipping due to lack of geojson plugin');
return done();
}
var filepath = './test/data/你好_points.geojson';
assert.ok(existsSync(filepath));
var ds = new mapnik.Datasource({type:'geojson',file:filepath});
assert.ok(ds);
done();
});
it('open sqlite with unicode name', function(done){
if (available_ds.indexOf('sqlite') == -1) {
console.log('skipping due to lack of sqlite plugin');
return done();
}
var filepath = './test/data/你好_points.sqlite';
assert.ok(existsSync(filepath));
var ds = new mapnik.Datasource({type:'sqlite',file:filepath,use_spatial_index:false,table_by_index:0});
assert.ok(ds);
done();
});
});