@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
package/index.js ADDED
@@ -0,0 +1,9 @@
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
+ export * from '@supermapgis/iclient-common/index.common';
5
+ export * from './control';
6
+ export * from './core';
7
+ export * from './mapping';
8
+ export * from './overlay';
9
+ export * from './services';
@@ -0,0 +1,121 @@
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 TileImage from 'ol/source/TileImage';
5
+ import * as asserts from 'ol/asserts';
6
+ import TileGrid from 'ol/tilegrid/TileGrid';
7
+ import { Util } from '../core/Util';
8
+
9
+ /**
10
+ * @class BaiduMap
11
+ * @browsernamespace ol.source
12
+ * @category ThirdPartyMap
13
+ * @classdesc 百度地图图层源。
14
+ * @modulecategory Mapping
15
+ * @param {Object} opt_options - 参数。
16
+ * @param {string} [opt_options.url='https://maponline{num}.bdimg.com/onlinelabel/?qt=tile&x={x}&y={y}&z={z}&styles={styles}&udt=20170408'] - 服务地址。
17
+ * @param {string} [opt_options.tileProxy] - 代理地址。
18
+ * @param {boolean} [hidpi = false] - 是否使用高分辨率地图。
19
+ * @extends {ol.source.TileImage}
20
+ * @usage
21
+ */
22
+ export class BaiduMap extends TileImage {
23
+ constructor(opt_options) {
24
+ var options = opt_options || {};
25
+ var attributions =
26
+ options.attributions ||
27
+ "Map Data © 2018 Baidu - GS(2016)2089号 - Data © 长地万方 with <span>© SuperMap iClient</span>";
28
+ var tileGrid = BaiduMap.defaultTileGrid();
29
+ var crossOrigin = options.crossOrigin !== undefined ? options.crossOrigin : 'anonymous';
30
+
31
+ var url =
32
+ options.url !== undefined
33
+ ? options.url
34
+ : 'https://maponline{num}.bdimg.com/onlinelabel/?qt=tile&x={x}&y={y}&z={z}&styles={styles}&udt=20170408';
35
+ var hidpi =
36
+ options.hidpi || (window.devicePixelRatio || window.screen.deviceXDPI / window.screen.logicalXDPI) > 1;
37
+ url = url.replace('{styles}', hidpi ? 'ph' : 'pl');
38
+ super({
39
+ attributions: attributions,
40
+ cacheSize: options.cacheSize,
41
+ crossOrigin: crossOrigin,
42
+ opaque: options.opaque !== undefined ? options.opaque : true,
43
+ maxZoom: options.maxZoom !== undefined ? options.maxZoom : 19,
44
+ reprojectionErrorThreshold: options.reprojectionErrorThreshold,
45
+ tileLoadFunction: options.tileLoadFunction,
46
+ projection: 'EPSG:3857',
47
+ wrapX: options.wrapX,
48
+ tilePixelRatio: hidpi ? 2 : 1,
49
+ tileGrid: tileGrid,
50
+ tileUrlFunction: tileUrlFunction
51
+ });
52
+
53
+ if (options.tileProxy) {
54
+ this.tileProxy = options.tileProxy;
55
+ }
56
+ var me = this;
57
+
58
+ // eslint-disable-next-line no-unused-vars
59
+ function tileUrlFunction(tileCoord, pixelRatio, projection) {
60
+ var tempUrl = url
61
+ .replace('{num}', Math.abs((tileCoord[1] + tileCoord[2]) % 4))
62
+ .replace('{z}', tileCoord[0].toString())
63
+ .replace('{x}', tileCoord[1].toString())
64
+ .replace('{y}', function() {
65
+ console.log(Util.getOlVersion());
66
+ var y = ['4', '5'].indexOf(Util.getOlVersion()) > -1 ? tileCoord[2] : -tileCoord[2] - 1;
67
+ return y.toString();
68
+ })
69
+ .replace('{-y}', function() {
70
+ var z = tileCoord[0];
71
+ var range = tileGrid.getFullTileRange(z);
72
+ asserts.assert(range, 55); // The {-y} placeholder requires a tile grid with extent
73
+ var y = range.getHeight() + tileCoord[2];
74
+ return y.toString();
75
+ });
76
+
77
+ //支持代理
78
+ if (me.tileProxy) {
79
+ tempUrl = me.tileProxy + encodeURIComponent(tempUrl);
80
+ }
81
+ return tempUrl;
82
+ }
83
+ }
84
+
85
+ // TODO 确认这个方法是否要开出去
86
+ /**
87
+ * @function BaiduMap.defaultTileGrid
88
+ * @description 获取默认瓦片格网。
89
+ * @returns {ol.tilegrid.TileGrid} 返回瓦片格网对象。
90
+ */
91
+ static defaultTileGrid() {
92
+ var tileGird = new TileGrid({
93
+ extent: [-33554432, -33554432, 33554432, 33554432],
94
+ resolutions: [
95
+ 131072 * 2,
96
+ 131072,
97
+ 65536,
98
+ 32768,
99
+ 16284,
100
+ 8192,
101
+ 4096,
102
+ 2048,
103
+ 1024,
104
+ 512,
105
+ 256,
106
+ 128,
107
+ 64,
108
+ 32,
109
+ 16,
110
+ 8,
111
+ 4,
112
+ 2,
113
+ 1,
114
+ 0.5
115
+ ],
116
+ origin: [0, 0],
117
+ minZoom: 3
118
+ });
119
+ return tileGird;
120
+ }
121
+ }
@@ -0,0 +1,252 @@
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 ImageSource, { defaultImageLoadFunction } from 'ol/source/Image';
10
+ import ImageWrapper from 'ol/Image';
11
+ import Geometry from 'ol/geom/Geometry';
12
+ import GeoJSON from 'ol/format/GeoJSON';
13
+ import { containsExtent, getCenter, getHeight, getWidth, getForViewAndSize } from 'ol/extent';
14
+
15
+ /**
16
+ * @class ImageSuperMapRest
17
+ * @browsernamespace ol.source
18
+ * @category iServer Map Tile
19
+ * @classdesc SuperMap iServer Image 图层源。
20
+ * @modulecategory Mapping
21
+ * @param {Object} options - 参数。
22
+ * @param {string} options.url - 地图服务地址,例如: http://{ip}:{port}/iserver/services/map-world/rest/maps/World。
23
+ * @param {ServerType} [options.serverType=SuperMap.ServerType.ISERVER] - 服务类型 ISERVER|IPORTAL|ONLINE。
24
+ * @param {boolean} [options.redirect=false] - 是否重定向。
25
+ * @param {boolean} [options.transparent=true] - 瓦片是否透明。
26
+ * @param {boolean} [options.antialias=false] - 是否反走样地图。
27
+ * @param {boolean} [options.cacheEnabled=true] - 是否使用服务端的缓存,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 {boolean} [options.markerAngleFixed=false] - 指定点状符号的角度是否固定。
35
+ * @param {boolean} [options.textAngleFixed=false] - 文本角度是否固定。
36
+ * @param {boolean} [options.textOrientationFixed=false] - 文本朝向是否固定。
37
+ * @param {boolean} [options.paintBackground=false] - 是否绘制地图背景。
38
+ * @param {boolean} [options.maxVisibleTextSize] - 文本的最大可见尺寸,单位为像素。
39
+ * @param {boolean} [options.maxVisibleVertex] - 最大几何对象可见节点数。如果几何对象的节点数超过指定的个数,则超过的那部分节点不显示。
40
+ * @param {boolean} [options.minVisibleTextSize] - 文本的最小可见尺寸,单位为像素。
41
+ * @param {string} [options.tileversion] - 切片版本名称,_cache 为 true 时有效。
42
+ * @param {string} [options.tileProxy] - 代理地址。
43
+ * @param {NDVIParameter|HillshadeParameter} [options.rasterfunction] - 栅格分析参数。
44
+ * @param {string} [options.format = 'png'] - 瓦片表述类型,支持 "png" 、"webp"、"bmp" 、"jpg"、"gif" 等图片类型。
45
+ * @param {Function} [options.imageLoadFunction] - 加载图片的方法。默认为function(imageTile, src) {imageTile.getImage().src = src;};
46
+ * @param {string} [options.ratio=1.5] - 请求图片大小比例。 1 表示请求图片大小和地图视窗范围一致,2 表示请求图片大小是地图视窗范围的2倍,以此类推。
47
+ * @extends {ol.source.Image}
48
+ * @usage
49
+ */
50
+ export class ImageSuperMapRest extends ImageSource {
51
+ constructor(options) {
52
+ super({
53
+ attributions: options.attributions,
54
+ imageSmoothing: options.imageSmoothing,
55
+ projection: options.projection,
56
+ resolutions: options.resolutions
57
+ });
58
+ if (options.url === undefined) {
59
+ return;
60
+ }
61
+ this.imageLoadFunction_ =
62
+ options.imageLoadFunction !== undefined ? options.imageLoadFunction : defaultImageLoadFunction;
63
+ this._image = null;
64
+ this.renderedRevision_ = 0;
65
+ this._crossOrigin = options.crossOrigin !== undefined ? options.crossOrigin : null;
66
+ this._url = options.url;
67
+ this.ratio_ = options.ratio !== undefined ? options.ratio : 1.5;
68
+
69
+ options.attributions =
70
+ options.attributions ||
71
+ "Map Data <span>© SuperMap iServer</span> with © SuperMap iClient";
72
+
73
+ options.format = options.format ? options.format : 'png';
74
+ this._layerUrl = CommonUtil.urlPathAppend(options.url, 'image.' + options.format);
75
+ //为url添加安全认证信息片段
76
+ this._layerUrl = SecurityManager.appendCredential(this._layerUrl);
77
+
78
+ const params = {};
79
+ //切片是否透明
80
+ const transparent = options.transparent !== undefined ? options.transparent : true;
81
+ params['transparent'] = transparent;
82
+
83
+ //是否使用缓存吗,默认为true
84
+ const cacheEnabled = options.cacheEnabled !== undefined ? options.cacheEnabled : true;
85
+ params['cacheEnabled'] = cacheEnabled;
86
+
87
+ //如果有layersID,则是在使用专题图
88
+ if (options.layersID !== undefined) {
89
+ params['layersID'] = options.layersID;
90
+ }
91
+ //是否重定向,默认为false
92
+ let redirect = false;
93
+ if (options.redirect !== undefined) {
94
+ redirect = options.redirect;
95
+ }
96
+ params['redirect'] = redirect;
97
+
98
+ if (options.prjCoordSys) {
99
+ params['prjCoordSys'] = JSON.stringify(options.prjCoordSys);
100
+ }
101
+ if (options.clipRegionEnabled && options.clipRegion instanceof Geometry) {
102
+ options.clipRegion = Util.toSuperMapGeometry(new GeoJSON().writeGeometryObject(options.clipRegion));
103
+ options.clipRegion = CommonUtil.toJSON(ServerGeometry.fromGeometry(options.clipRegion));
104
+ params['clipRegionEnabled'] = options.clipRegionEnabled;
105
+ params['clipRegion'] = JSON.stringify(options.clipRegion);
106
+ }
107
+ if (!!options.overlapDisplayed && options.overlapDisplayedOptions) {
108
+ // options.overlapDisplayedOptions = options.overlapDisplayedOptions;
109
+ params['overlapDisplayed'] = options.overlapDisplayed;
110
+ params['overlapDisplayedOptions'] = options.overlapDisplayedOptions.toString();
111
+ }
112
+ if (cacheEnabled === true && options.tileversion) {
113
+ params['tileversion'] = options.tileversion;
114
+ }
115
+ if (options.rasterfunction) {
116
+ params['rasterfunction'] = JSON.stringify(options.rasterfunction);
117
+ }
118
+ //是否反走样地图,默认为false
119
+ if (options.antialias !== undefined) {
120
+ params['antialias'] = options.antialias;
121
+ }
122
+ if (options.markerAngleFixed !== undefined) {
123
+ params['markerAngleFixed'] = options.markerAngleFixed;
124
+ }
125
+ if (options.textAngleFixed !== undefined) {
126
+ params['textAngleFixed'] = options.textAngleFixed;
127
+ }
128
+ if (options.textOrientationFixed !== undefined) {
129
+ params['textOrientationFixed'] = options.textOrientationFixed;
130
+ }
131
+ if (options.paintBackground !== undefined) {
132
+ params['paintBackground'] = options.paintBackground;
133
+ }
134
+ if (!isNaN(options.maxVisibleTextSize)) {
135
+ params['maxVisibleTextSize'] = +options.maxVisibleTextSize;
136
+ }
137
+ if (!isNaN(options.minVisibleTextSize)) {
138
+ params['maxVisibleTextSize'] = +options.minVisibleTextSize;
139
+ }
140
+ if (!isNaN(options.maxVisibleVertex)) {
141
+ params['maxVisibleVertex'] = Math.round(+options.maxVisibleVertex);
142
+ }
143
+
144
+ this._layerUrl = CommonUtil.urlAppend(this._layerUrl, CommonUtil.getParameterString(params));
145
+
146
+ //存储一个cacheEnabled
147
+ this.cacheEnabled = cacheEnabled;
148
+
149
+ if (options.tileProxy) {
150
+ this.tileProxy = options.tileProxy;
151
+ }
152
+ }
153
+ getImageInternal(extent, resolution, pixelRatio) {
154
+ resolution = this.findNearestResolution(resolution);
155
+ const imageResolution = resolution / pixelRatio;
156
+ const center = getCenter(extent);
157
+ const viewWidth = Math.ceil(getWidth(extent) / imageResolution);
158
+ const viewHeight = Math.ceil(getHeight(extent) / imageResolution);
159
+ const viewExtent = getForViewAndSize(center, imageResolution, 0, [viewWidth, viewHeight]);
160
+ const requestWidth = Math.ceil((this.ratio_ * getWidth(extent)) / imageResolution);
161
+ const requestHeight = Math.ceil((this.ratio_ * getHeight(extent)) / imageResolution);
162
+ const requestExtent = getForViewAndSize(center, imageResolution, 0, [requestWidth, requestHeight]);
163
+ const image = this._image;
164
+ if (
165
+ image &&
166
+ this.renderedRevision_ === this.getRevision() &&
167
+ image.getResolution() === resolution &&
168
+ image.getPixelRatio() === pixelRatio &&
169
+ containsExtent(image.getExtent(), viewExtent)
170
+ ) {
171
+ return image;
172
+ }
173
+ const imageSize = [
174
+ Math.round(getWidth(requestExtent) / imageResolution),
175
+ Math.round(getHeight(requestExtent) / imageResolution)
176
+ ];
177
+ const imageUrl = this._getRequestUrl(requestExtent, imageSize);
178
+ this._image = new ImageWrapper(
179
+ requestExtent,
180
+ resolution,
181
+ pixelRatio,
182
+ imageUrl,
183
+ this._crossOrigin,
184
+ this.imageLoadFunction_
185
+ );
186
+ this.renderedRevision_ = this.getRevision();
187
+ this._image.addEventListener('change', this.handleImageChange.bind(this));
188
+ return this._image;
189
+ }
190
+ _getRequestUrl(extent, imageSize) {
191
+ const params = {
192
+ width: imageSize[0],
193
+ height: imageSize[1],
194
+ viewBounds: { leftBottom: { x: extent[0], y: extent[1] }, rightTop: { x: extent[2], y: extent[3] } }
195
+ };
196
+ //不启用缓存时启用时间戳
197
+ if (!this.cacheEnabled) {
198
+ params['_t'] = new Date().getTime();
199
+ }
200
+ let imageUrl = CommonUtil.urlAppend(this._layerUrl, CommonUtil.getParameterString(params));
201
+ //支持代理
202
+ if (this.tileProxy) {
203
+ imageUrl = this.tileProxy + encodeURIComponent(imageUrl);
204
+ }
205
+ return imageUrl;
206
+ }
207
+ /**
208
+ * @function ImageSuperMapRest.optionsFromMapJSON
209
+ * @param {string} url - 地址。
210
+ * @param {Object} mapJSONObj - 地图 JSON。
211
+ * @description 获取地图 JSON 信息。
212
+ */
213
+ static optionsFromMapJSON(url, mapJSONObj) {
214
+ var extent = [mapJSONObj.bounds.left, mapJSONObj.bounds.bottom, mapJSONObj.bounds.right, mapJSONObj.bounds.top];
215
+ var resolutions = getResolutions();
216
+
217
+ function getResolutions() {
218
+ var level = 28;
219
+ var dpi = 96;
220
+ var width = extent[2] - extent[0];
221
+ var height = extent[3] - extent[1];
222
+ var tileSize = width >= height ? width : height;
223
+ var maxReolution;
224
+ if (tileSize === width) {
225
+ maxReolution = tileSize / mapJSONObj.viewer.width;
226
+ } else {
227
+ maxReolution = tileSize / mapJSONObj.viewer.height;
228
+ }
229
+ var resolutions = [];
230
+ var unit = Unit.METER;
231
+ if (mapJSONObj.coordUnit === Unit.DEGREE) {
232
+ unit = Unit.DEGREE;
233
+ }
234
+ if (mapJSONObj.visibleScales.length > 0) {
235
+ for (let i = 0; i < mapJSONObj.visibleScales.length; i++) {
236
+ resolutions.push(Util.scaleToResolution(mapJSONObj.visibleScales[i], dpi, unit));
237
+ }
238
+ } else {
239
+ for (let i = 0; i < level; i++) {
240
+ resolutions.push(maxReolution / Math.pow(2, i));
241
+ }
242
+ }
243
+
244
+ function sortNumber(a, b) {
245
+ return b - a;
246
+ }
247
+
248
+ return resolutions.sort(sortNumber);
249
+ }
250
+ return { url,resolutions };
251
+ }
252
+ }
@@ -0,0 +1,99 @@
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 XYZ from 'ol/source/XYZ';
6
+ import { SecurityManager } from '@supermapgis/iclient-common/security/SecurityManager';
7
+ import { Util as CommonUtil } from '@supermapgis/iclient-common/commontypes/Util';
8
+
9
+ /**
10
+ * @class ImageTileSuperMapRest
11
+ * @browsernamespace ol.source
12
+ * @version 10.2.0
13
+ * @category iServer Image
14
+ * @classdesc iServer影像服务图层源。根据指定的请求参数,返回影像数据栅格瓦片并渲染。
15
+ * @param {Object} options - 参数。
16
+ * @param {string} options.url - 服务地址。例如: http://{ip}:{port}/iserver/{imageservice-imageserviceName}/restjsr/
17
+ * @param {string} options.collectionId - 影像集合(Collection)的ID,在一个影像服务中唯一标识影像集合。
18
+ * @param {string} [options.sqlFilter] 显示影像的过滤条件。相当于SQL查询中的where子句。支持st_geometry空间函数过滤。11.0版本暂不支持通过ECQL进行过滤。
19
+ * @param {ImageRenderingRule} [options.renderingRule] 指定影像显示的风格,包含拉伸显示方式、颜色表、波段组合以及应用栅格函数进行快速处理等。不指定时,使用发布服务时所配置的风格。
20
+ * @param {Array.<number>} [options.ids] 返回影像集合中指定ID的影像,该ID为系统维护的一个自增ID,为SuperMap SDX引擎的SmID字段内容。
21
+ * @param {Array.<string>} [options.names] 返回影像集合中指定名称影像的瓦片资源。影像名称包含文件后缀,如S-60-45.tif。
22
+ * @param {string} [options.format='png'] - 瓦片表述类型,瓦片格式目前支持png、jpg和webp三种格式。
23
+ * @param {boolean} [options.transparent=true] - 瓦片是否透明。默认透明。
24
+ * @param {boolean} [options.cacheEnabled=true] - 启用缓存。
25
+ * @param {string} [options.tileProxy] - 代理地址。
26
+ * @param {string} [options.attribution='Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' title='SuperMap iServer' target='_blank'>SuperMap iServer</a></span>'] - 版权信息。
27
+ * @extends {ol.source.XYZ}
28
+ * @usage
29
+ */
30
+ export class ImageTileSuperMapRest extends XYZ {
31
+ constructor(options) {
32
+ options = options || {};
33
+ options.format = options.format || 'png';
34
+ options.transparent = options.transparent === undefined ? true : options.transparent === true;
35
+ options.cacheEnabled = options.cacheEnabled === undefined ? true : options.cacheEnabled === true;
36
+ var attributions = options.attributions || "Map Data <span>© SuperMap iServer</span>";
37
+ var url = _createLayerUrl(options.url, options);
38
+ var superOptions = {
39
+ ...options,
40
+ attributions: attributions,
41
+ url: url
42
+ };
43
+ //需要代理时走自定义 tileLoadFunction,否则走默认的tileLoadFunction
44
+ if (!options.tileLoadFunction && options.tileProxy) {
45
+ superOptions.tileLoadFunction = tileLoadFunction;
46
+ }
47
+ super(superOptions);
48
+ var me = this;
49
+ this.options = options;
50
+ if (options.tileProxy) {
51
+ this.tileProxy = options.tileProxy;
52
+ }
53
+ function tileLoadFunction(imageTile, src) {
54
+ imageTile.getImage().src = me.tileProxy + encodeURIComponent(src);
55
+ }
56
+
57
+ function _createLayerUrl(url, options) {
58
+ var layerUrl = CommonUtil.urlPathAppend(
59
+ url,
60
+ `/collections/${options.collectionId}/tile.${options.format}?x={x}&y={y}&z={z}`
61
+ );
62
+ var requestParams = _getAllRequestParams(options);
63
+ layerUrl = CommonUtil.urlAppend(layerUrl, _getParamString(requestParams));
64
+ layerUrl = SecurityManager.appendCredential(layerUrl);
65
+
66
+ if (!options.cacheEnabled) {
67
+ layerUrl += '&_t=' + new Date().getTime();
68
+ }
69
+ return layerUrl;
70
+ }
71
+
72
+ function _getAllRequestParams(options) {
73
+ var params = {};
74
+ params['transparent'] = options.transparent;
75
+ params['cacheEnabled'] = !(options.cacheEnabled === false);
76
+ if (options.sqlFilter) {
77
+ params['sqlFilter'] = options.sqlFilter;
78
+ }
79
+ if (options.renderingRule) {
80
+ params['renderingRule'] = JSON.stringify(options.renderingRule);
81
+ }
82
+ if (options.ids) {
83
+ params['ids'] = options.ids.join(',');
84
+ }
85
+ if (options.names) {
86
+ params['names'] = options.names.join(',');
87
+ }
88
+ return params;
89
+ }
90
+
91
+ function _getParamString(obj) {
92
+ var params = [];
93
+ for (var i in obj) {
94
+ params.push(encodeURIComponent(i) + '=' + encodeURIComponent(obj[i]));
95
+ }
96
+ return params.join('&');
97
+ }
98
+ }
99
+ }
@@ -0,0 +1,125 @@
1
+ import { MapService } from '../services/MapService';
2
+ import { InitMapServiceBase, isPlaneProjection } from '@supermapgis/iclient-common/iServer/InitMapServiceBase';
3
+ import olMap from 'ol/Map';
4
+ import View from 'ol/View';
5
+ import Tile from 'ol/layer/Tile';
6
+ import { TileSuperMapRest } from './TileSuperMapRest';
7
+ import { Util } from '../core/Util';
8
+ import proj4 from 'proj4';
9
+ import * as olProj4 from 'ol/proj/proj4';
10
+ import { get } from 'ol/proj';
11
+
12
+ window.proj4 = proj4;
13
+
14
+ /**
15
+ * @function initMap
16
+ * @description 根据 SuperMap iServer 服务参数,创建地图与图层。目前仅支持SuperMap iServer 地图服务,创建的图层为 ol.Tile。
17
+ * @category BaseTypes Util
18
+ * @version 11.0.1
19
+ * @param {number} url - 服务地址,例如: http://{ip}:{port}/iserver/services/map-world/rest/maps/World。
20
+ * @param {Object} options - 参数。
21
+ * @param {Object} [options.mapOptions] - 地图配置,参数设置参考 {@link https://openlayers.org/en/v6.15.1/apidoc/module-ol_Map-Map.html}。
22
+ * @param {Object} [options.viewOptions] - 视图配置,参数设置参考 {@link https://openlayers.org/en/v6.15.1/apidoc/module-ol_View-View.html} ,未设置的情况下,默认使用 SuperMap iServer 服务参数进行设置。
23
+ * @param {Object} [options.layerOptions] - 图层配置,参数设置参考 {@link https://openlayers.org/en/v6.15.1/apidoc/module-ol_layer_Tile-TileLayer.html} ,未设置的情况下,默认使用 SuperMap iServer 服务参数进行设置。
24
+ * @param {Object} [options.sourceOptions] - 数据源配置,参数设置参考 {@link TileSuperMapRest} ,未设置的情况下,默认使用 SuperMap iServer 服务参数进行设置。
25
+ * @param {string} [options.proxy] - 服务代理地址。
26
+ * @param {boolean} [options.withCredentials=false] - 请求是否携带 cookie。
27
+ * @param {boolean} [options.crossOrigin] - 是否允许跨域请求。
28
+ * @param {Object} [options.headers] - 请求头。
29
+ * @returns {Object} 实例对象,对象包括地图实例,图层实例,数据源实例。
30
+ * @usage
31
+ * ```
32
+ * // 浏览器
33
+ * <script type="text/javascript" src="{cdn}"></script>
34
+ * <script>
35
+ * const initMap = {namespace}.initMap(url, { mapOptions, viewOptions, layerOptions, sourceOptions });
36
+ *
37
+ * </script>
38
+ * // ES6 Import
39
+ * import { initMap } from '{npm}';
40
+ *
41
+ * initMap(url, { mapOptions, viewOptions, layerOptions, sourceOptions })
42
+ * ```
43
+ * */
44
+ export function initMap(url, options = {}) {
45
+ const { mapOptions, viewOptions, layerOptions, sourceOptions } = options;
46
+ const initMapService = new InitMapServiceBase(MapService, url, options);
47
+ return initMapService.getMapInfo(async function (serviceResult, resolve, reject) {
48
+ if (!serviceResult || !serviceResult.result) {
49
+ reject('service is not work!');
50
+ return;
51
+ }
52
+ let { prjCoordSys, bounds } = serviceResult.result;
53
+ if (!get(`EPSG:${prjCoordSys.epsgCode}`) && !isPlaneProjection(prjCoordSys.type)) {
54
+ const wkt = await initMapService.getWKT();
55
+ registerProj(prjCoordSys.epsgCode, wkt, bounds);
56
+ }
57
+
58
+ let map = createMap(serviceResult.result, mapOptions, viewOptions);
59
+ let { layer, source } = createLayer(url, serviceResult.result, sourceOptions, layerOptions);
60
+ map.addLayer(layer);
61
+ resolve({
62
+ map,
63
+ source,
64
+ layer
65
+ });
66
+ });
67
+ }
68
+
69
+ /**
70
+ * @function viewOptionsFromMapJSON
71
+ * @category BaseTypes Util
72
+ * @version 11.0.1
73
+ * @description 通过 iServer REST 地图参数构造 ol 视图对象。
74
+ * @param {Object} mapJSONObj - 地图 JSON 对象。
75
+ * @param {number} [level=22] - 地图最大级别。
76
+ * @returns {Object} ol视图参数,包括中心点、投影、级别、分辨率数组。
77
+ */
78
+
79
+ export function viewOptionsFromMapJSON(mapJSONObj, level = 22) {
80
+ let { bounds, dpi, center, visibleScales, scale, coordUnit, prjCoordSys } = mapJSONObj;
81
+ const mapCenter =
82
+ center.x && center.y ? [center.x, center.y] : [(bounds.left + bounds.right) / 2, (bounds.bottom + bounds.top) / 2];
83
+ const extent = [bounds.left, bounds.bottom, bounds.right, bounds.top];
84
+ let projection = Util.getProjection(prjCoordSys, extent);
85
+ var resolutions = Util.scalesToResolutions(visibleScales, bounds, dpi, coordUnit, level);
86
+ const zoom = Util.getZoomByResolution(Util.scaleToResolution(scale, dpi, coordUnit), resolutions);
87
+ return {
88
+ center: mapCenter,
89
+ projection,
90
+ zoom,
91
+ resolutions
92
+ };
93
+ }
94
+
95
+ function createMap(result, mapOptions, viewOptions) {
96
+ let view = viewOptionsFromMapJSON(result);
97
+ var map = new olMap({
98
+ target: 'map',
99
+ view: new View({ ...view, ...viewOptions }),
100
+ ...mapOptions
101
+ });
102
+ return map;
103
+ }
104
+
105
+ function registerProj(epsgCode, wkt, bounds) {
106
+ const extent = [bounds.left, bounds.bottom, bounds.right, bounds.top];
107
+ let epsgCodeStr = `EPSG:${epsgCode}`;
108
+ !get(epsgCodeStr) && proj4.defs(epsgCodeStr, wkt);
109
+ if (olProj4 && olProj4.register) {
110
+ olProj4.register(proj4);
111
+ var prj = get(epsgCodeStr);
112
+ prj.setExtent(extent);
113
+ }
114
+ }
115
+
116
+ function createLayer(url, result, sourceOptions, layerOptions) {
117
+ let options = TileSuperMapRest.optionsFromMapJSON(url, result, true);
118
+ options = { ...options, ...sourceOptions };
119
+ var source = new TileSuperMapRest(options);
120
+ var layer = new Tile({
121
+ source,
122
+ ...layerOptions
123
+ });
124
+ return { layer, source };
125
+ }
@@ -0,0 +1,56 @@
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 XYZ from 'ol/source/XYZ';
6
+
7
+ /**
8
+ * @class SuperMapCloud
9
+ * @browsernamespace ol.source
10
+ * @category ThirdPartyMap
11
+ * @classdesc 超图云地图图层源。
12
+ * @modulecategory Mapping
13
+ * @param {Object} opt_options - 参数。
14
+ * @param {string} [opt_options.url='http://t2.dituhui.com/FileService/image?map={mapName}&type={type}&x={x}&y={y}&z={z}'] - 服务地址。
15
+ * @param {string} [opt_options.tileProxy] - 代理地址。
16
+ * @extends {ol.source.XYZ}
17
+ * @usage
18
+ */
19
+ export class SuperMapCloud extends XYZ {
20
+
21
+ constructor(opt_options) {
22
+ var options = opt_options || {};
23
+
24
+ var attributions = options.attributions || "Map Data ©2014 SuperMap - GS(2014)6070号-data©Navinfo with <span>© SuperMap iClient</span>"
25
+ var mapName = options.mapName || 'quanguo';
26
+ var mapType = options.mapType || 'web';
27
+ var url = options.url || 'http://t2.dituhui.com/FileService/image?map={mapName}&type={type}&x={x}&y={y}&z={z}';
28
+ url = url.replace('{mapName}', mapName).replace('{type}', mapType);
29
+
30
+ var superOptions = {
31
+ attributions: attributions,
32
+ cacheSize: options.cacheSize,
33
+ crossOrigin: options.crossOrigin,
34
+ opaque: options.opaque === undefined ? true : options.opaque,
35
+ maxZoom: options.maxZoom || 18,
36
+ reprojectionErrorThreshold: options.reprojectionErrorThreshold,
37
+ url: url,
38
+ wrapX: options.wrapX
39
+ };
40
+ //需要代理时走自定义 tileLoadFunction,否则走默认的tileLoadFunction
41
+ if (options.tileProxy) {
42
+ superOptions.tileLoadFunction = tileLoadFunction;
43
+ }
44
+ super(superOptions);
45
+
46
+ if (options.tileProxy) {
47
+ this.tileProxy = options.tileProxy;
48
+ }
49
+ //需要代理时,走以下代码
50
+ var me = this;
51
+ function tileLoadFunction(imageTile, src) {
52
+ //支持代理
53
+ imageTile.getImage().src = me.tileProxy + encodeURIComponent(src);
54
+ }
55
+ }
56
+ }