summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Makefile4
-rw-r--r--package.json1
-rw-r--r--src/node_map_render_worker.cpp8
-rw-r--r--test/fixtures/tiles.tilejson13
-rw-r--r--test/fixtures/tiles/0-0-0.vector.pbfbin0 -> 9660 bytes
-rw-r--r--test/map.test.js103
m---------vendor/mbgl6
8 files changed, 101 insertions, 35 deletions
diff --git a/.gitignore b/.gitignore
index b8de80b584..c27d12d2f2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
/build
/lib
/node_modules
+/test/results \ No newline at end of file
diff --git a/Makefile b/Makefile
index d26f9f032e..5d53a8b44d 100644
--- a/Makefile
+++ b/Makefile
@@ -11,6 +11,10 @@ HOST ?= osx
endif
HOST ?= linux
+# Explicitly disable the default FileSource implementation
+ASSET = none
+HTTP = none
+CACHE = none
include $(MBGL)/config/defaults.mk
diff --git a/package.json b/package.json
index c93a4cb8a0..e55d388041 100644
--- a/package.json
+++ b/package.json
@@ -3,6 +3,7 @@
"version": "0.0.1",
"main": "lib/mbgl.node",
"dependencies": {
+ "mkdirp": "^0.5.0",
"mocha": "^2.1.0",
"nan": "^1.4.1",
"request": "^2.51.0"
diff --git a/src/node_map_render_worker.cpp b/src/node_map_render_worker.cpp
index d11b5a0097..d117a6c9a2 100644
--- a/src/node_map_render_worker.cpp
+++ b/src/node_map_render_worker.cpp
@@ -16,7 +16,6 @@ NodeMap::RenderWorker::~RenderWorker() {
}
void NodeMap::RenderWorker::Execute() {
- fprintf(stderr, "executing render worker\n");
try {
nodeMap->view.resize(options->width, options->height, options->ratio);
nodeMap->map.setAccessToken(options->accessToken);
@@ -28,12 +27,11 @@ void NodeMap::RenderWorker::Execute() {
// Run the loop. It will terminate when we don't have any further listeners.
nodeMap->map.run();
- fprintf(stderr, "run completed\n");
const unsigned int width = options->width * options->ratio;
const unsigned int height = options->height * options->ratio;
- image = mbgl::util::compress_png(width, height, nodeMap->view.readPixels().get());
- fprintf(stderr, "png compressed\n");
- } catch (const std::exception &ex) {
+ auto pixels = nodeMap->view.readPixels();
+ image = mbgl::util::compress_png(width, height, pixels.get());
+ } catch (mbgl::exception &ex) {
SetErrorMessage(ex.what());
}
}
diff --git a/test/fixtures/tiles.tilejson b/test/fixtures/tiles.tilejson
new file mode 100644
index 0000000000..320c17500e
--- /dev/null
+++ b/test/fixtures/tiles.tilejson
@@ -0,0 +1,13 @@
+{
+ "bounds": [ -180, -85.0511, 180, 85.0511 ],
+ "center": [ 0, 0, 0 ],
+ "format": "pbf",
+ "id": "mapbox.mapbox-streets-v6-dev",
+ "maskLevel": 8,
+ "maxzoom": 15,
+ "minzoom": 0,
+ "name": "Mapbox Streets V6",
+ "scheme": "xyz",
+ "tilejson": "2.0.0",
+ "tiles": [ "./fixtures/tiles/{z}-{x}-{y}.vector.pbf" ]
+}
diff --git a/test/fixtures/tiles/0-0-0.vector.pbf b/test/fixtures/tiles/0-0-0.vector.pbf
new file mode 100644
index 0000000000..87628e06cf
--- /dev/null
+++ b/test/fixtures/tiles/0-0-0.vector.pbf
Binary files differ
diff --git a/test/map.test.js b/test/map.test.js
index e719e789e5..dff28b0031 100644
--- a/test/map.test.js
+++ b/test/map.test.js
@@ -4,6 +4,38 @@
var assert = require('assert');
var mbgl = require('..');
+var fs = require('fs');
+var path = require('path');
+var mkdirp = require('mkdirp');
+
+mkdirp.sync('test/results');
+
+var style = {
+ 'version': 7,
+ 'name': 'Empty',
+ 'sources': {
+ 'mapbox': {
+ 'type': 'vector',
+ 'url': './fixtures/tiles.tilejson',
+ 'maxzoom': 15
+ }
+ },
+ 'layers': [{
+ 'id': 'background',
+ 'type': 'background',
+ 'paint': {
+ 'background-color': 'white'
+ }
+ }, {
+ 'id': 'water',
+ 'type': 'fill',
+ 'source': 'mapbox',
+ 'source-layer': 'water',
+ 'paint': {
+ 'fill-color': 'blue'
+ }
+ }]
+};
describe('Map', function() {
@@ -29,30 +61,30 @@ describe('Map', function() {
});
it('should require the FileSource object to have request and cancel methods', function() {
- var fs = new mbgl.FileSource();
+ var fileSource = new mbgl.FileSource();
assert.throws(function() {
- new mbgl.Map(fs);
+ new mbgl.Map(fileSource);
}, /FileSource must have a request member function/);
- fs.request = 'test';
+ fileSource.request = 'test';
assert.throws(function() {
- new mbgl.Map(fs);
+ new mbgl.Map(fileSource);
}, /FileSource must have a request member function/);
- fs.request = function() {};
+ fileSource.request = function() {};
assert.throws(function() {
- new mbgl.Map(fs);
+ new mbgl.Map(fileSource);
}, /FileSource must have a cancel member function/);
- fs.cancel = 'test';
+ fileSource.cancel = 'test';
assert.throws(function() {
- new mbgl.Map(fs);
+ new mbgl.Map(fileSource);
}, /FileSource must have a cancel member function/);
- fs.cancel = function() {};
+ fileSource.cancel = function() {};
assert.doesNotThrow(function() {
- new mbgl.Map(fs);
+ new mbgl.Map(fileSource);
});
});
@@ -61,11 +93,12 @@ describe('Map', function() {
describe('load styles', function() {
var map;
+ var fileSource = new mbgl.FileSource();
+ fileSource.request = function() {};
+ fileSource.cancel = function() {};
+
beforeEach(function() {
- var fs = new mbgl.FileSource();
- fs.request = function() {};
- fs.cancel = function() {};
- map = new mbgl.Map(fs);
+ map = new mbgl.Map(fileSource);
});
afterEach(function() {
@@ -82,28 +115,40 @@ describe('Map', function() {
}, /Expect either an object or array at root/);
});
- it('accepts a stylesheet string', function() {
+ it('accepts an empty stylesheet string', function() {
map.load('{}');
});
- });
+ it('accepts a JSON stylesheet', function() {
+ map.load(style);
+ });
+ it('accepts a stringified stylesheet', function() {
+ map.load(JSON.stringify(style));
+ });
+ });
- describe('render arguments', function() {
+ describe('render argument requirements', function() {
var map;
+ var fileSource = new mbgl.FileSource();
+ fileSource.request = function(req) {
+ fs.readFile(path.join('test', req.url), function(err, data) {
+ req.respond(err, { data: data });
+ assert.ifError(err);
+ });
+ };
+ fileSource.cancel = function() {};
+
beforeEach(function() {
- var fs = new mbgl.FileSource();
- fs.request = function() {};
- fs.cancel = function() {};
- map = new mbgl.Map(fs);
+ map = new mbgl.Map(fileSource);
});
afterEach(function() {
map = null;
});
- it('requires a string or object as the first parameter', function() {
+ it('requires an object as the first parameter', function() {
assert.throws(function() {
map.render();
}, /First argument must be an options object/);
@@ -123,12 +168,22 @@ describe('Map', function() {
}, /Second argument must be a callback function/);
});
- it('requires a callback as the second parameter', function(done) {
+ it('requires a style to be set', function(done) {
map.render({}, function(err) {
- done(err);
+ assert.ok(err);
+ assert.equal(err.message, 'Style is not set');
+ done();
});
});
+ it('returns an image', function(done) {
+ map.load(style);
+ map.render({}, function(err, data) {
+ assert.ifError(err);
+ fs.writeFileSync('test/results/image.png', data);
+ done();
+ });
+ });
});
});
diff --git a/vendor/mbgl b/vendor/mbgl
-Subproject da981e78253ab2b8715f4e10e175be4bea43c13
+Subproject 8422b8b8a84d10f9c69c9295d1070eeb22d46db