From 0461901a86d82d6a46be6e5b7a2ed48b28faa564 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Wed, 26 Mar 2014 17:58:05 +0100 Subject: [PATCH] Add new 'weight' option to ol.layer.Heatmap --- src/objectliterals.jsdoc | 2 ++ src/ol/layer/heatmaplayer.js | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index 75fd408663..ccb0219162 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -595,6 +595,8 @@ * @property {number|undefined} radius Radius size in pixels. Default is `8`. * @property {number|undefined} blur Blur size in pixels. Default is `15`. * @property {number|undefined} shadow Shadow size in pixels. Default is `250`. + * @property {string|function(ol.Feature):number|undefined} weight The feature attribute to use for the + * weight or a function that returns a weight from a feature. Default is `weight`. * @property {number|undefined} minResolution The minimum resolution * (inclusive) at which this layer will be visible. * @property {number|undefined} maxResolution The maximum resolution diff --git a/src/ol/layer/heatmaplayer.js b/src/ol/layer/heatmaplayer.js index 01435527ed..8440b426a0 100644 --- a/src/ol/layer/heatmaplayer.js +++ b/src/ol/layer/heatmaplayer.js @@ -55,8 +55,19 @@ ol.layer.Heatmap = function(opt_options) { */ var styleCache = new Array(256); + var weight = goog.isDef(options.weight) ? options.weight : 'weight'; + var weightFunction; + if (goog.isString(weight)) { + weightFunction = function(feature) { + return feature.get(weight); + }; + } else { + weightFunction = weight; + } + goog.asserts.assert(goog.isFunction(weightFunction)); + this.setStyle(function(feature, resolution) { - var weight = feature.get('weight'); + var weight = weightFunction(feature); var opacity = goog.isDef(weight) ? weight : 1; // cast to 8 bits var index = (255 * opacity) | 0;