generated from arnofiva/arcgis-core-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTransformedRegion.ts
129 lines (111 loc) · 3.19 KB
/
TransformedRegion.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import Accessor from "@arcgis/core/core/Accessor";
import {
property,
subclass,
} from "@arcgis/core/core/accessorSupport/decorators";
import Handles from "@arcgis/core/core/Handles";
import Point from "@arcgis/core/geometry/Point";
import Polygon from "@arcgis/core/geometry/Polygon";
import Graphic from "@arcgis/core/Graphic";
import ObjectSymbol3DLayer from "@arcgis/core/symbols/ObjectSymbol3DLayer";
import PointSymbol3D from "@arcgis/core/symbols/PointSymbol3D";
import TextSymbol3DLayer from "@arcgis/core/symbols/TextSymbol3DLayer";
import { countryLabel, graphicFromCountry } from "./countryUtils";
import { view } from "./globals";
import PolygonTransform from "./PolygonTransform";
import SelectedRegion from "./SelectedRegion";
const polygonTransform = new PolygonTransform(view);
interface TransformedRegionProps {
selection: SelectedRegion;
}
const centerSymbol = new PointSymbol3D({
symbolLayers: [
new ObjectSymbol3DLayer({
material: {
color: [0, 0, 0, 0],
},
width: 5_000,
height: 5_000,
depth: 5_000,
resource: {
primitive: "diamond",
},
}),
],
});
@subclass("TrueSize.TransformedRegion")
export default class TransformedRegion extends Accessor {
@property({ constructOnly: true })
selection: SelectedRegion;
@property()
graphic: Graphic;
@property()
center = new Graphic({
symbol: centerSymbol,
});
@property()
label: Graphic;
@property({ readOnly: true })
get angle() {
const symbol = this.center.symbol as PointSymbol3D;
const symbolLayer = symbol.symbolLayers.getItemAt(0) as ObjectSymbol3DLayer;
return symbolLayer.heading;
}
@property()
private handlers = new Handles();
constructor(props: TransformedRegionProps) {
super(props);
const color = props.selection.color;
const region = (this.graphic = graphicFromCountry(
props.selection.graphic,
view,
color
));
const centroid = (region.geometry as Polygon).centroid;
this.center.geometry = centroid;
const text = countryLabel(props.selection.graphic);
const halo = color.main.clone();
halo.a = 0.7;
this.label = new Graphic({
geometry: centroid.clone(),
symbol: new PointSymbol3D({
symbolLayers: [
new TextSymbol3DLayer({
text,
material: {
color: [255, 255, 255, 0.9], //outlineColor
},
halo: {
size: 0.5,
color: color.dark, // [0, 0, 0, 0.8]
},
font: {
size: 12,
},
}),
],
}),
});
this.handlers.add(
this.watch("center.geometry", (center: Point) => {
this.graphic.geometry = polygonTransform.moveTo(
this.graphic.geometry as Polygon,
center
);
this.label.geometry = center;
})
);
this.handlers.add(
this.watch("angle", (newAngle: number, oldAngle = 0) => {
const rad = ((oldAngle - newAngle) * Math.PI) / 180;
this.graphic.geometry = polygonTransform.rotate(
this.graphic.geometry as Polygon,
rad
);
})
);
}
destroy(): void {
this.handlers.removeAll();
}
}