Adding zoom-level logic

This commit is contained in:
Tom MacWright 2011-01-19 18:01:41 -05:00
parent 98de9014d5
commit bde844e349

View File

@ -1,7 +1,7 @@
(function(tree) {
tree.Filter = function(key, op, val, index) {
var max_zoom = 22; // maximum number of zoom levels
this.max_zoom = 22; // maximum number of zoom levels
this.key = key;
this.op = op;
this.val = val;
@ -9,13 +9,19 @@ tree.Filter = function(key, op, val, index) {
if (this.key === 'zoom') {
var val = parseInt(this.val, 10);
this.zoom_range = [];
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
for (var i = 0; i < this.max_zoom; i++) {
this.zoom_range[i] = (i <= val);
}
} else {
// TODO: non-correct ops will fail here
if (this.op.value === '<') val--;
this.zoom_range = [0, val]
for (var i = 0; i < this.max_zoom; i++) {
this.zoom_range[i] = (i >= val);
}
}
}
@ -47,10 +53,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])
];
for (var i = 0; i < this.max_zoom; i++) {
this.zoom_range[i] = this.zoom_range[i] && filter.zoom_range[i];
}
}
}
tree.Filter.prototype.inverse = function() {
for (var i = 0; i < this.max_zoom; i++) {
this.zoom_range[i] = !this.zoom_range[i];
}
}
@ -60,7 +71,7 @@ tree.Filter.prototype.toCSS = function(env) {
throw {
message: 'Only zoom levels between 0 and 22 supported.',
index: this.index
};
}
}
if (this.op.toCSS() == '&gt;') {
return '<MaxScaleDenominator>' + this.zooms[this.val][0] +