|
@@ -1,6 +1,10 @@
|
|
|
import FeatureLayer from "@arcgis/core/layers/FeatureLayer.js";
|
|
|
import Graphic from "@arcgis/core/Graphic.js";
|
|
|
import Polygon from "@arcgis/core/geometry/Polygon.js";
|
|
|
+import GraphicsLayer from "@arcgis/core/layers/GraphicsLayer.js";
|
|
|
+import Polyline from "@arcgis/core/geometry/Polyline.js";
|
|
|
+import {SimpleLineSymbol, TextSymbol} from "@arcgis/core/symbols.js";
|
|
|
+import Point from "@arcgis/core/geometry/Point.js";
|
|
|
|
|
|
class FeaturePolygonPlottingEvent {
|
|
|
constructor(options) {
|
|
@@ -8,10 +12,16 @@ class FeaturePolygonPlottingEvent {
|
|
|
this.data = options.data;
|
|
|
this.id =options.id;
|
|
|
this.featureLayer = null;
|
|
|
+ this.graphicsLayer = null;
|
|
|
+ this.showText = options.showText;
|
|
|
this.add();
|
|
|
}
|
|
|
add() {
|
|
|
let resultPolygonGraphics = [];
|
|
|
+
|
|
|
+ let resultLineGraphics = [];
|
|
|
+ let resultTextGraphics = [];
|
|
|
+
|
|
|
this.data.forEach((item) => {
|
|
|
let rings = new Polygon({
|
|
|
type: "polygon",
|
|
@@ -25,10 +35,70 @@ class FeaturePolygonPlottingEvent {
|
|
|
}
|
|
|
});
|
|
|
resultPolygonGraphics.push(graphic);
|
|
|
+
|
|
|
+ if(this.showText){
|
|
|
+ let textPoint = new Point({
|
|
|
+ x: 5804,
|
|
|
+ y: 1697,
|
|
|
+ z: item.symbol.height + item.symbol.size/2,
|
|
|
+ spatialReference: this.view.spatialReference
|
|
|
+ });
|
|
|
+ // 添加三维注释
|
|
|
+ let textSymbol = new TextSymbol({
|
|
|
+ text: item.symbol.height +"--"+ (item.symbol.height + item.symbol.size) * 1 ,
|
|
|
+ font: {
|
|
|
+ size: 14,
|
|
|
+ family: "Arial",
|
|
|
+ weight: "bold"
|
|
|
+ },
|
|
|
+ haloColor: "black",
|
|
|
+ haloSize: "2px",
|
|
|
+ color: "#FFD700", // 金色字体
|
|
|
+ backgroundColor: "rgba(0, 0, 0, 0.7)", // 添加半透明黑色背景
|
|
|
+ verticalAlignment: "middle",
|
|
|
+ horizontalAlignment: "left",
|
|
|
+ callout: {
|
|
|
+ type: "line", // 使用线条作为标注
|
|
|
+ color: "#FFD700", // 金色线条
|
|
|
+ border: { color: "black", width: 1 }, // 边框
|
|
|
+ size: 1.5
|
|
|
+ },
|
|
|
+ screenOffset: {
|
|
|
+ x: 10, // 偏移到右边
|
|
|
+ y: 0
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ let textGraphic = new Graphic({
|
|
|
+ geometry: textPoint,
|
|
|
+ symbol: textSymbol
|
|
|
+ });
|
|
|
+ resultTextGraphics.push(textGraphic);
|
|
|
+
|
|
|
+ // 添加对应的线
|
|
|
+ let polyline = new Polyline({
|
|
|
+ paths: [
|
|
|
+ [5412, 2331,item.symbol.height + item.symbol.size/2],
|
|
|
+ [5804,1697,item.symbol.height + item.symbol.size/2]
|
|
|
+ ],
|
|
|
+ spatialReference: this.view.spatialReference
|
|
|
+ });
|
|
|
+ let lineSymbol = new SimpleLineSymbol({
|
|
|
+ color: "#FFD700", // 与文字匹配的金色
|
|
|
+ width: 2, // 线条宽度
|
|
|
+ style: "short-dot" // 虚线样式
|
|
|
+ });
|
|
|
+ let lineGraphic = new Graphic({
|
|
|
+ geometry: polyline,
|
|
|
+ symbol: lineSymbol
|
|
|
+ });
|
|
|
+ resultLineGraphics.push(lineGraphic);
|
|
|
+ }
|
|
|
+
|
|
|
});
|
|
|
|
|
|
this.featureLayer = new FeatureLayer({
|
|
|
- id: this.id,
|
|
|
+ id: this.id + "_polygon",
|
|
|
title: "面标绘",
|
|
|
source: resultPolygonGraphics, // 数据源
|
|
|
objectIdField: "FID", // 必须字段,定义唯一标识
|
|
@@ -63,14 +133,28 @@ class FeaturePolygonPlottingEvent {
|
|
|
},
|
|
|
elevationInfo: { mode: "relative-to-ground" }, // 相对于地面高度
|
|
|
});
|
|
|
-
|
|
|
this.view.map.add(this.featureLayer);
|
|
|
+ this.graphicsLayer = new GraphicsLayer({
|
|
|
+ id: this.id + "_text",
|
|
|
+ title: "面标注",
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+ this.graphicsLayer.addMany(resultTextGraphics);
|
|
|
+ this.graphicsLayer.addMany(resultLineGraphics);
|
|
|
+
|
|
|
+ this.view.map.add(this.graphicsLayer);
|
|
|
+
|
|
|
}
|
|
|
clear() {
|
|
|
if (this.featureLayer) {
|
|
|
this.view.map.remove(this.featureLayer);
|
|
|
this.featureLayer = null;
|
|
|
}
|
|
|
+ if (this.graphicsLayer) {
|
|
|
+ this.view.map.remove(this.graphicsLayer);
|
|
|
+ this.graphicsLayer = null;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
export default FeaturePolygonPlottingEvent;
|