Skip to content

Commit a543e2b

Browse files
committed
优化openlayer对接iServer tile
1 parent cdc2e2d commit a543e2b

33 files changed

+78
-166
lines changed

build/deps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ var deps = {
177177
"Map": {
178178
"name": "地图服务",
179179
"src": [
180-
"./src/OL3/SuperMap/iServer/Tile.js",
180+
"./src/OL3/SuperMap/iServer/TileSuperMapRest.js",
181181
"./src/OL3/SuperMap/iServer/MapService.js",
182182
"./src/OL3/SuperMap/iServer/QueryService.js",
183183
"./src/OL3/SuperMap/iServer/ChartQueryService.js",

dist/iclient9-openlayers.js

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,11 @@
7171

7272
__webpack_require__(2)
7373

74-
ol.supermap.Tile = function (options) {
74+
ol.supermap.TileSuperMapRest = function (options) {
7575
if (options.url === undefined) {
7676
return;
7777
}
78-
var tileGrid = options.tileGrid;
79-
var height = tileGrid.tileSize === undefined ? 256 : tileGrid.tileSize[0];
80-
var width = tileGrid.tileSize === undefined ? 256 : tileGrid.tileSize[1];
81-
var layerUrl = options.url + "/image.png?redirect=false&width=" + width + "&height=" + height;
78+
var layerUrl = options.url + "/image.png?redirect=false";
8279
//为url添加安全认证信息片段
8380
if (SuperMap.Credential && SuperMap.Credential.CREDENTIAL) {
8481
layerUrl += "&" + SuperMap.Credential.CREDENTIAL.getUrlParameters();
@@ -101,31 +98,15 @@
10198
if (options.layersID !== undefined) {
10299
layerUrl += "&layersID=" + options.layersID;
103100
}
104-
var extent = tileGrid.extent_;
105-
var origin = tileGrid.origin_;
106-
var origins = tileGrid.origins_;
107-
var resolutions = tileGrid.resolutions_;
108-
109-
var tileUrlFunction = function (tileCoord, pixelRatio, projection) {
110-
var z = tileCoord[0], x = tileCoord[1], y = tileCoord[2], left, bottom, right, top;
111-
var tileOrigin = getTileOrigin(z);
112-
left = tileOrigin[0] + (x * width * resolutions[z]);
113-
bottom = tileOrigin[1] + (y * height * resolutions[z]);
114-
right = tileOrigin[0] + ((x + 1) * width * resolutions[z]);
115-
top = tileOrigin[1] + ((y + 1) * height * resolutions[z]);
116-
return layerUrl + "&viewBounds=" + "{\"leftBottom\" : {\"x\":" + left + ",\"y\":" + bottom + "},\"rightTop\" : {\"x\":" + right + ",\"y\":" + top + "}}";
117-
}
118-
119-
function getTileOrigin(z) {
120-
if (extent) {
121-
return [extent[0], extent[3]];
122-
}
123-
if (origin) {
124-
return origin;
125-
}
126-
if (origins && z) {
127-
return origins[z];
128-
}
101+
function tileUrlFunction(tileCoord, pixelRatio, projection) {
102+
if (!this.tileGrid) {
103+
this.tileGrid = this.getTileGridForProjection(projection);
104+
}
105+
var tileExtent = this.tileGrid.getTileCoordExtent(
106+
tileCoord, this.tmpExtent_);
107+
var tileSize = ol.size.toSize(
108+
this.tileGrid.getTileSize(tileCoord[0]), this.tmpSize);
109+
return layerUrl + "&width=" + tileSize[0] + "&height=" + tileSize[1] + "&viewBounds=" + "{\"leftBottom\" : {\"x\":" + tileExtent[0] + ",\"y\":" + tileExtent[1] + "},\"rightTop\" : {\"x\":" + tileExtent[2] + ",\"y\":" + tileExtent[3] + "}}";
129110
}
130111

131112
ol.source.TileImage.call(this, {
@@ -150,9 +131,8 @@
150131

151132
});
152133
};
153-
ol.inherits(ol.supermap.Tile, ol.source.TileImage);
154-
155-
ol.supermap.Tile.optionsFromMapJSON = function (url, mapJSONObj) {
134+
ol.inherits(ol.supermap.TileSuperMapRest, ol.source.TileImage);
135+
ol.supermap.TileSuperMapRest.optionsFromMapJSON = function (url, mapJSONObj) {
156136
var options = {};
157137
options.url = url;
158138
var extent = [mapJSONObj.bounds.left, mapJSONObj.bounds.bottom, mapJSONObj.bounds.right, mapJSONObj.bounds.top];
@@ -194,7 +174,7 @@
194174
return options;
195175
}
196176

197-
module.exports = ol.supermap.Tile;
177+
module.exports = ol.supermap.TileSuperMapRest;
198178

199179
/***/ },
200180
/* 2 */

examples/ol3/01_layerService.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
overlays: [overlay],
8989
});
9090
var layer = new ol.layer.Tile({
91-
source: new ol.supermap.Tile({
91+
source: new ol.supermap.TileSuperMapRest({
9292
url: url,
9393
tileGrid: new ol.tilegrid.TileGrid({
9494
extent: extent,

examples/ol3/01_mapQueryByBounds.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
})
3434
});
3535
var layer = new ol.layer.Tile({
36-
source: new ol.supermap.Tile({
36+
source: new ol.supermap.TileSuperMapRest({
3737
url: url,
3838
tileGrid: new ol.tilegrid.TileGrid({
3939
extent: extent,

examples/ol3/01_mapQueryByDistance.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
})
3434
});
3535
var layer = new ol.layer.Tile({
36-
source: new ol.supermap.Tile({
36+
source: new ol.supermap.TileSuperMapRest({
3737
url: url,
3838
tileGrid: new ol.tilegrid.TileGrid({
3939
extent: extent,

examples/ol3/01_mapQueryByGeometry.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
})
3434
});
3535
var layer = new ol.layer.Tile({
36-
source: new ol.supermap.Tile({
36+
source: new ol.supermap.TileSuperMapRest({
3737
url: url,
3838
tileGrid: new ol.tilegrid.TileGrid({
3939
extent: extent,

examples/ol3/01_mapQueryBySQL.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
})
3434
});
3535
var layer = new ol.layer.Tile({
36-
source: new ol.supermap.Tile({
36+
source: new ol.supermap.TileSuperMapRest({
3737
url: url,
3838
tileGrid: new ol.tilegrid.TileGrid({
3939
extent: extent,

examples/ol3/01_mapService.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
overlays: [overlay],
9090
});
9191
var layer = new ol.layer.Tile({
92-
source: new ol.supermap.Tile({
92+
source: new ol.supermap.TileSuperMapRest({
9393
url: url,
9494
tileGrid: new ol.tilegrid.TileGrid({
9595
extent: extent,

examples/ol3/01_measure.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
})
3636
});
3737
var layer = new ol.layer.Tile({
38-
source: new ol.supermap.Tile({
38+
source: new ol.supermap.TileSuperMapRest({
3939
url: url,
4040
tileGrid: new ol.tilegrid.TileGrid({
4141
extent: extent,

examples/ol3/01_tiledMapLayer3857.html

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,6 @@
99
<script type="text/javascript" src="../../dist/iclient9-openlayers.js"></script>
1010
<script type="text/javascript">
1111
var map, url = "http://support.supermap.com.cn:8090/iserver/services/map-china400/rest/maps/China";
12-
var dpi = 96;
13-
var extent = [-20037508.34, -20037508.34, 20037508.34, 20037508.34];
14-
var resolutions = [
15-
ol.supermap.Util.scaleToResolution(1.6901635716026555E-9, dpi, Unit.METER),
16-
ol.supermap.Util.scaleToResolution(3.3803271432053056E-9, dpi, Unit.METER),
17-
ol.supermap.Util.scaleToResolution(6.760654286410611E-9, dpi, Unit.METER),
18-
ol.supermap.Util.scaleToResolution(1.3521308572821242E-8, dpi, Unit.METER),
19-
ol.supermap.Util.scaleToResolution(2.7042617145642484E-8, dpi, Unit.METER),
20-
ol.supermap.Util.scaleToResolution(5.408523429128511E-8, dpi, Unit.METER),
21-
ol.supermap.Util.scaleToResolution(1.0817046858256998E-7, dpi, Unit.METER),
22-
ol.supermap.Util.scaleToResolution(2.1634093716513974E-7, dpi, Unit.METER),
23-
ol.supermap.Util.scaleToResolution(4.3268187433028044E-7, dpi, Unit.METER),
24-
ol.supermap.Util.scaleToResolution(8.653637486605571E-7, dpi, Unit.METER),
25-
ol.supermap.Util.scaleToResolution(1.7307274973211203E-6, dpi, Unit.METER),
26-
ol.supermap.Util.scaleToResolution(3.4614549946422405E-6, dpi, Unit.METER),
27-
ol.supermap.Util.scaleToResolution(6.9229099892844565E-6, dpi, Unit.METER),
28-
];
2912
function init() {
3013
var map = new ol.Map({
3114
target: 'map',
@@ -36,14 +19,9 @@
3619
})
3720
});
3821
var layer = new ol.layer.Tile({
39-
source: new ol.supermap.Tile({
22+
source: new ol.supermap.TileSuperMapRest({
4023
url: url,
41-
tileGrid: new ol.tilegrid.TileGrid({
42-
extent: extent,
43-
resolutions: resolutions,
44-
})
4524
}),
46-
projection: 'EPSG:3857'
4725
})
4826
map.addLayer(layer);
4927
}

0 commit comments

Comments
 (0)