MapImageLayer - 标签子图层的要素
这个例子演示了如何在 MapImageLayer 子图层 中标记要素。当 labelsVisible 属性设置为 true
并且 labelingInfo 属性包含至少一个 LabelClass 时应用标签,它定义了标签表达式、位置和符号属性。
请参阅 标签指南页面 了解更多信息和已知的限制。
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
const layer = new MapImageLayer({
url: "https://sampleserver6.geosceneonline.cn/arcgis/rest/services/USA/MapServer",
sublayers: [
{
id: 2,
// labelingInfo autocasts to an array of LabelClass objects
// this sublayer has two label classes. The first sets the
// label as the state abbreviation at small scales. When the view
// zooms to larger scales the whole state name is used instead
labelingInfo: [
{
labelExpression: "[state_abbr]",
labelPlacement: "always-horizontal",
symbol: {
type: "text", // autocasts as new TextSymbol()
color: [255, 255, 255, 0.85],
font: {
size: 16,
weight: "bolder"
}
},
minScale: 18500000,
maxScale: 9250000
},
{
labelExpression: "[state_name]",
labelPlacement: "always-horizontal",
symbol: {
type: "text", // autocasts as new TextSymbol()
color: [255, 255, 255, 0.85],
haloColor: "gray",
haloSize: 1,
font: {
size: 14,
weight: "bold"
}
},
minScale: 9250000,
maxScale: 2400000
}
]
}
]
});