1
1
/* Copyright© 2000 - 2020 SuperMap Software Co.Ltd. All rights reserved.
2
2
* This program are made available under the terms of the Apache License, Version 2.0
3
3
* 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' ;
5
7
import mapboxgl from 'mapbox-gl' ;
6
- import { getMeterPerMapUnit } from '@supermap/iclient-common' ;
8
+ import {
9
+ getMeterPerMapUnit
10
+ } from '@supermap/iclient-common' ;
7
11
8
12
var BaseLayer = baiduMapLayer ? baiduMapLayer . __proto__ : Function ;
9
13
@@ -35,17 +39,7 @@ export class MapvRenderer extends BaseLayer {
35
39
this . animation = options . animation ;
36
40
this . clickEvent = this . clickEvent . bind ( this ) ;
37
41
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 ( ) ;
49
43
this . bindEvent ( ) ;
50
44
this . _expectShow = true ;
51
45
}
@@ -92,7 +86,6 @@ export class MapvRenderer extends BaseLayer {
92
86
*/
93
87
unbindEvent ( ) {
94
88
var map = this . map ;
95
-
96
89
if ( this . options . methods ) {
97
90
if ( this . options . methods . click ) {
98
91
map . off ( 'click' , this . clickEvent ) ;
@@ -167,7 +160,7 @@ export class MapvRenderer extends BaseLayer {
167
160
return ;
168
161
}
169
162
var newData = this . dataSet . get ( {
170
- filter : function ( data ) {
163
+ filter : function ( data ) {
171
164
return filter != null && typeof filter === 'function' ? ! filter ( data ) : true ;
172
165
}
173
166
} ) ;
@@ -255,7 +248,7 @@ export class MapvRenderer extends BaseLayer {
255
248
var center = map . getCenter ( ) ;
256
249
var centerPx = map . project ( center ) ;
257
250
var dataGetOptions = {
258
- transferCoordinate : function ( coordinate ) {
251
+ transferCoordinate : function ( coordinate ) {
259
252
if ( map . transform . rotationMatrix || self . context === '2d' ) {
260
253
var worldPoint = map . project ( new mapboxgl . LngLat ( coordinate [ 0 ] , coordinate [ 1 ] ) ) ;
261
254
return [ worldPoint . x , worldPoint . y ] ;
@@ -266,7 +259,7 @@ export class MapvRenderer extends BaseLayer {
266
259
} ;
267
260
268
261
if ( time !== undefined ) {
269
- dataGetOptions . filter = function ( item ) {
262
+ dataGetOptions . filter = function ( item ) {
270
263
var trails = animationOptions . trails || 10 ;
271
264
return time && item . time > time - trails && item . time < time ;
272
265
} ;
@@ -297,6 +290,7 @@ export class MapvRenderer extends BaseLayer {
297
290
this . drawContext ( context , data , self . options , worldPoint ) ;
298
291
299
292
self . options . updateCallback && self . options . updateCallback ( time ) ;
293
+
300
294
}
301
295
302
296
init ( options ) {
@@ -307,26 +301,72 @@ export class MapvRenderer extends BaseLayer {
307
301
this . initDataRange ( options ) ;
308
302
309
303
this . context = self . options . context || '2d' ;
310
-
311
304
if ( self . options . zIndex ) {
312
305
this . canvasLayer && this . canvasLayer . setZIndex ( self . options . zIndex ) ;
313
306
}
314
-
315
307
this . initAnimator ( ) ;
316
308
}
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
+ }
317
355
318
356
/**
319
357
* @function L.supermap.MapVRenderer.prototype.destroy
320
358
* @description 释放资源。
321
359
*/
322
360
destroy ( ) {
361
+ this . unbindMapEvent ( ) ;
323
362
this . unbindEvent ( ) ;
324
363
this . clearData ( ) ;
325
364
this . animator && this . animator . stop ( ) ;
326
365
this . animator = null ;
327
366
this . canvasLayer = null ;
328
367
}
329
368
369
+
330
370
/**
331
371
* @function MapvRenderer.prototype.addAnimatorEvent
332
372
* @description 添加动画事件。
0 commit comments