@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.
- package/README.md +56 -0
- package/control/ChangeTileVersion.js +438 -0
- package/control/Logo.js +99 -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 +478 -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 +121806 -0
- package/dist/iclient-openlayers-es6.min.js +8 -0
- package/dist/iclient-openlayers.css +668 -0
- package/dist/iclient-openlayers.js +132335 -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 +125 -0
- package/mapping/SuperMapCloud.js +56 -0
- package/mapping/Tianditu.js +152 -0
- package/mapping/TileSuperMapRest.js +358 -0
- package/mapping/WebMap.js +5185 -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 +97 -0
- package/overlay/Graph.js +436 -0
- package/overlay/GraphMap.js +91 -0
- package/overlay/Graphic.js +587 -0
- package/overlay/HeatMap.js +444 -0
- package/overlay/Label.js +964 -0
- package/overlay/Mapv.js +146 -0
- package/overlay/Range.js +127 -0
- package/overlay/RankSymbol.js +94 -0
- package/overlay/Turf.js +298 -0
- package/overlay/Unique.js +123 -0
- package/overlay/VectorTileSuperMapRest.js +466 -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 +63 -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 +410 -0
- package/overlay/mapv/index.js +5 -0
- package/overlay/theme/GeoFeature.js +275 -0
- package/overlay/theme/Theme.js +585 -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 +375 -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 +29 -0
- package/services/AddressMatchService.js +60 -0
- package/services/ChartService.js +74 -0
- package/services/DataFlowService.js +118 -0
- package/services/DatasetService.js +104 -0
- package/services/DatasourceService.js +76 -0
- package/services/FeatureService.js +196 -0
- package/services/FieldService.js +53 -0
- package/services/GeoprocessingService.js +156 -0
- package/services/GridCellInfosService.js +53 -0
- package/services/ImageCollectionService.js +92 -0
- package/services/ImageService.js +69 -0
- package/services/KnowledgeGraphService.js +82 -0
- package/services/LayerInfoService.js +85 -0
- package/services/MapService.js +85 -0
- package/services/MeasureService.js +77 -0
- package/services/NetworkAnalyst3DService.js +88 -0
- package/services/NetworkAnalystService.js +252 -0
- package/services/ProcessingService.js +478 -0
- package/services/QueryService.js +116 -0
- package/services/ServiceBase.js +26 -0
- package/services/SpatialAnalystService.js +432 -0
- package/services/ThemeService.js +50 -0
- package/services/TrafficTransferAnalystService.js +88 -0
- package/services/WebPrintingJobService.js +112 -0
- package/services/index.js +27 -0
|
@@ -0,0 +1,466 @@
|
|
|
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 { Unit } from '@supermapgis/iclient-common/REST';
|
|
8
|
+
import { Util as CommonUtil } from '@supermapgis/iclient-common/commontypes/Util';
|
|
9
|
+
import { Bounds } from '@supermapgis/iclient-common/commontypes/Bounds';
|
|
10
|
+
import { Size } from '@supermapgis/iclient-common/commontypes/Size';
|
|
11
|
+
import { Point as GeometryPoint } from '@supermapgis/iclient-common/commontypes/geometry/Point';
|
|
12
|
+
import { VectorTileStyles } from './vectortile/VectorTileStyles';
|
|
13
|
+
import VectorTile from 'ol/source/VectorTile';
|
|
14
|
+
import MVT from 'ol/format/MVT';
|
|
15
|
+
import GeoJSON from 'ol/format/GeoJSON';
|
|
16
|
+
import * as olSize from 'ol/size';
|
|
17
|
+
import Projection from 'ol/proj/Projection';
|
|
18
|
+
import TileGrid from 'ol/tilegrid/TileGrid';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @class VectorTileSuperMapRest
|
|
22
|
+
* @browsernamespace ol.source
|
|
23
|
+
* @category Visualization VectorTile
|
|
24
|
+
* @classdesc 矢量瓦片图层源。
|
|
25
|
+
* @modulecategory Overlay
|
|
26
|
+
* @param {Object} options - 参数。
|
|
27
|
+
* @param {(string|undefined)} options.url - 服务地址。
|
|
28
|
+
* @param {(string|Object|undefined)} options.style - Mapbox Style JSON 对象或获取 Mapbox Style JSON 对象的 URL。当 `options.format` 为 {@link ol.format.MVT} 且 `options.source` 不为空时有效,优先级高于 `options.url`。
|
|
29
|
+
* @param {(string|undefined)} options.source - Mapbox Style JSON 对象中的source名称。当 `options.style` 设置时有效。当不配置时,默认为 Mapbox Style JSON 的 `sources` 对象中的第一个。
|
|
30
|
+
* @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>'] - 版权信息。
|
|
31
|
+
* @param {Object} [options.format] - 瓦片的要素格式化。
|
|
32
|
+
* @param {boolean} [options.withCredentials] - 请求是否携带 cookie。
|
|
33
|
+
* @extends {ol.source.VectorTile}
|
|
34
|
+
* @usage
|
|
35
|
+
*/
|
|
36
|
+
export class VectorTileSuperMapRest extends VectorTile {
|
|
37
|
+
constructor(options) {
|
|
38
|
+
if (options.url === undefined && options.style === undefined) {
|
|
39
|
+
console.error("one of 'options.style' or 'options.style' is required");
|
|
40
|
+
}
|
|
41
|
+
var zRegEx = /\{z\}/g;
|
|
42
|
+
var xRegEx = /\{x\}/g;
|
|
43
|
+
var yRegEx = /\{y\}/g;
|
|
44
|
+
var dashYRegEx = /\{-y\}/g;
|
|
45
|
+
|
|
46
|
+
options.attributions =
|
|
47
|
+
options.attributions ||
|
|
48
|
+
"Tile Data <span>© SuperMap iServer</span> with <span>© SuperMap iClient</span>";
|
|
49
|
+
if (['4', '5'].indexOf(Util.getOlVersion()) < 0) {
|
|
50
|
+
options.tileSize = options.format instanceof MVT && options.style ? 512 : 256;
|
|
51
|
+
}
|
|
52
|
+
super({
|
|
53
|
+
attributions: options.attributions,
|
|
54
|
+
cacheSize: options.cacheSize,
|
|
55
|
+
format: options.format || new GeoJSON(),
|
|
56
|
+
logo: Util.getOlVersion() === '4' ? options.logo : null,
|
|
57
|
+
overlaps: options.overlaps,
|
|
58
|
+
projection: options.projection,
|
|
59
|
+
state:
|
|
60
|
+
options.format instanceof MVT &&
|
|
61
|
+
options.style &&
|
|
62
|
+
Object.prototype.toString.call(options.style) == '[object String]'
|
|
63
|
+
? 'loading'
|
|
64
|
+
: options.state,
|
|
65
|
+
tileClass: options.tileClass,
|
|
66
|
+
tileGrid: options.tileGrid,
|
|
67
|
+
tilePixelRatio: options.tilePixelRatio,
|
|
68
|
+
tileUrlFunction: options.tileUrlFunction || (options.format instanceof MVT && options.style ? zxyTileUrlFunction : tileUrlFunction),
|
|
69
|
+
tileLoadFunction: options.tileLoadFunction || (options.format instanceof MVT ? mvtTileLoadFunction : tileLoadFunction),
|
|
70
|
+
wrapX: options.wrapX !== undefined ? options.wrapX : false,
|
|
71
|
+
tileSize: options.tileSize || null,
|
|
72
|
+
zDirection: ['4', '5'].indexOf(Util.getOlVersion()) > -1 ? null : 0
|
|
73
|
+
});
|
|
74
|
+
var me = this;
|
|
75
|
+
me.withCredentials = options.withCredentials;
|
|
76
|
+
me._tileType = options.tileType || 'ScaleXY';
|
|
77
|
+
this.vectorTileStyles = new VectorTileStyles();
|
|
78
|
+
if (options.format instanceof MVT && options.style) {
|
|
79
|
+
if (Object.prototype.toString.call(options.style) == '[object String]') {
|
|
80
|
+
var url = SecurityManager.appendCredential(options.style);
|
|
81
|
+
FetchRequest.get(url, null, { withCredentials: options.withCredentials })
|
|
82
|
+
.then((response) => response.json())
|
|
83
|
+
.then((mbStyle) => {
|
|
84
|
+
this._fillByStyleJSON(mbStyle, options.source);
|
|
85
|
+
this.setState('ready');
|
|
86
|
+
});
|
|
87
|
+
} else {
|
|
88
|
+
this._fillByStyleJSON(options.style, options.source);
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
this._fillByRestMapOptions(options.url, options);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function tileUrlFunction(tileCoord, pixelRatio, projection) {
|
|
95
|
+
if (!me.tileGrid) {
|
|
96
|
+
me.tileGrid = me.getTileGridForProjection(projection);
|
|
97
|
+
}
|
|
98
|
+
var z = tileCoord[0];
|
|
99
|
+
var x = tileCoord[1];
|
|
100
|
+
var y = ['4', '5'].indexOf(Util.getOlVersion()) > -1 ? -tileCoord[2] - 1 : tileCoord[2];
|
|
101
|
+
var tileSize = olSize.toSize(me.tileGrid.getTileSize(z, me.tmpSize));
|
|
102
|
+
var params = '';
|
|
103
|
+
if (me.tileType === 'ZXY') {
|
|
104
|
+
params = '&width=' + tileSize[0] + '&height=' + tileSize[1] + '&x=' + x + '&y=' + y + '&z=' + z;
|
|
105
|
+
} else if (me.tileType === 'ViewBounds') {
|
|
106
|
+
var tileExtent = me.tileGrid.getTileCoordExtent(tileCoord);
|
|
107
|
+
params =
|
|
108
|
+
'&width=' +
|
|
109
|
+
tileSize[0] +
|
|
110
|
+
'&height=' +
|
|
111
|
+
tileSize[1] +
|
|
112
|
+
'&viewBounds=' +
|
|
113
|
+
tileExtent[0] +
|
|
114
|
+
',' +
|
|
115
|
+
tileExtent[1] +
|
|
116
|
+
',' +
|
|
117
|
+
tileExtent[2] +
|
|
118
|
+
',' +
|
|
119
|
+
tileExtent[3];
|
|
120
|
+
} else {
|
|
121
|
+
var origin = me.tileGrid.getOrigin(z);
|
|
122
|
+
var resolution = me.tileGrid.getResolution(z);
|
|
123
|
+
var dpi = 96;
|
|
124
|
+
var unit = projection.getUnits() || 'degrees';
|
|
125
|
+
if (unit === 'degrees') {
|
|
126
|
+
unit = Unit.DEGREE;
|
|
127
|
+
}
|
|
128
|
+
if (unit === 'm') {
|
|
129
|
+
unit = Unit.METER;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
var scale = Util.resolutionToScale(resolution, dpi, unit);
|
|
133
|
+
params =
|
|
134
|
+
'&x=' +
|
|
135
|
+
x +
|
|
136
|
+
'&y=' +
|
|
137
|
+
y +
|
|
138
|
+
'&width=' +
|
|
139
|
+
tileSize[0] +
|
|
140
|
+
'&height=' +
|
|
141
|
+
tileSize[1] +
|
|
142
|
+
'&scale=' +
|
|
143
|
+
scale +
|
|
144
|
+
"&origin={'x':" +
|
|
145
|
+
origin[0] +
|
|
146
|
+
",'y':" +
|
|
147
|
+
origin[1] +
|
|
148
|
+
'}';
|
|
149
|
+
}
|
|
150
|
+
return me._tileUrl + encodeURI(params);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function zxyTileUrlFunction(tileCoord) {
|
|
154
|
+
if (!tileCoord) {
|
|
155
|
+
return undefined;
|
|
156
|
+
} else {
|
|
157
|
+
return me._tileUrl
|
|
158
|
+
.replace(zRegEx, tileCoord[0].toString())
|
|
159
|
+
.replace(xRegEx, tileCoord[1].toString())
|
|
160
|
+
.replace(yRegEx, function () {
|
|
161
|
+
var y = ['4', '5'].indexOf(Util.getOlVersion()) > -1 ? -tileCoord[2] - 1 : tileCoord[2];
|
|
162
|
+
return y.toString();
|
|
163
|
+
})
|
|
164
|
+
.replace(dashYRegEx, function () {
|
|
165
|
+
var z = tileCoord[0];
|
|
166
|
+
var range = me.tileGrid.getFullTileRange(z);
|
|
167
|
+
var y = range.getHeight() + tileCoord[2];
|
|
168
|
+
return y.toString();
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* @private
|
|
174
|
+
* @function VectorTileSuperMapRest.prototype.tileLoadFunction
|
|
175
|
+
* @description 加载瓦片。
|
|
176
|
+
* @param {Object} tile -瓦片类。
|
|
177
|
+
* @param {string} tileUrl - 瓦片地址。
|
|
178
|
+
*/
|
|
179
|
+
function tileLoadFunction(tile, tileUrl) {
|
|
180
|
+
var regWidth = new RegExp('(^|\\?|&)' + 'width' + '=([^&]*)(\\s|&|$)');
|
|
181
|
+
var regHeight = new RegExp('(^|\\?|&)' + 'height' + '=([^&]*)(\\s|&|$)');
|
|
182
|
+
var width = Number(tileUrl.match(regWidth)[2]);
|
|
183
|
+
var height = Number(tileUrl.match(regHeight)[2]);
|
|
184
|
+
|
|
185
|
+
tile.setLoader(function (extent, resolution, projection) {
|
|
186
|
+
FetchRequest.get(tileUrl)
|
|
187
|
+
.then(function (response) {
|
|
188
|
+
if (tile.getFormat() instanceof GeoJSON) {
|
|
189
|
+
return response.json();
|
|
190
|
+
}
|
|
191
|
+
})
|
|
192
|
+
.then(function (tileFeatureJson) {
|
|
193
|
+
var features = [];
|
|
194
|
+
if (tile.getFormat() instanceof GeoJSON) {
|
|
195
|
+
tileFeatureJson.recordsets.map(function (recordset) {
|
|
196
|
+
recordset.features.map(function (feature) {
|
|
197
|
+
var points = [];
|
|
198
|
+
var startIndex = 0;
|
|
199
|
+
for (var i = 0; i < feature.geometry.parts.length; i++) {
|
|
200
|
+
var partPointsLength = feature.geometry.parts[i] * 2;
|
|
201
|
+
for (var j = 0, index = startIndex; j < partPointsLength; j += 2, index += 2) {
|
|
202
|
+
points.push(
|
|
203
|
+
new GeometryPoint(
|
|
204
|
+
feature.geometry.points[index],
|
|
205
|
+
feature.geometry.points[index + 1]
|
|
206
|
+
)
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
startIndex += partPointsLength;
|
|
210
|
+
}
|
|
211
|
+
feature.geometry.points = points;
|
|
212
|
+
return feature;
|
|
213
|
+
});
|
|
214
|
+
return recordset;
|
|
215
|
+
});
|
|
216
|
+
tileFeatureJson.recordsets.map(function (recordset) {
|
|
217
|
+
recordset.features.map(function (feature) {
|
|
218
|
+
feature.layerName = recordset.layerName;
|
|
219
|
+
feature.type = feature.geometry.type;
|
|
220
|
+
features.push(feature);
|
|
221
|
+
return feature;
|
|
222
|
+
});
|
|
223
|
+
return recordset;
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
let dataProjection = new Projection({
|
|
227
|
+
extent: [0, 0, 256, 256],
|
|
228
|
+
code: 'TILE_PIXELS',
|
|
229
|
+
units: 'tile-pixels'
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
if (['4', '5'].indexOf(Util.getOlVersion()) > -1) {
|
|
233
|
+
tile.setExtent([0, 0, width, height]);
|
|
234
|
+
tile.setProjection(dataProjection);
|
|
235
|
+
features = tile.getFormat().readFeatures(Util.toGeoJSON(features));
|
|
236
|
+
} else {
|
|
237
|
+
features = tile.getFormat().readFeatures(Util.toGeoJSON(features), {
|
|
238
|
+
extent,
|
|
239
|
+
dataProjection,
|
|
240
|
+
featureProjection: projection
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
tile.setFeatures(features);
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* @private
|
|
250
|
+
* @function VectorTileSuperMapRest.prototype.tileLoadFunction
|
|
251
|
+
* @description 加载瓦片。
|
|
252
|
+
* @param {Object} tile -瓦片类。
|
|
253
|
+
* @param {string} tileUrl - 瓦片地址。
|
|
254
|
+
*/
|
|
255
|
+
function mvtTileLoadFunction(tile, tileUrl) {
|
|
256
|
+
const format = tile.getFormat();
|
|
257
|
+
const success = tile.onLoad.bind(tile);
|
|
258
|
+
const failure = tile.onError.bind(tile);
|
|
259
|
+
tile.setLoader(function (extent, resolution, projection) {
|
|
260
|
+
const xhr = new XMLHttpRequest();
|
|
261
|
+
xhr.open(
|
|
262
|
+
'GET',
|
|
263
|
+
typeof tileUrl === 'function' ? tileUrl(extent, resolution, projection) : tileUrl,
|
|
264
|
+
true
|
|
265
|
+
);
|
|
266
|
+
if (format.getType() == 'arraybuffer') {
|
|
267
|
+
xhr.responseType = 'arraybuffer';
|
|
268
|
+
}
|
|
269
|
+
xhr.withCredentials = me.withCredentials;
|
|
270
|
+
xhr.onload = function () {
|
|
271
|
+
if (!xhr.status || (xhr.status >= 200 && xhr.status < 300)) {
|
|
272
|
+
const type = format.getType();
|
|
273
|
+
let source = void 0;
|
|
274
|
+
if (type === 'json' || type === 'text') {
|
|
275
|
+
source = xhr.responseText;
|
|
276
|
+
} else if (type === 'xml') {
|
|
277
|
+
source = xhr.responseXML;
|
|
278
|
+
if (!source) {
|
|
279
|
+
source = new DOMParser().parseFromString(xhr.responseText, 'application/xml');
|
|
280
|
+
}
|
|
281
|
+
} else if (type === 'arraybuffer') {
|
|
282
|
+
source = xhr.response;
|
|
283
|
+
}
|
|
284
|
+
if (source) {
|
|
285
|
+
if (['4', '5'].indexOf(Util.getOlVersion()) > -1) {
|
|
286
|
+
success.call(
|
|
287
|
+
this,
|
|
288
|
+
format.readFeatures(source, { featureProjection: projection }),
|
|
289
|
+
format.readProjection(source),
|
|
290
|
+
format.getLastExtent()
|
|
291
|
+
);
|
|
292
|
+
} else {
|
|
293
|
+
success.call(
|
|
294
|
+
this,
|
|
295
|
+
format.readFeatures(source, {
|
|
296
|
+
extent: extent,
|
|
297
|
+
featureProjection: projection
|
|
298
|
+
}),
|
|
299
|
+
format.readProjection(source)
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
} else {
|
|
303
|
+
failure.call(this);
|
|
304
|
+
}
|
|
305
|
+
} else {
|
|
306
|
+
failure.call(this);
|
|
307
|
+
}
|
|
308
|
+
}.bind(this);
|
|
309
|
+
xhr.onerror = function () {
|
|
310
|
+
failure.call(this);
|
|
311
|
+
}.bind(this);
|
|
312
|
+
xhr.send();
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
_fillByStyleJSON(style, source) {
|
|
317
|
+
if (!source) {
|
|
318
|
+
source = Object.keys(style.sources)[0];
|
|
319
|
+
}
|
|
320
|
+
if (style.sources && style.sources[source]) {
|
|
321
|
+
//ToDo 支持多个tiles地址
|
|
322
|
+
this._tileUrl = SecurityManager.appendCredential(style.sources[source].tiles[0]);
|
|
323
|
+
}
|
|
324
|
+
if (style.metadata && style.metadata.indexbounds) {
|
|
325
|
+
const indexbounds = style.metadata.indexbounds;
|
|
326
|
+
var max = Math.max(indexbounds[2] - indexbounds[0], indexbounds[3] - indexbounds[1]);
|
|
327
|
+
const defaultResolutions = [];
|
|
328
|
+
for (let index = 0; index < 30; index++) {
|
|
329
|
+
defaultResolutions.push(max / 512 / Math.pow(2, index));
|
|
330
|
+
}
|
|
331
|
+
this.tileGrid = new TileGrid({
|
|
332
|
+
extent: style.metadata.indexbounds,
|
|
333
|
+
resolutions: defaultResolutions,
|
|
334
|
+
tileSize: [512, 512]
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
_fillByRestMapOptions(url, options) {
|
|
339
|
+
this._tileUrl = CommonUtil.urlPathAppend(options.url, 'tileFeature.json');
|
|
340
|
+
if (options.format instanceof MVT) {
|
|
341
|
+
this._tileUrl = CommonUtil.urlPathAppend(options.url, 'tileFeature.mvt');
|
|
342
|
+
}
|
|
343
|
+
//为url添加安全认证信息片段
|
|
344
|
+
this._tileUrl = SecurityManager.appendCredential(this._tileUrl);
|
|
345
|
+
|
|
346
|
+
var returnAttributes = true;
|
|
347
|
+
if (options.returnAttributes !== undefined) {
|
|
348
|
+
returnAttributes = options.returnAttributes;
|
|
349
|
+
}
|
|
350
|
+
var params = {};
|
|
351
|
+
params['returnAttributes'] = returnAttributes;
|
|
352
|
+
if (options._cache !== undefined) {
|
|
353
|
+
params['_cache'] = options._cache;
|
|
354
|
+
}
|
|
355
|
+
if (options.layersID !== undefined) {
|
|
356
|
+
params['layersID'] = options.layersID;
|
|
357
|
+
}
|
|
358
|
+
if (options.layerNames !== undefined) {
|
|
359
|
+
params['layerNames'] = options.layerNames;
|
|
360
|
+
}
|
|
361
|
+
if (options.expands !== undefined) {
|
|
362
|
+
params['expands'] = options.expands;
|
|
363
|
+
}
|
|
364
|
+
if (options.compressTolerance !== undefined) {
|
|
365
|
+
params['compressTolerance'] = options.compressTolerance;
|
|
366
|
+
}
|
|
367
|
+
if (options.coordinateType !== undefined) {
|
|
368
|
+
params['coordinateType'] = options.coordinateType;
|
|
369
|
+
}
|
|
370
|
+
if (options.returnCutEdges !== undefined) {
|
|
371
|
+
params['returnCutEdges'] = options.returnCutEdges;
|
|
372
|
+
}
|
|
373
|
+
this._tileUrl = CommonUtil.urlAppend(this._tileUrl, CommonUtil.getParameterString(params));
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* @function VectorTileSuperMapRest.optionsFromMapJSON
|
|
378
|
+
* @param {string} url - 地址。
|
|
379
|
+
* @param {Object} mapJSONObj - 地图 JSON。
|
|
380
|
+
* @description 获取地图 JSON 信息。
|
|
381
|
+
*/
|
|
382
|
+
static optionsFromMapJSON(url, mapJSONObj) {
|
|
383
|
+
var options = {};
|
|
384
|
+
options.url = url;
|
|
385
|
+
options.crossOrigin = 'anonymous';
|
|
386
|
+
var extent = [mapJSONObj.bounds.left, mapJSONObj.bounds.bottom, mapJSONObj.bounds.right, mapJSONObj.bounds.top];
|
|
387
|
+
var resolutions = getResolutions();
|
|
388
|
+
|
|
389
|
+
function getResolutions() {
|
|
390
|
+
var level = 17;
|
|
391
|
+
var dpi = 96;
|
|
392
|
+
var width = extent[2] - extent[0];
|
|
393
|
+
var height = extent[3] - extent[1];
|
|
394
|
+
var tileSize = width >= height ? width : height;
|
|
395
|
+
var maxReolution;
|
|
396
|
+
if (tileSize === width) {
|
|
397
|
+
maxReolution = tileSize / mapJSONObj.viewer.width;
|
|
398
|
+
} else {
|
|
399
|
+
maxReolution = tileSize / mapJSONObj.viewer.height;
|
|
400
|
+
}
|
|
401
|
+
var resolutions = [];
|
|
402
|
+
var unit = Unit.METER;
|
|
403
|
+
if (mapJSONObj.coordUnit === Unit.DEGREE) {
|
|
404
|
+
unit = Unit.DEGREE;
|
|
405
|
+
}
|
|
406
|
+
if (mapJSONObj.visibleScales.length > 0) {
|
|
407
|
+
var scales = initScales(mapJSONObj);
|
|
408
|
+
for (let i = 0; i < scales.length; i++) {
|
|
409
|
+
resolutions.push(Util.scaleToResolution(scales[i], dpi, unit));
|
|
410
|
+
}
|
|
411
|
+
} else {
|
|
412
|
+
for (let i = 0; i < level; i++) {
|
|
413
|
+
resolutions.push(maxReolution / Math.pow(2, i));
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
return resolutions;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
function initScales(mapJSONObj) {
|
|
420
|
+
var scales = mapJSONObj.visibleScales;
|
|
421
|
+
if (!scales) {
|
|
422
|
+
return null;
|
|
423
|
+
}
|
|
424
|
+
var viewBounds = mapJSONObj.viewBounds,
|
|
425
|
+
coordUnit = mapJSONObj.coordUnit,
|
|
426
|
+
viewer = mapJSONObj.viewer,
|
|
427
|
+
scale = mapJSONObj.scale,
|
|
428
|
+
datumAxis = mapJSONObj.datumAxis;
|
|
429
|
+
//将jsonObject转化为SuperMap.Bounds,用于计算dpi。
|
|
430
|
+
viewBounds = new Bounds(viewBounds.left, viewBounds.bottom, viewBounds.right, viewBounds.top);
|
|
431
|
+
viewer = new Size(viewer.rightBottom.x, viewer.rightBottom.y);
|
|
432
|
+
coordUnit = coordUnit.toLowerCase();
|
|
433
|
+
datumAxis = datumAxis || 6378137;
|
|
434
|
+
var units = coordUnit;
|
|
435
|
+
var dpi = CommonUtil.calculateDpi(viewBounds, viewer, scale, units, datumAxis);
|
|
436
|
+
var resolutions = _resolutionsFromScales(scales);
|
|
437
|
+
var len = resolutions.length;
|
|
438
|
+
scales = [len];
|
|
439
|
+
for (var i = 0; i < len; i++) {
|
|
440
|
+
scales[i] = CommonUtil.getScaleFromResolutionDpi(resolutions[i], dpi, units, datumAxis);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
function _resolutionsFromScales(scales) {
|
|
444
|
+
if (scales === null) {
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
var resolutions, len;
|
|
448
|
+
len = scales.length;
|
|
449
|
+
resolutions = [len];
|
|
450
|
+
for (var i = 0; i < len; i++) {
|
|
451
|
+
resolutions[i] = CommonUtil.getResolutionFromScaleDpi(scales[i], dpi, units, datumAxis);
|
|
452
|
+
}
|
|
453
|
+
return resolutions;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
return scales;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
options.tileGrid = new TileGrid({
|
|
460
|
+
extent: extent,
|
|
461
|
+
resolutions: resolutions
|
|
462
|
+
});
|
|
463
|
+
//options.projection = 'EPSG:' + mapJSONObj.prjCoordSys.epsgCode;
|
|
464
|
+
return options;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
@@ -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
|
+
}
|