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

Method calculateLabelBounds

src/openlayers/overlay/Label.js:482–530  ·  view source on GitHub ↗

* @function Label.prototype.calculateLabelBounds * @description 获得标签要素的最终范围。 * @param {FeatureVector} feature - 需要计算范围的标签要素数。 * @param {Object} loc - 标签位置,例如:{"x":1,"y":1}。 * @returns {Array. } 四边形节点数组。例如:[{"x":1,"y":1},{"x":3,"y":1},{"x":6,"y":4},{"x":2,"y":10},{"x":1,"y

(feature, loc)

Source from the content-addressed store, hash-verified

480 * @returns {Array.<Object>} 四边形节点数组。例如:[{"x":1,"y":1},{"x":3,"y":1},{"x":6,"y":4},{"x":2,"y":10},{"x":1,"y":1}]。
481 */
482 calculateLabelBounds(feature, loc) {
483 var geoText = feature.geometry;
484
485 //标签范围(未旋转前)
486 var labB = null;
487 var labelInfo = null;
488 //获取bounds的方式
489 if (this.getPxBoundsMode == 0) {
490 labB = geoText.getLabelPxBoundsByText(loc, feature.style);
491 } else if (this.getPxBoundsMode === 1) {
492 //canvas
493 labelInfo = this.getLabelInfo(feature.geometry.getCentroid(), feature.style);
494 labB = geoText.getLabelPxBoundsByLabel(loc, labelInfo.w, labelInfo.h, feature.style);
495 } else {
496 return null;
497 }
498
499 //旋转Bounds
500 var boundsQuad = [];
501 if ((feature.style.labelRotation % 180) == 0) {
502 boundsQuad = [{
503 "x": labB.left,
504 "y": labB.top
505 },
506 {
507 "x": labB.right,
508 "y": labB.top
509 },
510 {
511 "x": labB.right,
512 "y": labB.bottom
513 },
514 {
515 "x": labB.left,
516 "y": labB.bottom
517 },
518 {
519 "x": labB.left,
520 "y": labB.top
521 }
522 ];
523 } else {
524 boundsQuad = this.rotationBounds(labB, loc, feature.style.labelRotation);
525 }
526
527 //重置GeoText的bounds
528 geoText.bounds = new Bounds(boundsQuad[1].x, boundsQuad[3].y, boundsQuad[2].x, boundsQuad[4].y);
529 return boundsQuad;
530 }
531
532 /**
533 * @function Label.prototype.calculateLabelBounds2

Callers 5

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

Calls 5

getLabelInfoMethod · 0.95
rotationBoundsMethod · 0.95
getCentroidMethod · 0.80

Tested by

no test coverage detected