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:
javi 2015-10-02 17:29:53 +02:00
parent ff99d21c71
commit ff269a5ecf
5 changed files with 73 additions and 2 deletions

View File

@ -35,7 +35,7 @@ add-header:
node lib/header.js node lib/header.js
prepare-test-suite: prepare-test-suite:
browserify test/suite.js > test/suite-bundle.js $(BROWSERIFY) test/suite.js > test/suite-bundle.js
test: prepare-test-suite test: prepare-test-suite
@echo "***tests***" @echo "***tests***"
@ -43,7 +43,7 @@ test: prepare-test-suite
test-acceptance: clean-results test-acceptance: clean-results
@echo "***acceptance***" @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 test-all: test test-acceptance

View File

@ -175,6 +175,7 @@ GMapsTorqueLayer.prototype = torque.extend({},
// don't load tiles that are not being shown // don't load tiles that are not being shown
if (t.zoom !== self.options.map.getZoom()) return; if (t.zoom !== self.options.map.getZoom()) return;
self._tileLoaded(t, tileData); self._tileLoaded(t, tileData);
self.fire('tileLoaded');
if (tileData) { if (tileData) {
self.redraw(); self.redraw();
} }
@ -316,6 +317,20 @@ GMapsTorqueLayer.prototype = torque.extend({},
google.maps.event.removeListener(this._cacheListener); 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) { getValueForPos: function(x, y, step) {
step = step === undefined ? this.key: step; step = step === undefined ? this.key: step;
var t, tile, pos, value = null, xx, yy; var t, tile, pos, value = null, xx, yy;

View File

@ -94,6 +94,7 @@ L.TorqueLayer = L.CanvasLayer.extend({
if (tileData) { if (tileData) {
self.redraw(); self.redraw();
} }
self.fire('tileLoaded');
}); });
}, this); }, this);
@ -369,6 +370,20 @@ L.TorqueLayer = L.CanvasLayer.extend({
return positions; 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 * return the value for position relative to map coordinates. null for no value
*/ */

View File

@ -313,6 +313,28 @@ var Filters = require('./torque_filters');
return positions; 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) // return the value for x, y (tile coordinates)
// null for no value // null for no value
getValueFor: function(tile, step, px, py) { getValueFor: function(tile, step, px, py) {

View File

@ -115,3 +115,22 @@ test('get value for position', function() {
v = renderer.getValueFor(tile, 0, 99, 255 - 3); v = renderer.getValueFor(tile, 0, 99, 255 - 3);
equal(v, null); 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);
});