arcgis for javascript在FeatureLayer上添加文本信息

方法一:

 1      //创建图形曾
 2         var graphicsLayer = new GraphicsLayer();
 3         //创建文本符号
 4         var textSymbol = new TextSymbol();
 5         //文本的内容的实在
 6         textSymbol = {
 7             type: "text",
 8             text: "姓名:张三",
 9             //字体设置
10             font: {
11                 family: "Merriweather",
12                 size: 12,
13                 style: "italic",
14                 weight: "bold",
15             },
16         };
17         //创建图形,设置图形的经纬度和文本内容
18         var graphic = new Graphic(new Point(97.88486481, 23.97676849), textSymbol);
19         //形将显示在‎‎图形图层‎‎中。‎
20         graphicsLayer.add(graphic);
21         view.map.add(graphicsLayer);

方法二:

 1       //为图层上的标注定义标注表达式、符号、比例范围、标注优先级和标注放置选项
 2         const statesLabelClass = new LabelClass({
 3             // 显示文本内容
 4             labelExpressionInfo: {
 5                 expression:
 6                     '"姓名:" + $feature.xm +\n"\\n性别:" + $feature.xb +\n"\\n学历:" + $feature.xl '
 7             },
 8             // 标注所在位置
 9             labelPlacement: "above-left",
10             // 符号设置,文字设置
11             symbol: {
12                 type: "text", // autocasts as new TextSymbol()
13                 color: "red",
14                 // haloSize: 1,
15                 haloColor: "white",
16                 // 调整多行文本的水平对齐方式。
17                 horizontalAlignment: "left",
18                 // 调整文本的垂直对齐方式。
19                 verticalAlignment: "middle",
20             },
21         });
22         // FeatureLayer的labelingInfo存放此图层的标注信息
23         featureLayer.labelingInfo = [statesLabelClass];

 

posted @ 2022-02-19 21:31  写前端的扛把子  阅读(459)  评论(0)    收藏  举报