Skip to content
Navigation Menu
{{ message }}
forked from woliqiang/iClient-for-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasicalGeometry.html
More file actions
251 lines (239 loc) · 10.1 KB
/
Copy pathbasicalGeometry.html
File metadata and controls
251 lines (239 loc) · 10.1 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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>基础矢量图形</title>
<style type="text/css">
body{
margin: 0;
overflow: hidden;
background: #fff;
}
#map{
position: relative;
height: 510px;
border:1px solid #3473b7;
}
#toolbar {
position: relative;
padding-top: 5px;
padding-bottom: 10px;
}
</style>
<link href='./css/bootstrap.min.css' rel='stylesheet' />
<link href='./css/bootstrap-responsive.min.css' rel='stylesheet' />
<script src = '../libs/SuperMap.Include.js'></script>
<script type="text/javascript">
var map,layer,pointVector,dataAdded=false,
host = document.location.toString().match(/file:\/\//) ? "http://localhost:8090" : 'http://' + document.location.host;
url = host + "/iserver/services/map-world/rest/maps/World";
function init()
{
map = new SuperMap.Map("map",{controls:[
new SuperMap.Control.Zoom() ,
new SuperMap.Control.Navigation() ,
new SuperMap.Control.LayerSwitcher()
]});
layer= new SuperMap.Layer.TiledDynamicRESTLayer("World", url, null,{maxResolution:"auto"});
layer.events.on({"layerInitialized":addLayer});
vector = new SuperMap.Layer.Vector("vector");
addData();
}
function addLayer(){
map.addLayers([layer,vector]);
//显示地图范围
map.setCenter(new SuperMap.LonLat(0, 0), 0);
}
function addData()
{
if(!dataAdded)
{
vector.removeAllFeatures();
//点对象
var point= new SuperMap.Geometry.Point(0,0);
var pointVector = new SuperMap.Feature.Vector(point);
pointVector.style={
fillColor:"red",
strokeColor:"yellow",
pointRadius:6
};
//线串几何对象
var points2=[
new SuperMap.Geometry.Point(0,29.4),
new SuperMap.Geometry.Point(-50,39.4),
new SuperMap.Geometry.Point(-30,19.4),
new SuperMap.Geometry.Point(100,49.4)
];
var line1 = new SuperMap.Geometry.LineString(points2);
var linecVector = new SuperMap.Feature.Vector(line1);
linecVector.style={
strokeColor:"#7B68EE",
strokeWidth:2
} ;
//几何对象线环类
var points1=[
new SuperMap.Geometry.Point(0,19.4),
new SuperMap.Geometry.Point(10,-20),
new SuperMap.Geometry.Point(14,-22),
new SuperMap.Geometry.Point(24,-5),
new SuperMap.Geometry.Point(34,15),
new SuperMap.Geometry.Point(45,25),
new SuperMap.Geometry.Point(50,29.4)
];
var line = new SuperMap.Geometry.LinearRing(points1);
var lineVector = new SuperMap.Feature.Vector(line);
lineVector.style={
strokeColor:"#C0FF3E",
fill:false,
strokeWidth:2
} ;
//创建多次贝塞尔曲线
var bezierPoint =[
new SuperMap.Geometry.Point(0,39.5),
new SuperMap.Geometry.Point(30,69.5),
new SuperMap.Geometry.Point(90,49.4),
new SuperMap.Geometry.Point(120,75.5),
new SuperMap.Geometry.Point(150,63.4),
new SuperMap.Geometry.Point(156,80.3)];
var bezier5= SuperMap.Geometry.LineString.createBezierN(bezierPoint,20) ;
var bezier5Vector = new SuperMap.Feature.Vector(bezier5);
bezier5Vector.style={
strokeWidth:3
};
//创建3次贝塞尔曲线
var points =[
new SuperMap.Geometry.Point(80,19.4),
new SuperMap.Geometry.Point(179,39.8),
new SuperMap.Geometry.Point(164,40) ,
new SuperMap.Geometry.Point(126,43.4)
] ;
var bezier3= SuperMap.Geometry.LineString.createBezier(points,5);
var bezier3Vector = new SuperMap.Feature.Vector(bezier3);
bezier3Vector.style={
strokeColor:"#1E90FF",
strokeWidth: 2
};
//创建2次贝塞尔曲线
var bezierpoints = [
new SuperMap.Geometry.Point(-80,20),
new SuperMap.Geometry.Point(-60,60),
new SuperMap.Geometry.Point(0,60)
];
var bezier2 = SuperMap.Geometry.LineString.createBezier2(bezierpoints, 20);
var bezierVector = new SuperMap.Feature.Vector(bezier2);
bezierVector.style={
strokeColor:"#9AFF9A",
strokeWidth: 3
};
//扇形
var origion = new SuperMap.Geometry.Point(20,-20);
var sides=30;
var cuvre= SuperMap.Geometry.Polygon.createRegularPolygonCurve(origion,50,sides,80,220);
var cuvreVector= new SuperMap.Feature.Vector(cuvre);
cuvreVector.style={
strokeColor:"#1E90FF",
fillColor:"#C6E2FF",
strokeWidth:2 ,
fillOpacity:0.5
};
//椭圆
var points=createEllipse(100,-10,50,25);
linearRings = new SuperMap.Geometry.LinearRing(points),
region = new SuperMap.Geometry.Polygon([linearRings]);
var ellipseVector= new SuperMap.Feature.Vector(region);
ellipseVector.style={
fillColor:"#B0E2FF",
strokeColor:"#C1FFC1",
fillOpacity:0.5
};
//六边形
var points2=[
new SuperMap.Geometry.Point(-120,54.142),
new SuperMap.Geometry.Point(-110,40),
new SuperMap.Geometry.Point(-120,25.857),
new SuperMap.Geometry.Point(-140,25.857),
new SuperMap.Geometry.Point(-150,40),
new SuperMap.Geometry.Point(-140,54.142)
],
linearRings = new SuperMap.Geometry.LinearRing(points2),
region = new SuperMap.Geometry.Polygon([linearRings]);
var polygonVector = new SuperMap.Feature.Vector(region);
// 矩形
var x = -70;
var y = -30;
var w = 40;
var h = 30;
var rectangle = new SuperMap.Geometry.Rectangle(x, y, w, h);
var rectangleVector = new SuperMap.Feature.Vector(rectangle);
//圆
var centerPoint=new SuperMap.Geometry.Point(-120,-50);
var circleP=createCircle(centerPoint,30,256,360,360);
var circleVector= new SuperMap.Feature.Vector(circleP);
circleVector.style={
strokeColor:"#CAFF70",
fillColor:"#C6E2FF",
strokeWidth:2 ,
fillOpacity:0.5
};
vector.addFeatures([pointVector,lineVector,bezier3Vector,bezierVector,bezier5Vector,cuvreVector,ellipseVector,polygonVector,rectangleVector,circleVector,linecVector]);
dataAdded=true;
} else{
alert("数据已加载。");
}
}
//函数的参数x,y为椭圆中心;a,b分别为椭圆横半轴
function createEllipse(x,y,a,b){
var step = (a > b) ? 1 / a : 1 / b,points=[];
//step是等于1除以长轴值a和b中的较大者
//i每次循环增加1/step,表示度数的增加
//这样可以使得每次循环所绘制的路径(弧线)接近1像素
for (var i = 0; i < 2 * Math.PI; i += step)
{
//参数方程为x = a * cos(i), y = b * sin(i),
//参数为i,表示度数(弧度)
var point=new SuperMap.Geometry.Point(x+a*Math.cos(i),y+b*Math.sin(i));
points.push(point);
}
return points;
}
//圆
function createCircle(origin, radius, sides,r,angel){
var rR = r*Math.PI/(180*sides);
var rotatedAngle, x, y;
var points = [];
for(var i=0; i<sides; ++i) {
rotatedAngle = rR*i;
x = origin.x + (radius * Math.cos(rotatedAngle));
y = origin.y + (radius * Math.sin(rotatedAngle));
points.push(new SuperMap.Geometry.Point(x, y));
}
rotatedAngle = r*Math.PI/180;
x = origin.x + (radius * Math.cos(rotatedAngle));
y = origin.y + (radius * Math.sin(rotatedAngle));
points.push(new SuperMap.Geometry.Point(x, y));
var ring = new SuperMap.Geometry.LinearRing(points);
ring.rotate(parseFloat(angel),origin);
var geo = new SuperMap.Geometry.Collection([ring]);
geo.origin = origin;
geo.radius = radius;
geo.r = r;
geo.angel = angel;
geo.sides = sides;
geo.polygonType = "Curve";
return geo;
}
function removeData()
{ dataAdded =false;
vector.removeAllFeatures();
vector.refresh();
}
</script>
</head>
<body onload="init()" >
<div id="toolbar">
<input type="button" class="btn"value ="加载数据"onclick="addData()"/>
<input type="button" class="btn"value ="移除数据"onclick="removeData()"/>
</div>
<div id="map"></div>
</body>
</html>
You can’t perform that action at this time.
