MCPcopy Create free account
hub / github.com/SuperMap/iClient-JavaScript / getAvoidInfo

Method getAvoidInfo

src/openlayers/overlay/Label.js:794–898  ·  view source on GitHub ↗

* @function Label.prototype.getAvoidInfo * @description 获取避让的信息。 * @param {Bounds} bounds - 地图像素范围。 * @param {Array. } quadrilateral - 四边形节点数组。例如:[{"x":1,"y":1},{"x":3,"y":1},{"x":6,"y":4},{"x":2,"y":10},{"x":1,"y":1}]。 * @returns {Object} 避让的信息。

(bounds, quadrilateral)

Source from the content-addressed store, hash-verified

792 * @returns {Object} 避让的信息。
793 */
794 getAvoidInfo(bounds, quadrilateral) {
795 if (quadrilateral.length !== 5) {
796 return null;
797 } //不是四边形
798
799 //将bound序列化为点数组形式
800 var bounddQuad = [{
801 "x": bounds.left,
802 "y": bounds.top
803 },
804 {
805 "x": bounds.right,
806 "y": bounds.top
807 },
808 {
809 "x": bounds.right,
810 "y": bounds.bottom
811 },
812 {
813 "x": bounds.left,
814 "y": bounds.bottom
815 },
816 {
817 "x": bounds.left,
818 "y": bounds.top
819 }
820 ];
821
822 var isIntersection = false,
823 bqLen = bounddQuad.length,
824 quadLen = quadrilateral.length;
825
826 var offsetX = 0,
827 offsetY = 0,
828 aspectH = "",
829 aspectW = "";
830 for (var i = 0; i < bqLen - 1; i++) {
831 for (var j = 0; j < quadLen - 1; j++) {
832 var isLineIn = CommonUtil.lineIntersection(bounddQuad[i], bounddQuad[i + 1], quadrilateral[j], quadrilateral[j + 1]);
833 if (isLineIn.CLASS_NAME === "SuperMap.Geometry.Point") {
834 //设置避让信息
835 setInfo(quadrilateral[j]);
836 setInfo(quadrilateral[j + 1]);
837 isIntersection = true;
838 }
839 }
840 }
841
842 if (isIntersection) {
843 //组织避让操作所需的信息
844 return {
845 "aspectW": aspectW,
846 "aspectH": aspectH,
847 "offsetX": offsetX,
848 "offsetY": offsetY
849 };
850 } else {
851 return null;

Callers 5

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

Calls 1

setInfoFunction · 0.85

Tested by

no test coverage detected