一、判断graphicslayer层【地块注记】是否存在,如果不存在则新建、如果存在则删除所有要素
dim graphicslayer = pmap.getlayersasflattenedlist().oftype(of arcgis.desktop.mapping.graphicslayer).firstordefault() '获取当前map对象中的getlayer图层
await queuedtask.run(sub()
if graphicslayer is nothing = true then
'创建 graphicslayer
if pmap.maptype <> maptype.map then exit sub ' not 2d
dim gl_param = new graphicslayercreationparams
gl_param.name = "地块注记"
'默认情况下会添加到目录的顶部
graphicslayer = layerfactory.instance.createlayer(of arcgis.desktop.mapping.graphicslayer)(gl_param, pmap)
else
'全选文本
dim zj_zdmane as string = ""
zj_zdmane = "地块注记"
dim elements = graphicslayer.getelementsasflattenedlist().where(function(gele as graphicelement) gele.name.startswith(zj_zdmane)) ’获取getlayer图层中定义的元素(本例为text)
'删除选择text
graphicslayer.selectelements(elements)
graphicslayer.removeelements(graphicslayer.getselectedelements())
end if
mapview.active.redraw(true) '视图刷新
end sub)
二、createtextgraphicelement 方法
graphicelement createtextgraphicelement(
ielementcontainer elementcontainer,
texttype texttype,
geometry geometry,
cimtextsymbol textsymbol,
string text,
string elementname,
bool select, 【可选】
elementinfo elementinfo 【可选】
)
texttype:要创建的文本图形的类型
成员 | 描述 |
circleparagraph | 圆文本 |
ellipseparagraph | 椭圆文本 |
none | none- 默认 |
pointtext | 点文本 |
polygonparagraph | 多边形文本 |
rectangleparagraph | 矩形文本 |
splinedtext | 沿直线或曲线样条的文本 |
三、检查应用程序中是否有特定字体可用于 pro 会话。 必须在 mct 上调用此方法。isfontavailable 方法 (symbolfactory)
public bool isfontavailable(
string fontname,
string fontstyle,
fonttype fonttype,
list<cimfontvariation> fontvariationsettings
)
fontname:字体簇的名称。
fontstyle :字体样式的名称。
fonttype:字体类型。
fontvariationsettings:要应用的任何字体变体设置。可以为 null。
返回值:一个布尔值,表示字体是否可用。例如:
dim boot=symbolfactory.instance.isfontavailable("arial", "bold", fonttype.unspecified, null)
四、创建文本
1、创建简单的文本符号(creates a simple text symbol)创建一个大小为8.5、字体系列为“corbel”、字体样式为“regular”的简单黑色文本符号。
await queuedtask.run(sub()
pmap = mapview.active.map ‘获取激活的map对象
dim graphicslayer = pmap.getlayersasflattenedlist().oftype(of arcgis.desktop.mapping.graphicslayer).firstordefault() ‘获取的graphicslayer对象
dim textsymbol =symbolfactory.instance.constructtextsymbol(colorfactory.instance.blackrgb, 8.5, "corbel", "regular")
'文本的偏移量
textsymbol.offsetx = 0.5
textsymbol.offsety = 0.5
dim location as mappoint = mappointbuilderex.createmappoint(px,py)
dim text as string = "forest grove"
dim polytxtelm as graphicelement = elementfactory.instance.createtextgraphicelement(graphicslayer, texttype.pointtext, location, textsymbol, text, "地块注记")
end sub)
效果:
2、创建创建带有光晕环的文本符号(creates a text symbol with a halo)
await queuedtask.run(sub()
pmap = mapview.active.map ‘获取激活的map对象
dim graphicslayer = pmap.getlayersasflattenedlist().oftype(of arcgis.desktop.mapping.graphicslayer).firstordefault() ‘获取的graphicslayer对象
dim halopoly = symbolfactory.instance.constructpolygonsymbol(colorfactory.instance.redrgb, simplefillstyle.solid)
dim textsymbol = symbolfactory.instance.constructtextsymbol(halopoly, 10, "arial", "bold")
'文本的偏移量
textsymbol.offsetx = 0.5
textsymbol.offsety = 0.5
dim location as mappoint = mappointbuilderex.createmappoint(px,py)
dim text as string = "portland"
dim polytxtelm as graphicelement = elementfactory.instance.createtextgraphicelement(graphicslayer, texttype.pointtext, location, textsymbol, text, "地块注记")
end sub)
效果:
3、创建简单的牵引文本符号(creates a text symbol with a halo)
await queuedtask.run(sub()
pmap = mapview.active.map ‘获取激活的map对象
dim graphicslayer = pmap.getlayersasflattenedlist().oftype(of arcgis.desktop.mapping.graphicslayer).firstordefault() ‘获取的graphicslayer对象
dim textsymbol = symbolfactory.instance.constructtextsymbol(colorfactory.instance.blackrgb, 10, "verdana", "regular")
dim linecalloutsymbol = new cimsimplelinecallout()
dim linesymbol = symbolfactory.instance.constructlinesymbol(colorfactory.instance.blackrgb, 1, simplelinestyle.dashdotdot)
linecalloutsymbol.linesymbol = linesymbol
'文本的偏移量
textsymbol.offsetx = 10
textsymbol.offsety = 10
textsymbol.callout = linecalloutsymbol
dim location as mappoint = mappointbuilderex.createmappoint(px,py)
dim text as string = "forest grove"
dim polytxtelm as graphicelement = elementfactory.instance.createtextgraphicelement(graphicslayer, texttype.pointtext, location, textsymbol, text, "地块注记")
end sub)
效果:
4、创建圆角矩形的牵引文本框符号(creates a balloon callout text symbol)
await queuedtask.run(sub()
pmap = mapview.active.map ‘获取激活的map对象
dim graphicslayer = pmap.getlayersasflattenedlist().oftype(of arcgis.desktop.mapping.graphicslayer).firstordefault() ‘获取的graphicslayer对象
dim location as mappoint = mappointbuilderex.createmappoint(px,py)
dim textsymbol = symbolfactory.instance.constructtextsymbol(colorfactory.instance.whitergb, 11, "corbel", "regular")
dim ballooncallout = new cimballooncallout()
ballooncallout.balloonstyle = ballooncalloutstyle.roundedrectangle
dim polysymbol = symbolfactory.instance.constructpolygonsymbol(colorfactory.instance.blackrgb, simplefillstyle.solid)
ballooncallout.backgroundsymbol = polysymbol
ballooncallout.margin = new cimtextmargin
with ballooncallout.margin
.left = 5
.right = 5
.bottom = 5
.top = 5
end with
textsymbol.callout = ballooncallout
dim text as string = "forest grove"
dim polytxtelm as graphicelement = elementfactory.instance.createtextgraphicelement(graphicslayer, texttype.rectangleparagraph, location, textsymbol, text, "地块注记")
end sub)
效果:
5、创建点符号的文本符号(creates a point callout text symbol)
await queuedtask.run(sub()
pmap = mapview.active.map ‘获取激活的map对象
dim graphicslayer = pmap.getlayersasflattenedlist().oftype(of arcgis.desktop.mapping.graphicslayer).firstordefault() ‘获取的graphicslayer对象
dim textsymbol = symbolfactory.instance.constructtextsymbol(colorfactory.instance.whitergb, 6, "tahoma", "bold")
dim shieldcalloutsymbol = new cimpointsymbolcallout()
dim symbolstyleitem = getpointsymbol("arcgis 2d", "shield 1")
shieldcalloutsymbol.pointsymbol = symbolstyleitem.symbol as cimpointsymbol
shieldcalloutsymbol.pointsymbol.setsize(18.0)
textsymbol.callout = shieldcalloutsymbol
dim location as mappoint = mappointbuilderex.createmappoint(px,py)
dim text as string = "i5"
dim polytxtelm as graphicelement = elementfactory.instance.createtextgraphicelement(graphicslayer, texttype.pointtext, location, textsymbol, text, "地块注记")
end sub)
效果:
6、创建设置矩形背景色的牵引文本框符号(creates a background callout text symbol)
await queuedtask.run(sub()
pmap = mapview.active.map ‘获取激活的map对象
dim graphicslayer = pmap.getlayersasflattenedlist().oftype(of arcgis.desktop.mapping.graphicslayer).firstordefault() ‘获取的graphicslayer对象
dim location as mappoint = mappointbuilderex.createmappoint(px,py)
dim textsymbol = symbolfactory.instance.constructtextsymbol(colorfactory.instance.blackrgb, 8, "tahoma", "bold")
dim backgroundcalloutsymbol = new cimbackgroundcallout()
dim linesymbol = symbolfactory.instance.constructlinesymbol(colorfactory.instance.blackrgb, 1, simplelinestyle.dashdotdot)
dim aquabackground = colorfactory.instance.creatergbcolor(190, 255, 232, 100)
dim polysymbol = symbolfactory.instance.constructpolygonsymbol(aquabackground, simplefillstyle.solid)
backgroundcalloutsymbol.leaderlinesymbol = linesymbol
textsymbol.offsetx = 10
textsymbol.offsety = 10
backgroundcalloutsymbol.backgroundsymbol = polysymbol
dim accentsymbol = symbolfactory.instance.constructlinesymbol(colorfactory.instance.blackrgb, 2, simplelinestyle.solid)
backgroundcalloutsymbol.accentbarsymbol = accentsymbol
backgroundcalloutsymbol.margin = new cimtextmargin
with ballooncallout.margin
.left = 5
.right = 5
.bottom = 5
.top = 5
end with
textsymbol.callout = backgroundcalloutsymbol
dim text as string = "forest grove"
dim polytxtelm as graphicelement = elementfactory.instance.createtextgraphicelement(graphicslayer,texttype.rectangleparagraph, poly, textsymbol, text, "地块注记")
end sub)
效果:
发表评论