标注 有助于标识要素,建立重要要素的视觉层次结构,并将用户的注意力集中在地图的目的上。标注选项和功能(如标注放置和可用字体)因图层类型、几何类型和视图类型(2D 或 3D)而异。
本指南页面将展示基于这些不同属性和字体的可能标注场景。底部的常见问题解答 包含有关有用工作流的信息以及常见问题的答案。此外,本指南页面将探讨相邻标注用例,如 TextSymbol 和 TextSymbol3DLayer 中的文本,以使用 symbolUtils.renderPreviewHTML 进行文本符号预览,以及打印 注意事项。
2D MapView 标注 在 2D MapViews 中,FeatureLayer 、CSVLayer 、GeoJSONLayer 、StreamLayer 、OGCFeatureLayer 和 WFSLayer 均支持标注。labelingInfo 属性被指定为 LabelClass 对象数组,其中包含 labelExpressionInfo 、labelPlacement 和 TextSymbol。TextSymbol 类支持更改标注图形的 color 、font 、halo 和其他属性。点、折线和面均支持标注。
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
const labelClass = { // autocasts as new LabelClass()
symbol : {
type : "text" , // autocasts as new TextSymbol()
color : "white" ,
haloColor : "blue" ,
haloSize : 1 ,
font : { // autocast as new Font()
family : "Noto Sans" ,
size : 14
}
},
labelPlacement : "above-right" ,
labelExpressionInfo : {
expression : "$feature.Team + TextFormatting.NewLine + $feature.Division"
},
maxScale : 0 ,
minScale : 25000000 ,
where : "Conference = 'AFC'"
};
const labelLayer = new FeatureLayer({
portalItem : { // autocasts as new PortalItem()
id : "7f0bfc7bf67a407d8efebf584f6d956d"
},
labelingInfo : [labelClass]
});
3D SceneView 标注 所有具有 labelingInfo 属性的图层类型 (例如 FeatureLayer 和 SceneLayer ) 均支持标注。此属性被指定为 LabelClass 对象数组,其中包含 labelExpressionInfo 、labelPlacement 和 TextSymbol3DLayer 。TextSymbol3DLayer 类支持更改标注图形的 material 、font 、halo 和其他属性。
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
const labelClass = { // autocasts as new LabelClass()
symbol : {
type : "label-3d" , // autocasts as new LabelSymbol3D()
symbolLayers : [
{
type : "text" , // autocasts as new TextSymbol3DLayer()
material : {
color : "purple"
},
font : { // autocasts as new Font()
family : "Just Another Hand" ,
weight : bold
},
size : 22
}
]
},
labelPlacement : "below-center" ,
labelExpressionInfo : {
expression : 'DefaultValue($feature.CITY_NAME, "no data")'
}
};
const labelLayer = new FeatureLayer({
url : “url” ,
labelingInfo : [labelClass]
});
字体 通常,您无需关心字体文件的托管位置或使用的文件类型。但是,如果您正在使用自定义字体或在断开连接的环境中工作,则建议您阅读整个部分。有不同类型的字体文件可用于标注,这些文件可从不同的位置访问,具体取决于类、图层类型以及您是在 2D 还是 3D 中工作。字体有多种使用方式:
来自 https: //doc.geoscene.cn/resources/fonts
的 pbf
格式文件 来自 https: //doc.geoscene.cn/resources/fonts/woff2
的 woff2
格式文件 以 pbf
、otf
、ttf
、woff
或 woff2
格式从服务器引用 来自用户计算机和 web 浏览器上的字体 MapImageLayer 字体 MapImageLayer 字体来自 web 浏览器或用户计算机。
通过在 Sublayer 类上设置 labelingInfo 属性,MapImageLayer 可支持标注。labelingInfo 属性被指定为 LabelClass 对象数组,其中包含 labelExpression 、labelPlacement 和 TextSymbol 。TextSymbol 类支持更改标注图形的 color 、font 、halo 和其他属性。点、折线和面均支持标注。
MapView 中 MapImageLayers 支持的字体系列 取决于安装在用于发布图层的 GeoScene Server 上的字体。2D MapViews 和 3D SceneViews 也是如此。要检查 GeoScene Server 上的可用字体,请运行 Home > services > System > Publishing Tools (GPServer)
下的 Available Fonts
任务 (需要管理员访问)。要添加新字体,该字体必须安装在您的计算机上,并可通过使用 GeoScene Desktop 注册它来访问 GeoScene Server。如果应用程序使用了未安装的字体,则 Font 类将实现一个回退机制,该机制将使用默认字体系列 值,即 sans-serif
。
非 MapImageLayer 字体 对 Font.family 、Font.style 和 Font.weight 属性的支持基于字体文件。我们在 https: //doc.geoscene.cn/resources/fonts
上托管了许多字体,可以方便地访问这些字体以进行标注。
如果 Font 不可用,则将使用默认字体系列 sans-serif
。这使用 Arial Unicode MS
字体文件。具有粗体或斜体的字体需要在 Font.style 和 Font.weight 属性中设置这些属性,而不是在 Font.family 中进行设置。要查看字体所支持的字符类型 (例如 Latin、Cyrillic、CJKV),可在 Microsoft Typography 中搜索字体名称。
可进行标注的非 MapImageLayer 图层: CSVLayer、FeatureLayer、GeoJSONLayer、OGCFeatureLayer、StreamLayer、WFSLayer。
当前托管在 https: //doc.geoscene.cn/resources/fonts
中的字体列表使用 pbf
和 woff2
格式 (目前,Palatino Linotype Regular 仅在 pbf
中可用):
字体 预览 代码 Abril Fatface Regular 复制 Alegreya Bold 复制 Alegreya Bold Italic 复制 Alegreya Italic 复制 Alegreya Regular 复制 Alegreya SC Bold 复制 Alegreya SC Italic 复制 Alegreya SC Regular 复制 Alegreya Sans Italic 复制 Amarante Regular 复制 Amatic SC Bold 复制 Arial Bold 复制 Arial Bold Italic 复制 Arial Italic 复制 Arial Regular 复制 Arial Unicode MS Bold 复制 Arial Unicode MS Regular 复制 Atomic Age Regular 复制 Audiowide Regular 复制 Avenir Next LT Pro Bold 复制 Avenir Next LT Pro Bold Italic 复制 Avenir Next LT Pro Demi Italic 复制 Avenir Next LT Pro Italic 复制 Avenir Next LT Pro Light 复制 Avenir Next LT Pro Light Italic 复制 Avenir Next LT Pro Medium Bold 复制 Avenir Next LT Pro Medium Bold Italic 复制 Avenir Next LT Pro Regular 复制 Avenir Next LT Pro Regular Bold 复制 BellTopo Sans Bold 复制 BellTopo Sans Bold Italic 复制 BellTopo Sans Italic 复制 BellTopo Sans Regular 复制 Belleza Regular 复制 Black Ops One Regular 复制 Cabin Sketch Bold 复制 Cabin Sketch Regular 复制 Coming Soon Regular 复制 FGDC GeoAge Regular 复制 Homemade Apple Regular 复制 IM FELL DW Pica PRO Italic 复制 IM FELL DW Pica PRO Regular 复制 Josefin Sans Regular 复制 Josefin Sans Semibold Italic 复制 Josefin Slab Bold 复制 Josefin Slab Bold Italic 复制 Josefin Slab Italic 复制 Josefin Slab Light Italic 复制 Josefin Slab Regular 复制 Josefin Slab Thin Italic 复制 Just Another Hand Regular 复制 Kranky Regular 复制 Life Savers Bold 复制 Loved by the King Regular 复制 Merriweather Bold 复制 Merriweather Bold Italic 复制 Merriweather Italic 复制 Merriweather Regular 复制 Montserrat Bold 复制 Montserrat Italic 复制 Montserrat Medium Italic 复制 Montserrat Regular 复制 Montserrat Semibold Italic 复制 Noto Sans Bold 复制 Noto Sans Bold Italic 复制 Noto Sans Italic 复制 Noto Sans Regular 复制 Noto Serif Bold 复制 Noto Serif Bold Italic 复制 Noto Serif Italic 复制 Noto Serif Regular 复制 Old Standard TT Bold 复制 Old Standard TT Italic 复制 Old Standard TT Regular 复制 Orbitron Bold 复制 Orbitron Regular 复制 Oregano Italic 复制 Oregano Regular 复制 Oswald Bold 复制 Oswald Regular 复制 Pacifico Regular 复制 Palatino Linotype Regular 复制 Playfair Display Black 复制 Playfair Display Bold 复制 Playfair Display Bold Italic 复制 Playfair Display Italic 复制 Playfair Display Regular 复制 Playfair Display SC Bold 复制 Playfair Display SC Regular 复制 Redressed Regular 复制 Risque Regular 复制 Roboto Bold 复制 Roboto Bold Italic 复制 Roboto Condensed Italic 复制 Roboto Condensed Light Italic 复制 Roboto Italic 复制 Roboto Regular 复制 Rye Regular 复制 Special Elite Regular 复制 Syncopate Bold 复制 Syncopate Regular 复制 Tangerine Regular 复制 Ubuntu Bold 复制 Ubuntu Bold Italic 复制 Ubuntu Condensed Regular 复制 Ubuntu Italic 复制 Ubuntu Light 复制 Ubuntu Light Bold 复制 Ubuntu Light Bold Italic 复制 Ubuntu Light Italic 复制 Ubuntu Medium Italic 复制 Ubuntu Mono Bold 复制 Ubuntu Mono Bold Italic 复制 Ubuntu Mono Italic 复制 Ubuntu Mono Regular 复制 Ubuntu Regular 复制 UnifrakturCook Bold 复制 Vast Shadow Regular 复制 Walter Turncoat Regular 复制
预览: SceneView 字体 3D SceneViews 支持的字体系列 取决于 (按优先级顺序):安装在用户计算机和 Web 浏览器上的字体,然后是 https: //doc.geoscene.cn/resources/fonts/woff2
中的字体或从服务器引用的字体。如果应用程序使用了未安装在用户计算机和 web 浏览器上的字体,则应用程序将搜索托管字体。如果字体 不可用,则 Font 类将实现一个回退机制,该机制将使用默认字体系列 值,即 sans-serif
。有关如何在 Windows 或 Mac 上安装新字体的说明,请参阅这些参考资料。
注意,这些字体也适用于 TextSymbol3DLayer ,无论是将其用作 3D SceneView 中的图形还是用作标注。
本地未安装的字体也可通过在 css 文件中定义 @font-face 来从 url 加载。
1
2
3
4
5
6
7
@font-face {
font-family : "MyFont" ;
font-style : normal;
font-weight : 400 ;
font-display : auto;
src : url ( "./my-font.ttf" ) format ( "truetype" );
}
并从符号图层的 Font.family 属性中引用它:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const labelSymbol = {
type : "label-3d" , // autocasts as new LabelSymbol3D
symbolLayers : [
{
type : "text" , // autocasts as new TextSymbol3DLayer()
material : {
color : [ 0 , 0 , 0 , 0.8 ]
},
font : {
size : 30 ,
family : "MyFont"
}
}
]
}
默认情况下,字体也可从 https: //doc.geoscene.cn/resources/fonts/woff2
进行引用:
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
const labelClass = { // autocasts as new LabelClass()
symbol : {
type : "label-3d" , // autocasts as new LabelSymbol3D()
symbolLayers : [
{
type : "text" , // autocasts as new TextSymbol3DLayer()
material : {
color : "black"
},
halo : {
color : [ 255 , 255 , 255 , 0.7 ],
size : 2
},
font : {
family : "Noto Sans"
},
size : 10
}
]
},
labelPlacement : "above-right" ,
labelExpressionInfo : {
expression : `$feature.NAME + TextFormatting.NewLine + Text($feature.HOEHE, "#,### m")`
}
};
const labelLayer = new FeatureLayer({
url : "url" ,
elevationInfo : {
mode : "relative-to-ground"
},
labelingInfo : [labelClass]
});
自定义字体和断开连接的环境 在 2D MapViews 中,对于所有非 MapImageLayer 图层和 TextSymbol,使用的字体文件为 pbf
,对于 renderPreviewHTML,使用的是 woff2
。
在 3D SceneViews 中,对于所有非 MapImageLayer 图层和 TextSymbol3DLayer,使用的字体文件为 ttf
、otf
、woff
或 woff2
格式,对于 renderPreviewHTML,使用的是 woff2
。此外,对于 3D SceneViews,字体文件来自 https: //doc.geoscene.cn/resources/fonts
,且仅使用 woff2
格式。
默认情况下,可用字体大多与 GeoScene 矢量底图使用的字体相同。 这些字体可通过 https: //doc.geoscene.cn/resources/fonts
获得。应用程序需要访问该 URL 才能渲染标注。如果此 URL 不可访问 (例如,断开网络连接或在离线环境中),或者使用的字体未托管在其中,则可通过设置 geosceneConfig.fontsUrl 属性将 fonts Url
配置为指向您自己的字体文件。这些字体文件必须是正确的文件类型才能显示。请参考下表,查看所需的字体文件类型,具体取决于所使用的类以及是在 2D 还是 3D 环境中工作。
视图 应用于 字体源 2D & 3D MapImageLayer 用户的计算机和 web 浏览器 (ttf
、otf
、woff
或 woff2
格式) 2D & 3D renderPreviewHTML https: //doc.geoscene.cn/resources/fonts/woff2
(woff2
格式) 托管在服务器上 (woff2
格式)2D MapView 非 MapImageLayer https: //doc.geoscene.cn/resources/fonts
(pbf
格式) 托管在服务器上 (pbf
格式)3D SceneView 非 MapImageLayer 用户的计算机和 web 浏览器 https: //doc.geoscene.cn/resources/fonts/woff2
(woff2
格式) 引用自服务器 (ttf
、otf
、woff
或 woff2
格式)
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
geosceneConfig.fontsUrl = "https://myserver.com/fonts" ; // reference fonts from a server in `pbf`
const labelClass = { // autocasts as new LabelClass()
symbol : {
type : "text" , // autocasts as new TextSymbol()
color : "white" ,
haloColor : "blue" ,
haloSize : 1 ,
font : { // autocast as new Font()
family : "Wes Welker" ,
size : 83
}
},
labelPlacement : "above-right" ,
labelExpressionInfo : {
expression : "$feature.Team + TextFormatting.NewLine + $feature.Division"
},
maxScale : 0 ,
minScale : 25000000 ,
where : "Conference = 'AFC'"
};
const labelLayer = new FeatureLayer({
portalItem : { // autocasts as new PortalItem()
id : "7f0bfc7bf67a407d8efebf584f6d956d"
},
labelingInfo : [labelClass]
});
备选标注方案 此外,本指南页面将探讨相邻标注用例。标注工作流不会以标注图层结束。还有其他标注要素的方法,以及这些标注要素的其他应用程序注意事项。
TextSymbol 和 TextSymbol3DLayer TextSymbol 和 TextSymbol3DLayer 都是典型标注工作流的一部分,也可用于其他标注体验。这些符号本身可以用作单独的标注,标注的字体和文本表示可视化。
以下是使用格式化文本将 TextSymbol 添加到 2D MapView 的示例:
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
const textSymbol = {
type : "text" , // autocasts as new TextSymbol()
color : "blue" ,
haloColor : "red" ,
haloSize : "1px" ,
text : "Wish you were here" ,
xoffset : 3 ,
yoffset : 3 ,
font : { // autocasts as new Font()
size : 12 ,
family : "Orbitron" ,
weight : "bold"
}
};
const point = {
type : "point" , // autocasts as new Point()
longitude : - 71.26 ,
latitude : 42.09
};
const pointGraphic = new Graphic({
geometry : point,
symbol : textSymbol
});
view.graphics.add(pointGraphic);
以下是使用格式化文本将 TextSymbol3DLayer 添加到 3D SceneView 的示例:
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
const textSymbol3D = {
type : "point-3d" , // autocasts as new PointSymbol3D()
symbolLayers : [{
type : "text" , // autocasts as new TextSymbol3DLayer()
font : { // autocasts as new Font()
size : 12 ,
family : "Just Another Hand"
},
text : "Wish I was here" ,
material : {
color : "green"
},
size : 12
}]
};
const point = {
type : "point" , // autocasts as new Point()
longitude : - 71.26 ,
latitude : 42.09
};
const pointGraphic3D = new Graphic({
geometry : point,
symbol : threeDpoint
});
view.graphics.add(pointGraphic3D);
GeoScene 图标字体 GeoScene 图标字体 可以用作某些图层的 LabelClass 的 font.family 属性。在以下代码片段中,通过将符号 类型自动转换为 text
、color 和 font 来创建 LabelClass。最后,定义了 labelPlacement 和 labelExpressionInfo 。
可使用 GeoScene 图标字体标注的图层: CSVLayer、FeatureLayer、GeoJSONLayer、OGCFeatureLayer、StreamLayer、WFSLayer。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const labelClass = { // autocasts as new LabelClass()
symbol : {
type : 'text' , // autocasts as new TextSymbol()
color : 'green' ,
font : { // autocast as new Font()
family : 'CalciteWebCoreIcons' ,
size : 12
}
},
labelPlacement : 'above-left' ,
labelExpressionInfo : {
expression : '"\ue61d"' // geoscene-icon-map-pin
}
};
const fl = new FeatureLayer({
url : "url" ,
labelingInfo : labelClass
});
renderPreviewHTML symbolUtils 类用于生成符号的较小预览图像。当工作流需要显示符号 (用于表示图层中要素) 的较小预览时,此实用程序非常有用。renderPreviewHTML() 方法可生成给定符号的预览图像,该图像可以显示在自定义微件或其他 DOM 元素中,包括标注。此标注的字体文件 (woff2
格式) 来自我们的托管字体文件,或者托管在服务器上 (如果通过 geosceneConfig.fontsUrl 使用不同的源)。
打印 打印 带有标注的地图时,需要注意以下几点 (当前仅 2D MapViews 中支持打印)。当前不支持在旋转地图时打印旋转标注。 打印服务必须能够访问字体文件的源,标注才能显示在打印的地图中,因此,如果文件托管在专用服务器上,则打印服务也必须能够访问该专用服务器。
常见问题解答 此常见问题解答包含有关有用工作流的信息以及常见问题的答案!
如何在标注中创建新行? 可以使用模板文字 将标注分隔为多行。此处,MARKER_ACTIVITY 将在第一行上,RECAREANAM 将在新的行上。示例:
1
2
3
4
5
// template literal
"$feature.MARKER_ACTIVITY + '\\n' + $feature.RECAREANAM"
// TextFormatting.NewLine
"$feature.MARKER_ACTIVITY + TextFormatting.NewLine + $feature.RECAREANAM"