|
|
|
@ -12,9 +12,8 @@ carto.Renderer = function Renderer(env, options) {
|
|
|
|
|
* XML Style fragment (mostly useful for debugging)
|
|
|
|
|
*
|
|
|
|
|
* @param {String} data the mss contents as a string.
|
|
|
|
|
* @param {Object} callback renderer environment options.
|
|
|
|
|
*/
|
|
|
|
|
carto.Renderer.prototype.renderMSS = function render(data, callback) {
|
|
|
|
|
carto.Renderer.prototype.renderMSS = function render(data) {
|
|
|
|
|
// effects is a container for side-effects, which currently
|
|
|
|
|
// are limited to FontSets.
|
|
|
|
|
var env = _(this.env).defaults({
|
|
|
|
@ -24,7 +23,7 @@ carto.Renderer.prototype.renderMSS = function render(data, callback) {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!carto.tree.Reference.setVersion(this.options.mapnik_version)) {
|
|
|
|
|
return callback(new Error("Could not set mapnik version to " + this.options.mapnik_version), null);
|
|
|
|
|
throw new Error("Could not set mapnik version to " + this.options.mapnik_version);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var output = [];
|
|
|
|
@ -58,8 +57,8 @@ carto.Renderer.prototype.renderMSS = function render(data, callback) {
|
|
|
|
|
if (env.benchmark) console.timeEnd(bench_name);
|
|
|
|
|
}
|
|
|
|
|
if (env.benchmark) console.timeEnd('Total Style generation');
|
|
|
|
|
if (env.errors) return callback(env.errors);
|
|
|
|
|
return callback(null, output.join('\n'));
|
|
|
|
|
if (env.errors) throw env.errors;
|
|
|
|
|
return output.join('\n');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -67,9 +66,8 @@ carto.Renderer.prototype.renderMSS = function render(data, callback) {
|
|
|
|
|
* fully-localized XML file ready for Mapnik2 consumption
|
|
|
|
|
*
|
|
|
|
|
* @param {String} m - the JSON file as a string.
|
|
|
|
|
* @param {Object} callback - renderer environment options.
|
|
|
|
|
*/
|
|
|
|
|
carto.Renderer.prototype.render = function render(m, callback) {
|
|
|
|
|
carto.Renderer.prototype.render = function render(m) {
|
|
|
|
|
// effects is a container for side-effects, which currently
|
|
|
|
|
// are limited to FontSets.
|
|
|
|
|
var env = _(this.env).defaults({
|
|
|
|
@ -80,7 +78,7 @@ carto.Renderer.prototype.render = function render(m, callback) {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!carto.tree.Reference.setVersion(this.options.mapnik_version)) {
|
|
|
|
|
return callback(new Error("Could not set mapnik version to " + this.options.mapnik_version), null);
|
|
|
|
|
throw new Error("Could not set mapnik version to " + this.options.mapnik_version);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var output = [];
|
|
|
|
@ -89,13 +87,12 @@ carto.Renderer.prototype.render = function render(m, callback) {
|
|
|
|
|
var definitions = _(m.Stylesheet).chain()
|
|
|
|
|
.map(function(s) {
|
|
|
|
|
if (typeof s == 'string') {
|
|
|
|
|
callback(new Error("Stylesheet object is expected not a string: '" + s + "'"));
|
|
|
|
|
throw new Error("Stylesheet object is expected not a string: '" + s + "'");
|
|
|
|
|
}
|
|
|
|
|
// Passing the environment from stylesheet to stylesheet,
|
|
|
|
|
// allows frames and effects to be maintained.
|
|
|
|
|
env = _(env).extend({filename:s.id});
|
|
|
|
|
|
|
|
|
|
// @TODO try/catch?
|
|
|
|
|
var time = +new Date(),
|
|
|
|
|
root = (carto.Parser(env)).parse(s.data);
|
|
|
|
|
if (env.benchmark)
|
|
|
|
@ -149,16 +146,10 @@ carto.Renderer.prototype.render = function render(m, callback) {
|
|
|
|
|
return e.toXML(env);
|
|
|
|
|
}).join('\n'));
|
|
|
|
|
|
|
|
|
|
var map_properties;
|
|
|
|
|
try {
|
|
|
|
|
map_properties = getMapProperties(m, definitions, env);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
env.error(err);
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
var map_properties = getMapProperties(m, definitions, env);
|
|
|
|
|
|
|
|
|
|
// Exit on errors.
|
|
|
|
|
if (env.errors) return callback(env.errors);
|
|
|
|
|
if (env.errors) throw env.errors;
|
|
|
|
|
|
|
|
|
|
// Pass TileJSON and other custom parameters through to Mapnik XML.
|
|
|
|
|
var parameters = _(m).reduce(function(memo, v, k) {
|
|
|
|
@ -222,7 +213,7 @@ carto.Renderer.prototype.render = function render(m, callback) {
|
|
|
|
|
'<!DOCTYPE Map[]>\n' +
|
|
|
|
|
'<Map' + properties +'>\n');
|
|
|
|
|
output.push('</Map>');
|
|
|
|
|
return callback(null, output.join('\n'));
|
|
|
|
|
return output.join('\n');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|