@supermapgis/iclient-ol 11.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/README.md +56 -0
  2. package/control/ChangeTileVersion.js +438 -0
  3. package/control/Logo.js +99 -0
  4. package/control/ScaleLine.js +164 -0
  5. package/control/index.js +6 -0
  6. package/core/MapExtend.js +49 -0
  7. package/core/StyleUtils.js +1253 -0
  8. package/core/Util.js +478 -0
  9. package/core/index.js +6 -0
  10. package/css/ChangeTileVersion.css +347 -0
  11. package/css/index.js +5 -0
  12. package/dist/iclient-openlayers-es6.js +121806 -0
  13. package/dist/iclient-openlayers-es6.min.js +8 -0
  14. package/dist/iclient-openlayers.css +668 -0
  15. package/dist/iclient-openlayers.js +132335 -0
  16. package/dist/iclient-openlayers.min.css +8 -0
  17. package/dist/iclient-openlayers.min.js +8 -0
  18. package/index.js +9 -0
  19. package/mapping/BaiduMap.js +121 -0
  20. package/mapping/ImageSuperMapRest.js +252 -0
  21. package/mapping/ImageTileSuperMapRest.js +99 -0
  22. package/mapping/InitMap.js +125 -0
  23. package/mapping/SuperMapCloud.js +56 -0
  24. package/mapping/Tianditu.js +152 -0
  25. package/mapping/TileSuperMapRest.js +358 -0
  26. package/mapping/WebMap.js +5185 -0
  27. package/mapping/index.js +11 -0
  28. package/mapping/webmap/Util.js +176 -0
  29. package/mapping/webmap/config/MunicipalCenter.json +1 -0
  30. package/mapping/webmap/config/ProvinceCenter.json +1 -0
  31. package/mapping/webmap/config/SampleDataInfo.json +55 -0
  32. package/namespace.js +150 -0
  33. package/overlay/DataFlow.js +114 -0
  34. package/overlay/FGB.js +97 -0
  35. package/overlay/Graph.js +436 -0
  36. package/overlay/GraphMap.js +91 -0
  37. package/overlay/Graphic.js +587 -0
  38. package/overlay/HeatMap.js +444 -0
  39. package/overlay/Label.js +964 -0
  40. package/overlay/Mapv.js +146 -0
  41. package/overlay/Range.js +127 -0
  42. package/overlay/RankSymbol.js +94 -0
  43. package/overlay/Turf.js +298 -0
  44. package/overlay/Unique.js +123 -0
  45. package/overlay/VectorTileSuperMapRest.js +466 -0
  46. package/overlay/graphic/CanvasRenderer.js +177 -0
  47. package/overlay/graphic/CloverShape.js +133 -0
  48. package/overlay/graphic/Graphic.js +174 -0
  49. package/overlay/graphic/HitCloverShape.js +63 -0
  50. package/overlay/graphic/WebGLRenderer.js +356 -0
  51. package/overlay/graphic/index.js +9 -0
  52. package/overlay/index.js +21 -0
  53. package/overlay/mapv/MapvCanvasLayer.js +104 -0
  54. package/overlay/mapv/MapvLayer.js +410 -0
  55. package/overlay/mapv/index.js +5 -0
  56. package/overlay/theme/GeoFeature.js +275 -0
  57. package/overlay/theme/Theme.js +585 -0
  58. package/overlay/theme/ThemeFeature.js +46 -0
  59. package/overlay/theme/index.js +6 -0
  60. package/overlay/vectortile/DeafultCanvasStyle.js +125 -0
  61. package/overlay/vectortile/MapboxStyles.js +375 -0
  62. package/overlay/vectortile/StyleMap.js +252 -0
  63. package/overlay/vectortile/VectorTileStyles.js +554 -0
  64. package/overlay/vectortile/index.js +7 -0
  65. package/overlay/vectortile/olExtends.js +382 -0
  66. package/package.json +29 -0
  67. package/services/AddressMatchService.js +60 -0
  68. package/services/ChartService.js +74 -0
  69. package/services/DataFlowService.js +118 -0
  70. package/services/DatasetService.js +104 -0
  71. package/services/DatasourceService.js +76 -0
  72. package/services/FeatureService.js +196 -0
  73. package/services/FieldService.js +53 -0
  74. package/services/GeoprocessingService.js +156 -0
  75. package/services/GridCellInfosService.js +53 -0
  76. package/services/ImageCollectionService.js +92 -0
  77. package/services/ImageService.js +69 -0
  78. package/services/KnowledgeGraphService.js +82 -0
  79. package/services/LayerInfoService.js +85 -0
  80. package/services/MapService.js +85 -0
  81. package/services/MeasureService.js +77 -0
  82. package/services/NetworkAnalyst3DService.js +88 -0
  83. package/services/NetworkAnalystService.js +252 -0
  84. package/services/ProcessingService.js +478 -0
  85. package/services/QueryService.js +116 -0
  86. package/services/ServiceBase.js +26 -0
  87. package/services/SpatialAnalystService.js +432 -0
  88. package/services/ThemeService.js +50 -0
  89. package/services/TrafficTransferAnalystService.js +88 -0
  90. package/services/WebPrintingJobService.js +112 -0
  91. package/services/index.js +27 -0
