方法一:
//创建图形曾
var graphicsLayer = new GraphicsLayer();
//创建文本符号
var textSymbol = new TextSymbol();
//文本的内容的实在
textSymbol = {
type: "text",
text: "姓名:张三",
//字体设置
font: {
family: "Merriweather",
size: 12,
style: "italic",
weight: "bold",
},
};
//创建图形,设置图形的经纬度和文本内容
var graphic = new Graphic(new Point(97.88486481, 23.97676849), textSymbol);
//形将显示在图形图层中。
graphicsLayer.add(graphic);
view.map.add(graphicsLayer);
方法二:
//为图层上的标注定义标注表达式、符号、比例范围、标注优先级和标注放置选项
const statesLabelClass = new LabelClass({
// 显示文本内容
labelExpressionInfo: {
expression:
'"姓名:" + $feature.xm +\n"\\n性别:" + $feature.xb +\n"\\n学历:" + $feature.xl '
},
// 标注所在位置
labelPlacement: "above-left",
// 符号设置,文字设置
symbol: {
type: "text", // autocasts as new TextSymbol()
color: "red",
// haloSize: 1,
haloColor: "white",
// 调整多行文本的水平对齐方式。
horizontalAlignment: "left",
// 调整文本的垂直对齐方式。
verticalAlignment: "middle",
},
});
// FeatureLayer的labelingInfo存放此图层的标注信息
featureLayer.labelingInfo = [statesLabelClass];