diff --git a/lib/carto/tree/reference.js b/lib/carto/tree/reference.js index 29af19612..757cb5f89 100644 --- a/lib/carto/tree/reference.js +++ b/lib/carto/tree/reference.js @@ -43,34 +43,57 @@ ref.selectorData = function(selector, i) { }; ref.validSelector = function(selector) { return !!ref.selector_cache[selector]; }; -ref.selectorName = function(selector) { return ref.selectorData(selector, 2); }; -ref.selector = function(selector) { return ref.selectorData(selector, 0); }; -ref.symbolizer = function(selector) { return ref.selectorData(selector, 1); }; +ref.selectorName = function(selector) { return ref.selectorData(selector, 3); }; +ref.selector = function(selector) { return ref.selectorData(selector, 1); }; +ref.symbolizer = function(selector) { return ref.selectorData(selector, 2); }; function generateSelectorCache(data) { var index = {}; - for (var i in data.symbolizers) { - for (var j in data.symbolizers[i]) { - if (data.symbolizers[i][j].hasOwnProperty('css')) { - index[data.symbolizers[i][j].css] = [data.symbolizers[i][j], i, j]; - } + _.forEach(data.style, function (rule, i) { + if (_.has(rule, 'css')) { + index[rule.css] = ['style', rule, '*', i]; } - } + }); + _.forEach(data.layer, function (rule, i) { + if (_.has(rule, 'css')) { + index[rule.css] = ['layer', rule, '*', i]; + } + }); + _.forEach(data.symbolizers, function (symbolizer, i) { + _.forEach(symbolizer, function (rule, j) { + if (_.has(rule, 'css')) { + index[rule.css] = ['symbolizer', rule, i, j]; + } + }); + }); return index; } function generateMapnikFunctions(data) { var functions = {}; - for (var i in data.symbolizers) { - for (var j in data.symbolizers[i]) { - if (data.symbolizers[i][j].type === 'functions') { - for (var k = 0; k < data.symbolizers[i][j].functions.length; k++) { - var fn = data.symbolizers[i][j].functions[k]; - functions[fn[0]] = fn[1]; - } - } + _.forEach(data.style, function (rule) { + if (rule.type === 'functions') { + _.forEach(rule.functions, function (func) { + functions[func[0]] = func[1]; + }); } - } + }); + _.forEach(data.layer, function (rule) { + if (rule.type === 'functions') { + _.forEach(rule.functions, function (func) { + functions[func[0]] = func[1]; + }); + } + }); + _.forEach(data.symbolizers, function (symbolizer) { + _.forEach(symbolizer, function (rule) { + if (rule.type === 'functions') { + _.forEach(rule.functions, function (func) { + functions[func[0]] = func[1]; + }); + } + }); + }); return functions; }