addBackgroundTextSymbol('0', number.format(Number(result.areas[0]) * 1.145 * 1.145, {
pattern: '#.000'
}) + "平方公里", spoint, 0, 0, 0, -3);
/* type 类型
infoTem 文字
point 点位
x, y, x1, y1 偏移的数值
**/
function addBackgroundTextSymbol(type, infoTem, point, x, y, x1, y1) {
var _fontsize = 10;
var _radius = 6;
var _infoTem = infoTem;
var point = point;
var bglineSymbol = new SimpleLineSymbol("solid", new Color("gray"), 1);
var width = (chkstrlen(_infoTem)) * 0.5 * (_fontsize + 3) + 4; //
var height = _fontsize * 1.8;
var radius = _radius;
//设置背景框的大小
var path = "M0" + " " + radius + "L0" + " " + (height - radius) + "Q0" + " " + height + " " + radius + " " + height + "L" + (width - radius) + " " + height + "Q" + width + " " + height + " " + width + " " + (height - radius) + "L" + width + " " + radius + "Q" + width + " " + "0" + " " + (width - radius) + " " + "0L" + radius + " " + "0Q0" + " " + "0" + " " + "0" + " " + radius;
var bgSymbol = new SimpleMarkerSymbol();
bgSymbol.setPath(path);
bgSymbol.setColor(new Color("gray"));
bgSymbol.setOutline(bglineSymbol);
var size = Math.max(height, width);
bgSymbol.setSize(size);
var bgGraphic = new Graphic(point, bgSymbol);
bgSymbol.xoffset = x;
bgSymbol.yoffset = y;
if (type != "1") {
gismap.graphics.add(bgGraphic);
} else {
BgCGraphic = gismap.graphics.add(bgGraphic);
}
var sfs = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SHORTDASHDOT),
new Color([0, 0, 255, 0.5]));
var font = new Font(_fontsize + "px", Font.STYLE_NORMAL, Font.VARIANT_NORMAL, Font.WEIGHT_LIGHTER);
var ts = new TextSymbol(_infoTem, font, new Color([255, 255, 255]));
ts.setAlign(Font.ALIGN_START);
ts.xoffset = x1;
ts.yoffset = y1;
var textGraphic = new Graphic(point, ts, sfs);
if (type != "1") {
gismap.graphics.add(textGraphic);
} else {
totalGraphic = gismap.graphics.add(textGraphic);
}
}
function chkstrlen(str) {
var strlen = 0;
for (var i = 0; i < str.length; i++) {
if (str.charCodeAt(i) > 255) //如果是汉字,则字符串长度加2
strlen += 2;
else
strlen++;
}
return strlen;
}
arcgis for js 3在地图上给文子图层添加背景色
最新推荐文章于 2024-04-10 19:03:44 发布