@supermapgis/iclient-ol 11.2.0
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.
- package/README.md +56 -0
- package/control/ChangeTileVersion.js +438 -0
- package/control/Logo.js +97 -0
- package/control/ScaleLine.js +164 -0
- package/control/index.js +6 -0
- package/core/MapExtend.js +49 -0
- package/core/StyleUtils.js +1253 -0
- package/core/Util.js +500 -0
- package/core/index.js +6 -0
- package/css/ChangeTileVersion.css +347 -0
- package/css/index.js +5 -0
- package/dist/iclient-openlayers-es6.js +124963 -0
- package/dist/iclient-openlayers-es6.min.js +8 -0
- package/dist/iclient-openlayers.css +668 -0
- package/dist/iclient-openlayers.js +142946 -0
- package/dist/iclient-openlayers.min.css +8 -0
- package/dist/iclient-openlayers.min.js +8 -0
- package/index.js +9 -0
- package/mapping/BaiduMap.js +121 -0
- package/mapping/ImageSuperMapRest.js +252 -0
- package/mapping/ImageTileSuperMapRest.js +99 -0
- package/mapping/InitMap.js +150 -0
- package/mapping/SuperMapCloud.js +56 -0
- package/mapping/Tianditu.js +152 -0
- package/mapping/TileSuperMapRest.js +374 -0
- package/mapping/WebMap.js +5485 -0
- package/mapping/index.js +11 -0
- package/mapping/webmap/Util.js +176 -0
- package/mapping/webmap/config/MunicipalCenter.json +1 -0
- package/mapping/webmap/config/ProvinceCenter.json +1 -0
- package/mapping/webmap/config/SampleDataInfo.json +55 -0
- package/namespace.js +150 -0
- package/overlay/DataFlow.js +114 -0
- package/overlay/FGB.js +100 -0
- package/overlay/Graph.js +439 -0
- package/overlay/GraphMap.js +140 -0
- package/overlay/Graphic.js +588 -0
- package/overlay/HeatMap.js +450 -0
- package/overlay/Label.js +966 -0
- package/overlay/Mapv.js +149 -0
- package/overlay/Range.js +129 -0
- package/overlay/RankSymbol.js +94 -0
- package/overlay/Turf.js +299 -0
- package/overlay/Unique.js +124 -0
- package/overlay/VectorTileSuperMapRest.js +501 -0
- package/overlay/graphic/CanvasRenderer.js +177 -0
- package/overlay/graphic/CloverShape.js +133 -0
- package/overlay/graphic/Graphic.js +174 -0
- package/overlay/graphic/HitCloverShape.js +64 -0
- package/overlay/graphic/WebGLRenderer.js +356 -0
- package/overlay/graphic/index.js +9 -0
- package/overlay/index.js +21 -0
- package/overlay/mapv/MapvCanvasLayer.js +104 -0
- package/overlay/mapv/MapvLayer.js +413 -0
- package/overlay/mapv/index.js +5 -0
- package/overlay/theme/GeoFeature.js +275 -0
- package/overlay/theme/Theme.js +587 -0
- package/overlay/theme/ThemeFeature.js +46 -0
- package/overlay/theme/index.js +6 -0
- package/overlay/vectortile/DeafultCanvasStyle.js +125 -0
- package/overlay/vectortile/MapboxStyles.js +377 -0
- package/overlay/vectortile/StyleMap.js +252 -0
- package/overlay/vectortile/VectorTileStyles.js +554 -0
- package/overlay/vectortile/index.js +7 -0
- package/overlay/vectortile/olExtends.js +382 -0
- package/package.json +30 -0
- package/services/AddressMatchService.js +60 -0
- package/services/ChartService.js +97 -0
- package/services/DataFlowService.js +119 -0
- package/services/DatasetService.js +104 -0
- package/services/DatasourceService.js +76 -0
- package/services/FeatureService.js +260 -0
- package/services/FieldService.js +53 -0
- package/services/GeoprocessingService.js +157 -0
- package/services/GridCellInfosService.js +53 -0
- package/services/ImageCollectionService.js +93 -0
- package/services/ImageService.js +70 -0
- package/services/KnowledgeGraphService.js +96 -0
- package/services/LayerInfoService.js +85 -0
- package/services/MapService.js +85 -0
- package/services/MeasureService.js +77 -0
- package/services/NetworkAnalyst3DService.js +93 -0
- package/services/NetworkAnalystService.js +268 -0
- package/services/ProcessingService.js +507 -0
- package/services/QueryService.js +116 -0
- package/services/ServiceBase.js +26 -0
- package/services/SpatialAnalystService.js +466 -0
- package/services/ThemeService.js +50 -0
- package/services/TrafficTransferAnalystService.js +93 -0
- package/services/WebPrintingJobService.js +112 -0
- package/services/index.js +27 -0
|
@@ -0,0 +1,501 @@
|
|
|
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 { Util } from '../core/Util';
|
|
5
|
+
import { SecurityManager } from '@supermapgis/iclient-common/security/SecurityManager';
|
|
6
|
+
import { FetchRequest } from '@supermapgis/iclient-common/util/FetchRequest';
|
|
7
|
+
import { getServiceKey } from '@supermapgis/iclient-common/util/EncryptRequest';
|
|
8
|
+
import { Unit } from '@supermapgis/iclient-common/REST';
|
|
9
|
+
import { Util as CommonUtil } from '@supermapgis/iclient-common/commontypes/Util';
|
|
10
|
+
import { Bounds } from '@supermapgis/iclient-common/commontypes/Bounds';
|
|
11
|
+
import { Size } from '@supermapgis/iclient-common/commontypes/Size';
|
|
12
|
+
import { Point as GeometryPoint } from '@supermapgis/iclient-common/commontypes/geometry/Point';
|
|
13
|
+
import { VectorTileStyles } from './vectortile/VectorTileStyles';
|
|
14
|
+
import VectorTile from 'ol/source/VectorTile';
|
|
15
|
+
import MVT from 'ol/format/MVT';
|
|
16
|
+
import GeoJSON from 'ol/format/GeoJSON';
|
|
17
|
+
import * as olSize from 'ol/size';
|
|
18
|
+
import Projection from 'ol/proj/Projection';
|
|
19
|
+
import TileGrid from 'ol/tilegrid/TileGrid';
|
|
20
|
+
import decryptTileUtil from '@supermapgis/tile-decryptor';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @class VectorTileSuperMapRest
|
|
24
|
+
* @browsernamespace ol.source
|
|
25
|
+
* @category Visualization VectorTile
|
|
26
|
+
* @classdesc 矢量瓦片是将矢量数据通过不同的描述文件来组织和定义,在客户端实时解析数据并完成绘制。
|
|
27
|
+
* 矢量瓦片体积小,可高度压缩,数据传输体量小,地图更新的代价小,常用于存储用于查询、变更频繁的矢量图层,
|
|
28
|
+
* 适合于地图中对时效性要求较高的地物要素的表达,如 POI 信息、路线信息等。
|
|
29
|
+
* @modulecategory Overlay
|
|
30
|
+
* @param {Object} options - 参数。
|
|
31
|
+
* @param {(string|undefined)} options.url - 服务地址。
|
|
32
|
+
* @param {(string|Object|undefined)} options.style - Mapbox Style JSON 对象或获取 Mapbox Style JSON 对象的 URL。当 `options.format` 为 {@link ol.format.MVT} 且 `options.source` 不为空时有效,优先级高于 `options.url`。
|
|
33
|
+
* @param {(string|undefined)} options.source - Mapbox Style JSON 对象中的 source 名称。当 `options.style` 设置时有效。当不配置时,默认为 Mapbox Style JSON 的 `sources` 对象中的第一个。
|
|
34
|
+
* @param {(string|Object)} [options.attributions='Tile Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a></span>'] - 版权描述信息。
|
|
35
|
+
* @param {Object} [options.format] - 瓦片的要素格式化。
|
|
36
|
+
* @param {boolean} [options.withCredentials] - 请求是否携带 cookie。
|
|
37
|
+
* @param {boolean|Function} [options.decrypt] - 瓦片解密。如果是 true 表示用内置的解密方法, 如 decrypt: true;如果是function 则是自定义解密如 decrypt: function ({ key, bytes })。
|
|
38
|
+
* @param {Function} [options.decryptCompletedFunction] - 解密完成后触发。如 decryptCompletedFunction(completeData)。
|
|
39
|
+
* @extends {ol.source.VectorTile}
|
|
40
|
+
* @usage
|
|
41
|
+
*/
|
|
42
|
+
export class VectorTileSuperMapRest extends VectorTile {
|
|
43
|
+
constructor(options) {
|
|
44
|
+
if (options.url === undefined && options.style === undefined) {
|
|
45
|
+
console.error("one of 'options.style' or 'options.style' is required");
|
|
46
|
+
}
|
|
47
|
+
var zRegEx = /\{z\}/g;
|
|
48
|
+
var xRegEx = /\{x\}/g;
|
|
49
|
+
var yRegEx = /\{y\}/g;
|
|
50
|
+
var dashYRegEx = /\{-y\}/g;
|
|
51
|
+
|
|
52
|
+
options.attributions =
|
|
53
|
+
options.attributions ||
|
|
54
|
+
"Tile Data <span>© SuperMap iServer</span> with <span>© SuperMap iClient</span>";
|
|
55
|
+
if (['4', '5'].indexOf(Util.getOlVersion()) < 0) {
|
|
56
|
+
options.tileSize = options.format instanceof MVT && options.style ? 512 : 256;
|
|
57
|
+
}
|
|
58
|
+
super({
|
|
59
|
+
attributions: options.attributions,
|
|
60
|
+
cacheSize: options.cacheSize,
|
|
61
|
+
format: options.format || new GeoJSON(),
|
|
62
|
+
logo: Util.getOlVersion() === '4' ? options.logo : null,
|
|
63
|
+
overlaps: options.overlaps,
|
|
64
|
+
projection: options.projection,
|
|
65
|
+
state:
|
|
66
|
+
options.format instanceof MVT
|
|
67
|
+
? 'loading'
|
|
68
|
+
: options.state,
|
|
69
|
+
tileClass: options.tileClass,
|
|
70
|
+
tileGrid: options.tileGrid,
|
|
71
|
+
tilePixelRatio: options.tilePixelRatio,
|
|
72
|
+
tileUrlFunction: options.tileUrlFunction || (options.format instanceof MVT && options.style ? zxyTileUrlFunction : tileUrlFunction),
|
|
73
|
+
tileLoadFunction: options.tileLoadFunction || (options.format instanceof MVT ? mvtTileLoadFunction : tileLoadFunction),
|
|
74
|
+
wrapX: options.wrapX !== undefined ? options.wrapX : false,
|
|
75
|
+
tileSize: options.tileSize || null,
|
|
76
|
+
zDirection: ['4', '5'].indexOf(Util.getOlVersion()) > -1 ? null : 0
|
|
77
|
+
});
|
|
78
|
+
var me = this;
|
|
79
|
+
me.withCredentials = options.withCredentials;
|
|
80
|
+
me._tileType = options.tileType || 'ScaleXY';
|
|
81
|
+
this.vectorTileStyles = new VectorTileStyles();
|
|
82
|
+
this._initialized(options);
|
|
83
|
+
|
|
84
|
+
function tileUrlFunction(tileCoord, pixelRatio, projection) {
|
|
85
|
+
if (!me.tileGrid) {
|
|
86
|
+
me.tileGrid = me.getTileGridForProjection(projection);
|
|
87
|
+
}
|
|
88
|
+
var z = tileCoord[0];
|
|
89
|
+
var x = tileCoord[1];
|
|
90
|
+
var y = ['4', '5'].indexOf(Util.getOlVersion()) > -1 ? -tileCoord[2] - 1 : tileCoord[2];
|
|
91
|
+
var tileSize = olSize.toSize(me.tileGrid.getTileSize(z, me.tmpSize));
|
|
92
|
+
var params = '';
|
|
93
|
+
if (me.tileType === 'ZXY') {
|
|
94
|
+
params = '&width=' + tileSize[0] + '&height=' + tileSize[1] + '&x=' + x + '&y=' + y + '&z=' + z;
|
|
95
|
+
} else if (me.tileType === 'ViewBounds') {
|
|
96
|
+
var tileExtent = me.tileGrid.getTileCoordExtent(tileCoord);
|
|
97
|
+
params =
|
|
98
|
+
'&width=' +
|
|
99
|
+
tileSize[0] +
|
|
100
|
+
'&height=' +
|
|
101
|
+
tileSize[1] +
|
|
102
|
+
'&viewBounds=' +
|
|
103
|
+
tileExtent[0] +
|
|
104
|
+
',' +
|
|
105
|
+
tileExtent[1] +
|
|
106
|
+
',' +
|
|
107
|
+
tileExtent[2] +
|
|
108
|
+
',' +
|
|
109
|
+
tileExtent[3];
|
|
110
|
+
} else {
|
|
111
|
+
var origin = me.tileGrid.getOrigin(z);
|
|
112
|
+
var resolution = me.tileGrid.getResolution(z);
|
|
113
|
+
var dpi = 96;
|
|
114
|
+
var unit = projection.getUnits() || 'degrees';
|
|
115
|
+
|
|
116
|
+
var scale = Util.resolutionToScale(resolution, dpi, unit);
|
|
117
|
+
params =
|
|
118
|
+
'&x=' +
|
|
119
|
+
x +
|
|
120
|
+
'&y=' +
|
|
121
|
+
y +
|
|
122
|
+
'&width=' +
|
|
123
|
+
tileSize[0] +
|
|
124
|
+
'&height=' +
|
|
125
|
+
tileSize[1] +
|
|
126
|
+
'&scale=' +
|
|
127
|
+
scale +
|
|
128
|
+
"&origin={'x':" +
|
|
129
|
+
origin[0] +
|
|
130
|
+
",'y':" +
|
|
131
|
+
origin[1] +
|
|
132
|
+
'}';
|
|
133
|
+
}
|
|
134
|
+
return me._tileUrl + encodeURI(params);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function zxyTileUrlFunction(tileCoord) {
|
|
138
|
+
if (!tileCoord) {
|
|
139
|
+
return undefined;
|
|
140
|
+
} else {
|
|
141
|
+
return me._tileUrl
|
|
142
|
+
.replace(zRegEx, tileCoord[0].toString())
|
|
143
|
+
.replace(xRegEx, tileCoord[1].toString())
|
|
144
|
+
.replace(yRegEx, function () {
|
|
145
|
+
var y = ['4', '5'].indexOf(Util.getOlVersion()) > -1 ? -tileCoord[2] - 1 : tileCoord[2];
|
|
146
|
+
return y.toString();
|
|
147
|
+
})
|
|
148
|
+
.replace(dashYRegEx, function () {
|
|
149
|
+
var z = tileCoord[0];
|
|
150
|
+
var range = me.tileGrid.getFullTileRange(z);
|
|
151
|
+
var y = range.getHeight() + tileCoord[2];
|
|
152
|
+
return y.toString();
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* @private
|
|
158
|
+
* @function VectorTileSuperMapRest.prototype.tileLoadFunction
|
|
159
|
+
* @description 加载瓦片。
|
|
160
|
+
* @param {Object} tile -瓦片类。
|
|
161
|
+
* @param {string} tileUrl - 瓦片地址。
|
|
162
|
+
*/
|
|
163
|
+
function tileLoadFunction(tile, tileUrl) {
|
|
164
|
+
var regWidth = new RegExp('(^|\\?|&)' + 'width' + '=([^&]*)(\\s|&|$)');
|
|
165
|
+
var regHeight = new RegExp('(^|\\?|&)' + 'height' + '=([^&]*)(\\s|&|$)');
|
|
166
|
+
var width = Number(tileUrl.match(regWidth)[2]);
|
|
167
|
+
var height = Number(tileUrl.match(regHeight)[2]);
|
|
168
|
+
|
|
169
|
+
tile.setLoader(function (extent, resolution, projection) {
|
|
170
|
+
FetchRequest.get(tileUrl)
|
|
171
|
+
.then(function (response) {
|
|
172
|
+
if (tile.getFormat() instanceof GeoJSON) {
|
|
173
|
+
return response.json();
|
|
174
|
+
}
|
|
175
|
+
})
|
|
176
|
+
.then(function (tileFeatureJson) {
|
|
177
|
+
var features = [];
|
|
178
|
+
if (tile.getFormat() instanceof GeoJSON) {
|
|
179
|
+
tileFeatureJson.recordsets.map(function (recordset) {
|
|
180
|
+
recordset.features.map(function (feature) {
|
|
181
|
+
var points = [];
|
|
182
|
+
var startIndex = 0;
|
|
183
|
+
for (var i = 0; i < feature.geometry.parts.length; i++) {
|
|
184
|
+
var partPointsLength = feature.geometry.parts[i] * 2;
|
|
185
|
+
for (var j = 0, index = startIndex; j < partPointsLength; j += 2, index += 2) {
|
|
186
|
+
points.push(
|
|
187
|
+
new GeometryPoint(
|
|
188
|
+
feature.geometry.points[index],
|
|
189
|
+
feature.geometry.points[index + 1]
|
|
190
|
+
)
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
startIndex += partPointsLength;
|
|
194
|
+
}
|
|
195
|
+
feature.geometry.points = points;
|
|
196
|
+
return feature;
|
|
197
|
+
});
|
|
198
|
+
return recordset;
|
|
199
|
+
});
|
|
200
|
+
tileFeatureJson.recordsets.map(function (recordset) {
|
|
201
|
+
recordset.features.map(function (feature) {
|
|
202
|
+
feature.layerName = recordset.layerName;
|
|
203
|
+
feature.type = feature.geometry.type;
|
|
204
|
+
features.push(feature);
|
|
205
|
+
return feature;
|
|
206
|
+
});
|
|
207
|
+
return recordset;
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
let dataProjection = new Projection({
|
|
211
|
+
extent: [0, 0, 256, 256],
|
|
212
|
+
code: 'TILE_PIXELS',
|
|
213
|
+
units: 'tile-pixels'
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
if (['4', '5'].indexOf(Util.getOlVersion()) > -1) {
|
|
217
|
+
tile.setExtent([0, 0, width, height]);
|
|
218
|
+
tile.setProjection(dataProjection);
|
|
219
|
+
features = tile.getFormat().readFeatures(Util.toGeoJSON(features));
|
|
220
|
+
} else {
|
|
221
|
+
features = tile.getFormat().readFeatures(Util.toGeoJSON(features), {
|
|
222
|
+
extent,
|
|
223
|
+
dataProjection,
|
|
224
|
+
featureProjection: projection
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
tile.setFeatures(features);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* @private
|
|
234
|
+
* @function VectorTileSuperMapRest.prototype.tileLoadFunction
|
|
235
|
+
* @description 加载瓦片。
|
|
236
|
+
* @param {Object} tile -瓦片类。
|
|
237
|
+
* @param {string} tileUrl - 瓦片地址。
|
|
238
|
+
*/
|
|
239
|
+
function mvtTileLoadFunction(tile, tileUrl) {
|
|
240
|
+
const format = tile.getFormat();
|
|
241
|
+
const success = tile.onLoad.bind(tile);
|
|
242
|
+
const failure = tile.onError.bind(tile);
|
|
243
|
+
tile.setLoader(function (extent, resolution, projection) {
|
|
244
|
+
const xhr = new XMLHttpRequest();
|
|
245
|
+
xhr.open(
|
|
246
|
+
'GET',
|
|
247
|
+
typeof tileUrl === 'function' ? tileUrl(extent, resolution, projection) : tileUrl,
|
|
248
|
+
true
|
|
249
|
+
);
|
|
250
|
+
if (format.getType() == 'arraybuffer') {
|
|
251
|
+
xhr.responseType = 'arraybuffer';
|
|
252
|
+
}
|
|
253
|
+
xhr.withCredentials = me.withCredentials;
|
|
254
|
+
xhr.onload = function () {
|
|
255
|
+
if (!xhr.status || (xhr.status >= 200 && xhr.status < 300)) {
|
|
256
|
+
const type = format.getType();
|
|
257
|
+
let source = void 0;
|
|
258
|
+
if (type === 'json' || type === 'text') {
|
|
259
|
+
source = xhr.responseText;
|
|
260
|
+
} else if (type === 'xml') {
|
|
261
|
+
source = xhr.responseXML;
|
|
262
|
+
if (!source) {
|
|
263
|
+
source = new DOMParser().parseFromString(xhr.responseText, 'application/xml');
|
|
264
|
+
}
|
|
265
|
+
} else if (type === 'arraybuffer') {
|
|
266
|
+
source = xhr.response;
|
|
267
|
+
}
|
|
268
|
+
if (source) {
|
|
269
|
+
source = me._decryptMvt(source);
|
|
270
|
+
if (['4', '5'].indexOf(Util.getOlVersion()) > -1) {
|
|
271
|
+
success.call(
|
|
272
|
+
this,
|
|
273
|
+
format.readFeatures(source, { featureProjection: projection }),
|
|
274
|
+
format.readProjection(source),
|
|
275
|
+
format.getLastExtent()
|
|
276
|
+
);
|
|
277
|
+
} else {
|
|
278
|
+
success.call(
|
|
279
|
+
this,
|
|
280
|
+
format.readFeatures(source, {
|
|
281
|
+
extent: extent,
|
|
282
|
+
featureProjection: projection
|
|
283
|
+
}),
|
|
284
|
+
format.readProjection(source)
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
} else {
|
|
288
|
+
failure.call(this);
|
|
289
|
+
}
|
|
290
|
+
} else {
|
|
291
|
+
failure.call(this);
|
|
292
|
+
}
|
|
293
|
+
}.bind(this);
|
|
294
|
+
xhr.onerror = function () {
|
|
295
|
+
failure.call(this);
|
|
296
|
+
}.bind(this);
|
|
297
|
+
xhr.send();
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
async _initialized(options) {
|
|
303
|
+
if (options.format instanceof MVT && options.style) {
|
|
304
|
+
let style = options.style;
|
|
305
|
+
if (Object.prototype.toString.call(options.style) == '[object String]') {
|
|
306
|
+
var url = SecurityManager.appendCredential(options.style);
|
|
307
|
+
const response = await FetchRequest.get(url, null, { withCredentials: options.withCredentials })
|
|
308
|
+
style = await response.json();
|
|
309
|
+
}
|
|
310
|
+
this._fillByStyleJSON(style, options.source);
|
|
311
|
+
} else {
|
|
312
|
+
this._fillByRestMapOptions(options.url, options);
|
|
313
|
+
}
|
|
314
|
+
if (options.format instanceof MVT) {
|
|
315
|
+
if (options.decrypt) {
|
|
316
|
+
await this._verifyVectorTileIsEncrypt(options);
|
|
317
|
+
}
|
|
318
|
+
this.setState('ready');
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
_fillByStyleJSON(style, source) {
|
|
323
|
+
if (!source) {
|
|
324
|
+
source = Object.keys(style.sources)[0];
|
|
325
|
+
}
|
|
326
|
+
if (style.sources && style.sources[source]) {
|
|
327
|
+
//ToDo 支持多个tiles地址
|
|
328
|
+
this._tileUrl = SecurityManager.appendCredential(style.sources[source].tiles[0]);
|
|
329
|
+
}
|
|
330
|
+
if (style.metadata && style.metadata.indexbounds) {
|
|
331
|
+
const indexbounds = style.metadata.indexbounds;
|
|
332
|
+
var max = Math.max(indexbounds[2] - indexbounds[0], indexbounds[3] - indexbounds[1]);
|
|
333
|
+
const defaultResolutions = [];
|
|
334
|
+
for (let index = 0; index < 30; index++) {
|
|
335
|
+
defaultResolutions.push(max / 512 / Math.pow(2, index));
|
|
336
|
+
}
|
|
337
|
+
this.tileGrid = new TileGrid({
|
|
338
|
+
extent: style.metadata.indexbounds,
|
|
339
|
+
resolutions: defaultResolutions,
|
|
340
|
+
tileSize: [512, 512]
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
_fillByRestMapOptions(url, options) {
|
|
345
|
+
this._tileUrl = CommonUtil.urlPathAppend(options.url, 'tileFeature.json');
|
|
346
|
+
if (options.format instanceof MVT) {
|
|
347
|
+
this._tileUrl = CommonUtil.urlPathAppend(options.url, 'tileFeature.mvt');
|
|
348
|
+
}
|
|
349
|
+
//为url添加安全认证信息片段
|
|
350
|
+
this._tileUrl = SecurityManager.appendCredential(this._tileUrl);
|
|
351
|
+
|
|
352
|
+
var returnAttributes = true;
|
|
353
|
+
if (options.returnAttributes !== undefined) {
|
|
354
|
+
returnAttributes = options.returnAttributes;
|
|
355
|
+
}
|
|
356
|
+
var params = {};
|
|
357
|
+
params['returnAttributes'] = returnAttributes;
|
|
358
|
+
if (options._cache !== undefined) {
|
|
359
|
+
params['_cache'] = options._cache;
|
|
360
|
+
}
|
|
361
|
+
if (options.layersID !== undefined) {
|
|
362
|
+
params['layersID'] = options.layersID;
|
|
363
|
+
}
|
|
364
|
+
if (options.layerNames !== undefined) {
|
|
365
|
+
params['layerNames'] = options.layerNames;
|
|
366
|
+
}
|
|
367
|
+
if (options.expands !== undefined) {
|
|
368
|
+
params['expands'] = options.expands;
|
|
369
|
+
}
|
|
370
|
+
if (options.compressTolerance !== undefined) {
|
|
371
|
+
params['compressTolerance'] = options.compressTolerance;
|
|
372
|
+
}
|
|
373
|
+
if (options.coordinateType !== undefined) {
|
|
374
|
+
params['coordinateType'] = options.coordinateType;
|
|
375
|
+
}
|
|
376
|
+
if (options.returnCutEdges !== undefined) {
|
|
377
|
+
params['returnCutEdges'] = options.returnCutEdges;
|
|
378
|
+
}
|
|
379
|
+
this._tileUrl = CommonUtil.urlAppend(this._tileUrl, CommonUtil.getParameterString(params));
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
async _verifyVectorTileIsEncrypt(options) {
|
|
383
|
+
try {
|
|
384
|
+
let serviceUrl = options.url || typeof options.style === 'string' && options.style;
|
|
385
|
+
|
|
386
|
+
if (!serviceUrl && Object.prototype.toString.call(options.style) == '[object Object]') {
|
|
387
|
+
const firstSource = Object.keys(options.style.sources)[0];
|
|
388
|
+
serviceUrl = options.style.sources[firstSource].tiles[0];
|
|
389
|
+
}
|
|
390
|
+
const res = await getServiceKey(serviceUrl);
|
|
391
|
+
if (res) {
|
|
392
|
+
this.decryptOptions = {
|
|
393
|
+
key: res.serviceKey,
|
|
394
|
+
algorithm: res.algorithm,
|
|
395
|
+
decrypt: typeof options.decrypt === 'boolean' ? undefined : options.decrypt,
|
|
396
|
+
decryptCompletedFunction: options.decryptCompletedFunction
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
} catch (error) {
|
|
400
|
+
console.error(error);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
_decryptMvt(mvtData) {
|
|
405
|
+
if (this.decryptOptions) {
|
|
406
|
+
return decryptTileUtil({ ...this.decryptOptions, arrayBuffer: mvtData });
|
|
407
|
+
}
|
|
408
|
+
return mvtData;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* @function VectorTileSuperMapRest.optionsFromMapJSON
|
|
413
|
+
* @param {string} url - 地址。
|
|
414
|
+
* @param {Object} mapJSONObj - 地图 JSON。
|
|
415
|
+
* @description 获取地图 JSON 信息。
|
|
416
|
+
*/
|
|
417
|
+
static optionsFromMapJSON(url, mapJSONObj) {
|
|
418
|
+
var options = {};
|
|
419
|
+
options.url = url;
|
|
420
|
+
options.crossOrigin = 'anonymous';
|
|
421
|
+
var extent = [mapJSONObj.bounds.left, mapJSONObj.bounds.bottom, mapJSONObj.bounds.right, mapJSONObj.bounds.top];
|
|
422
|
+
var resolutions = getResolutions();
|
|
423
|
+
|
|
424
|
+
function getResolutions() {
|
|
425
|
+
var level = 17;
|
|
426
|
+
var dpi = 96;
|
|
427
|
+
var width = extent[2] - extent[0];
|
|
428
|
+
var height = extent[3] - extent[1];
|
|
429
|
+
var tileSize = width >= height ? width : height;
|
|
430
|
+
var maxReolution;
|
|
431
|
+
if (tileSize === width) {
|
|
432
|
+
maxReolution = tileSize / mapJSONObj.viewer.width;
|
|
433
|
+
} else {
|
|
434
|
+
maxReolution = tileSize / mapJSONObj.viewer.height;
|
|
435
|
+
}
|
|
436
|
+
var resolutions = [];
|
|
437
|
+
var unit = Unit.METER;
|
|
438
|
+
if (mapJSONObj.coordUnit === Unit.DEGREE) {
|
|
439
|
+
unit = Unit.DEGREE;
|
|
440
|
+
}
|
|
441
|
+
if (mapJSONObj.visibleScales.length > 0) {
|
|
442
|
+
var scales = initScales(mapJSONObj);
|
|
443
|
+
for (let i = 0; i < scales.length; i++) {
|
|
444
|
+
resolutions.push(Util.scaleToResolution(scales[i], dpi, unit));
|
|
445
|
+
}
|
|
446
|
+
} else {
|
|
447
|
+
for (let i = 0; i < level; i++) {
|
|
448
|
+
resolutions.push(maxReolution / Math.pow(2, i));
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
return resolutions;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function initScales(mapJSONObj) {
|
|
455
|
+
var scales = mapJSONObj.visibleScales;
|
|
456
|
+
if (!scales) {
|
|
457
|
+
return null;
|
|
458
|
+
}
|
|
459
|
+
var viewBounds = mapJSONObj.viewBounds,
|
|
460
|
+
coordUnit = mapJSONObj.coordUnit,
|
|
461
|
+
viewer = mapJSONObj.viewer,
|
|
462
|
+
scale = mapJSONObj.scale,
|
|
463
|
+
datumAxis = mapJSONObj.datumAxis;
|
|
464
|
+
//将jsonObject转化为SuperMap.Bounds,用于计算dpi。
|
|
465
|
+
viewBounds = new Bounds(viewBounds.left, viewBounds.bottom, viewBounds.right, viewBounds.top);
|
|
466
|
+
viewer = new Size(viewer.rightBottom.x, viewer.rightBottom.y);
|
|
467
|
+
coordUnit = coordUnit.toLowerCase();
|
|
468
|
+
datumAxis = datumAxis || 6378137;
|
|
469
|
+
var units = coordUnit;
|
|
470
|
+
var dpi = CommonUtil.calculateDpi(viewBounds, viewer, scale, units, datumAxis);
|
|
471
|
+
var resolutions = _resolutionsFromScales(scales);
|
|
472
|
+
var len = resolutions.length;
|
|
473
|
+
scales = [len];
|
|
474
|
+
for (var i = 0; i < len; i++) {
|
|
475
|
+
scales[i] = CommonUtil.getScaleFromResolutionDpi(resolutions[i], dpi, units, datumAxis);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
function _resolutionsFromScales(scales) {
|
|
479
|
+
if (scales === null) {
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
var resolutions, len;
|
|
483
|
+
len = scales.length;
|
|
484
|
+
resolutions = [len];
|
|
485
|
+
for (var i = 0; i < len; i++) {
|
|
486
|
+
resolutions[i] = CommonUtil.getResolutionFromScaleDpi(scales[i], dpi, units, datumAxis);
|
|
487
|
+
}
|
|
488
|
+
return resolutions;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
return scales;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
options.tileGrid = new TileGrid({
|
|
495
|
+
extent: extent,
|
|
496
|
+
resolutions: resolutions
|
|
497
|
+
});
|
|
498
|
+
//options.projection = 'EPSG:' + mapJSONObj.prjCoordSys.epsgCode;
|
|
499
|
+
return options;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
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 { Util as CommonUtil } from '@supermapgis/iclient-common/commontypes/Util';
|
|
5
|
+
import { Util } from '../../core/Util';
|
|
6
|
+
import olObject from 'ol/Object';
|
|
7
|
+
import * as olStyle from 'ol/style';
|
|
8
|
+
import Point from 'ol/geom/Point';
|
|
9
|
+
import * as olRender from 'ol/render';
|
|
10
|
+
|
|
11
|
+
//获取某像素坐标点pixelP相对于中心center进行缩放scaleRatio倍后的像素点坐标。
|
|
12
|
+
function scale(pixelP, center, scaleRatio) {
|
|
13
|
+
let x = (pixelP[0] - center[0]) * scaleRatio + center[0];
|
|
14
|
+
let y = (pixelP[1] - center[1]) * scaleRatio + center[1];
|
|
15
|
+
return [x, y];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @private
|
|
20
|
+
* @class GraphicCanvasRenderer
|
|
21
|
+
* @classdesc 高效率点图层 canvas 渲染器。
|
|
22
|
+
* @category Visualization Graphic
|
|
23
|
+
* @extends {ol.Object}
|
|
24
|
+
* @param {Graphic} layer - 高效率点图层。
|
|
25
|
+
* @param {Object} options - 图层参数。
|
|
26
|
+
* @param {number} options.width - 地图宽度。
|
|
27
|
+
* @param {number} options.height - 地图高度。
|
|
28
|
+
* @param {HTMLElement} options.container - 放置渲染器的父元素。
|
|
29
|
+
* @param {Array.<number>} [options.colo=[0, 0, 0, 255]] - 颜色,目前只支持 rgba 数组。默认[0, 0, 0, 255],
|
|
30
|
+
* @param {number} [options.radius=10] - 半径。
|
|
31
|
+
* @param {number} [options.opacity=0.8] - 不透明度。
|
|
32
|
+
* @param {Array} [options.highlightColor] - 高亮颜色,目前只支持 rgba 数组。
|
|
33
|
+
* @param {number} [options.radiusScale] - 点放大倍数。
|
|
34
|
+
* @param {number} [options.radiusMinPixels] - 半径最小值,单位为像素。
|
|
35
|
+
* @param {number} [options.radiusMaxPixels] - 半径最大值,单位为像素。
|
|
36
|
+
* @param {number} [options.strokeWidth] - 边框大小。
|
|
37
|
+
* @param {boolean} [options.outline] - 是否显示边框。
|
|
38
|
+
* @param {function} [options.onClick] - 点击事件。
|
|
39
|
+
* @param {function} [options.onHover] - 悬停事件。
|
|
40
|
+
*/
|
|
41
|
+
export class GraphicCanvasRenderer extends olObject {
|
|
42
|
+
constructor(layer, options) {
|
|
43
|
+
super();
|
|
44
|
+
this.layer = layer;
|
|
45
|
+
this.map = layer.map;
|
|
46
|
+
let opt = options || {};
|
|
47
|
+
CommonUtil.extend(this, opt);
|
|
48
|
+
this.highLightStyle = this.layer.highLightStyle;
|
|
49
|
+
|
|
50
|
+
this.mapWidth = this.size[0] / this.pixelRatio;
|
|
51
|
+
this.mapHeight = this.size[1] / this.pixelRatio;
|
|
52
|
+
this.width = this.map.getSize()[0];
|
|
53
|
+
this.height = this.map.getSize()[1];
|
|
54
|
+
this.context = Util.createCanvasContext2D(this.mapWidth, this.mapHeight);
|
|
55
|
+
this.context.scale(this.pixelRatio, this.pixelRatio);
|
|
56
|
+
this.canvas = this.context.canvas;
|
|
57
|
+
this.canvas.style.width = this.width + 'px';
|
|
58
|
+
this.canvas.style.height = this.height + 'px';
|
|
59
|
+
this._registerEvents();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
_registerEvents() {
|
|
63
|
+
this.map.on('change:size', this._resizeEvent.bind(this), this);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
_resizeEvent() {
|
|
67
|
+
this._resize();
|
|
68
|
+
this._clearAndRedraw();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
_resize() {
|
|
72
|
+
let size = this.map.getSize();
|
|
73
|
+
let width = size[0];
|
|
74
|
+
let height = size[1];
|
|
75
|
+
let xRatio = width / this.width;
|
|
76
|
+
let yRatio = height / this.height;
|
|
77
|
+
this.width = width;
|
|
78
|
+
this.height = height;
|
|
79
|
+
this.mapWidth = this.mapWidth * xRatio;
|
|
80
|
+
this.mapHeight = this.mapHeight * yRatio;
|
|
81
|
+
this.canvas.width = this.mapWidth;
|
|
82
|
+
this.canvas.height = this.mapHeight;
|
|
83
|
+
this.canvas.style.width = this.width + 'px';
|
|
84
|
+
this.canvas.style.height = this.height + 'px';
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
_clearAndRedraw() {
|
|
88
|
+
this._clearBuffer();
|
|
89
|
+
this.layer.changed();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
update() {
|
|
93
|
+
this.layer.changed();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
_clearBuffer() {}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @private
|
|
100
|
+
* @function GraphicCanvasRenderer.prototype.getCanvas
|
|
101
|
+
* @description 返回画布。
|
|
102
|
+
* @returns {HTMLCanvasElement} canvas 对象。
|
|
103
|
+
*/
|
|
104
|
+
getCanvas() {
|
|
105
|
+
return this.canvas;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @private
|
|
110
|
+
* @function GraphicCanvasRenderer.prototype.drawGraphics
|
|
111
|
+
* @description 绘制点要素。
|
|
112
|
+
*/
|
|
113
|
+
drawGraphics(graphics) {
|
|
114
|
+
this.graphics_ = graphics || [];
|
|
115
|
+
let mapWidth = this.mapWidth;
|
|
116
|
+
let mapHeight = this.mapHeight;
|
|
117
|
+
|
|
118
|
+
let vectorContext = olRender.toContext(this.context, {
|
|
119
|
+
size: [mapWidth, mapHeight],
|
|
120
|
+
pixelRatio: this.pixelRatio
|
|
121
|
+
});
|
|
122
|
+
let defaultStyle = this.layer._getDefaultStyle();
|
|
123
|
+
let me = this,
|
|
124
|
+
layer = me.layer,
|
|
125
|
+
map = layer.map;
|
|
126
|
+
graphics.map(function (graphic) {
|
|
127
|
+
let style = graphic.getStyle() || defaultStyle;
|
|
128
|
+
if (me.selected === graphic) {
|
|
129
|
+
let defaultHighLightStyle = style;
|
|
130
|
+
if (style instanceof olStyle.Circle) {
|
|
131
|
+
defaultHighLightStyle = new olStyle.Circle({
|
|
132
|
+
radius: style.getRadius(),
|
|
133
|
+
fill: new olStyle.Fill({
|
|
134
|
+
color: 'rgba(0, 153, 255, 1)'
|
|
135
|
+
}),
|
|
136
|
+
stroke: style.getStroke(),
|
|
137
|
+
snapToPixel: Util.getOlVersion() === '4' ? style.getSnapToPixel() : null
|
|
138
|
+
});
|
|
139
|
+
} else if (style instanceof olStyle.RegularShape) {
|
|
140
|
+
defaultHighLightStyle = new olStyle.RegularShape({
|
|
141
|
+
radius: style.getRadius(),
|
|
142
|
+
radius2: style.getRadius2(),
|
|
143
|
+
points: style.getPoints(),
|
|
144
|
+
angle: style.getAngle(),
|
|
145
|
+
snapToPixel: Util.getOlVersion() === '4' ? style.getSnapToPixel() : null,
|
|
146
|
+
rotation: style.getRotation(),
|
|
147
|
+
rotateWithView: style.getRotateWithView(),
|
|
148
|
+
fill: new olStyle.Fill({
|
|
149
|
+
color: 'rgba(0, 153, 255, 1)'
|
|
150
|
+
}),
|
|
151
|
+
stroke: style.getStroke()
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
style = me.highLightStyle || defaultHighLightStyle;
|
|
155
|
+
}
|
|
156
|
+
vectorContext.setStyle(
|
|
157
|
+
new olStyle.Style({
|
|
158
|
+
image: style
|
|
159
|
+
})
|
|
160
|
+
);
|
|
161
|
+
let geometry = graphic.getGeometry();
|
|
162
|
+
let coordinate = geometry.getCoordinates();
|
|
163
|
+
let center = map.getView().getCenter();
|
|
164
|
+
let mapCenterPx = map.getPixelFromCoordinate(center);
|
|
165
|
+
let resolution = map.getView().getResolution();
|
|
166
|
+
let x = (coordinate[0] - center[0]) / resolution;
|
|
167
|
+
let y = (center[1] - coordinate[1]) / resolution;
|
|
168
|
+
let scaledP = [x + mapCenterPx[0], y + mapCenterPx[1]];
|
|
169
|
+
scaledP = scale(scaledP, mapCenterPx, 1);
|
|
170
|
+
//处理放大或缩小级别*/
|
|
171
|
+
let result = [scaledP[0] + me.offset[0], scaledP[1] + me.offset[1]];
|
|
172
|
+
let pixelGeometry = new Point(result);
|
|
173
|
+
vectorContext.drawGeometry(pixelGeometry);
|
|
174
|
+
return graphic;
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|