ArcGIS API for Silverlight 之ElementLayer使用及TextSymbol的模板使用

2024-03-17 12:48

本文主要是介绍ArcGIS API for Silverlight 之ElementLayer使用及TextSymbol的模板使用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

在开发中动态在地图上添加文字信息,可以使用TextSymbol添加文字

//动态添加文本
TextSymbol textSymbol = new TextSymbol()
{
FontFamily = new System.Windows.Media.FontFamily("Microsoft YaHei"),
Foreground = new System.Windows.Media.SolidColorBrush(Color.FromArgb(255, 255, 0, 0)),
FontSize = 14,
Text = item.ZDMC,
OffsetX = 12,
OffsetY = -5
};
Graphic graphicText1 = new Graphic()
{
Geometry = mercator.FromGeographic(new MapPoint(double.Parse(item.Latitute.ToString().Trim(), System.Globalization.CultureInfo.InvariantCulture), double.Parse(item.Longitute.ToString().Trim(), System.Globalization.CultureInfo.InvariantCulture))),
Symbol = textSymbol
};
graphicText1.Attributes["TextYLZMC"] = item.ZDMC;
graphicsLayer1.Graphics.Add(graphicText1);

 


如果要考虑给文字加背景颜色的话,该类就无法起作用了

//动态添加带背景颜色的文字信息
Border b = new Border();
b.Background = new SolidColorBrush(Colors.Blue);
b.Height = 20;
b.CornerRadius = new CornerRadius(5);
TextBlock tb = new TextBlock();
tb.Text = item.ZDMC;
tb.Foreground = new SolidColorBrush(Colors.White);
tb.HorizontalAlignment = HorizontalAlignment.Center;
tb.FontSize = 15;
b.Child = tb;
ElementLayer.SetEnvelope(b, new Envelope(new MapPoint(double.Parse(item.Latitute.ToString().Trim(), System.Globalization.CultureInfo.InvariantCulture), double.Parse(item.Longitute.ToString().Trim(), System.Globalization.CultureInfo.InvariantCulture))),new MapPoint(double.Parse(item.Latitute.ToString().Trim(), System.Globalization.CultureInfo.InvariantCulture), double.Parse(item.Longitute.ToString().Trim(), System.Globalization.CultureInfo.InvariantCulture))));
elementLayer.Children.Add(b);

效果如下

 

提供第二种方法,使用TextSymbol的模板使用:

          <esri:TextSymbol x:Key="SWZTextSymbol">
<esri:TextSymbol.ControlTemplate>
<ControlTemplate>
<Border Background="White" BorderBrush="Black" CornerRadius="5"  BorderThickness="1,1,1,1">
<TextBlock
Width="70"
FontSize="14" 
Text="{Binding Attributes[TextSWZMC]}" //注意这里的TextSWZMC,和后台代码中要一致
Foreground="Blue"
FontFamily="Microsoft YaHei"
HorizontalAlignment="Center" />
</Border>
</ControlTemplate>
</esri:TextSymbol.ControlTemplate>
</esri:TextSymbol>


 

  TextSymbol textSymbol = LayoutRoot.Resources["SWZTextSymbol"] as TextSymbol; //这里和模板的Key名称要一致
textSymbol.OffsetX = 15;
textSymbol.OffsetY = -15;
Graphic graphicText = new Graphic()
{
Geometry = mercator.FromGeographic(new MapPoint(double.Parse(item.Latitute.ToString().Trim(), System.Globalization.CultureInfo.InvariantCulture), double.Parse(item.Longitute.ToString().Trim(), System.Globalization.CultureInfo.InvariantCulture))),
Symbol = textSymbol
};
graphicText.Attributes["TextSWZMC"] = item.ZDMC; //注意这里的TextSWZMC,和前台xaml代码中要一致
   graphicsLayer11.Graphics.Add(graphicText);



 

 

