Skip to content

Commit bf58ad4

Browse files
author
zhaokai
committed
合并版本去除贴地
1 parent b91f002 commit bf58ad4

31 files changed

+416
-465
lines changed

src/service/2DPlot/PlotCanvas.js

Lines changed: 81 additions & 20 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-16 19:10:38
7+
* @LastEditTime: 2022-05-19 11:28:26
88
*/
99

1010
import { DrawPlotObjectFactory2D } from './Draw/DrawPlotObjectFactory2D';
@@ -17,15 +17,15 @@ export default class PlotCanvas {
1717
constructor() {
1818
// 标绘对象
1919
this.m_plotObjects = [];
20-
// fabricCanvas
20+
// fabricCanvas
2121
this._fabricCanvas = null;
2222
// uuid
2323
this._layerId = createGuid();
2424
// visible
2525
this._visible = true;
2626
// event
2727
this._objectModifiedEventAction = this._objectModifiedEventAction.bind(this);
28-
this._eventHandlers=[]
28+
this._eventHandlers = [];
2929
}
3030

3131
/**
@@ -66,6 +66,9 @@ export default class PlotCanvas {
6666
removeEvent() {
6767
this._fabricCanvas && this._fabricCanvas.off('object:modified', this._objectModifiedEventAction);
6868
}
69+
/**
70+
* @param {{ target: any; action: string; }} event
71+
*/
6972
_objectModifiedEventAction(event) {
7073
const target = event.target;
7174
if (this.m_plotObjects.indexOf(target) === -1) {
@@ -92,37 +95,37 @@ export default class PlotCanvas {
9295
* @param {String} eventName 事件名,参考fabricjs Canvas类事件
9396
* @param {Function} handler 绑定函数
9497
*/
95-
on(eventName,handler){
96-
this._eventHandlers.push({eventName,handler})
97-
this._fabricCanvas.on(eventName,handler)
98+
on(eventName, handler) {
99+
this._eventHandlers.push({ eventName, handler });
100+
this._fabricCanvas.on(eventName, handler);
98101
}
99102
/**
100103
* @function: Module:PlotCanvas.prototype.off
101104
* @description: 移除监听事件
102105
* @param {String} eventName 事件名
103106
* @return {*}
104107
*/
105-
off(eventName){
106-
this._eventHandlers.forEach((s)=>{
107-
if(s.eventName===eventName){
108-
this._fabricCanvas.off(s.eventName,s.handler)
109-
}
110-
})
108+
off(eventName) {
109+
this._eventHandlers.forEach((s) => {
110+
if (s.eventName === eventName) {
111+
this._fabricCanvas.off(s.eventName, s.handler);
112+
}
113+
});
111114
}
112115
/**
113116
* @function: Module:PlotCanvas.prototype._createHandler
114117
* @description: 监听函数包装
115118
* @param {*} handler
116119
* @return {*}
117120
*/
118-
_createHandler(handler){
119-
return (event)=>{
121+
_createHandler(handler) {
122+
return (/** @type {{ target: any; }} */ event) => {
120123
const target = event.target;
121124
if (this.m_plotObjects.indexOf(target) === -1) {
122125
return;
123126
}
124-
handler(event)
125-
}
127+
handler(event);
128+
};
126129
}
127130
/**
128131
* @function: Module:PlotCanvas.prototype.setCoordSys
@@ -255,7 +258,7 @@ export default class PlotCanvas {
255258
fromGeoJSON(geoJson) {
256259
if (geoJson.type === 'FeatureCollection') {
257260
const { features } = geoJson;
258-
features.forEach((s) => {
261+
features.forEach((/** @type {any} */ s) => {
259262
this.addGeoJSONObject(s);
260263
});
261264
} else {
@@ -307,7 +310,7 @@ export default class PlotCanvas {
307310
/**
308311
* @function: Module:PlotCanvas.prototype.getPlotObjects
309312
* @description: 获取标绘对象列表
310-
* @return {Array<Object>}
313+
* @return {Array<Object>}
311314
*/
312315
getPlotObjects() {
313316
return this.m_plotObjects;
@@ -338,11 +341,69 @@ export default class PlotCanvas {
338341
}
339342
this._fabricCanvas.requestRenderAll();
340343
}
344+
345+
/**
346+
* @function: Module:PlotCanvas.prototype.queryPlotByPoint
347+
* @description: 点选标绘对象
348+
* @param {{ x: number; y: number; } | [number,number]} point
349+
* @return {null | Object} 标绘对象
350+
*/
351+
queryPlotByPoint(point) {
352+
const p = Array.isArray(point) ? point : [point.x, point.y];
353+
for (let i = 0; i < this.m_plotObjects.length; i++) {
354+
const plot = this.m_plotObjects[i];
355+
const element = plot.getElement();
356+
const bounds = element.getBounds();
357+
if (!this._isInBounds(p, bounds)) {
358+
return plot;
359+
}
360+
}
361+
return null;
362+
}
363+
364+
/**
365+
* @function: Module:PlotCanvas.prototype.queryPlotsByBounds
366+
* @description: 矩阵选查询
367+
* @param {{ left: number; right: number; bottom: number; top: number; }} bounds
368+
* @return {*}
369+
*/
370+
queryPlotsByBounds(bounds) {
371+
const expPlots = [];
372+
const p1 = [bounds.left, bounds.right];
373+
const p2 = [bounds.bottom, bounds.top];
374+
for (let i = 0; i < this.m_plotObjects.length; i++) {
375+
const plot = this.m_plotObjects[i];
376+
const element = plot.getElement();
377+
const ebounds = element.getBounds();
378+
if (!this._isInBounds(p1, ebounds)) {
379+
expPlots.push(plot);
380+
}
381+
if (!this._isInBounds(p2, ebounds)) {
382+
expPlots.push(plot);
383+
}
384+
}
385+
return expPlots;
386+
}
387+
/**
388+
* @param {any[]} p
389+
* @param {{ left: any; bottom: any; top: any; right: any; }} bounds
390+
*/
391+
_isInBounds(p, bounds) {
392+
const left = bounds.left;
393+
const bottom = bounds.bottom;
394+
const top = bounds.top;
395+
const right = bounds.right;
396+
if (left < p[0] && p[0] < right && bottom < p[1] && p[1] < top) {
397+
return false;
398+
}
399+
return false;
400+
}
401+
341402
/**
342403
* @function: Module:PlotCanvas.prototype.requestRenderAll
343404
* @description: 请求渲染
344405
*/
345-
requestRenderAll(){
346-
this._fabricCanvas.requestRenderAll()
406+
requestRenderAll() {
407+
this._fabricCanvas.requestRenderAll();
347408
}
348409
}

src/service/2DPlot/PlotCanvasGroup.js

Lines changed: 20 additions & 27 deletions
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-18 14:52:57
7+
* @LastEditTime: 2022-05-19 14:54:49
88
*/
99

1010
import { fabric } from 'fabric';
@@ -199,35 +199,20 @@ export const PlotCanvasGroup = fabric.util.createClass(fabric.Canvas, {
199199
/**
200200
* @function: Module:PlotCanvasGroup.prototype.getPlotObjectById
201201
* @description: 根据要素id获取要素对象
202-
* @param {*} uid
202+
* @param {String} uid
203203
* @return {*}
204204
*/
205205
getPlotObjectById(uid) {
206-
let t;
207-
this._objects.forEach((s) => {
208-
const elem = s.getElement();
206+
let t=null;
207+
for(let i =0;i<this._objects.length;i++){
208+
const object = this._objects[i]
209+
const elem = object.getElement();
209210
if (elem && elem.getFeatureId() === uid) {
210-
t = s;
211-
}
212-
});
213-
return t;
214-
},
215-
_isInMapBounds(positions, mapBounds) {
216-
let flag = false;
217-
218-
const nw = mapBounds[0];
219-
const es = mapBounds[1];
220-
221-
for (let i = 0; i < positions.length; i++) {
222-
const x = positions[i].x;
223-
const y = positions[i].y;
224-
225-
if (x > nw[0] && x < es[0] && y < es[1] && y > nw[1]) {
226-
flag = true;
227-
break;
228-
}
211+
t = object;
212+
break
213+
}
229214
}
230-
return flag;
215+
return t;
231216
},
232217
/**
233218
* @function: Module:PlotCanvasGroup.prototype._renderObjects
@@ -236,12 +221,20 @@ export const PlotCanvasGroup = fabric.util.createClass(fabric.Canvas, {
236221
* @param {Array<Object>} objects
237222
*/
238223
_renderObjects(ctx, objects) {
239-
const mapBounds = this.getCoordSys().getBounds();
240224
var i, len;
241225
for (i = 0, len = objects.length; i < len; ++i) {
242226
const object = objects[i];
243227
const element = object.getElement();
244-
const flag = element ? this._isInMapBounds(element.positions, mapBounds) : false;
228+
const bounds = element.getBounds()
229+
const left = bounds.left
230+
const bottom= bounds.bottom
231+
const top= bounds.top
232+
const right= bounds.right
233+
234+
let flag = true
235+
if((this.width<left && this.height<bottom) || (top<0 && right<0 ) ){
236+
flag=false
237+
}
245238
flag && object && object.render(ctx);
246239
}
247240
}

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-18 14:49:44
6+
* @LastEditTime: 2022-05-19 14:03:41
77
*/
88

99
import { fabric } from 'fabric';

src/service/3DPlot/Draw/DrawPolyline.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export default class DrawPolyline extends DrawObject {
4747
const viewer = this._viewer;
4848
const symbol = this._symbol;
4949
const handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas);
50-
const {classificationType} = symbol;
5150
let that = this;
5251

5352
handler.setInputAction((event) => {
@@ -63,7 +62,6 @@ export default class DrawPolyline extends DrawObject {
6362
that._primitive = PrimitiveFactory.createInstance(symbol.type, {
6463
positions: that.m_coords,
6564
element: res,
66-
classificationType: classificationType
6765
});
6866
that._isAdded = true;
6967
that._plotLayer._primitiveCollection.add(that._primitive);

src/service/3DPlot/PlotLayer3D.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,20 @@ class PlotLayer3D extends Observable {
271271
}
272272
return plots;
273273
}
274+
275+
_mercatorTolonlat(mercator) {
276+
let lonlat = {lon: 0, lat: 0};
277+
278+
let x = mercator.x / 20037508.34 * 180;
279+
let y = mercator.y / 20037508.34 * 180;
280+
281+
y = 180 / Math.PI * (2 * Math.atan(Math.exp(y * Math.PI / 180)) - Math.PI / 2);
282+
283+
lonlat.lon = x;
284+
lonlat.lat = y;
285+
286+
return lonlat;
287+
};
274288
}
275289

276290
Object.defineProperties(PlotLayer3D.prototype, {

src/service/3DPlot/Primitive/ElementInstance/KidneyAreaElementInstance.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,9 @@ import RegularLine1ElementInstance from "./RegularLine1ElementInstance";
1010
import {CesiumGeomUtil} from "../../Utils/CesiumUtil";
1111
export default class KidneyAreaElementInstance extends RegularLine1ElementInstance {
1212
transfromGeoCesium(elem, cesgeo, options) {
13-
let {dimModHeight} = options;
14-
if(typeof this._classificationType === 'number' && this._classificationType >= 0){
15-
dimModHeight = 0;
16-
}
17-
1813
CesiumGeomUtil.degreesWithHeightToWorldCoords(
1914
cesgeo,
20-
dimModHeight
15+
options.dimModHeight
2116
);
2217
this._rotatePart(elem, cesgeo, options);
2318
}

src/service/3DPlot/Primitive/ElementInstance/RegularLine1ElementInstance.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
22
* @Author: your name
33
* @Date: 2021-10-25 10:26:48
4-
* @LastEditTime: 2022-05-18 20:29:50
5-
* @LastEditors: zk
4+
* @LastEditTime: 2022-03-31 14:41:20
5+
* @LastEditors: Do not edit
66
* @Description: In User Settings Edit
77
* @FilePath: \MapGISPlotBase\src\3DPlot\Primitive\ElementInstance\RegularLine1ElementInstance.js
88
*/
@@ -12,21 +12,21 @@ import MainElement from "../../../../service/PlotBase/SvgLoader/element/extend/M
1212
import RegularLineElementInstance from "./RegularLineElementInstance";
1313

1414
export default class RegularLine1ElementInstance extends RegularLineElementInstance {
15-
pathElemToWallGeomInstance(pathElem, options, sampleHeights) {
15+
pathElemToWallGeomInstance(pathElem, options) {
1616
if (!(pathElem instanceof MainElement)) return undefined;
17-
return super.pathElemToWallGeomInstance(pathElem, options, sampleHeights);
17+
return super.pathElemToWallGeomInstance(pathElem, options);
1818
}
1919

2020
transfromGeoCesium(elem, cesgeo, options) {
2121
super.transfromGeoCesium(elem, cesgeo, options);
2222
const {dimModAttitude}=options
23-
if (dimModAttitude === 1 && elem.getAttitude()){
23+
if (dimModAttitude === 1){
2424
this._rotatePart(elem, cesgeo, options);
2525
}
2626
}
2727

2828
_rotatePart(ele, cesGeom, options) {
29-
let { dimModHeight } = options;
29+
const { dimModHeight } = options;
3030
if (ele instanceof MainElement) return;
3131

3232
if (!ele._dimModal.is3DTran()) return;
@@ -42,10 +42,6 @@ export default class RegularLine1ElementInstance extends RegularLineElementInsta
4242
translatePoint.y
4343
);
4444

45-
//这个地方控制抬起高度,贴地或贴模型时抬高高度为0
46-
if(typeof this._classificationType === 'number' && this._classificationType >= 0){
47-
dimModHeight = 0;
48-
}
4945
const originPnt = Cesium.Cartesian3.fromDegreesArrayHeights([
5046
t.x,
5147
t.y,

0 commit comments

Comments
 (0)