@@ -17,6 +17,7 @@ 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' ;
20
21
21
22
const defaultProps = {
22
23
color : [ 0 , 0 , 0 , 255 ] ,
@@ -79,34 +80,48 @@ export class Graphic extends ImageCanvasSource {
79
80
this . isHighLight = typeof options . isHighLight === 'undefined' ? true : options . isHighLight ;
80
81
this . hitGraphicLayer = null ;
81
82
this . _forEachFeatureAtCoordinate = _forEachFeatureAtCoordinate ;
82
-
83
+ this . _options = options ;
83
84
const me = this ;
84
85
85
86
if ( options . onClick ) {
86
87
me . map . on ( 'click' , function ( e ) {
87
- if ( me . renderer instanceof GraphicWebGLRenderer ) {
88
- return ;
89
- }
90
- const features = me . map . getFeaturesAtPixel ( e . pixel ) || [ ] ;
91
- for ( let index = 0 ; index < features . length ; index ++ ) {
92
- const graphic = features [ index ] ;
93
- if ( me . graphics . indexOf ( graphic ) > - 1 ) {
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
- }
105
- break ;
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
+ ) ;
106
104
}
105
+ }
106
+
107
107
}
108
108
} ) ;
109
109
}
110
+ if ( options . onHover || options . highlightColor ) {
111
+ me . map . on ( 'pointermove' , function ( e ) {
112
+ const graphic = me . findGraphicByPixel ( e , me ) ;
113
+ if ( graphic ) {
114
+ console . log ( 'moveeeeeeeee' )
115
+ if ( me . isDeckGLRender ) {
116
+ if ( options . highlightColor ) {
117
+ me . renderer . deckGL . pickObject ( { x : e . pixel [ 0 ] , y : e . pixel [ 1 ] } ) ;
118
+ }
119
+ const params = me . getDeckglArguments ( me , e , graphic ) ;
120
+ options . onHover && options . onHover ( params ) ;
121
+ }
122
+ }
123
+ } ) ;
124
+ }
110
125
//eslint-disable-next-line no-unused-vars
111
126
function canvasFunctionInternal_ ( extent , resolution , pixelRatio , size , projection ) {
112
127
var mapWidth = size [ 0 ] / pixelRatio ;
@@ -124,6 +139,7 @@ export class Graphic extends ImageCanvasSource {
124
139
me . renderer . _clearBuffer ( ) ;
125
140
me . renderer . selected = this . selected ;
126
141
me . renderer . drawGraphics ( graphics ) ;
142
+ me . isDeckGLRender = me . renderer instanceof GraphicWebGLRenderer ;
127
143
return me . renderer . getCanvas ( ) ;
128
144
}
129
145
@@ -175,11 +191,12 @@ export class Graphic extends ImageCanvasSource {
175
191
function _forEachFeatureAtCoordinate ( coordinate , resolution , callback , evtPixel , e ) {
176
192
let graphics = me . getGraphicsInExtent ( ) ;
177
193
// FIX 无法高亮元素
178
- me . _highLightClose ( ) ;
194
+ // me._highLightClose();
195
+ console . log ( 'foreach' )
179
196
for ( let i = graphics . length - 1 ; i >= 0 ; i -- ) {
180
197
let style = graphics [ i ] . getStyle ( ) ;
181
- if ( ! style ) {
182
- return ;
198
+ if ( ! me . isDeckGLRender && ! style ) {
199
+ return ;
183
200
}
184
201
//已经被高亮的graphics 不被选选中
185
202
if ( style instanceof HitCloverShape ) {
@@ -214,7 +231,7 @@ export class Graphic extends ImageCanvasSource {
214
231
if ( geo . intersectsCoordinate ( this . map . getCoordinateFromPixel ( evtPixel ) ) ) {
215
232
contain = true ;
216
233
}
217
- } else {
234
+ } else if ( image ) {
218
235
let extent = [ ] ;
219
236
extent [ 0 ] = center [ 0 ] - image . getAnchor ( ) [ 0 ] * resolution ;
220
237
extent [ 2 ] = center [ 0 ] + image . getAnchor ( ) [ 0 ] * resolution ;
@@ -223,6 +240,15 @@ export class Graphic extends ImageCanvasSource {
223
240
if ( olExtent . containsCoordinate ( extent , coordinate ) ) {
224
241
contain = true ;
225
242
}
243
+ } else {
244
+ let extent = [ ] ;
245
+ extent [ 0 ] = center [ 0 ] - me . _options . radius * resolution ;
246
+ extent [ 2 ] = center [ 0 ] + me . _options . radius * resolution ;
247
+ extent [ 1 ] = center [ 1 ] - me . _options . radius * resolution ;
248
+ extent [ 3 ] = center [ 1 ] + me . _options . radius * resolution ;
249
+ if ( olExtent . containsCoordinate ( extent , coordinate ) ) {
250
+ contain = true ;
251
+ }
226
252
}
227
253
228
254
if ( contain === true ) {
@@ -239,6 +265,35 @@ export class Graphic extends ImageCanvasSource {
239
265
}
240
266
}
241
267
268
+ findGraphicByPixel ( e , me ) {
269
+ const features = me . map . getFeaturesAtPixel ( e . pixel ) || [ ] ;
270
+ for ( let index = 0 ; index < features . length ; index ++ ) {
271
+ const graphic = features [ index ] ;
272
+ if ( me . graphics . indexOf ( graphic ) > - 1 ) {
273
+ return graphic ;
274
+ }
275
+ }
276
+ return undefined ;
277
+ }
278
+
279
+ getDeckglArguments ( me , e , graphic ) {
280
+ const view = me . map . getView ( ) ;
281
+ const projection = view . getProjection ( ) . getCode ( ) ;
282
+ return {
283
+ object : graphic ,
284
+ layer : me . renderer . _renderLayer ,
285
+ pixel : e . pixel ,
286
+ x : e . pixel [ 0 ] ,
287
+ y : e . pixel [ 1 ] ,
288
+ pixelRatio : me . renderer . pixelRatio ,
289
+ lngLat : transform ( graphic . getGeometry ( ) . getCoordinates ( ) , projection , 'EPSG:4326' ) ,
290
+ picked : true ,
291
+ index :1 ,
292
+ color : me . _options . color ,
293
+ devicePixel : e . devicePixel
294
+ }
295
+ }
296
+
242
297
/**
243
298
* @function Graphic.prototype.setGraphics
244
299
* @description 设置绘制的点要素,会覆盖之前的所有要素。
@@ -477,7 +532,7 @@ export class Graphic extends ImageCanvasSource {
477
532
this . map . removeLayer ( this . hitGraphicLayer ) ;
478
533
this . hitGraphicLayer = null ;
479
534
}
480
- this . changed ( ) ;
535
+ ! this . isDeckGLRender && this . changed ( ) ;
481
536
}
482
537
483
538
/**
0 commit comments