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

Method getAvoidInfo

src/mapboxgl/overlay/LabelThemeLayer.js:821–924  ·  view source on GitHub ↗

* @function LabelThemeLayer.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

819 * @returns {Object} 避让的信息。
820 */
821 getAvoidInfo(bounds, quadrilateral) {
822 if (quadrilateral.length !== 5) {
823 return null;
824 } //不是四边形
825
826 //将bound序列化为点数组形式
827 var bounddQuad = [{
828 "x": bounds.left,
829 "y": bounds.top
830 },
831 {
832 "x": bounds.right,
833 "y": bounds.top
834 },
835 {
836 "x": bounds.right,
837 "y": bounds.bottom
838 },
839 {
840 "x": bounds.left,
841 "y": bounds.bottom
842 },
843 {
844 "x": bounds.left,
845 "y": bounds.top
846 }
847 ];
848
849 var isIntersection = false,
850 bqLen = bounddQuad.length,
851 quadLen = quadrilateral.length;
852
853 var offsetX = 0,
854 offsetY = 0,
855 aspectH = "",
856 aspectW = "";
857 for (var i = 0; i < bqLen - 1; i++) {
858 for (var j = 0; j < quadLen - 1; j++) {
859 var isLineIn = Util.lineIntersection(bounddQuad[i], bounddQuad[i + 1], quadrilateral[j], quadrilateral[j + 1]);
860 if (isLineIn.CLASS_NAME === "SuperMap.Geometry.Point") {
861 //设置避让信息
862 setInfo(quadrilateral[j]);
863 setInfo(quadrilateral[j + 1]);
864 isIntersection = true;
865 }
866 }
867 }
868
869 if (isIntersection) {
870 //组织避让操作所需的信息
871 return {
872 "aspectW": aspectW,
873 "aspectH": aspectH,
874 "offsetX": offsetX,
875 "offsetY": offsetY
876 };
877 } else {
878 return null;

Callers 1

getDrawnLabelsMethod · 0.95

Calls 1

setInfoFunction · 0.85

Tested by

no test coverage detected