* @function Label.prototype.setStyle * @description 设置标签要素的风格。 * @param {FeatureVector} feat - 需要赋予风格的要素。
(feat)
| 401 | * @param {FeatureVector} feat - 需要赋予风格的要素。 |
| 402 | */ |
| 403 | setStyle(feat) { |
| 404 | var feature = feat; |
| 405 | feature.style = CommonUtil.copyAttributes(feature.style, this.defaultStyle); |
| 406 | //将style赋给标签 |
| 407 | if (this.style && this.style.fontSize && parseFloat(this.style.fontSize) < 12) { |
| 408 | this.style.fontSize = "12px"; |
| 409 | } |
| 410 | feature.style = CommonUtil.copyAttributes(feature.style, this.style); |
| 411 | |
| 412 | if (this.groupField && this.styleGroups && feature.attributes) { |
| 413 | var Sf = this.groupField; |
| 414 | var attributes = feature.attributes; |
| 415 | var groups = this.styleGroups; |
| 416 | var isSfInAttrs = false; //指定的 groupField 是否是geotext的属性字段之一 |
| 417 | var attr = null; //属性值 |
| 418 | |
| 419 | for (var property in attributes) { |
| 420 | if (Sf === property) { |
| 421 | isSfInAttrs = true; |
| 422 | attr = attributes[property]; |
| 423 | break; |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | //判断属性值是否属于styleGroups的某一个范围,以便对标签分组 |
| 428 | if (isSfInAttrs) { |
| 429 | for (var i = 0, len = groups.length; i < len; i++) { |
| 430 | if ((attr >= groups[i].start) && (attr < groups[i].end)) { |
| 431 | var sty1 = groups[i].style; |
| 432 | if (sty1 && sty1.fontSize && parseFloat(sty1.fontSize) < 12) { |
| 433 | sty1.fontSize = "12px"; |
| 434 | } |
| 435 | feature.style = CommonUtil.copyAttributes(feature.style, sty1); |
| 436 | } |
| 437 | } |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | //将文本内容赋到标签要素的style上 |
| 442 | feature.style.label = feature.geometry.text; |
| 443 | |
| 444 | return feature; |
| 445 | } |
| 446 | |
| 447 | /** |
| 448 | * @function Label.prototype.getLabelPxLocation |
no outgoing calls
no test coverage detected