11/* Copyright© 2000 - 2020 SuperMap Software Co.Ltd. All rights reserved.
22 * This program are made available under the terms of the Apache License, Version 2.0
33 * which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
4- import { baiduMapLayer } from 'mapv' ;
4+ import {
5+ baiduMapLayer
6+ } from 'mapv' ;
57import mapboxgl from 'mapbox-gl' ;
6- import { getMeterPerMapUnit } from '@supermap/iclient-common' ;
8+ import {
9+ getMeterPerMapUnit
10+ } from '@supermap/iclient-common' ;
711
812var BaseLayer = baiduMapLayer ? baiduMapLayer . __proto__ : Function ;
913
@@ -35,17 +39,7 @@ export class MapvRenderer extends BaseLayer {
3539 this . animation = options . animation ;
3640 this . clickEvent = this . clickEvent . bind ( this ) ;
3741 this . mousemoveEvent = this . mousemoveEvent . bind ( this ) ;
38- this . map . on ( 'resize' , this . resizeEvent . bind ( this ) ) ;
39- this . map . on ( 'zoomstart' , this . zoomStartEvent . bind ( this ) ) ;
40- this . map . on ( 'zoomend' , this . zoomEndEvent . bind ( this ) ) ;
41- this . map . on ( 'rotatestart' , this . rotateStartEvent . bind ( this ) ) ;
42- this . map . on ( 'rotate' , this . rotateEvent . bind ( this ) ) ;
43- this . map . on ( 'rotateend' , this . rotateEndEvent . bind ( this ) ) ;
44- // this.map.on('dragend', this.dragEndEvent.bind(this));
45- this . map . on ( 'movestart' , this . moveStartEvent . bind ( this ) ) ;
46- this . map . on ( 'move' , this . moveEvent . bind ( this ) ) ;
47- this . map . on ( 'moveend' , this . moveEndEvent . bind ( this ) ) ;
48- this . map . on ( 'remove' , this . removeEvent . bind ( this ) ) ;
42+ this . bindMapEvent ( ) ;
4943 this . bindEvent ( ) ;
5044 this . _expectShow = true ;
5145 }
@@ -92,7 +86,6 @@ export class MapvRenderer extends BaseLayer {
9286 */
9387 unbindEvent ( ) {
9488 var map = this . map ;
95-
9689 if ( this . options . methods ) {
9790 if ( this . options . methods . click ) {
9891 map . off ( 'click' , this . clickEvent ) ;
@@ -167,7 +160,7 @@ export class MapvRenderer extends BaseLayer {
167160 return ;
168161 }
169162 var newData = this . dataSet . get ( {
170- filter : function ( data ) {
163+ filter : function ( data ) {
171164 return filter != null && typeof filter === 'function' ? ! filter ( data ) : true ;
172165 }
173166 } ) ;
@@ -255,7 +248,7 @@ export class MapvRenderer extends BaseLayer {
255248 var center = map . getCenter ( ) ;
256249 var centerPx = map . project ( center ) ;
257250 var dataGetOptions = {
258- transferCoordinate : function ( coordinate ) {
251+ transferCoordinate : function ( coordinate ) {
259252 if ( map . transform . rotationMatrix || self . context === '2d' ) {
260253 var worldPoint = map . project ( new mapboxgl . LngLat ( coordinate [ 0 ] , coordinate [ 1 ] ) ) ;
261254 return [ worldPoint . x , worldPoint . y ] ;
@@ -266,7 +259,7 @@ export class MapvRenderer extends BaseLayer {
266259 } ;
267260
268261 if ( time !== undefined ) {
269- dataGetOptions . filter = function ( item ) {
262+ dataGetOptions . filter = function ( item ) {
270263 var trails = animationOptions . trails || 10 ;
271264 return time && item . time > time - trails && item . time < time ;
272265 } ;
@@ -297,6 +290,7 @@ export class MapvRenderer extends BaseLayer {
297290 this . drawContext ( context , data , self . options , worldPoint ) ;
298291
299292 self . options . updateCallback && self . options . updateCallback ( time ) ;
293+
300294 }
301295
302296 init ( options ) {
@@ -307,26 +301,72 @@ export class MapvRenderer extends BaseLayer {
307301 this . initDataRange ( options ) ;
308302
309303 this . context = self . options . context || '2d' ;
310-
311304 if ( self . options . zIndex ) {
312305 this . canvasLayer && this . canvasLayer . setZIndex ( self . options . zIndex ) ;
313306 }
314-
315307 this . initAnimator ( ) ;
316308 }
309+ /**
310+ * @function L.supermap.MapVRenderer.prototype.bindMapEvent
311+ * @description 绑定鼠标移动事件。
312+ */
313+ bindMapEvent ( ) {
314+ this . mapEvent = {
315+ resizeEvent : this . resizeEvent . bind ( this ) ,
316+ zoomStartEvent : this . zoomStartEvent . bind ( this ) ,
317+ zoomEndEvent : this . zoomEndEvent . bind ( this ) ,
318+ rotateStartEvent : this . rotateStartEvent . bind ( this ) ,
319+ rotateEvent : this . rotateEvent . bind ( this ) ,
320+ moveStartEvent : this . moveStartEvent . bind ( this ) ,
321+ rotateEndEvent : this . rotateEndEvent . bind ( this ) ,
322+ moveEvent : this . moveEvent . bind ( this ) ,
323+ moveEndEvent : this . moveEndEvent . bind ( this ) ,
324+ removeEvent : this . removeEvent . bind ( this )
325+ }
326+ this . map . on ( 'resize' , this . mapEvent . resizeEvent ) ;
327+ this . map . on ( 'zoomstart' , this . mapEvent . zoomStartEvent ) ;
328+ this . map . on ( 'zoomend' , this . mapEvent . zoomEndEvent ) ;
329+ this . map . on ( 'rotatestart' , this . mapEvent . rotateStartEvent ) ;
330+ this . map . on ( 'rotate' , this . mapEvent . rotateEvent ) ;
331+ this . map . on ( 'rotateend' , this . mapEvent . rotateEndEvent ) ;
332+ // this.map.on('dragend', this.dragEndEvent.bind(this));
333+ this . map . on ( 'movestart' , this . mapEvent . moveStartEvent ) ;
334+ this . map . on ( 'move' , this . mapEvent . moveEvent ) ;
335+ this . map . on ( 'moveend' , this . mapEvent . moveEndEvent ) ;
336+ this . map . on ( 'remove' , this . mapEvent . removeEvent ) ;
337+ }
338+
339+ /**
340+ * @function L.supermap.MapVRenderer.prototype.unbindMapEvent
341+ * @description 解绑鼠标移动事件。
342+ */
343+ unbindMapEvent ( ) {
344+ this . map . off ( 'resize' , this . mapEvent . resizeEvent ) ;
345+ this . map . off ( 'zoomstart' , this . mapEvent . zoomStartEvent ) ;
346+ this . map . off ( 'zoomend' , this . mapEvent . zoomEndEvent ) ;
347+ this . map . off ( 'rotatestart' , this . mapEvent . rotateStartEvent ) ;
348+ this . map . off ( 'rotate' , this . mapEvent . rotateEvent ) ;
349+ this . map . off ( 'rotateend' , this . mapEvent . rotateEndEvent ) ;
350+ this . map . off ( 'movestart' , this . mapEvent . moveStartEvent ) ;
351+ this . map . off ( 'move' , this . mapEvent . moveEvent ) ;
352+ this . map . off ( 'moveend' , this . mapEvent . moveEndEvent ) ;
353+ this . map . off ( 'remove' , this . mapEvent . removeEvent ) ;
354+ }
317355
318356 /**
319357 * @function L.supermap.MapVRenderer.prototype.destroy
320358 * @description 释放资源。
321359 */
322360 destroy ( ) {
361+ this . unbindMapEvent ( ) ;
323362 this . unbindEvent ( ) ;
324363 this . clearData ( ) ;
325364 this . animator && this . animator . stop ( ) ;
326365 this . animator = null ;
327366 this . canvasLayer = null ;
328367 }
329368
369+
330370 /**
331371 * @function MapvRenderer.prototype.addAnimatorEvent
332372 * @description 添加动画事件。
0 commit comments