MCPcopy Index your code
hub / github.com/SuperMap/iClient-JavaScript / calculateLabelBounds2

Method calculateLabelBounds2

src/openlayers/overlay/Label.js:539–624  ·  view source on GitHub ↗

* @function Label.prototype.calculateLabelBounds2 * @description 获得标签要素的最终范围的另一种算法(通过记录下的标签宽高),提高计算范围的效率。 * @param {FeatureVector} feature - 需要计算范围的标签要素数。 * @param {Object} loc - 标签位置,例如:{"x":1,"y":1}。 * @returns {Array. } 四边形节点数组。例如:[{"x":1,"y":1},{"x":3,"y":1},{"x":6,"y"

(feature, loc)

Source from the content-addressed store, hash-verified

537 * @returns {Array.<Object>} 四边形节点数组。例如:[{"x":1,"y":1},{"x":3,"y":1},{"x":6,"y":4},{"x":2,"y":10},{"x":1,"y":1}]。
538 */
539 calculateLabelBounds2(feature, loc) {
540 var labB, left, bottom, top, right;
541 var labelSize = feature.geometry.bsInfo;
542 var style = feature.style;
543 var locationPx = CommonUtil.cloneObject(loc);
544
545 //处理文字对齐
546 if (style.labelAlign && style.labelAlign !== "cm") {
547 switch (style.labelAlign) {
548 case "lt":
549 locationPx.x += labelSize.w / 2;
550 locationPx.y += labelSize.h / 2;
551 break;
552 case "lm":
553 locationPx.x += labelSize.w / 2;
554 break;
555 case "lb":
556 locationPx.x += labelSize.w / 2;
557 locationPx.y -= labelSize.h / 2;
558 break;
559 case "ct":
560 locationPx.y += labelSize.h / 2;
561 break;
562 case "cb":
563 locationPx.y -= labelSize.h / 2;
564 break;
565 case "rt":
566 locationPx.x -= labelSize.w / 2;
567 locationPx.y += labelSize.h / 2;
568 break;
569 case "rm":
570 locationPx.x -= labelSize.w / 2;
571 break;
572 case "rb":
573 locationPx.x -= labelSize.w / 2;
574 locationPx.y -= labelSize.h / 2;
575 break;
576 default:
577 break;
578 }
579 }
580
581 left = locationPx.x - labelSize.w / 2;
582 bottom = locationPx.y + labelSize.h / 2;
583 //处理斜体字
584 if (style.fontStyle && style.fontStyle === "italic") {
585 right = locationPx.x + labelSize.w / 2 + parseInt(parseFloat(style.fontSize) / 2);
586 } else {
587 right = locationPx.x + labelSize.w / 2;
588 }
589 top = locationPx.y - labelSize.h / 2;
590
591 labB = new Bounds(left, bottom, right, top);
592
593 //旋转Bounds
594 var boundsQuad = [];
595 if ((style.labelRotation % 180) == 0) {
596 boundsQuad = [{

Callers 5

getDrawnLabelsMethod · 0.95
LabelSpec.jsFile · 0.45
LabelThemeLayer.jsFile · 0.45

Calls 1

rotationBoundsMethod · 0.95

Tested by

no test coverage detected