@@ -17,7 +17,6 @@ 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' ;
2120
2221const defaultProps = {
2322 color : [ 0 , 0 , 0 , 255 ] ,
@@ -85,42 +84,38 @@ export class Graphic extends ImageCanvasSource {
8584
8685 if ( options . onClick ) {
8786 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+ ) ;
105104 }
106-
107- }
105+
106+ }
108107 } ) ;
109108 }
110- if ( options . onHover || options . highlightColor ) {
109+
111110 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 ) ;
121115 }
116+ }
122117 } ) ;
123- }
118+
124119 //eslint-disable-next-line no-unused-vars
125120 function canvasFunctionInternal_ ( extent , resolution , pixelRatio , size , projection ) {
126121 var mapWidth = size [ 0 ] / pixelRatio ;
@@ -139,6 +134,12 @@ export class Graphic extends ImageCanvasSource {
139134 me . renderer . selected = this . selected ;
140135 me . renderer . drawGraphics ( graphics ) ;
141136 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+ }
142143 return me . renderer . getCanvas ( ) ;
143144 }
144145
@@ -193,7 +194,7 @@ export class Graphic extends ImageCanvasSource {
193194 me . _highLightClose ( ) ;
194195 for ( let i = graphics . length - 1 ; i >= 0 ; i -- ) {
195196 let style = graphics [ i ] . getStyle ( ) ;
196- if ( ! me . isDeckGLRender && ! style ) {
197+ if ( ! style ) {
197198 return ;
198199 }
199200 //已经被高亮的graphics 不被选选中
@@ -229,7 +230,7 @@ export class Graphic extends ImageCanvasSource {
229230 if ( geo . intersectsCoordinate ( this . map . getCoordinateFromPixel ( evtPixel ) ) ) {
230231 contain = true ;
231232 }
232- } else if ( image ) {
233+ } else {
233234 let extent = [ ] ;
234235 extent [ 0 ] = center [ 0 ] - image . getAnchor ( ) [ 0 ] * resolution ;
235236 extent [ 2 ] = center [ 0 ] + image . getAnchor ( ) [ 0 ] * resolution ;
@@ -238,15 +239,6 @@ export class Graphic extends ImageCanvasSource {
238239 if ( olExtent . containsCoordinate ( extent , coordinate ) ) {
239240 contain = true ;
240241 }
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- }
250242 }
251243
252244 if ( contain === true ) {
@@ -274,24 +266,6 @@ export class Graphic extends ImageCanvasSource {
274266 return undefined ;
275267 }
276268
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-
295269 /**
296270 * @function Graphic.prototype.setGraphics
297271 * @description 设置绘制的点要素,会覆盖之前的所有要素。
@@ -530,7 +504,7 @@ export class Graphic extends ImageCanvasSource {
530504 this . map . removeLayer ( this . hitGraphicLayer ) ;
531505 this . hitGraphicLayer = null ;
532506 }
533- ! this . isDeckGLRender && this . changed ( ) ;
507+ this . changed ( ) ;
534508 }
535509
536510 /**
0 commit comments