Convert.js
3.62 KB
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
var CesiumToSuperMap = {
convertPoint : function(Cesium,SuperMap,point){
if(!Cesium || !SuperMap || !point){
return undefined;
}
var lonlatPoint = Cesium.Cartographic.fromCartesian(point);
var x = Cesium.Math.toDegrees(lonlatPoint.longitude);
var y = Cesium.Math.toDegrees(lonlatPoint.latitude);
if(x && y){
return new SuperMap.Geometry.Point(x,y);
}
return undefined;
},
convertPolyline : function(Cesium,SuperMap,polyline){
if(!Cesium || !SuperMap || !polyline){
throw undefined;
}
var points = polyline.positions;
if(points && points instanceof Array && points.length >= 2){
var arr = [];
for(var i = 0,j = points.length;i < j;i++){
var point = this.convertPoint(Cesium,SuperMap,points[i]);
if(point){
arr.push(point);
}
}
return new SuperMap.Geometry.LineString(arr);
}
return undefined;
},
convertPolygon : function(Cesium, SuperMap, polygon){
if(!Cesium || !SuperMap || !polygon){
throw undefined;
}
var points = polygon.positions;
if(points && points instanceof Array && points.length >= 3){
var arr = [];
for(var i = 0,j = points.length;i < j;i++){
var point = this.convertPoint(Cesium,SuperMap,points[i]);
if(point){
arr.push(point);
}
}
var linearRing = new SuperMap.Geometry.LinearRing(arr);
return new SuperMap.Geometry.Polygon(linearRing);
}
return undefined;
}
};
var SuperMapToCesium = {
geometryToEntity : function(Cesium,SuperMap,geometry){
var className = geometry.CLASS_NAME;
if(className == 'SuperMap.Geometry.MultiPolygon'){
return this.multipolygonToEntities(Cesium,SuperMap,geometry);
}
else if(className == 'SuperMap.Geometry.Polygon'){
return [this.polygonToEntity(Cesium,SuperMap,geometry)];
}
return undefined;
},
polygonToEntity : function(Cesium,SuperMap,geometry){
var hierarchy = {};
for(var i = 0,j = geometry.components.length;i < j;i++){
if(i == 0){
hierarchy.positions = this.GeometrytoDegreesArray(Cesium,SuperMap,geometry.components[i]);
}
else{
if(!hierarchy.holes){
hierarchy.holes = [];
}
hierarchy.holes.push({
positions : this.GeometrytoDegreesArray(Cesium,SuperMap,geometry.components[i])
});
}
}
return new Cesium.Entity({
polygon : {
hierarchy : hierarchy,
material : Cesium.Color.BLUE.withAlpha(0.5)
},
depthTestEnabled : false
});
},
multipolygonToEntities : function(Cesium,SuperMap,geometry){
var components = geometry.components;
var resultEntities = [];
var entity;
for(var item in components){
entity = this.polygonToEntity(Cesium,SuperMap,components[item]);
resultEntities.push(entity);
}
return resultEntities;
},
GeometrytoDegreesArray : function(Cesium,SuperMap,geometry){
var vertices = geometry.getVertices();
var degreesArr = [];
for(var o in vertices){
degreesArr.push(vertices[o].x,vertices[o].y);
}
return Cesium.Cartesian3.fromDegreesArray(degreesArr);
}
};