Skip to content

Commit

Permalink
Fix some issues setting max and min intensity.
Browse files Browse the repository at this point in the history
Precalculating position must always be done, too.
  • Loading branch information
manthey authored and aashish24 committed May 11, 2016
1 parent f2c6a68 commit f52faa5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
5 changes: 4 additions & 1 deletion src/canvas/heatmapFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,12 @@ var canvas_heatmapFeature = function (arg) {
for (var idx = data.length - 1; idx >= 0; idx -= 1) {
pos = map.worldToDisplay(position[idx]);
intensity = (intensityFunc(data[idx]) - minIntensity) / rangeIntensity;
if (intensity <= 0) {
continue;
}
// Small values are not visible because globalAlpha < .01
// cannot be read from imageData
context2d.globalAlpha = intensity < 0.01 ? 0.01 : intensity;
context2d.globalAlpha = intensity < 0.01 ? 0.01 : (intensity > 1 ? 1 : intensity);
context2d.drawImage(m_this._circle, pos.x - radius, pos.y - radius);
}
canvas = layer.canvas()[0];
Expand Down
40 changes: 24 additions & 16 deletions src/heatmapFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ var heatmapFeature = function (arg) {

m_position = arg.position || function (d) { return d; };
m_intensity = arg.intensity || function (d) { return 1; };
m_maxIntensity = arg.maxIntensity || null;
m_minIntensity = arg.minIntensity ? arg.minIntensity : null;
m_maxIntensity = arg.maxIntensity !== undefined ? arg.maxIntensity : null;
m_minIntensity = arg.minIntensity !== undefined ? arg.minIntensity : null;
m_updateDelay = arg.updateDelay ? parseInt(arg.updateDelay, 10) : 1000;

////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -206,23 +206,31 @@ var heatmapFeature = function (arg) {
this._build = function () {
var data = m_this.data(),
intensity = null,
position = [];
position = [],
setMax = (m_maxIntensity === null || m_maxIntensity === undefined),
setMin = (m_minIntensity === null || m_minIntensity === undefined);

if (!m_maxIntensity || !m_minIntensity) {
data.forEach(function (d) {
position.push(m_this.position()(d));
data.forEach(function (d) {
position.push(m_this.position()(d));
if (setMax || setMin) {
intensity = m_this.intensity()(d);
if (!m_maxIntensity && !m_minIntensity) {
m_maxIntensity = m_minIntensity = intensity;
} else {
if (intensity > m_maxIntensity) {
m_maxIntensity = intensity;
}
if (intensity < m_minIntensity) {
m_minIntensity = intensity;
}
if (m_maxIntensity === null || m_maxIntensity === undefined) {
m_maxIntensity = intensity;
}
});
if (m_minIntensity === null || m_minIntensity === undefined) {
m_minIntensity = intensity;
}
if (setMax && intensity > m_maxIntensity) {
m_maxIntensity = intensity;
}
if (setMin && intensity < m_minIntensity) {
m_minIntensity = intensity;
}

}
});
if (setMin && setMax && m_minIntensity === m_maxIntensity) {
m_minIntensity -= 1;
}
m_gcsPosition = transform.transformCoordinates(
m_this.gcs(), m_this.layer().map().gcs(), position);
Expand Down

0 comments on commit f52faa5

Please sign in to comment.