44 * @Author : zk
55 * @Date : 2022-05-13 10:34:57
66 * @LastEditors : zk
7- * @LastEditTime : 2022-05-19 11:28:26
7+ * @LastEditTime : 2022-05-24 11:12:29
88 */
99
1010import { DrawPlotObjectFactory2D } from './Draw/DrawPlotObjectFactory2D' ;
@@ -342,6 +342,18 @@ export default class PlotCanvas {
342342 this . _fabricCanvas . requestRenderAll ( ) ;
343343 }
344344
345+ /**
346+ * @function : Module:PlotCanvas.prototype.queryPlotByLatLng
347+ * @description : 点选标绘对象
348+ * @param {{lng:number,lat:number}|[number,number] } latlng
349+ * @return {* }
350+ */
351+ queryPlotByLatLng ( latlng ) {
352+ const latlngArr = Array . isArray ( latlng ) ? latlng : [ latlng . lng , latlng . lat ] ;
353+ const point = this . getCoordSys ( ) . dataToPoint ( latlngArr ) ;
354+ return this . queryPlotByPoint ( point ) ;
355+ }
356+
345357 /**
346358 * @function : Module:PlotCanvas.prototype.queryPlotByPoint
347359 * @description : 点选标绘对象
@@ -354,13 +366,27 @@ export default class PlotCanvas {
354366 const plot = this . m_plotObjects [ i ] ;
355367 const element = plot . getElement ( ) ;
356368 const bounds = element . getBounds ( ) ;
357- if ( ! this . _isInBounds ( p , bounds ) ) {
369+ if ( this . _isInBounds ( p , bounds ) ) {
358370 return plot ;
359371 }
360372 }
361373 return null ;
362374 }
363375
376+ /**
377+ * @function : Module:PlotCanvas.prototype.queryPlotsByLatlngBounds
378+ * @description : 矩阵选查询
379+ * @param {{ left: number; right: number; bottom: number; top: number; } } bounds
380+ * @return {* }
381+ */
382+ queryPlotsByLatlngBounds ( bounds ) {
383+ const p1 = [ bounds . left , bounds . bottom ] ;
384+ const p2 = [ bounds . right , bounds . top ] ;
385+ const coordSys = this . getCoordSys ( ) ;
386+ const leftBottom = coordSys . dataToPoint ( p1 ) ;
387+ const rightTop = coordSys . dataToPoint ( p2 ) ;
388+ return this . queryPlotsByBounds ( { left : leftBottom [ 0 ] , top : leftBottom [ 1 ] , bottom : rightTop [ 1 ] , right : rightTop [ 0 ] } ) ;
389+ }
364390 /**
365391 * @function : Module:PlotCanvas.prototype.queryPlotsByBounds
366392 * @description : 矩阵选查询
@@ -369,16 +395,14 @@ export default class PlotCanvas {
369395 */
370396 queryPlotsByBounds ( bounds ) {
371397 const expPlots = [ ] ;
372- const p1 = [ bounds . left , bounds . right ] ;
373- const p2 = [ bounds . bottom , bounds . top ] ;
374398 for ( let i = 0 ; i < this . m_plotObjects . length ; i ++ ) {
375399 const plot = this . m_plotObjects [ i ] ;
376400 const element = plot . getElement ( ) ;
377401 const ebounds = element . getBounds ( ) ;
378- if ( ! this . _isInBounds ( p1 , ebounds ) ) {
379- expPlots . push ( plot ) ;
380- }
381- if ( ! this . _isInBounds ( p2 , ebounds ) ) {
402+
403+ const p1 = [ ebounds . left , ebounds . bottom ] ;
404+ const p2 = [ ebounds . right , ebounds . bottom ] ;
405+ if ( this . _isInBounds ( p1 , bounds ) && this . _isInBounds ( p2 , bounds ) ) {
382406 expPlots . push ( plot ) ;
383407 }
384408 }
@@ -393,12 +417,18 @@ export default class PlotCanvas {
393417 const bottom = bounds . bottom ;
394418 const top = bounds . top ;
395419 const right = bounds . right ;
396- if ( left < p [ 0 ] && p [ 0 ] < right && bottom < p [ 1 ] && p [ 1 ] < top ) {
397- return false ;
420+ if ( left <= p [ 0 ] && p [ 0 ] <= right && bottom <= p [ 1 ] && p [ 1 ] <= top ) {
421+ return true ;
398422 }
399423 return false ;
400424 }
401425
426+ initCoords ( ) {
427+ this . m_plotObjects . forEach ( ( s ) => {
428+ s . dataToPoint && s . dataToPoint ( )
429+ } )
430+ }
431+
402432 /**
403433 * @function : Module:PlotCanvas.prototype.requestRenderAll
404434 * @description : 请求渲染
0 commit comments