@@ -17,7 +17,6 @@ import * as olExtent from 'ol/extent';
17
17
import Polygon from 'ol/geom/Polygon' ;
18
18
import Point from 'ol/geom/Point' ;
19
19
import ImageLayer from 'ol/layer/Image' ;
20
- import { transform } from 'ol/proj' ;
21
20
22
21
const defaultProps = {
23
22
color : [ 0 , 0 , 0 , 255 ] ,
@@ -85,42 +84,38 @@ export class Graphic extends ImageCanvasSource {
85
84
86
85
if ( options . onClick ) {
87
86
me . map . on ( 'click' , function ( e ) {
88
- const graphic = me . findGraphicByPixel ( e , me ) ;
89
- if ( graphic ) {
90
- if ( me . isDeckGLRender ) {
91
- const params = me . getDeckglArguments ( me , e , graphic ) ;
92
- options . onClick ( params ) ;
93
- } else {
94
- options . onClick ( graphic , e ) ;
95
- if ( me . isHighLight ) {
96
- me . _highLight (
97
- graphic . getGeometry ( ) . getCoordinates ( ) ,
98
- new Style ( {
99
- image : graphic . getStyle ( )
100
- } ) . getImage ( ) ,
101
- graphic ,
102
- e . pixel
103
- ) ;
104
- }
87
+ if ( me . isDeckGLRender ) {
88
+ const params = me . renderer . deckGL . pickObject ( { x : e . pixel [ 0 ] , y : e . pixel [ 1 ] } ) ;
89
+ options . onClick ( params ) ;
90
+ return ;
91
+ }
92
+ const graphic = me . findGraphicByPixel ( e , me ) ;
93
+ if ( graphic ) {
94
+ options . onClick ( graphic , e ) ;
95
+ if ( me . isHighLight ) {
96
+ me . _highLight (
97
+ graphic . getGeometry ( ) . getCoordinates ( ) ,
98
+ new Style ( {
99
+ image : graphic . getStyle ( )
100
+ } ) . getImage ( ) ,
101
+ graphic ,
102
+ e . pixel
103
+ ) ;
105
104
}
106
-
107
- }
105
+
106
+ }
108
107
} ) ;
109
108
}
110
- if ( options . onHover || options . highlightColor ) {
109
+
111
110
me . map . on ( 'pointermove' , function ( e ) {
112
- const graphic = me . findGraphicByPixel ( e , me ) ;
113
- if ( graphic ) {
114
- if ( me . isDeckGLRender ) {
115
- if ( options . highlightColor ) {
116
- me . renderer . deckGL . pickObject ( { x : e . pixel [ 0 ] , y : e . pixel [ 1 ] } ) ;
117
- }
118
- const params = me . getDeckglArguments ( me , e , graphic ) ;
119
- options . onHover && options . onHover ( params ) ;
120
- }
111
+ if ( me . isDeckGLRender ) {
112
+ const params = me . renderer . deckGL . pickObject ( { x : e . pixel [ 0 ] , y : e . pixel [ 1 ] } ) ;
113
+ if ( options . onHover ) {
114
+ options . onHover ( params ) ;
121
115
}
116
+ }
122
117
} ) ;
123
- }
118
+
124
119
//eslint-disable-next-line no-unused-vars
125
120
function canvasFunctionInternal_ ( extent , resolution , pixelRatio , size , projection ) {
126
121
var mapWidth = size [ 0 ] / pixelRatio ;
@@ -139,6 +134,12 @@ export class Graphic extends ImageCanvasSource {
139
134
me . renderer . selected = this . selected ;
140
135
me . renderer . drawGraphics ( graphics ) ;
141
136
me . isDeckGLRender = me . renderer instanceof GraphicWebGLRenderer ;
137
+ if ( me . isDeckGLRender ) {
138
+ if ( ! me . context ) {
139
+ me . context = Util . createCanvasContext2D ( mapWidth , mapHeight ) ;
140
+ }
141
+ return me . context . canvas ;
142
+ }
142
143
return me . renderer . getCanvas ( ) ;
143
144
}
144
145
@@ -193,7 +194,7 @@ export class Graphic extends ImageCanvasSource {
193
194
me . _highLightClose ( ) ;
194
195
for ( let i = graphics . length - 1 ; i >= 0 ; i -- ) {
195
196
let style = graphics [ i ] . getStyle ( ) ;
196
- if ( ! me . isDeckGLRender && ! style ) {
197
+ if ( ! style ) {
197
198
return ;
198
199
}
199
200
//已经被高亮的graphics 不被选选中
@@ -229,7 +230,7 @@ export class Graphic extends ImageCanvasSource {
229
230
if ( geo . intersectsCoordinate ( this . map . getCoordinateFromPixel ( evtPixel ) ) ) {
230
231
contain = true ;
231
232
}
232
- } else if ( image ) {
233
+ } else {
233
234
let extent = [ ] ;
234
235
extent [ 0 ] = center [ 0 ] - image . getAnchor ( ) [ 0 ] * resolution ;
235
236
extent [ 2 ] = center [ 0 ] + image . getAnchor ( ) [ 0 ] * resolution ;
@@ -238,15 +239,6 @@ export class Graphic extends ImageCanvasSource {
238
239
if ( olExtent . containsCoordinate ( extent , coordinate ) ) {
239
240
contain = true ;
240
241
}
241
- } else {
242
- let extent = [ ] ;
243
- extent [ 0 ] = center [ 0 ] - me . _options . radius * resolution ;
244
- extent [ 2 ] = center [ 0 ] + me . _options . radius * resolution ;
245
- extent [ 1 ] = center [ 1 ] - me . _options . radius * resolution ;
246
- extent [ 3 ] = center [ 1 ] + me . _options . radius * resolution ;
247
- if ( olExtent . containsCoordinate ( extent , coordinate ) ) {
248
- contain = true ;
249
- }
250
242
}
251
243
252
244
if ( contain === true ) {
@@ -274,24 +266,6 @@ export class Graphic extends ImageCanvasSource {
274
266
return undefined ;
275
267
}
276
268
277
- getDeckglArguments ( me , e , graphic ) {
278
- const view = me . map . getView ( ) ;
279
- const projection = view . getProjection ( ) . getCode ( ) ;
280
- return {
281
- object : graphic ,
282
- layer : me . renderer . _renderLayer ,
283
- pixel : e . pixel ,
284
- x : e . pixel [ 0 ] ,
285
- y : e . pixel [ 1 ] ,
286
- pixelRatio : me . renderer . pixelRatio ,
287
- lngLat : transform ( graphic . getGeometry ( ) . getCoordinates ( ) , projection , 'EPSG:4326' ) ,
288
- picked : true ,
289
- index :1 ,
290
- color : me . _options . color ,
291
- devicePixel : e . devicePixel
292
- }
293
- }
294
-
295
269
/**
296
270
* @function Graphic.prototype.setGraphics
297
271
* @description 设置绘制的点要素,会覆盖之前的所有要素。
@@ -530,7 +504,7 @@ export class Graphic extends ImageCanvasSource {
530
504
this . map . removeLayer ( this . hitGraphicLayer ) ;
531
505
this . hitGraphicLayer = null ;
532
506
}
533
- ! this . isDeckGLRender && this . changed ( ) ;
507
+ this . changed ( ) ;
534
508
}
535
509
536
510
/**
0 commit comments