mirror of
https://github.com/ethan-zf/cesium-plot-js.git
synced 2025-06-24 03:27:29 +00:00
add polygon
This commit is contained in:
parent
996b545edf
commit
ad33236562
@ -66,6 +66,9 @@ const buttonGroup = document.getElementById('button-group') as HTMLElement;
|
|||||||
buttonGroup.onclick = (evt) => {
|
buttonGroup.onclick = (evt) => {
|
||||||
const targetElement = evt.target as HTMLElement;
|
const targetElement = evt.target as HTMLElement;
|
||||||
switch (targetElement.id) {
|
switch (targetElement.id) {
|
||||||
|
case 'drawPolygon':
|
||||||
|
geometry = new CesiumPlot.Polygon(Cesium, viewer);
|
||||||
|
break;
|
||||||
case 'drawReactangle':
|
case 'drawReactangle':
|
||||||
geometry = new CesiumPlot.Reactangle(Cesium, viewer);
|
geometry = new CesiumPlot.Reactangle(Cesium, viewer);
|
||||||
break;
|
break;
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
<div id="root"></div>
|
<div id="root"></div>
|
||||||
<div id="cesiumContainer"></div>
|
<div id="cesiumContainer"></div>
|
||||||
<div class="button-container" id="button-group">
|
<div class="button-container" id="button-group">
|
||||||
|
<button id="drawPolygon">多边形</button>
|
||||||
<button id="drawReactangle">矩形</button>
|
<button id="drawReactangle">矩形</button>
|
||||||
<button id="drawTriangle">三角形</button>
|
<button id="drawTriangle">三角形</button>
|
||||||
<button id="drawStraightArrow">细直箭头</button>
|
<button id="drawStraightArrow">细直箭头</button>
|
||||||
|
@ -14,6 +14,7 @@ import Ellipse from './polygon/ellipse';
|
|||||||
import Lune from './polygon/lune';
|
import Lune from './polygon/lune';
|
||||||
import Reactangle from './polygon/rectangle';
|
import Reactangle from './polygon/rectangle';
|
||||||
import Triangle from './polygon/triangle';
|
import Triangle from './polygon/triangle';
|
||||||
|
import Polygon from './polygon/polygon';
|
||||||
|
|
||||||
const CesiumPlot = {
|
const CesiumPlot = {
|
||||||
FineArrow,
|
FineArrow,
|
||||||
@ -31,7 +32,8 @@ const CesiumPlot = {
|
|||||||
Ellipse,
|
Ellipse,
|
||||||
Lune,
|
Lune,
|
||||||
Reactangle,
|
Reactangle,
|
||||||
Triangle
|
Triangle,
|
||||||
|
Polygon,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default CesiumPlot;
|
export default CesiumPlot;
|
||||||
|
56
src/polygon/polygon.ts
Normal file
56
src/polygon/polygon.ts
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
import Base from '../base';
|
||||||
|
// @ts-ignore
|
||||||
|
import { Cartesian3 } from '@examples/cesium';
|
||||||
|
|
||||||
|
import { PolygonStyle } from '../interface';
|
||||||
|
|
||||||
|
export default class Polygon extends Base {
|
||||||
|
points: Cartesian3[] = [];
|
||||||
|
|
||||||
|
constructor(cesium: any, viewer: any, style?: PolygonStyle) {
|
||||||
|
super(cesium, viewer, style);
|
||||||
|
this.cesium = cesium;
|
||||||
|
this.setState('drawing');
|
||||||
|
this.onDoubleClick();
|
||||||
|
}
|
||||||
|
|
||||||
|
getType(): 'polygon' | 'line' {
|
||||||
|
return 'polygon';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add points only on click events
|
||||||
|
*/
|
||||||
|
addPoint(cartesian: Cartesian3) {
|
||||||
|
this.points.push(cartesian);
|
||||||
|
if (this.points.length === 1) {
|
||||||
|
this.onMouseMove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw a shape based on mouse movement points during the initial drawing.
|
||||||
|
*/
|
||||||
|
updateMovingPoint(cartesian: Cartesian3) {
|
||||||
|
const tempPoints = [...this.points, cartesian];
|
||||||
|
this.setGeometryPoints(tempPoints);
|
||||||
|
if (tempPoints.length === 2) {
|
||||||
|
this.addFirstLineOfTheArrow();
|
||||||
|
} else {
|
||||||
|
this.drawPolygon();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In edit mode, drag key points to update corresponding key point data.
|
||||||
|
*/
|
||||||
|
updateDraggingPoint(cartesian: Cartesian3, index: number) {
|
||||||
|
this.points[index] = cartesian;
|
||||||
|
this.setGeometryPoints(this.points);
|
||||||
|
this.drawPolygon();
|
||||||
|
}
|
||||||
|
|
||||||
|
getPoints() {
|
||||||
|
return this.points;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user