@@ -0,0 +1,152 @@
1
+ /* Copyright© 2000 - 2024 SuperMap Software Co.Ltd. All rights reserved.
2
+ * This program are made available under the terms of the Apache License, Version 2.0
3
+ * which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
4
+
5
+ import WMTS from 'ol/source/WMTS';
6
+ import WMTSTileGrid from 'ol/tilegrid/WMTS';
7
+
8
+ /**
9
+ * @class Tianditu
10
+ * @browsernamespace ol.source
11
+ * @category ThirdPartyMap
12
+ * @classdesc 天地图图层源。
13
+ * @modulecategory Mapping
14
+ * @param {Object} opt_options - 参数。
15
+ * @param {string} [opt_options.url='http://t{0-7}.tianditu.gov.cn/{layer}_{proj}/wmts?'] - 服务地址。
16
+ * @param {string} opt_options.key - 天地图服务密钥。详见{@link http://lbs.tianditu.gov.cn/server/MapService.html}
17
+ * @param {string} [opt_options.layerType='vec'] - 图层类型。(vec:矢量图层,img:影像图层,ter:地形图层)
18
+ * @param {string} [opt_options.attributions] - 版权描述信息。
19
+ * @param {number} [opt_options.cacheSize = 2048] - 缓冲大小。
20
+ * @param {function} [opt_options.tileLoadFunction] - 切片加载完成后执行函数。
21
+ * @param {string} [opt_options.style] - 图层风格。
22
+ * @param {string} [opt_options.format='tiles'] - 格式。
23
+ * @param {boolean} [opt_options.isLabel] - 是否是标注图层。
24
+ * @param {boolean} [opt_options.opaque=true] - 是否透明。
25
+ * @param {string} [opt_options.tileProxy] - 代理地址。
26
+ * @extends {ol.source.WMTS}
27
+ * @usage
28
+ */
29
+ export class Tianditu extends WMTS {
30
+ constructor(opt_options) {
31
+ var layerLabelMap = {
32
+ "vec": "cva",
33
+ "ter": "cta",
34
+ "img": "cia"
35
+ }
36
+ var layerZoomMap = {
37
+ "vec": 18,
38
+ "ter": 14,
39
+ "img": 18
40
+ }
41
+ var options = opt_options || {};
42
+ var attributions = options.attributions || "Map Data <a href='http://www.tianditu.gov.cn' target='_blank'><img style='background-color:transparent;bottom:2px;opacity:1;' " +
43
+ "src='http://api.tianditu.gov.cn/img/map/logo.png' width='53px' height='22px' opacity='0'></a> with " +
44
+ "<span>© SuperMap iClient</span>"
45
+ options.layerType = options.layerType || "vec";
46
+ options.layerType = options.isLabel ? layerLabelMap[options.layerType] : options.layerType;
47
+ options.matrixSet = (options.projection === 'EPSG:4326' || options.projection === 'EPSG:4490') ? "c" : "w";
48
+ if (!options.url && !options.urls) {
49
+ options.url = "http://t{0-7}.tianditu.gov.cn/{layer}_{proj}/wmts?"
50
+ }
51
+ if (options.key) {
52
+ options.url = `${options.url}tk=${options.key}`;
53
+ }
54
+ options.url = options.url.replace("{layer}", options.layerType).replace("{proj}", options.matrixSet);
55
+ var tileGrid = options.tileGrid || Tianditu.getTileGrid(options.projection || 'EPSG:3857');
56
+
57
+ var crossOrigin = options.crossOrigin !== undefined ? options.crossOrigin : 'anonymous';
58
+
59
+ var superOptions = {
60
+ version: options.version || '1.0.0',
61
+ format: options.format || 'tiles',
62
+ dimensions: options.dimensions || {},
63
+ layer: options.layerType,
64
+ matrixSet: options.matrixSet,
65
+ tileGrid: tileGrid,
66
+ style: options.style || 'default',
67
+ attributions: attributions,
68
+ cacheSize: options.cacheSize,
69
+ crossOrigin: crossOrigin,
70
+ opaque: options.opaque === undefined ? true : options.opaque,
71
+ maxZoom: layerZoomMap[options.layerType],
72
+ reprojectionErrorThreshold: options.reprojectionErrorThreshold,
73
+ url: options.url,
74
+ urls: options.urls,
75
+ projection: options.projection || 'EPSG:3857',
76
+ wrapX: options.wrapX
77
+ };
78
+ //需要代理时走自定义 tileLoadFunction,否则走默认的tileLoadFunction
79
+ if (options.tileProxy) {
80
+ superOptions.tileLoadFunction = tileLoadFunction;
81
+ }
82
+ super(superOptions);
83
+
84
+ if (options.tileProxy) {
85
+ this.tileProxy = options.tileProxy;
86
+ }
87
+ //需要代理时,走以下代码
88
+ var me = this;
89
+
90
+ function tileLoadFunction(imageTile, src) {
91
+ //支持代理
92
+ imageTile.getImage().src = me.tileProxy + encodeURIComponent(src);
93
+ }
94
+ }
95
+
96
+ /**
97
+ * @function Tianditu.getTileGrid
98
+ * @description 获取瓦片网格。
99
+ * @param {string} projection - 投影参考对象。
100
+ * @returns {ol.tilegrid.WMTS} 返回瓦片网格对象。
101
+ */
102
+ static getTileGrid(projection) {
103
+ if (projection === "EPSG:4326" || projection === "EPSG:4490") {
104
+ return Tianditu.default4326TileGrid();
105
+ }
106
+ return Tianditu.default3857TileGrid();
107
+ }
108
+
109
+ /**
110
+ * @function Tianditu.default4326TileGrid
111
+ * @description 获取默认 4326 网格瓦片。
112
+ * @returns {ol.tilegrid.WMTS} 返回默认 4326 网格瓦片对象。
113
+ */
114
+ static default4326TileGrid() {
115
+ var tdt_WGS84_resolutions = [];
116
+ var matrixIds = [];
117
+ for (var i = 1; i < 19; i++) {
118
+ tdt_WGS84_resolutions.push(0.703125 * 2 / (Math.pow(2, i)));
119
+ matrixIds.push(i);
120
+ }
121
+ var tileGird = new WMTSTileGrid({
122
+ extent: [-180, -90, 180, 90],
123
+ resolutions: tdt_WGS84_resolutions,
124
+ origin: [-180, 90],
125
+ matrixIds: matrixIds,
126
+ minZoom: 1
127
+ });
128
+ return tileGird;
129
+ }
130
+
131
+ /**
132
+ * @function Tianditu.default3857TileGrid
133
+ * @description 获取默认 3857 网格瓦片。
134
+ * @returns {ol.tilegrid.WMTS} 返回默认 3857 网格瓦片对象。
135
+ */
136
+ static default3857TileGrid() {
137
+ var tdt_Mercator_resolutions = [];
138
+ var matrixIds = [];
139
+ for (var i = 1; i < 19; i++) {
140
+ tdt_Mercator_resolutions.push(78271.5169640203125 * 2 / (Math.pow(2, i)));
141
+ matrixIds.push(i);
142
+ }
143
+ var tileGird = new WMTSTileGrid({
144
+ extent: [-20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892],
145
+ resolutions: tdt_Mercator_resolutions,
146
+ matrixIds: matrixIds,
147
+ origin: [-20037508.3427892, 20037508.3427892],
148
+ minZoom: 1
149
+ });
150
+ return tileGird;
151
+ }
152
+ }
@@ -0,0 +1,358 @@
1
+ /* Copyright© 2000 - 2024 SuperMap Software Co.Ltd. All rights reserved.
2
+ * This program are made available under the terms of the Apache License, Version 2.0
3
+ * which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
4
+ import { SecurityManager } from '@supermapgis/iclient-common/security/SecurityManager';
5
+ import { Unit } from '@supermapgis/iclient-common/REST';
6
+ import { Util as CommonUtil } from '@supermapgis/iclient-common/commontypes/Util';
7
+ import { ServerGeometry } from '@supermapgis/iclient-common/iServer/ServerGeometry';
8
+ import { Util } from '../core/Util';
9
+ import TileImage from 'ol/source/TileImage';
10
+ import Geometry from 'ol/geom/Geometry';
11
+ import GeoJSON from 'ol/format/GeoJSON';
12
+ import * as olSize from 'ol/size';
13
+ import * as olTilegrid from 'ol/tilegrid';
14
+ import TileGrid from 'ol/tilegrid/TileGrid';
15
+
16
+ /**
17
+ * @class TileSuperMapRest
18
+ * @browsernamespace ol.source
19
+ * @category iServer Map Tile
20
+ * @modulecategory Mapping
21
+ * @classdesc SuperMap iServer TileImage 图层源。
22
+ * @param {Object} options - 参数。
23
+ * @param {string} options.url - 服务地址,例如: http://{ip}:{port}/iserver/services/map-world/rest/maps/World。
24
+ * @param {ol.tilegrid.TileGrid} [options.tileGrid] - 瓦片网格对象。当不指定时,会通过 options.extent 或投影范围生成。
25
+ * @param {boolean} [options.redirect = false] - 是否重定向。
26
+ * @param {boolean} [options.transparent = true] - 瓦片是否透明。
27
+ * @param {boolean} [options.cacheEnabled = true] - 是否使用服务端的缓存。
28
+ * @param {Object} [options.prjCoordSys] - 请求的地图的坐标参考系统。当此参数设置的坐标系统不同于地图的原有坐标系统时,系统会进行动态投影,并返回动态投影后的地图瓦片。例如:{"epsgCode":3857}。
29
+ * @param {string} [options.layersID] - 获取进行切片的地图图层 ID,即指定进行地图切片的图层,可以是临时图层集,也可以是当前地图中图层的组合。
30
+ * @param {boolean} [options.clipRegionEnabled = false] - 是否只地图只显示该区域覆盖的部分。true 表示地图只显示该区域覆盖的部分。
31
+ * @param {ol.geom.Geometry} [options.clipRegion] - 地图显示裁剪的区域。是一个面对象,当 clipRegionEnabled = true 时有效,即地图只显示该区域覆盖的部分。
32
+ * @param {boolean} [options.overlapDisplayed = false] - 地图对象在同一范围内时,是否重叠显示。如果为 true,则同一范围内的对象会直接压盖;如果为 false 则通过 overlapDisplayedOptions 控制对象不压盖显示。
33
+ * @param {OverlapDisplayedOptions} [options.overlapDisplayedOptions] - 避免地图对象压盖显示的过滤选项,当 overlapDisplayed 为 false 时有效,用来增强对地图对象压盖时的处理。
34
+ * @param {string} [options.tileversion] - 切片版本名称,_cache 为 true 时有效。
35
+ * @param {string} [options.tileProxy] - 服务代理地址。
36
+ * @param {string} [options.format = 'png'] - 瓦片表述类型,支持 "png" 、"webp"、"bmp" 、"jpg"、"gif" 等图片类型。
37
+ * @param {(NDVIParameter|HillshadeParameter)} [options.rasterfunction] - 栅格分析参数。
38
+ * @extends {ol.source.TileImage}
39
+ * @usage
40
+ */
41
+ export class TileSuperMapRest extends TileImage {
42
+ constructor(options) {
43
+ options = options || {};
44
+ options.attributions =
45
+ options.attributions || "Map Data <span>© SuperMap iServer</span> with <span>© SuperMap iClient</span>";
46
+
47
+ options.format = options.format ? options.format : 'png';
48
+
49
+ super({
50
+ attributions: options.attributions,
51
+ cacheSize: options.cacheSize,
52
+ crossOrigin: options.crossOrigin,
53
+ logo: Util.getOlVersion() === '4' ? options.logo : null,
54
+ opaque: options.opaque,
55
+ projection: options.projection,
56
+ reprojectionErrorThreshold: options.reprojectionErrorThreshold,
57
+ state: options.state,
58
+ tileClass: options.tileClass,
59
+ tileGrid: options.tileGrid,
60
+ tileLoadFunction: options.tileLoadFunction,
61
+ tilePixelRatio: options.tilePixelRatio,
62
+ tileUrlFunction: tileUrlFunction,
63
+ wrapX: options.wrapX !== undefined ? options.wrapX : false,
64
+ cacheEnabled: options.cacheEnabled,
65
+ layersID: options.layersID
66
+ });
67
+ if (options.tileProxy) {
68
+ this.tileProxy = options.tileProxy;
69
+ }
70
+ this.options = options;
71
+ this._url = options.url;
72
+ //当前切片在切片集中的index
73
+ this.tileSetsIndex = -1;
74
+ this.tempIndex = -1;
75
+ this.dpi = this.options.dpi || 96;
76
+ var me = this;
77
+ var layerUrl = CommonUtil.urlPathAppend(options.url, 'tileImage.' + options.format);
78
+
79
+ /**
80
+ * @function TileSuperMapRest.prototype.getAllRequestParams
81
+ * @description 获取全部请求参数。
82
+ */
83
+ function getAllRequestParams() {
84
+ var me = this,
85
+ params = {};
86
+
87
+ params['redirect'] = options.redirect !== undefined ? options.redirect : false;
88
+ //切片是否透明
89
+ params['transparent'] = options.transparent !== undefined ? options.transparent : true;
90
+ params['cacheEnabled'] = !(options.cacheEnabled === false);
91
+ //存储一个cacheEnabled参数
92
+ me.cacheEnabled = params['cacheEnabled'];
93
+ params['_cache'] = params['cacheEnabled'];
94
+
95
+ //设置切片原点
96
+ if (this.origin) {
97
+ params['origin'] = JSON.stringify({
98
+ x: this.origin[0],
99
+ y: this.origin[1]
100
+ });
101
+ }
102
+
103
+ if (options.prjCoordSys) {
104
+ params['prjCoordSys'] = JSON.stringify(options.prjCoordSys);
105
+ }
106
+
107
+ if (options.layersID) {
108
+ params['layersID'] = options.layersID.toString();
109
+ }
110
+
111
+ if (options.clipRegion instanceof Geometry) {
112
+ options.clipRegionEnabled = true;
113
+ options.clipRegion = Util.toSuperMapGeometry(new GeoJSON().writeGeometryObject(options.clipRegion));
114
+ options.clipRegion = CommonUtil.toJSON(ServerGeometry.fromGeometry(options.clipRegion));
115
+ params['clipRegionEnabled'] = options.clipRegionEnabled;
116
+ params['clipRegion'] = JSON.stringify(options.clipRegion);
117
+ }
118
+
119
+ if (!options.overlapDisplayed) {
120
+ params['overlapDisplayed'] = false;
121
+ if (options.overlapDisplayedOptions) {
122
+ params['overlapDisplayedOptions'] = me.overlapDisplayedOptions.toString();
123
+ }
124
+ } else {
125
+ params['overlapDisplayed'] = true;
126
+ }
127
+
128
+ if (params.cacheEnabled && options.tileversion) {
129
+ params['tileversion'] = options.tileversion.toString();
130
+ }
131
+ if (options.rasterfunction) {
132
+ params['rasterfunction'] = JSON.stringify(options.rasterfunction);
133
+ }
134
+
135
+ return params;
136
+ }
137
+
138
+ /**
139
+ * @function TileSuperMapRest.prototype.getFullRequestUrl
140
+ * @description 获取完整的请求地址。
141
+ */
142
+ function getFullRequestUrl() {
143
+ if (this._paramsChanged) {
144
+ this._layerUrl = createLayerUrl.call(this);
145
+ this._paramsChanged = false;
146
+ }
147
+ return this._layerUrl || createLayerUrl.call(this);
148
+ }
149
+
150
+ /**
151
+ * @function TileSuperMapRest.prototype.createLayerUrl
152
+ * @description 获取新建图层地址。
153
+ */
154
+ function createLayerUrl() {
155
+ this.requestParams = this.requestParams || getAllRequestParams.call(this);
156
+ this._layerUrl = CommonUtil.urlAppend(layerUrl, CommonUtil.getParameterString(this.requestParams));
157
+ //为url添加安全认证信息片段
158
+ this._layerUrl = SecurityManager.appendCredential(this._layerUrl);
159
+ return this._layerUrl;
160
+ }
161
+
162
+ function tileUrlFunction(tileCoord, pixelRatio, projection) {
163
+ if (!me.tileGrid) {
164
+ if (options.extent) {
165
+ me.tileGrid = TileSuperMapRest.createTileGrid(options.extent);
166
+ if (me.resolutions) {
167
+ me.tileGrid.resolutions = me.resolutions;
168
+ }
169
+ } else {
170
+ if (projection.getCode() === 'EPSG:3857') {
171
+ me.tileGrid = TileSuperMapRest.createTileGrid([
172
+ -20037508.3427892,
173
+ -20037508.3427892,
174
+ 20037508.3427892,
175
+ 20037508.3427892
176
+ ]);
177
+ me.extent = [-20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892];
178
+ }
179
+ if (projection.getCode() === 'EPSG:4326') {
180
+ me.tileGrid = TileSuperMapRest.createTileGrid([-180, -90, 180, 90]);
181
+ me.extent = [-180, -90, 180, 90];
182
+ }
183
+ }
184
+ }
185
+ me.origin = me.tileGrid.getOrigin(0);
186
+ var z = tileCoord[0];
187
+ var x = tileCoord[1];
188
+ var y = ['4', '5'].indexOf(Util.getOlVersion()) > -1 ? -tileCoord[2] - 1 : tileCoord[2];
189
+ var resolution = me.tileGrid.getResolution(z);
190
+ var dpi = me.dpi || 96;
191
+ var unit = projection.getUnits() || Unit.DEGREE;
192
+ // OGC WKT 解析出单位是 degree
193
+ if (unit === 'degrees' || unit === 'degree') {
194
+ unit = Unit.DEGREE;
195
+ }
196
+ //通过wkt方式自定义坐标系的时候,是meter
197
+ if (unit === 'm' || unit === 'meter') {
198
+ unit = Unit.METER;
199
+ }
200
+ var scale = Util.resolutionToScale(resolution, dpi, unit);
201
+ var tileSize = olSize.toSize(me.tileGrid.getTileSize(z, me.tmpSize));
202
+ var layerUrl = getFullRequestUrl.call(me);
203
+ var url =
204
+ layerUrl +
205
+ encodeURI(
206
+ '&x=' + x + '&y=' + y + '&width=' + tileSize[0] + '&height=' + tileSize[1] + '&scale=' + scale
207
+ );
208
+ //支持代理
209
+ if (me.tileProxy) {
210
+ url = me.tileProxy + encodeURIComponent(url);
211
+ }
212
+ if (!me.cacheEnabled) {
213
+ url += '&_t=' + new Date().getTime();
214
+ }
215
+ return url;
216
+ }
217
+ }
218
+
219
+ /**
220
+ * @function TileSuperMapRest.prototype.setTileSetsInfo
221
+ * @description 设置瓦片集信息。
222
+ * @param {Object} tileSets - 瓦片集合。
223
+ */
224
+ setTileSetsInfo(tileSets) {
225
+ this.tileSets = tileSets;
226
+ if (Util.isArray(this.tileSets)) {
227
+ this.tileSets = tileSets[0];
228
+ }
229
+ if (!this.tileSets) {
230
+ return;
231
+ }
232
+ this.dispatchEvent({
233
+ type: 'tilesetsinfoloaded',
234
+ value: {
235
+ tileVersions: this.tileSets.tileVersions
236
+ }
237
+ });
238
+ this.changeTilesVersion();
239
+ }
240
+
241
+ /**
242
+ * @function TileSuperMapRest.prototype.lastTilesVersion
243
+ * @description 请求上一个版本切片,并重新绘制。
244
+ */
245
+ lastTilesVersion() {
246
+ this.tempIndex = this.tileSetsIndex - 1;
247
+ this.changeTilesVersion();
248
+ }
249
+
250
+ /**
251
+ * @function TileSuperMapRest.prototype.nextTilesVersion
252
+ * @description 请求下一个版本切片,并重新绘制。
253
+ */
254
+ nextTilesVersion() {
255
+ this.tempIndex = this.tileSetsIndex + 1;
256
+ this.changeTilesVersion();
257
+ }
258
+
259
+ /**
260
+ * @function TileSuperMapRest.prototype.changeTilesVersion
261
+ * @description 切换到某一版本的切片,并重绘。通过 this.tempIndex 保存需要切换的版本索引。
262
+ */
263
+ changeTilesVersion() {
264
+ var me = this;
265
+ //切片版本集信息是否存在
266
+ if (me.tileSets == null) {
267
+ return;
268
+ }
269
+ if (me.tempIndex === me.tileSetsIndex || this.tempIndex < 0) {
270
+ return;
271
+ }
272
+ //检测index是否可用
273
+ var tileVersions = me.tileSets.tileVersions;
274
+ if (tileVersions && me.tempIndex < tileVersions.length && me.tempIndex >= 0) {
275
+ var name = tileVersions[me.tempIndex].name;
276
+ var result = me.mergeTileVersionParam(name);
277
+ if (result) {
278
+ me.tileSetsIndex = me.tempIndex;
279
+ me.dispatchEvent({
280
+ type: 'tileversionschanged',
281
+ value: {
282
+ tileVersion: tileVersions[me.tempIndex]
283
+ }
284
+ });
285
+ }
286
+ }
287
+ }
288
+
289
+ /**
290
+ * @function TileSuperMapRest.prototype.updateCurrentTileSetsIndex
291
+ * @description 更新当前切片集索引,目前主要提供给控件使用。
292
+ * @param {number} index - 索引号。
293
+ */
294
+ updateCurrentTileSetsIndex(index) {
295
+ this.tempIndex = index;
296
+ }
297
+
298
+ /**
299
+ * @function TileSuperMapRest.prototype.mergeTileVersionParam
300
+ * @description 更改 URL 请求参数中的切片版本号,并重绘。
301
+ * @param {Object} version - 版本信息。
302
+ * @returns {boolean} 是否成功。
303
+ */
304
+ mergeTileVersionParam(version) {
305
+ if (version) {
306
+ this.requestParams['tileversion'] = version;
307
+ this._paramsChanged = true;
308
+ this.refresh();
309
+ return true;
310
+ }
311
+ return false;
312
+ }
313
+
314
+ /**
315
+ * @function TileSuperMapRest.optionsFromMapJSON
316
+ * @description 从 MapJSON 中获取参数对象。
317
+ * @param {string} url - 服务地址。
318
+ * @param {Object} mapJSONObj - 地图 JSON 对象。
319
+ */
320
+ static optionsFromMapJSON(url, mapJSONObj) {
321
+ var options = {};
322
+ options.url = url;
323
+ options.crossOrigin = 'anonymous';
324
+ var extent = [mapJSONObj.bounds.left, mapJSONObj.bounds.bottom, mapJSONObj.bounds.right, mapJSONObj.bounds.top];
325
+ const { visibleScales, bounds, dpi, coordUnit } = mapJSONObj;
326
+ var resolutions = Util.scalesToResolutions(visibleScales, bounds, dpi, coordUnit);
327
+ options.tileGrid = new TileGrid({
328
+ extent: extent,
329
+ resolutions: resolutions
330
+ });
331
+ return options;
332
+ }
333
+
334
+ /**
335
+ * @function TileSuperMapRest.createTileGrid
336
+ * @description 创建切片网格。
337
+ * @param {number} extent - 长度。
338
+ * @param {number} maxZoom - 最大的放大级别。
339
+ * @param {number} minZoom - 最小的放大级别。
340
+ * @param {number} tileSize - 瓦片的尺寸。
341
+ * @param {number} origin - 原点。
342
+ * */
343
+ static createTileGrid(extent, maxZoom, minZoom, tileSize, origin) {
344
+ var tilegrid = olTilegrid.createXYZ({
345
+ extent: extent,
346
+ maxZoom: maxZoom,
347
+ minZoom: minZoom,
348
+ tileSize: tileSize
349
+ });
350
+ return new TileGrid({
351
+ extent: extent,
352
+ minZoom: minZoom,
353
+ origin: origin,
354
+ resolutions: tilegrid.getResolutions(),
355
+ tileSize: tilegrid.getTileSize()
356
+ });
357
+ }
358
+ }