Make ol.layer.Heatmap.createCircle_ an instance function
This commit is contained in:
@@ -52,6 +52,24 @@ ol.layer.Heatmap = function(opt_options) {
|
|||||||
*/
|
*/
|
||||||
this.gradient_ = null;
|
this.gradient_ = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
this.blur_ = goog.isDef(options.blur) ? options.blur : 15;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
this.radius_ = goog.isDef(options.radius) ? options.radius : 8;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
this.shadow_ = goog.isDef(options.shadow) ? options.shadow : 250;
|
||||||
|
|
||||||
goog.events.listen(this,
|
goog.events.listen(this,
|
||||||
ol.Object.getChangeEventType(ol.layer.HeatmapLayerProperty.GRADIENT),
|
ol.Object.getChangeEventType(ol.layer.HeatmapLayerProperty.GRADIENT),
|
||||||
this.handleGradientChanged_, false, this);
|
this.handleGradientChanged_, false, this);
|
||||||
@@ -59,10 +77,7 @@ ol.layer.Heatmap = function(opt_options) {
|
|||||||
this.setGradient(goog.isDef(options.gradient) ?
|
this.setGradient(goog.isDef(options.gradient) ?
|
||||||
options.gradient : ol.layer.Heatmap.DEFAULT_GRADIENT);
|
options.gradient : ol.layer.Heatmap.DEFAULT_GRADIENT);
|
||||||
|
|
||||||
var circle = ol.layer.Heatmap.createCircle_(
|
var circle = this.createCircle_();
|
||||||
goog.isDef(options.radius) ? options.radius : 8,
|
|
||||||
goog.isDef(options.blur) ? options.blur : 15,
|
|
||||||
goog.isDef(options.shadow) ? options.shadow : 250);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Array.<Array.<ol.style.Style>>}
|
* @type {Array.<Array.<ol.style.Style>>}
|
||||||
@@ -142,22 +157,19 @@ ol.layer.Heatmap.createGradient_ = function(colors) {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} radius Radius size in pixel.
|
|
||||||
* @param {number} blur Blur size in pixel.
|
|
||||||
* @param {number} shadow Shadow offset size in pixel.
|
|
||||||
* @return {string}
|
* @return {string}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.layer.Heatmap.createCircle_ = function(radius, blur, shadow) {
|
ol.layer.Heatmap.prototype.createCircle_ = function() {
|
||||||
var halfSize = radius + blur + 1;
|
var halfSize = this.radius_ + this.blur_ + 1;
|
||||||
var size = 2 * halfSize;
|
var size = 2 * halfSize;
|
||||||
var context = ol.dom.createCanvasContext2D(size, size);
|
var context = ol.dom.createCanvasContext2D(size, size);
|
||||||
context.shadowOffsetX = context.shadowOffsetY = shadow;
|
context.shadowOffsetX = context.shadowOffsetY = this.shadow_;
|
||||||
context.shadowBlur = blur;
|
context.shadowBlur = this.blur_;
|
||||||
context.shadowColor = '#000';
|
context.shadowColor = '#000';
|
||||||
context.beginPath();
|
context.beginPath();
|
||||||
var center = halfSize - shadow;
|
var center = halfSize - this.shadow_;
|
||||||
context.arc(center, center, radius, 0, Math.PI * 2, true);
|
context.arc(center, center, this.radius_, 0, Math.PI * 2, true);
|
||||||
context.fill();
|
context.fill();
|
||||||
return context.canvas.toDataURL();
|
return context.canvas.toDataURL();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user