Skip to content

Commit 01f4b82

Browse files
committed
增加legacy库;
增加iclient9源码范例
1 parent 9fec62a commit 01f4b82

12 files changed

+668
-0
lines changed
Lines changed: 304 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,304 @@
1+
//TODO 修改注释成标准的格式
2+
/**
3+
* Class: SuperMap.OpenLayers3
4+
* OpenLayers3适配器类
5+
*/
6+
SuperMap.OpenLayers3 = function(){
7+
8+
}
9+
/**
10+
* APIMethod: getLayer
11+
* 创建OpenLayers3的图层new ol.Layer.Tile,这里的图层中切片的来源为iserver服务器(支持3857的地图和4326的地图)
12+
* @param url {String} 地图服务的url地址,如:“http://localhost:8090/iserver/services/map-china400/rest/maps/China”
13+
* @param options 可选的参数
14+
* transparent - {Boolean} 设置切片是否透明,默认为true
15+
* cacheEnabled - {Boolean} 设置是否使用缓存,默认为false
16+
* layersID - {String} 设置临时图层的id,一般用于专题图的叠加使用
17+
* @returns {Object} 返回OpenLayers3的扩展图层对象
18+
*/
19+
SuperMap.OpenLayers3.TileLayer = function(url,options){
20+
if(url == undefined)
21+
{
22+
return;
23+
}
24+
var tileLayer= new ol.layer.Tile({
25+
source:getSource()
26+
});
27+
var layerUrl = url + "/image.png?redirect=false&width=256&height=256";
28+
29+
//为url添加安全认证信息片段
30+
if (SuperMap.Credential && SuperMap.Credential.CREDENTIAL) {
31+
layerUrl += "&" + SuperMap.Credential.CREDENTIAL.getUrlParameters();
32+
}
33+
34+
//切片是否透明
35+
var transparent = true;
36+
if(options && options.transparent !=undefined)
37+
{
38+
transparent = options.transparent;
39+
}
40+
layerUrl += "&transparent=" + transparent;
41+
42+
//是否使用缓存
43+
var cacheEnabled = false;
44+
if(options && options.cacheEnabled !=undefined)
45+
{
46+
cacheEnabled = options.cacheEnabled;
47+
}
48+
layerUrl += "&cacheEnabled=" + cacheEnabled;
49+
50+
//如果有layersID,则是在使用专题图
51+
if(options && options.layersID !=undefined)
52+
{
53+
layerUrl += "&layersID=" +options.layersID;
54+
}
55+
//如果有pro,并且只能是4326或者3857的地图。
56+
var pro="3857";
57+
if(options&&options.pro){
58+
if(options.pro==="4326"){
59+
pro="4326";
60+
}
61+
}
62+
layerUrl+="&projection="+pro;
63+
//计算分辨率和比例尺
64+
var resLen = 17;
65+
var resStart = 0;
66+
var dpi = 95.99999999999984;
67+
var scales3857=[];
68+
var scales4326=[];
69+
var resolutions3857=[];
70+
var resolutions4326=[];
71+
72+
for(var i=resStart;i<=resLen;i++){
73+
var res3857 = 156543.0339/Math.pow(2,i);
74+
75+
resolutions3857.push(res3857);
76+
77+
var scale3857 = 0.0254/dpi/res3857;
78+
scales3857.push(scale3857);
79+
}
80+
tileLayer.scales=scales3857;
81+
82+
83+
for(var i=resStart;i<=resLen;i++){
84+
var res4326 = 1.40625/Math.pow(2,i);
85+
resolutions4326.push(res4326);
86+
87+
var scale4326 = 0.0254*360/dpi/res4326/Math.PI/2/6378137;
88+
scales4326.push(scale4326);
89+
}
90+
tileLayer.scales=scales4326;
91+
92+
function getSource(){
93+
94+
var tileUrl;
95+
var source= new ol.source.TileImage({
96+
tileUrlFunction:function(tileCoord, pixelRatio, projection){
97+
var z=tileCoord[0], x= tileCoord[1],y =tileCoord[2];
98+
if(pro==="3857"){
99+
x-= Math.pow(2,z-1);
100+
y+=Math.pow(2,z-1);
101+
var left = x*256*resolutions3857[z];
102+
var bottom = y*256*resolutions3857[z];
103+
var right = (x + 1)*256*resolutions3857[z];
104+
var top = (y+1)*256*resolutions3857[z];
105+
tileUrl = layerUrl+"&viewBounds=" +"{\"leftBottom\" : {\"x\":" + left +",\"y\":" + bottom +"},\"rightTop\" : {\"x\":" + right +",\"y\":" +top + "}}";
106+
//tileUrl +="&scale=" +scales3857[z];
107+
108+
}
109+
else if(pro==="4326"){
110+
//x-= Math.pow(2,z-1);
111+
//y+=Math.pow(2,z-1);
112+
var left = -180+(x*256*resolutions4326[z]);
113+
var bottom =90+(y*256*resolutions4326[z]);
114+
var right = -180+((x + 1)*256*resolutions4326[z]);
115+
var top = 90+((y+1)*256*resolutions4326[z]);
116+
tileUrl = layerUrl+"&viewBounds=" +"{\"leftBottom\" : {\"x\":" + left +",\"y\":" + bottom +"},\"rightTop\" : {\"x\":" + right +",\"y\":" +top + "}}";
117+
//tileUrl +="&scale=" +scales4326[z];
118+
119+
}
120+
var epsg=pro==="3857"?3857:4326;
121+
tileUrl += "&prjCoordSys={\"epsgCode\":"+epsg+"}";
122+
return tileUrl;
123+
}
124+
});
125+
return source;
126+
}
127+
return tileLayer;
128+
}
129+
130+
/**
131+
* APIMethod:
132+
* 将其他坐标系下的点转换为OpenLayers3的点
133+
* @param array 点数组,支持四种形式的点:
134+
* 1、var points = [
135+
* {x:116.1,y:38.9},
136+
* {x:114.1,y:34.1}
137+
* ];
138+
* 2、var points = [
139+
* new SuperMap.Geometry.Point(116.1,38.9),
140+
* new SuperMap.Geometry.Point(116.1,38.9)
141+
* ];
142+
* 3、var points = [
143+
* new SuperMap.LonLat(116.1,38.9),
144+
* new SuperMap.LonLat(116.1,38.4)
145+
* ];
146+
* 4、var points = [
147+
* new ol.geom.Point([39.9,116.38]),
148+
* new ol.geom.Point([39.9,116.35])
149+
* ];
150+
* @param projection {SuperMap.Projection} 待转换点的投影系(数组里面的所有点投影系都必须是统一的),默认为4326.
151+
* @returns {Array} 返回ol.geom.Point对象的数组
152+
*/
153+
SuperMap.OpenLayers3.transferPoint = function(array,projection){
154+
if((typeof array) == "object" && array != null && array.constructor == Array)
155+
{
156+
var pro = projection || new SuperMap.Projection("EPSG:4326");
157+
var points = []
158+
//分几种不同的情况
159+
for(var i = 0;i<array.length;i++)
160+
{
161+
var smPoint;
162+
if(array[i].CLASS_NAME && array[i].CLASS_NAME == "SuperMap.LonLat")
163+
{
164+
//首先转换为标准4326的坐标
165+
smPoint = SuperMap.Projection.transform(new SuperMap.Geometry.Point(array[i].lon,array[i].lat),pro,new SuperMap.Projection("EPSG:4326"));
166+
167+
}
168+
//支持{x:118,y:38}和SuperMap.Geometry.Point的形式,因为都存在x和y
169+
else if(array[i].x != undefined && array[i].y != undefined)
170+
{
171+
//首先转换为标准4326的坐标
172+
smPoint = SuperMap.Projection.transform(new SuperMap.Geometry.Point(array[i].x,array[i].y),pro,new SuperMap.Projection("EPSG:4326"));
173+
174+
}
175+
//支持OpenLayers3的LatLng的形式
176+
else if(array[i].lat != undefined && array[i].lng != undefined)
177+
{
178+
//首先转换为标准4326的坐标
179+
smPoint = SuperMap.Projection.transform(new SuperMap.Geometry.Point(array[i].lng,array[i].lat),projection,new SuperMap.Projection("EPSG:4326"));
180+
181+
}
182+
var point = new ol.geom.Point([smPoint.x,smPoint.y]);
183+
points.push(point);
184+
}
185+
return points;
186+
}
187+
}
188+
/**
189+
* APIMethod:
190+
* 将其他坐标系下的线数组转换为OpenLayers3支持的线数组
191+
* @param array 线数组,支持两种形式
192+
* 1、var lines = [new SuperMap.Geometry.LineString(
193+
* new SuperMap.Geometry.Point(116.1,38.9),
194+
* new SuperMap.Geometry.Point(116.1,38.9)
195+
* )];
196+
* 2、var lines = [new ol.geom.LineString( [39.9,116.38],[0,0])];
197+
*
198+
*
199+
* @param projection {SuperMap.Projection} 需要转换的线的坐标系
200+
* @returns {Array} 返回LineString对象的数组
201+
*/
202+
SuperMap.OpenLayers3.transferLine = function(array,projection){
203+
if((typeof array) == "object" && array != null && array.constructor == Array)
204+
{
205+
var pro = projection || new SuperMap.Projection("EPSG:4326");
206+
var lines = [];
207+
//分几种不同的情况,现在只提供两种
208+
for(var i = 0;i<array.length;i++)
209+
{
210+
var line;
211+
//支持supermap的LineString
212+
if(array[i].CLASS_NAME && array[i].CLASS_NAME == "SuperMap.Geometry.LineString")
213+
{
214+
var points = SuperMap.OpenLayers3 .transferPoint(array[i].components,pro);
215+
216+
line = new ol.geom.LineString(getcoordinate(points));
217+
}
218+
else if(array[i].polygonType != undefined && array[i].getType() == 4)
219+
{
220+
var points = SuperMap.Web.iConnector.Tianditu.transferPoint(array[i].getLngLats(),pro);
221+
line = new ol.geom.LineString(getcoordinate(points));
222+
}
223+
lines.push(line);
224+
}
225+
return lines;
226+
}
227+
}
228+
function getcoordinate(points){
229+
var coordinates=[];
230+
for(var i=0;i<points.length;i++){
231+
coordinates.push(points[i].getCoordinates());
232+
}
233+
return coordinates;
234+
}
235+
236+
/**
237+
* APIMethod:
238+
* 将其他坐标系下的多边形数组转换为OpenLayers3支持的多边形数组
239+
* @param array 多边形数组,支持两种形式:
240+
* 1、var polygons = [new SuperMap.Geometry.Polygon(
241+
* [new SuperMap.Geometry.LinearRing(
242+
* new SuperMap.Geometry.Point(116.3786889372559,39.90762965106183),
243+
* new SuperMap.Geometry.Point(116.38632786853032,39.90795884517671),
244+
* new SuperMap.Geometry.Point(116.38534009082035,39.897432133833574),
245+
* new SuperMap.Geometry.Point(116.37624058825688,39.89789300648029)
246+
* )
247+
* ]
248+
* )];
249+
* 2、var polygons = [new ol.geom.Polygon([[39.9,116.38],[0,0],[30.34,110.34]])];
250+
*
251+
* @param projection {SuperMap.Projection} 需要转换的多边形的坐标系
252+
* @returns {Array} 返回Polygon对象的数组
253+
*/
254+
SuperMap.OpenLayers3.transferPolygon = function(array,projection){
255+
if((typeof array) == "object" && array != null && array.constructor == Array)
256+
{
257+
var pro = projection || new SuperMap.Projection("EPSG:4326");
258+
var polygons = [];
259+
//分几种不同的情况,现在只提供两种
260+
for(var i = 0;i<array.length;i++)
261+
{
262+
var polygon;
263+
//支持supermap的Polygon
264+
if(array[i].CLASS_NAME && array[i].CLASS_NAME == "SuperMap.Geometry.Polygon")
265+
{
266+
var points = SuperMap.OpenLayers3 .transferPoint(array[i].getVertices(false),pro);
267+
polygon = new ol.geom.Polygon([getcoordinate(points)]);
268+
}
269+
270+
//支持Polygon的对象
271+
else if(array[i].getType != undefined && array[i].getType() == 5)
272+
{
273+
var points = SuperMap.OpenLayers3 .transferPoint(array[i].getLngLats(),pro);
274+
polygon = new ol.geom.Polygon([getcoordinate(points)]);
275+
}
276+
277+
polygons.push(polygon);
278+
}
279+
return polygons;
280+
}
281+
}
282+
SuperMap.OpenLayers3.queryByDistance = function(url,queryByDistanceParams,completedCallBack,failedCallBack){
283+
var queryByDistanceService = new SuperMap.REST.QueryByDistanceService(url);
284+
queryByDistanceService.events.on({
285+
"processCompleted": function processCompleted(queryEventArgs) {
286+
var i, j, result = queryEventArgs.result;
287+
var features = [];
288+
for(i = 0;i < result.recordsets.length; i++) {
289+
for(j = 0; j < result.recordsets[i].features.length; j++) {
290+
var point = result.recordsets[i].features[j].geometry;
291+
var resultPoints=SuperMap.OpenLayers3.transferPoint([point])[0];
292+
var pointFeature=new ol.Feature({
293+
'geometry':resultPoints
294+
});
295+
features.push(pointFeature);
296+
}
297+
298+
}
299+
completedCallBack(features);
300+
},
301+
"processFailed": failedCallBack
302+
});
303+
queryByDistanceService.processAsync(queryByDistanceParams);
304+
}

src/iclient_legacy.js

Whitespace-only changes.

0 commit comments

Comments
 (0)