diff --git a/examples/heatmap-earthquakes.html b/examples/heatmap-earthquakes.html index d6ec6f8899..79a5e2e59a 100644 --- a/examples/heatmap-earthquakes.html +++ b/examples/heatmap-earthquakes.html @@ -45,6 +45,8 @@
diff --git a/examples/heatmap-earthquakes.js b/examples/heatmap-earthquakes.js index 0e41408931..277ed7fbe3 100644 --- a/examples/heatmap-earthquakes.js +++ b/examples/heatmap-earthquakes.js @@ -5,6 +5,7 @@ goog.require('ol.layer.Tile'); goog.require('ol.source.KML'); goog.require('ol.source.Stamen'); +var blur = $('#blur'); var radius = $('#radius'); var vector = new ol.layer.Heatmap({ @@ -13,6 +14,7 @@ var vector = new ol.layer.Heatmap({ projection: 'EPSG:3857', url: 'data/kml/2012_Earthquakes_Mag5.kml' }), + blur: parseInt(blur.val(), 10), radius: parseInt(radius.val(), 10) }); @@ -41,6 +43,10 @@ var map = new ol.Map({ }); +blur.on('input', function() { + vector.setBlur(parseInt(blur.val(), 10)); +}); + radius.on('input', function() { vector.setRadius(parseInt(radius.val(), 10)); }); diff --git a/src/ol/layer/heatmaplayer.js b/src/ol/layer/heatmaplayer.js index dd65d7906b..641d4df85d 100644 --- a/src/ol/layer/heatmaplayer.js +++ b/src/ol/layer/heatmaplayer.js @@ -16,6 +16,7 @@ goog.require('ol.style.Style'); * @enum {string} */ ol.layer.HeatmapLayerProperty = { + BLUR: 'blur', GRADIENT: 'gradient', RADIUS: 'radius' }; @@ -53,12 +54,6 @@ ol.layer.Heatmap = function(opt_options) { */ this.gradient_ = null; - /** - * @private - * @type {number} - */ - this.blur_ = goog.isDef(options.blur) ? options.blur : 15; - /** * @private * @type {number} @@ -81,9 +76,12 @@ ol.layer.Heatmap = function(opt_options) { ol.Object.getChangeEventType(ol.layer.HeatmapLayerProperty.GRADIENT), this.handleGradientChanged_, false, this); - goog.events.listen(this, - ol.Object.getChangeEventType(ol.layer.HeatmapLayerProperty.RADIUS), - this.handleStyleChanged_, false, this); + goog.events.listen(this, [ + ol.Object.getChangeEventType(ol.layer.HeatmapLayerProperty.BLUR), + ol.Object.getChangeEventType(ol.layer.HeatmapLayerProperty.RADIUS) + ], this.handleStyleChanged_, false, this); + + this.setBlur(goog.isDef(options.blur) ? options.blur : 15); this.setGradient(goog.isDef(options.gradient) ? options.gradient : ol.layer.Heatmap.DEFAULT_GRADIENT); @@ -168,11 +166,12 @@ ol.layer.Heatmap.createGradient_ = function(colors) { */ ol.layer.Heatmap.prototype.createCircle_ = function() { var radius = this.getRadius(); - var halfSize = radius + this.blur_ + 1; + var blur = this.getBlur(); + var halfSize = radius + blur + 1; var size = 2 * halfSize; var context = ol.dom.createCanvasContext2D(size, size); context.shadowOffsetX = context.shadowOffsetY = this.shadow_; - context.shadowBlur = this.blur_; + context.shadowBlur = blur; context.shadowColor = '#000'; context.beginPath(); var center = halfSize - this.shadow_; @@ -182,6 +181,20 @@ ol.layer.Heatmap.prototype.createCircle_ = function() { }; +/** + * @return {number} Blur size in pixels. + * @api + * @observable + */ +ol.layer.Heatmap.prototype.getBlur = function() { + return /** @type {number} */ (this.get(ol.layer.HeatmapLayerProperty.BLUR)); +}; +goog.exportProperty( + ol.layer.Heatmap.prototype, + 'getBlur', + ol.layer.Heatmap.prototype.getBlur); + + /** * @return {Array.