added getValues to fetch values for step. Also adds some signals needed to be able to use it and some fixes to the makefile
This commit is contained in:
parent
ff99d21c71
commit
ff269a5ecf
4
Makefile
4
Makefile
@ -35,7 +35,7 @@ add-header:
|
||||
node lib/header.js
|
||||
|
||||
prepare-test-suite:
|
||||
browserify test/suite.js > test/suite-bundle.js
|
||||
$(BROWSERIFY) test/suite.js > test/suite-bundle.js
|
||||
|
||||
test: prepare-test-suite
|
||||
@echo "***tests***"
|
||||
@ -43,7 +43,7 @@ test: prepare-test-suite
|
||||
|
||||
test-acceptance: clean-results
|
||||
@echo "***acceptance***"
|
||||
./node_modules/.bin/qunit -c lib/torque/ -t `find test/acceptance/ -name *.js`
|
||||
./node_modules/.bin/qunit -c lib/torque/ -t `find test/acceptance/ -name "*.js"`
|
||||
|
||||
test-all: test test-acceptance
|
||||
|
||||
|
@ -175,6 +175,7 @@ GMapsTorqueLayer.prototype = torque.extend({},
|
||||
// don't load tiles that are not being shown
|
||||
if (t.zoom !== self.options.map.getZoom()) return;
|
||||
self._tileLoaded(t, tileData);
|
||||
self.fire('tileLoaded');
|
||||
if (tileData) {
|
||||
self.redraw();
|
||||
}
|
||||
@ -316,6 +317,20 @@ GMapsTorqueLayer.prototype = torque.extend({},
|
||||
google.maps.event.removeListener(this._cacheListener);
|
||||
},
|
||||
|
||||
/**
|
||||
* return an array with the values for all the pixels active for the step
|
||||
*/
|
||||
getValues: function(step) {
|
||||
var values = [];
|
||||
step = step === undefined ? this.key: step;
|
||||
var t, tile, pos, value = null, xx, yy;
|
||||
for(t in this._tiles) {
|
||||
tile = this._tiles[t];
|
||||
this.renderer.getValues(tile, step, values);
|
||||
}
|
||||
return values;
|
||||
},
|
||||
|
||||
getValueForPos: function(x, y, step) {
|
||||
step = step === undefined ? this.key: step;
|
||||
var t, tile, pos, value = null, xx, yy;
|
||||
|
@ -94,6 +94,7 @@ L.TorqueLayer = L.CanvasLayer.extend({
|
||||
if (tileData) {
|
||||
self.redraw();
|
||||
}
|
||||
self.fire('tileLoaded');
|
||||
});
|
||||
}, this);
|
||||
|
||||
@ -369,6 +370,20 @@ L.TorqueLayer = L.CanvasLayer.extend({
|
||||
return positions;
|
||||
},
|
||||
|
||||
/**
|
||||
* return an array with the values for all the pixels active for the step
|
||||
*/
|
||||
getValues: function(step) {
|
||||
var values = [];
|
||||
step = step === undefined ? this.key: step;
|
||||
var t, tile, pos, value = null, xx, yy;
|
||||
for(t in this._tiles) {
|
||||
tile = this._tiles[t];
|
||||
this.renderer.getValues(tile, step, values);
|
||||
}
|
||||
return values;
|
||||
},
|
||||
|
||||
/**
|
||||
* return the value for position relative to map coordinates. null for no value
|
||||
*/
|
||||
|
@ -313,6 +313,28 @@ var Filters = require('./torque_filters');
|
||||
return positions;
|
||||
},
|
||||
|
||||
/**
|
||||
* returns an array with all the values for the active pixels
|
||||
* @tile tile object
|
||||
* @step integer with the step
|
||||
* @values (optional) an array where the values will be placed
|
||||
*/
|
||||
getValues: function(tile, step, values) {
|
||||
values = values || [];
|
||||
var res = this.options.resolution;
|
||||
var res2 = res >> 1;
|
||||
|
||||
var tileMax = this.options.resolution * (this.TILE_SIZE/this.options.resolution - 1);
|
||||
//this.renderer.renderTile(tile, this.key, pos.x, pos.y);
|
||||
var activePixels = tile.timeCount[step];
|
||||
var pixelIndex = tile.timeIndex[step];
|
||||
for(var p = 0; p < activePixels; ++p) {
|
||||
var posIdx = tile.renderDataPos[pixelIndex + p];
|
||||
values.push(tile.renderData[pixelIndex + p]);
|
||||
}
|
||||
return values;
|
||||
},
|
||||
|
||||
// return the value for x, y (tile coordinates)
|
||||
// null for no value
|
||||
getValueFor: function(tile, step, px, py) {
|
||||
|
@ -115,3 +115,22 @@ test('get value for position', function() {
|
||||
v = renderer.getValueFor(tile, 0, 99, 255 - 3);
|
||||
equal(v, null);
|
||||
});
|
||||
|
||||
test('get values for tile', function() {
|
||||
var mercator = new torque.Mercator();
|
||||
tile = {
|
||||
timeCount: [2],
|
||||
timeIndex: [0],
|
||||
renderDataPos: [0, 0],
|
||||
renderData: [5, 7],
|
||||
x: [100],
|
||||
y: [3],
|
||||
coord: { x: 0, y: 0, z: 0 }
|
||||
};
|
||||
renderer.options = {
|
||||
resolution: 1
|
||||
};
|
||||
v = renderer.getValues(tile, 0);
|
||||
equal(v[0], 5);
|
||||
equal(v[1], 7);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user