ansel0926
2022-05-17 00b733dc6ae372be365a01046ead5c062d8f5617
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
function drawPoint() {
    var options = {
        'viewer': viewer, //全局Cesium对象
        'pointcolor': Cesium.Color.RED, //点的颜色
        // 'printId':textid,  //用来存放返回坐标的文本框的id
        'text': '新',   //要印在PIN标签上的文字
        'size': 36    //PIN标签的大小(以像素为单位)
    };
    CesiumDraw.drawPoint(options);
}
function drawPolyline() {
    var options = {
        'viewer': viewer, //全局Cesium对象
        'polylinecolor': new Cesium.Color.fromBytes(255,124,0,255), //线的颜色)
        'pointcolor': Cesium.Color.WHITE, //画线时次点的颜色
        // 'printId':textid,    //用来存放返回坐标的文本框的id
        'text': "线"      //次点时生成的PIN标签上的文字
    };
    CesiumDraw.drawPolyline(options);
}
function drawPolygon(type) {
    var options = {
        'viewer': viewer,  //全局Cesium对象
        'polygoncolor': Cesium.Color.SALMON.withAlpha(0.5), //面的颜色(可设置透明度)
        'pointcolor': Cesium.Color.RED,  //画面时圈点的颜色
        // 'printId':textid,  //用来存放返回坐标的文本框的id
        'type': type 
    };
    CesiumDraw.drawPolygon(options);
}
function drawLabel(text) {
    var options = {
        'viewer': viewer,
        'label': {
            'text': text,
            'font': '30px SimSun',
            'fillColor': Cesium.Color.RED,
            'outlineColor': Cesium.Color.BLACK,
            'outlineWidth': 2,
            'style': Cesium.LabelStyle.FILL_AND_OUTLINE,
            'scaleByDistance': new Cesium.NearFarScalar(100, 1.0, 200, 0.4)
        },
    }
    CesiumDraw.drawLabel(options);
}
 
function drawText(text) {
    var options = {
        'viewer': viewer,
        'label': {
            'text': text,
            'font': '30px SimSun',
            'fillColor': Cesium.Color.RED,
            'outlineColor': Cesium.Color.BLACK,
            'outlineWidth': 2,
            'style': Cesium.LabelStyle.FILL_AND_OUTLINE,
            'scaleByDistance': new Cesium.NearFarScalar(100, 1.0, 200, 0.4)
        },
    }
    CesiumDraw.drawText(options);
}
function clearDraw() {
    var options = {
        'viewer': viewer, //全局Cesium对象
    };
    CesiumDraw.clearDraw(options);
}
 
function saveDrawEntity(type,drawEntity,id){//zzf:保存绘制的图形
    let saveData;
    if(type=='point'){
        var cartographic=Cesium.Cartographic.fromCartesian(drawEntity._position._value);
        var lng=Cesium.Math.toDegrees(cartographic.longitude);
        var lat=Cesium.Math.toDegrees(cartographic.latitude);
        var alt=cartographic.height;
        saveData= {
            "id":id,
            "type": type,
            "longitude": lng,
            "latitude": lat,
            "height": alt,
        }
    }
    else if(type=='polyline'||type=='polygon'){
        let longitudeList=[],latitudeList=[],heightList=[]
        for(let i=0;i<drawEntity.length;i++){
            var cartographic=Cesium.Cartographic.fromCartesian(drawEntity[i]._position._value);
            var lng=Cesium.Math.toDegrees(cartographic.longitude);
            var lat=Cesium.Math.toDegrees(cartographic.latitude);
            var alt=cartographic.height;
            longitudeList.push(lng)
            latitudeList.push(lat)
            heightList.push(alt)
        }
        saveData= {
            "id":id,
            "type": type,
            "longitude": longitudeList.toString(),
            "latitude": latitudeList.toString(),
            "height": heightList.toString(),
        }
    }
    else if(type=='label'){
        var cartographic=Cesium.Cartographic.fromCartesian(drawEntity._position._value);
        var lng=Cesium.Math.toDegrees(cartographic.longitude);
        var lat=Cesium.Math.toDegrees(cartographic.latitude);
        var alt=cartographic.height;
        saveData= {
            "id":id,
            "type": type,
            "longitude": lng,
            "latitude": lat,
            "height": alt,
            "content":drawEntity.title,
            "color":drawEntity._label._fillColor._value.toCssColorString(),
            "fontsize":30,
            "fontstyle":'SimSun',
        }
    }
 
    let token = window.localStorage.getItem("token");
    $.ajax({
        type: "get",
        async: false,
        url: parent.httpConfig.webApiUrl + "landstamp/front/addDrawEntity",
        data: saveData,
        contentType: "application/json;charset=utf-8",
        beforeSend:function(request){
            request.setRequestHeader("token",token);
        },
        success: function (data) {
            console.log(data)
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log("ajax请求失败!");
        }
    });
}