这篇关于ArcGIS API for Silverlight 之ElementLayer使用及TextSymbol的模板使用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/819000

相关文章

使用DeepSeek搭建个人知识库(在笔记本电脑上)

《使用DeepSeek搭建个人知识库(在笔记本电脑上)》本文介绍了如何在笔记本电脑上使用DeepSeek和开源工具搭建个人知识库,通过安装DeepSeek和RAGFlow,并使用CherryStudi... 目录部署环境软件清单安装DeepSeek安装Cherry Studio安装RAGFlow设置知识库总

Python FastAPI入门安装使用

《PythonFastAPI入门安装使用》FastAPI是一个现代、快速的PythonWeb框架,用于构建API,它基于Python3.6+的类型提示特性,使得代码更加简洁且易于绶护,这篇文章主要介... 目录第一节:FastAPI入门一、FastAPI框架介绍什么是ASGI服务(WSGI)二、FastAP

Spring-AOP-ProceedingJoinPoint的使用详解

《Spring-AOP-ProceedingJoinPoint的使用详解》:本文主要介绍Spring-AOP-ProceedingJoinPoint的使用方式,具有很好的参考价值,希望对大家有所帮... 目录ProceedingJoinPoijsnt简介获取环绕通知方法的相关信息1.proceed()2.g

Maven pom.xml文件中build,plugin标签的使用小结

《Mavenpom.xml文件中build,plugin标签的使用小结》本文主要介绍了Mavenpom.xml文件中build,plugin标签的使用小结,文中通过示例代码介绍的非常详细,对大家的学... 目录<build> 标签Plugins插件<build> 标签<build> 标签是 pom.XML

JAVA虚拟机中 -D, -X, -XX ,-server参数使用

《JAVA虚拟机中-D,-X,-XX,-server参数使用》本文主要介绍了JAVA虚拟机中-D,-X,-XX,-server参数使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有... 目录一、-D参数二、-X参数三、-XX参数总结:在Java开发过程中,对Java虚拟机(JVM)的启动参数进

Java中使用注解校验手机号格式的详细指南

《Java中使用注解校验手机号格式的详细指南》在现代的Web应用开发中,数据校验是一个非常重要的环节,本文将详细介绍如何在Java中使用注解对手机号格式进行校验,感兴趣的小伙伴可以了解下... 目录1. 引言2. 数据校验的重要性3. Java中的数据校验框架4. 使用注解校验手机号格式4.1 @NotBl

Python使用DeepSeek进行联网搜索功能详解

《Python使用DeepSeek进行联网搜索功能详解》Python作为一种非常流行的编程语言,结合DeepSeek这一高性能的深度学习工具包,可以方便地处理各种深度学习任务,本文将介绍一下如何使用P... 目录一、环境准备与依赖安装二、DeepSeek简介三、联网搜索与数据集准备四、实践示例:图像分类1.

Linux系统之authconfig命令的使用解读

《Linux系统之authconfig命令的使用解读》authconfig是一个用于配置Linux系统身份验证和账户管理设置的命令行工具,主要用于RedHat系列的Linux发行版,它提供了一系列选项... 目录linux authconfig命令的使用基本语法常用选项示例总结Linux authconfi

Windows server服务器使用blat命令行发送邮件

《Windowsserver服务器使用blat命令行发送邮件》在linux平台的命令行下可以使用mail命令来发送邮件,windows平台没有内置的命令,但可以使用开源的blat,其官方主页为ht... 目录下载blatBAT命令行示例备注总结在linux平台的命令行下可以使用mail命令来发送邮件,Win

Tomcat的下载安装与使用教程

《Tomcat的下载安装与使用教程》本文介绍了Tomcat的下载、安装和使用方法,包括在本机和云服务器上部署Tomcat的过程,以及解决启动失败问题的方法... 目录Tomcat的下载安装与使用Tomcat的下载与安装Tomcat在本机运行使用Tomcat在php云服务器上的使用总结Tomcat的下载安装与