@@ -17,6 +17,7 @@ import * as olExtent from 'ol/extent';
1717import Polygon from 'ol/geom/Polygon' ;
1818import Point from 'ol/geom/Point' ;
1919import ImageLayer from 'ol/layer/Image' ;
20+ import { transform } from 'ol/proj' ;
2021
2122const defaultProps = {
2223 color : [ 0 , 0 , 0 , 255 ] ,
@@ -79,34 +80,48 @@ export class Graphic extends ImageCanvasSource {
7980 this . isHighLight = typeof options . isHighLight === 'undefined' ? true : options . isHighLight ;
8081 this . hitGraphicLayer = null ;
8182 this . _forEachFeatureAtCoordinate = _forEachFeatureAtCoordinate ;
82-
83+ this . _options = options ;
8384 const me = this ;
8485
8586 if ( options . onClick ) {
8687 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+ ) ;
106104 }
105+ }
106+
107107 }
108108 } ) ;
109109 }
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+ }
110125 //eslint-disable-next-line no-unused-vars
111126 function canvasFunctionInternal_ ( extent , resolution , pixelRatio , size , projection ) {
112127 var mapWidth = size [ 0 ] / pixelRatio ;
@@ -124,6 +139,7 @@ export class Graphic extends ImageCanvasSource {
124139 me . renderer . _clearBuffer ( ) ;
125140 me . renderer . selected = this . selected ;
126141 me . renderer . drawGraphics ( graphics ) ;
142+ me . isDeckGLRender = me . renderer instanceof GraphicWebGLRenderer ;
127143 return me . renderer . getCanvas ( ) ;
128144 }
129145
@@ -175,11 +191,12 @@ export class Graphic extends ImageCanvasSource {
175191 function _forEachFeatureAtCoordinate ( coordinate , resolution , callback , evtPixel , e ) {
176192 let graphics = me . getGraphicsInExtent ( ) ;
177193 // FIX 无法高亮元素
178- me . _highLightClose ( ) ;
194+ // me._highLightClose();
195+ console . log ( 'foreach' )
179196 for ( let i = graphics . length - 1 ; i >= 0 ; i -- ) {
180197 let style = graphics [ i ] . getStyle ( ) ;
181- if ( ! style ) {
182- return ;
198+ if ( ! me . isDeckGLRender && ! style ) {
199+ return ;
183200 }
184201 //已经被高亮的graphics 不被选选中
185202 if ( style instanceof HitCloverShape ) {
@@ -214,7 +231,7 @@ export class Graphic extends ImageCanvasSource {
214231 if ( geo . intersectsCoordinate ( this . map . getCoordinateFromPixel ( evtPixel ) ) ) {
215232 contain = true ;
216233 }
217- } else {
234+ } else if ( image ) {
218235 let extent = [ ] ;
219236 extent [ 0 ] = center [ 0 ] - image . getAnchor ( ) [ 0 ] * resolution ;
220237 extent [ 2 ] = center [ 0 ] + image . getAnchor ( ) [ 0 ] * resolution ;
@@ -223,6 +240,15 @@ export class Graphic extends ImageCanvasSource {
223240 if ( olExtent . containsCoordinate ( extent , coordinate ) ) {
224241 contain = true ;
225242 }
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+ }
226252 }
227253
228254 if ( contain === true ) {
@@ -239,6 +265,35 @@ export class Graphic extends ImageCanvasSource {
239265 }
240266 }
241267
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+
242297 /**
243298 * @function Graphic.prototype.setGraphics
244299 * @description 设置绘制的点要素,会覆盖之前的所有要素。
@@ -477,7 +532,7 @@ export class Graphic extends ImageCanvasSource {
477532 this . map . removeLayer ( this . hitGraphicLayer ) ;
478533 this . hitGraphicLayer = null ;
479534 }
480- this . changed ( ) ;
535+ ! this . isDeckGLRender && this . changed ( ) ;
481536 }
482537
483538 /**
0 commit comments