Zoom range formalizing.

This commit is contained in:
Tom MacWright 2011-01-19 17:37:47 -05:00
parent 3550af0838
commit af9194dbfb

View File

@ -1,10 +1,24 @@
(function(tree) { (function(tree) {
tree.Filter = function(key, op, val, index) { tree.Filter = function(key, op, val, index) {
var max_zoom = 22; // maximum number of zoom levels
this.key = key; this.key = key;
this.op = op; this.op = op;
this.val = val; this.val = val;
this.index = index; this.index = index;
if (this.key === 'zoom') {
var val = parseInt(this.val, 10);
if (this.op.value === '>' || this.op.value === '>=') {
if (this.op.value === '>') val++;
this.zoom_range = [val, max_zoom]
// TODO: non-correct ops will fail here
} else {
if (this.op.value === '<') val--;
this.zoom_range = [0, val]
}
}
this.zooms = { this.zooms = {
'1': [200000000, 500000000], '1': [200000000, 500000000],
'2': [100000000, 200000000], '2': [100000000, 200000000],
@ -31,6 +45,15 @@ tree.Filter = function(key, op, val, index) {
}; };
}; };
tree.Filter.prototype.union = function(filter) {
if (filter.zoom_range) {
return [
Math.max(this.zoom_range[0], filter.zoom_range[0]),
Math.min(this.zoom_range[1], filter.zoom_range[1])
];
}
}
tree.Filter.prototype.toCSS = function(env) { tree.Filter.prototype.toCSS = function(env) {
if (this.key === 'zoom') { if (this.key === 'zoom') {
if (parseInt(this.val) > 22 || parseInt(this.val) < 0) { if (parseInt(this.val) > 22 || parseInt(this.val) < 0) {
@ -55,8 +78,7 @@ tree.Filter.prototype.toCSS = function(env) {
return '<MinScaleDenominator>' + this.zooms[this.val][0] + return '<MinScaleDenominator>' + this.zooms[this.val][0] +
'</MinScaleDenominator>'; '</MinScaleDenominator>';
} }
} } else {
else {
if (this.val.is) { if (this.val.is) {
this.val = this.val.toCSS((this.val.is == 'string')); this.val = this.val.toCSS((this.val.is == 'string'));
} }