Skip to content

Commit 0b1f681

Browse files
author
zhaokai
committed
几何查询测试
1 parent 0c6e71c commit 0b1f681

File tree

4 files changed

+52
-17
lines changed

4 files changed

+52
-17
lines changed

src/service/2DPlot/PlotCanvas.js

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
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

1010
import { 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: 请求渲染

src/service/2DPlot/PlotCanvasGroup.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @Author: zk
55
* @Date: 2022-05-13 11:01:10
66
* @LastEditors: zk
7-
* @LastEditTime: 2022-05-19 14:54:49
7+
* @LastEditTime: 2022-05-24 11:15:30
88
*/
99

1010
import { fabric } from 'fabric';
@@ -214,13 +214,19 @@ export const PlotCanvasGroup = fabric.util.createClass(fabric.Canvas, {
214214
}
215215
return t;
216216
},
217+
initLayerCoords(){
218+
this._plotCanvasLayers.forEach(layer => {
219+
layer.initCoords()
220+
});
221+
},
217222
/**
218223
* @function: Module:PlotCanvasGroup.prototype._renderObjects
219224
* @description: 渲染标绘对象代码
220225
* @param {CanvasRenderingContext2D} ctx
221226
* @param {Array<Object>} objects
222227
*/
223228
_renderObjects(ctx, objects) {
229+
this.initLayerCoords()
224230
var i, len;
225231
for (i = 0, len = objects.length; i < len; ++i) {
226232
const object = objects[i];

src/service/2DPlot/Shapes/PlotObject.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* @Author: your name
33
* @Date: 2021-07-05 11:32:52
4-
* @LastEditTime: 2022-05-16 18:53:37
4+
* @LastEditTime: 2022-05-24 11:10:01
55
* @LastEditors: zk
66
* @Description: In User Settings Edit
77
* @FilePath: \MapGISPlot\src\js\Shapes\PlotObject.js
@@ -41,10 +41,9 @@ const PlotObject = fabric.util.createClass(fabric.Object, {
4141
}
4242
},
4343
render: function render(ctx) {
44-
if (this.isNotVisible()) {
45-
return;
46-
}
47-
this.dataToPoint();
44+
if (this.isNotVisible()) {
45+
return;
46+
}
4847
this.setBounds(ctx);
4948
this.callSuper('render', ctx);
5049
},

src/service/2DPlot/Shapes/RegularShapes/PlotRegularObject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @Author: zk
44
* @Date: 2021-11-17 16:12:55
55
* @LastEditors: zk
6-
* @LastEditTime: 2022-05-19 14:03:41
6+
* @LastEditTime: 2022-05-24 11:19:36
77
*/
88

99
import { fabric } from 'fabric';

0 commit comments

Comments
 (0)