@@ -41,7 +41,7 @@ const defaultProps = {
41
41
* @param {Function } [options.onHover] - 图层鼠标悬停响应事件(只有 webgl 渲染时有用)。
42
42
*/
43
43
export var GraphicLayer = L . Path . extend ( {
44
- initialize : function ( graphics , options ) {
44
+ initialize : function ( graphics , options ) {
45
45
this . graphics = [ ] . concat ( graphics ) ;
46
46
let opt = options || { } ;
47
47
// 由于是canvas实现所以不能更改pane
@@ -53,7 +53,9 @@ export var GraphicLayer = L.Path.extend({
53
53
if ( ! Detector . supportWebGL2 ( ) ) {
54
54
this . options . render = Renderer [ 0 ] ;
55
55
}
56
- this . on ( 'click mousemove dblclick mousedown mouseup mouseout contextmenu' , this . _handleClick , this ) ;
56
+ if ( this . options . interactive ) {
57
+ this . on ( 'click mousemove dblclick mousedown mouseup mouseout contextmenu' , this . _handleClick , this ) ;
58
+ }
57
59
} ,
58
60
59
61
/**
@@ -62,7 +64,7 @@ export var GraphicLayer = L.Path.extend({
62
64
* @description 获取事件。
63
65
* @returns {Object } 返回该图层支持的事件对象。
64
66
*/
65
- getEvents : function ( ) {
67
+ getEvents : function ( ) {
66
68
const events = {
67
69
resize : this . _resize . bind ( this ) ,
68
70
moveend : this . _moveEnd . bind ( this )
@@ -75,12 +77,12 @@ export var GraphicLayer = L.Path.extend({
75
77
* @function L.supermap.graphicLayer.prototype.onAdd
76
78
* @description 添加图形。
77
79
*/
78
- onAdd : function ( map ) {
80
+ onAdd : function ( map ) {
79
81
this . _map = map ;
80
82
this . defaultStyle = this . _getDefaultStyle ( this . options ) ;
81
83
this . _renderer = this . _createRenderer ( ) ;
82
84
this . _container = this . _renderer . _container ;
83
- this . addInteractiveTarget ( this . _container ) ;
85
+ // this.addInteractiveTarget(this._container);
84
86
L . Path . prototype . onAdd . call ( this ) ;
85
87
} ,
86
88
@@ -90,7 +92,7 @@ export var GraphicLayer = L.Path.extend({
90
92
* @function L.supermap.graphicLayer.prototype.onRemove
91
93
* @description 移除图层。
92
94
*/
93
- onRemove : function ( ) {
95
+ onRemove : function ( ) {
94
96
this . off ( 'click mousemove dblclick mousedown mouseup contextmenu' , this . _handleClick , this ) ;
95
97
this . _renderer . _removePath ( this ) ;
96
98
} ,
@@ -100,7 +102,7 @@ export var GraphicLayer = L.Path.extend({
100
102
* @description 设置绘制的点要素数据,会覆盖之前的所有要素。
101
103
* @param {Array.<L.supermap.graphic> } graphics - 点要素对象数组。
102
104
*/
103
- setGraphics : function ( graphics ) {
105
+ setGraphics : function ( graphics ) {
104
106
this . graphics = this . graphics || [ ] ;
105
107
this . graphics . length = 0 ;
106
108
let sGraphics = ! L . Util . isArray ( graphics ) ? [ graphics ] : [ ] . concat ( graphics ) ;
@@ -113,7 +115,7 @@ export var GraphicLayer = L.Path.extend({
113
115
* @description 追加点要素,不会覆盖之前的要素。
114
116
* @param {Array.<L.supermap.graphic> } graphics - 点要素对象数组。
115
117
*/
116
- addGraphics : function ( graphics ) {
118
+ addGraphics : function ( graphics ) {
117
119
this . graphics = this . graphics || [ ] ;
118
120
let sGraphics = ! L . Util . isArray ( graphics ) ? [ graphics ] : [ ] . concat ( graphics ) ;
119
121
this . graphics = this . graphics . concat ( sGraphics ) ;
@@ -216,7 +218,7 @@ export var GraphicLayer = L.Path.extend({
216
218
* @param {number } [styleOptions.strokeWidth=1] - 边框大小。
217
219
* @param {boolean } [styleOptions.outline=false] - 是否显示边框。
218
220
*/
219
- setStyle : function ( styleOptions ) {
221
+ setStyle : function ( styleOptions ) {
220
222
let _opt = this . options ;
221
223
let styleOpt = {
222
224
color : _opt . color ,
@@ -238,15 +240,15 @@ export var GraphicLayer = L.Path.extend({
238
240
* @function L.supermap.graphicLayer.prototype.update
239
241
* @description 更新图层,数据或者样式改变后调用。
240
242
*/
241
- update : function ( ) {
243
+ update : function ( ) {
242
244
this . _layerRenderer . update ( this . graphics ) ;
243
245
} ,
244
246
245
247
/**
246
248
* @function L.supermap.graphicLayer.prototype.clear
247
249
* @description 释放图层资源。
248
250
*/
249
- clear : function ( ) {
251
+ clear : function ( ) {
250
252
this . removeGraphics ( ) ;
251
253
} ,
252
254
@@ -255,7 +257,7 @@ export var GraphicLayer = L.Path.extend({
255
257
* @description 获取渲染器。
256
258
* @returns {Object } 内部渲染器。
257
259
*/
258
- getRenderer : function ( ) {
260
+ getRenderer : function ( ) {
259
261
return this . _renderer ;
260
262
} ,
261
263
@@ -264,7 +266,7 @@ export var GraphicLayer = L.Path.extend({
264
266
* @description 获取当前地图及图层状态。
265
267
* @returns {Object } 地图及图层状态,包含地图状态信息和本图层相关状态。
266
268
*/
267
- getState : function ( ) {
269
+ getState : function ( ) {
268
270
let map = this . _map ;
269
271
let width = map . getSize ( ) . x ;
270
272
let height = map . getSize ( ) . y ;
@@ -302,7 +304,7 @@ export var GraphicLayer = L.Path.extend({
302
304
return state ;
303
305
} ,
304
306
305
- _resize : function ( ) {
307
+ _resize : function ( ) {
306
308
let size = this . _map . getSize ( ) ;
307
309
this . _container . width = size . x ;
308
310
this . _container . height = size . y ;
@@ -313,13 +315,13 @@ export var GraphicLayer = L.Path.extend({
313
315
L . DomUtil . setPosition ( this . _container , mapOffset ) ;
314
316
this . _update ( ) ;
315
317
} ,
316
- _moveEnd : function ( ) {
318
+ _moveEnd : function ( ) {
317
319
if ( this . _layerRenderer instanceof GraphicWebGLRenderer ) {
318
320
this . _update ( ) ;
319
321
}
320
322
} ,
321
323
//使用canvas渲染或webgl渲染
322
- _createRenderer : function ( ) {
324
+ _createRenderer : function ( ) {
323
325
let map = this . _map ;
324
326
let width = map . getSize ( ) . x ;
325
327
let height = map . getSize ( ) . y ;
@@ -354,7 +356,7 @@ export var GraphicLayer = L.Path.extend({
354
356
* @private
355
357
* @override
356
358
*/
357
- _update : function ( ) {
359
+ _update : function ( ) {
358
360
if ( this . _map ) {
359
361
this . _updatePath ( ) ;
360
362
}
@@ -364,7 +366,7 @@ export var GraphicLayer = L.Path.extend({
364
366
* @private
365
367
* @override
366
368
*/
367
- _updatePath : function ( ) {
369
+ _updatePath : function ( ) {
368
370
let graphics = this . _getGraphicsInBounds ( ) ;
369
371
this . _renderer . drawGraphics ( graphics , this . defaultStyle ) ;
370
372
} ,
@@ -373,9 +375,9 @@ export var GraphicLayer = L.Path.extend({
373
375
* @private
374
376
* @override
375
377
*/
376
- _project : function ( ) {
378
+ _project : function ( ) {
377
379
let me = this ;
378
- me . _getGraphicsInBounds ( ) . map ( function ( graphic ) {
380
+ me . _getGraphicsInBounds ( ) . map ( function ( graphic ) {
379
381
let point = me . _map . latLngToLayerPoint ( graphic . getLatLng ( ) ) ;
380
382
let w = me . _clickTolerance ( ) ;
381
383
let p = [ graphic . _anchor + w , graphic . _anchor + w ] ;
@@ -384,7 +386,7 @@ export var GraphicLayer = L.Path.extend({
384
386
} ) ;
385
387
me . _pxBounds = L . bounds ( L . point ( 0 , 0 ) , L . point ( this . _container . width , this . _container . height ) ) ;
386
388
} ,
387
- _getDefaultStyle : function ( options ) {
389
+ _getDefaultStyle : function ( options ) {
388
390
const target = { } ;
389
391
if ( options . color ) {
390
392
target . fill = true ;
@@ -410,11 +412,11 @@ export var GraphicLayer = L.Path.extend({
410
412
toRGBA ( colorArray ) {
411
413
return `rgba(${ colorArray [ 0 ] } ,${ colorArray [ 1 ] } ,${ colorArray [ 2 ] } ,${ ( colorArray [ 3 ] || 255 ) / 255 } )` ;
412
414
} ,
413
- _getGraphicsInBounds : function ( ) {
415
+ _getGraphicsInBounds : function ( ) {
414
416
let me = this ;
415
417
let graphicsInBounds = [ ] ;
416
418
let viewBounds = me . _map . getBounds ( ) ;
417
- this . graphics . map ( function ( graphic ) {
419
+ this . graphics . map ( function ( graphic ) {
418
420
if ( viewBounds . contains ( graphic . getLatLng ( ) ) ) {
419
421
graphicsInBounds . push ( graphic ) ;
420
422
}
@@ -423,7 +425,7 @@ export var GraphicLayer = L.Path.extend({
423
425
return graphicsInBounds ;
424
426
} ,
425
427
426
- _handleClick : function ( evt ) {
428
+ _handleClick : function ( evt ) {
427
429
this . _layerRenderer . _handleClick ( evt ) ;
428
430
} ,
429
431
/**
@@ -436,10 +438,12 @@ export var GraphicLayer = L.Path.extend({
436
438
* @private
437
439
* @override
438
440
*/
439
- _containsPoint : L . Util . falseFn
441
+ _containsPoint : function ( p ) {
442
+ return this . _layerRenderer . containsPoint ( p ) ;
443
+ }
440
444
} ) ;
441
445
442
- export let graphicLayer = function ( graphics , options ) {
446
+ export let graphicLayer = function ( graphics , options ) {
443
447
return new GraphicLayer ( graphics , options ) ;
444
448
} ;
445
449
0 commit comments