From 58bb7eb6e06f6f569b4d311b203ce2a01a14e55c Mon Sep 17 00:00:00 2001 From: liyujian Date: Thu, 28 Jun 2018 10:36:58 +0800 Subject: [PATCH 1/2] update canvas draw function,fix canvas element style offsite 0.5 bug --- src/map/baidu-map/CanvasLayer.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/map/baidu-map/CanvasLayer.js b/src/map/baidu-map/CanvasLayer.js index 4ebb4aa3..944fede2 100644 --- a/src/map/baidu-map/CanvasLayer.js +++ b/src/map/baidu-map/CanvasLayer.js @@ -68,15 +68,10 @@ if (global.BMap) { CanvasLayer.prototype._draw = function() { var map = this._map; - var size = map.getSize(); - var center = map.getCenter(); - if (center) { - var pixel = map.pointToOverlayPixel(center); - this.canvas.style.left = pixel.x - size.width / 2 + 'px'; - this.canvas.style.top = pixel.y - size.height / 2 + 'px'; - this.dispatchEvent('draw'); - this.options.update && this.options.update.call(this); - } + this.canvas.style.left = - map.offsetX + 'px'; + this.canvas.style.top = - map.offsetY + 'px'; + this.dispatchEvent('draw'); + this.options.update && this.options.update.apply(this, arguments); } CanvasLayer.prototype.getContainer = function() { From 872afe28f46bd91e60c9af76935744e92ebcde76 Mon Sep 17 00:00:00 2001 From: liyujian Date: Fri, 30 Nov 2018 18:34:23 +0800 Subject: [PATCH 2/2] add throttle for mousemove event --- src/map/baidu-map/Layer.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/map/baidu-map/Layer.js b/src/map/baidu-map/Layer.js index e453049f..9f5e8830 100644 --- a/src/map/baidu-map/Layer.js +++ b/src/map/baidu-map/Layer.js @@ -43,6 +43,13 @@ class Layer extends BaseLayer{ }); } + + throttle(fun, ctx, pixel, e) { + clearTimeout(fun.tId) + fun.tId = setTimeout(function(){ + fun.call(ctx, pixel, e); + }, 300); + } clickEvent(e) { var pixel = e.pixel; @@ -51,7 +58,8 @@ class Layer extends BaseLayer{ mousemoveEvent(e) { var pixel = e.pixel; - super.mousemoveEvent(pixel, e); + this.throttle(super.mousemoveEvent, this, pixel, e); + // super.mousemoveEvent(pixel, e); } bindEvent(e) {