Skip to content

Commit 1678640

Browse files
修复 mapvlayer 事件回调无效
1 parent 54f37ff commit 1678640

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

src/common/overlay/mapv/MapvRenderer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export class MapvRenderer extends BaseLayer {
3535
this.targetElement = targetElement;
3636
this.canvas = this._createCanvas(id, mapElement);
3737
this.canvasLayer = {
38-
canvas: this.canvas
38+
canvas: this.canvas,
39+
devicePixelRatio: this.devicePixelRatio
3940
}
4041
this.init(options);
4142
this.argCheck(options);

src/mapboxgl/overlay/MapvLayer.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ export class MapvLayer {
5555
transferCoordinate: this._transferCoordinate,
5656
getCenterPixel: this._getCenterPixel,
5757
getResolution: this._getResolution,
58-
validZoom: this._validZoom
58+
validZoom: this._validZoom.bind(this)
5959
}, { mapElement: this.map.getCanvas(), targetElement: this.mapContainer, id: this.id });
6060
this.mapContainer.style.perspective = this.map.transform.cameraToCenterDistance + 'px';
61+
this.bindEvent();
6162
}
6263

6364
/**
@@ -66,14 +67,15 @@ export class MapvLayer {
6667
*/
6768
onRemove() {
6869
this.renderer.destroy();
70+
this.unbindEvent();
6971
}
7072

7173
/**
7274
* @function MapvLayer.prototype.render
7375
* @description 渲染图层。
7476
*/
7577
render() {
76-
this.renderer.draw();
78+
this.renderer && this.renderer.draw();
7779
}
7880

7981
_transferCoordinate() {
@@ -98,10 +100,9 @@ export class MapvLayer {
98100
}
99101

100102
_validZoom() {
101-
var self = this;
102103
if (
103-
(self.options.minZoom && this.map.getZoom() < self.options.minZoom) ||
104-
(self.options.maxZoom && this.map.getZoom() > self.options.maxZoom)
104+
(this.mapVOptions.minZoom && this.map.getZoom() < this.mapVOptions.minZoom) ||
105+
(this.mapVOptions.maxZoom && this.map.getZoom() > this.mapVOptions.maxZoom)
105106
) {
106107
return false;
107108
}
@@ -218,12 +219,12 @@ export class MapvLayer {
218219
*/
219220
bindEvent() {
220221
var map = this.map;
221-
if (this.options.methods) {
222-
if (this.options.methods.click) {
223-
map.on('click', this.clickEvent);
222+
if (this.mapVOptions.methods) {
223+
if (this.mapVOptions.methods.click) {
224+
map.on('click', this.renderer.clickEvent);
224225
}
225-
if (this.options.methods.mousemove) {
226-
map.on('mousemove', this.mousemoveEvent);
226+
if (this.mapVOptions.methods.mousemove) {
227+
map.on('mousemove', this.renderer.mousemoveEvent);
227228
}
228229
}
229230
}
@@ -234,11 +235,11 @@ export class MapvLayer {
234235
*/
235236
unbindEvent() {
236237
var map = this.map;
237-
if (this.options.methods) {
238-
if (this.options.methods.click) {
238+
if (this.mapvOptions.methods) {
239+
if (this.mapvOptions.methods.click) {
239240
map.off('click', this.clickEvent);
240241
}
241-
if (this.options.methods.mousemove) {
242+
if (this.mapvOptions.methods.mousemove) {
242243
map.off('mousemove', this.mousemoveEvent);
243244
}
244245
}

src/maplibregl/overlay/MapvLayer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class MapvLayer {
4343
transferCoordinate: this._transferCoordinate,
4444
getCenterPixel: this._getCenterPixel,
4545
getResolution: this._getResolution,
46-
validZoom: this._validZoom
46+
validZoom: this._validZoom.bind(this)
4747
}, { id: this.id, targetElement: this.mapContainer, mapElement: this.map.getCanvas() });
4848
this._bindEvent();
4949
}

0 commit comments

Comments
 (0)