2015-03-05 00:26:05 +08:00
|
|
|
var Canvas = require('canvas');
|
|
|
|
var request = require('request');
|
|
|
|
var _ = require('underscore');
|
|
|
|
var fs = require('fs');
|
|
|
|
|
|
|
|
var torque = require('../../lib/torque/index');
|
|
|
|
|
|
|
|
|
|
|
|
function getTile(jsonRelPath, cartocss, z, x, y, step, callback) {
|
|
|
|
step = step || 0;
|
|
|
|
|
|
|
|
var cartoCssOptions = torque.common.TorqueLayer.optionsFromCartoCSS(cartocss);
|
|
|
|
|
|
|
|
var provider = new torque.providers.windshaft(_.extend({ no_fetch_map: true }, cartoCssOptions));
|
|
|
|
var rendererOptions = _.extend({cartocss: cartocss}, cartoCssOptions, {
|
|
|
|
canvasClass: Canvas,
|
|
|
|
imageClass: Canvas.Image,
|
|
|
|
setImageSrc: function(img, url, callback) {
|
|
|
|
var requestOpts = {
|
|
|
|
url: url,
|
|
|
|
method: 'GET',
|
|
|
|
encoding: null
|
|
|
|
};
|
|
|
|
request(requestOpts, function (err, response, body) {
|
|
|
|
if (!err && response.statusCode === 200) {
|
|
|
|
img.onload = function() {
|
|
|
|
callback(null);
|
|
|
|
};
|
|
|
|
img.onerror = function() {
|
|
|
|
callback(new Error('Could not load marker-file image: ' + url));
|
|
|
|
};
|
|
|
|
img.src = body;
|
|
|
|
} else {
|
|
|
|
callback(new Error('Could not load marker-file image: ' + url));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
qualifyURL: function(url) {
|
|
|
|
return url;
|
2017-11-15 23:36:36 +08:00
|
|
|
},
|
|
|
|
layer: {
|
|
|
|
showLimitErros: false
|
2015-03-05 00:26:05 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var rows = JSON.parse(fs.readFileSync(__dirname + '/../fixtures/json/' + jsonRelPath));
|
|
|
|
|
|
|
|
var canvas = new Canvas(256, 256);
|
|
|
|
var pointRenderer = new torque.renderer.Point(canvas, rendererOptions);
|
|
|
|
|
|
|
|
pointRenderer.renderTile(provider.proccessTile(rows, {x: x, y: y}, z), step, function(err) {
|
|
|
|
if (err) {
|
|
|
|
return callback(err, null);
|
|
|
|
}
|
|
|
|
pointRenderer.applyFilters();
|
|
|
|
return callback(null, canvas);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getTile: getTile
|
|
|
|
};
|