@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.
Files changed (91) hide show
  1. package/README.md +56 -0
  2. package/control/ChangeTileVersion.js +438 -0
  3. package/control/Logo.js +97 -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 +500 -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 +124963 -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 +142946 -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 +150 -0
  23. package/mapping/SuperMapCloud.js +56 -0
  24. package/mapping/Tianditu.js +152 -0
  25. package/mapping/TileSuperMapRest.js +374 -0
  26. package/mapping/WebMap.js +5485 -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 +100 -0
  35. package/overlay/Graph.js +439 -0
  36. package/overlay/GraphMap.js +140 -0
  37. package/overlay/Graphic.js +588 -0
  38. package/overlay/HeatMap.js +450 -0
  39. package/overlay/Label.js +966 -0
  40. package/overlay/Mapv.js +149 -0
  41. package/overlay/Range.js +129 -0
  42. package/overlay/RankSymbol.js +94 -0
  43. package/overlay/Turf.js +299 -0
  44. package/overlay/Unique.js +124 -0
  45. package/overlay/VectorTileSuperMapRest.js +501 -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 +64 -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 +413 -0
  55. package/overlay/mapv/index.js +5 -0
  56. package/overlay/theme/GeoFeature.js +275 -0
  57. package/overlay/theme/Theme.js +587 -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 +377 -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 +30 -0
  67. package/services/AddressMatchService.js +60 -0
  68. package/services/ChartService.js +97 -0
  69. package/services/DataFlowService.js +119 -0
  70. package/services/DatasetService.js +104 -0
  71. package/services/DatasourceService.js +76 -0
  72. package/services/FeatureService.js +260 -0
  73. package/services/FieldService.js +53 -0
  74. package/services/GeoprocessingService.js +157 -0
  75. package/services/GridCellInfosService.js +53 -0
  76. package/services/ImageCollectionService.js +93 -0
  77. package/services/ImageService.js +70 -0
  78. package/services/KnowledgeGraphService.js +96 -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 +93 -0
  83. package/services/NetworkAnalystService.js +268 -0
  84. package/services/ProcessingService.js +507 -0
  85. package/services/QueryService.js +116 -0
  86. package/services/ServiceBase.js +26 -0
  87. package/services/SpatialAnalystService.js +466 -0
  88. package/services/ThemeService.js +50 -0
  89. package/services/TrafficTransferAnalystService.js +93 -0
  90. package/services/WebPrintingJobService.js +112 -0
  91. package/services/index.js +27 -0
package/core/Util.js ADDED
@@ -0,0 +1,500 @@
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 { Bounds } from '@supermapgis/iclient-common/commontypes/Bounds';
5
+ import { GeoJSON as GeoJSONFormat } from '@supermapgis/iclient-common/format/GeoJSON';
6
+ import { getMeterPerMapUnit, scalesToResolutions, getZoomByResolution, getDpi } from '@supermapgis/iclient-common/util/MapCalculateUtil';
7
+ import * as olUtil from 'ol/util';
8
+ import Geometry from 'ol/geom/Geometry';
9
+ import { getVectorContext } from 'ol/render';
10
+ import VectorSource from 'ol/source/Vector';
11
+ import VectorLayer from 'ol/layer/Vector';
12
+ import { Fill, Style } from 'ol/style';
13
+ import Feature from 'ol/Feature';
14
+ import Projection from 'ol/proj/Projection';
15
+ import { get } from 'ol/proj';
16
+
17
+ /**
18
+ * @name Util
19
+ * @namespace
20
+ * @category BaseTypes Util
21
+ * @classdesc 工具类。
22
+ * @usage
23
+ * ```
24
+ * // 浏览器
25
+ * <script type="text/javascript" src="{cdn}"></script>
26
+ * <script>
27
+ * const result = {namespace}.Util.getOlVersion();
28
+ *
29
+ * </script>
30
+ *
31
+ * // ES6 Import
32
+ * import { Util } from '{npm}';
33
+ *
34
+ * const result = Util.setMask();
35
+ * ```
36
+ */
37
+ export const Util = {
38
+ getOlVersion() {
39
+ if (olUtil && olUtil.VERSION) {
40
+ return olUtil.VERSION.split('.')[0];
41
+ }
42
+ if (window && window.ol) {
43
+ if (window.ol.util) {
44
+ return '6';
45
+ }
46
+ if (window.ol.WebGLMap) {
47
+ return '5';
48
+ }
49
+ }
50
+ return '4';
51
+ },
52
+
53
+ /**
54
+ * @function Util.toGeoJSON
55
+ * @description 将传入对象转为 GeoJSON 格式。
56
+ * @param {Object} smObj - 待转换参数。
57
+ * @private
58
+ */
59
+ toGeoJSON(smObj) {
60
+ if (!smObj) {
61
+ return null;
62
+ }
63
+ return new GeoJSONFormat().toGeoJSON(smObj);
64
+ },
65
+
66
+ /**
67
+ * @function Util.toSuperMapGeometry
68
+ * @description 将 GeoJSON 对象转为 SuperMap 几何图形。
69
+ * @param {GeoJSONObject} geoJSON - GeoJSON 对象。
70
+ * @private
71
+ */
72
+ toSuperMapGeometry(geoJSON) {
73
+ if (!geoJSON || !geoJSON.type) {
74
+ return null;
75
+ }
76
+ const result = new GeoJSONFormat().read(geoJSON, 'FeatureCollection');
77
+ return result[0].geometry;
78
+ },
79
+
80
+ /**
81
+ * @function Util.resolutionToScale
82
+ * @description 通过分辨率计算比例尺。
83
+ * @param {number} resolution - 分辨率。
84
+ * @param {number} dpi - 屏幕分辨率。
85
+ * @param {string} mapUnit - 地图单位。
86
+ * @returns {number} 比例尺。
87
+ * @private
88
+ */
89
+ resolutionToScale(resolution, dpi, mapUnit) {
90
+ const inchPerMeter = 1 / 0.0254;
91
+ // 地球半径。
92
+ const meterPerMapUnit = getMeterPerMapUnit(mapUnit);
93
+ const scale = 1 / (resolution * dpi * inchPerMeter * meterPerMapUnit);
94
+ return scale;
95
+ },
96
+
97
+ /**
98
+ * @function Util.toSuperMapBounds
99
+ * @description 转为 SuperMapBounds 格式。
100
+ * @param {Array.<number>} bounds - bounds 数组。
101
+ * @returns {Bounds} 返回 SuperMap 的 Bounds 对象。
102
+ * @private
103
+ */
104
+ toSuperMapBounds(bounds) {
105
+ if (bounds instanceof Bounds) {
106
+ return bounds;
107
+ }
108
+ return new Bounds(bounds[0], bounds[1], bounds[2], bounds[3]);
109
+ },
110
+
111
+ /**
112
+ * @function Util.toProcessingParam
113
+ * @description 将 Region 节点数组转为 Processing 服务需要的分析参数。
114
+ * @param {Array} points - Region 各个节点数组。
115
+ * @returns processing 服务裁剪、查询分析的分析参数。
116
+ * @private
117
+ */
118
+ toProcessingParam(points) {
119
+ if (points.length < 1) {
120
+ return '';
121
+ }
122
+ const geometryParam = {};
123
+ const results = [];
124
+ for (let i = 0; i < points.length; i++) {
125
+ const point = { x: points[i][0], y: points[i][1] };
126
+ results.push(point);
127
+ }
128
+ results.push(results[0]);
129
+ geometryParam.type = 'REGION';
130
+ geometryParam.points = results;
131
+
132
+ return geometryParam;
133
+ },
134
+
135
+ /**
136
+ * @function Util.scaleToResolution
137
+ * @description 通过比例尺计算分辨率。
138
+ * @param {number} scale - 比例尺。
139
+ * @param {number} dpi - 屏幕分辨率。
140
+ * @param {string} mapUnit - 地图单位。
141
+ * @returns {number} 分辨率。
142
+ * @private
143
+ */
144
+ scaleToResolution(scale, dpi, mapUnit) {
145
+ const inchPerMeter = 1 / 0.0254;
146
+ const meterPerMapUnitValue = getMeterPerMapUnit(mapUnit);
147
+ const resolution = 1 / (scale * dpi * inchPerMeter * meterPerMapUnitValue);
148
+ return resolution;
149
+ },
150
+
151
+ /**
152
+ * @private
153
+ * @function Util.getMeterPerMapUnit
154
+ * @description 获取每地图单位多少米。
155
+ * @param {string} mapUnit - 地图单位。
156
+ * @returns {number} 返回每地图单位多少米。
157
+ * @private
158
+ */
159
+ getMeterPerMapUnit,
160
+
161
+ /**
162
+ * @function Util.isArray
163
+ * @description 判断是否为数组格式。
164
+ * @param {Object} obj - 待判断对象。
165
+ * @returns {boolean} 是否是数组。
166
+ * @private
167
+ */
168
+ isArray,
169
+
170
+ /**
171
+ * @function Util.Csv2GeoJSON
172
+ * @description 将 csv 格式转为 GeoJSON。
173
+ * @param {Object} csv - csv 对象。
174
+ * @param {Object} options - 转换参数。
175
+ * @private
176
+ */
177
+ Csv2GeoJSON(csv, options) {
178
+ const defaultOptions = {
179
+ titles: ['lon', 'lat'],
180
+ latitudeTitle: 'lat',
181
+ longitudeTitle: 'lon',
182
+ fieldSeparator: ',',
183
+ lineSeparator: '\n',
184
+ deleteDoubleQuotes: true,
185
+ firstLineTitles: false
186
+ };
187
+ options = options || defaultOptions;
188
+ const _propertiesNames = [];
189
+ if (typeof csv === 'string') {
190
+ let titulos = options.titles;
191
+ if (options.firstLineTitles) {
192
+ csv = csv.split(options.lineSeparator);
193
+ if (csv.length < 2) {
194
+ return;
195
+ }
196
+ titulos = csv[0];
197
+ csv.splice(0, 1);
198
+ csv = csv.join(options.lineSeparator);
199
+ titulos = titulos.trim().split(options.fieldSeparator);
200
+ for (let i = 0; i < titulos.length; i++) {
201
+ titulos[i] = _deleteDoubleQuotes(titulos[i]);
202
+ }
203
+ options.titles = titulos;
204
+ }
205
+ for (let i = 0; i < titulos.length; i++) {
206
+ let prop = titulos[i]
207
+ .toLowerCase()
208
+ .replace(/[^\w ]+/g, '')
209
+ .replace(/ +/g, '_');
210
+ if (prop === '' || prop === '_') {
211
+ prop = `prop-${i}`;
212
+ }
213
+ _propertiesNames[i] = prop;
214
+ }
215
+ csv = _csv2json(csv);
216
+ }
217
+ return csv;
218
+
219
+ function _deleteDoubleQuotes(cadena) {
220
+ if (options.deleteDoubleQuotes) {
221
+ cadena = cadena.trim().replace(/^"/, '').replace(/"$/, '');
222
+ }
223
+ return cadena;
224
+ }
225
+
226
+ function _csv2json(csv) {
227
+ const json = {};
228
+ json['type'] = 'FeatureCollection';
229
+ json['features'] = [];
230
+ const titulos = options.titles;
231
+ csv = csv.split(options.lineSeparator);
232
+ for (let num_linea = 0; num_linea < csv.length; num_linea++) {
233
+ const campos = csv[num_linea].trim().split(options.fieldSeparator),
234
+ lng = parseFloat(campos[titulos.indexOf(options.longitudeTitle)]),
235
+ lat = parseFloat(campos[titulos.indexOf(options.latitudeTitle)]);
236
+
237
+ const isInRange = lng < 180 && lng > -180 && lat < 90 && lat > -90;
238
+ if (!(campos.length === titulos.length && isInRange)) {
239
+ continue;
240
+ }
241
+
242
+ const feature = {};
243
+ feature['type'] = 'Feature';
244
+ feature['geometry'] = {};
245
+ feature['properties'] = {};
246
+ feature['geometry']['type'] = 'Point';
247
+ feature['geometry']['coordinates'] = [lng, lat];
248
+ for (let i = 0; i < titulos.length; i++) {
249
+ if (titulos[i] !== options.latitudeTitle && titulos[i] !== options.longitudeTitle) {
250
+ feature['properties'][_propertiesNames[i]] = _deleteDoubleQuotes(campos[i]);
251
+ }
252
+ }
253
+ json['features'].push(feature);
254
+ }
255
+ return json;
256
+ }
257
+ },
258
+
259
+ /**
260
+ * @function Util.createCanvasContext2D
261
+ * @description 创建 2D 画布。
262
+ * @param {number} opt_width - 画布宽度。
263
+ * @param {number} opt_height - 画布高度。
264
+ * @private
265
+ */
266
+ createCanvasContext2D(opt_width, opt_height) {
267
+ const canvas = document.createElement('CANVAS');
268
+ if (opt_width) {
269
+ canvas.width = opt_width;
270
+ }
271
+ if (opt_height) {
272
+ canvas.height = opt_height;
273
+ }
274
+ return canvas.getContext('2d');
275
+ },
276
+ /**
277
+ * @function Util.supportWebGL2
278
+ * @description 是否支持 webgl2。
279
+ * @private
280
+ */
281
+ supportWebGL2() {
282
+ const canvas = document.createElement('canvas');
283
+ return Boolean(canvas && canvas.getContext('webgl2'));
284
+ },
285
+
286
+ /**
287
+ * @function Util.isString
288
+ * @description 是否为字符串
289
+ * @param {string} str - 需要判断的内容
290
+ * @returns {boolean}
291
+ * @private
292
+ */
293
+ isString,
294
+ /**
295
+ * @function Util.isObject
296
+ * @description 是否为对象
297
+ * @param {any} obj - 需要判断的内容
298
+ * @returns {boolean}
299
+ * @private
300
+ */
301
+ isObject(obj) {
302
+ return Object.prototype.toString.call(obj) === '[object Object]';
303
+ },
304
+
305
+ /**
306
+ * @function Util.trim
307
+ * @description 字符串裁剪两边的空格
308
+ * @param {string} str - 需要裁剪的字符串
309
+ * @returns {boolean}
310
+ * @private
311
+ */
312
+ trim(str = '') {
313
+ return str.replace(/(^\s*)|(\s*$)/g, '');
314
+ },
315
+ /**
316
+ * @function Util.newGuid
317
+ * @description 随机生成id
318
+ * @param {string} attr - 几位数字的id
319
+ * @returns {string}
320
+ * @private
321
+ */
322
+ newGuid(attr) {
323
+ let len = attr || 32;
324
+ let guid = '';
325
+ for (let i = 1; i < len; i++) {
326
+ let n = Math.floor(Math.random() * 16.0).toString(16);
327
+ guid += n;
328
+ }
329
+ return guid;
330
+ },
331
+ /**
332
+ * @function Util.isNumber
333
+ * @description 检测数据是否为number
334
+ * @param {string} value - 值,未知数据类型
335
+ * @returns {boolean}
336
+ * @private
337
+ */
338
+ isNumber(value) {
339
+ if (value === '') {
340
+ return false;
341
+ }
342
+ let mdata = Number(value);
343
+ if (mdata === 0) {
344
+ return true;
345
+ }
346
+ return !isNaN(mdata);
347
+ },
348
+
349
+
350
+ /**
351
+ * @function Util.isMatchAdministrativeName
352
+ * @param {string} featureName 原始数据中的地名
353
+ * @param {string} fieldName 需要匹配的地名
354
+ * @returns {boolean} 是否匹配
355
+ * @private
356
+ */
357
+ isMatchAdministrativeName,
358
+
359
+ /**
360
+ * @function Util.getHighestMatchAdministration
361
+ * @param {string} featureName 初始匹配的要素数组
362
+ * @param {string} fieldName 要匹配的地名
363
+ * @returns {boolean} 是否匹配
364
+ * @private
365
+ */
366
+ getHighestMatchAdministration(features, fieldName) {
367
+ let filterFeatures = features.filter((item) => {
368
+ return isMatchAdministrativeName(item.properties.Name, fieldName);
369
+ });
370
+
371
+ let maxMatchPercent = 0,
372
+ maxMatchFeature = null;
373
+ filterFeatures.forEach((feature) => {
374
+ let count = 0;
375
+ Array.from(new Set(feature.properties.Name.split(''))).forEach((char) => {
376
+ if (fieldName.includes(char)) {
377
+ count++;
378
+ }
379
+ });
380
+ if (count > maxMatchPercent) {
381
+ maxMatchPercent = count;
382
+ maxMatchFeature = feature;
383
+ }
384
+ });
385
+ return maxMatchFeature;
386
+ },
387
+
388
+ /**
389
+ * @function Util.setMask
390
+ * @description 为图层设置掩膜。
391
+ * @version 10.1.0
392
+ * @param {ol.layer.Layer|Array.<ol.layer.Layer>} layers 图层
393
+ * @param {ol.geom.Geometry|ol.Feature} polygon 掩膜矢量要素,支持面类型的要素。
394
+ */
395
+ setMask(layers, polygon) {
396
+ if (!polygon) {
397
+ return;
398
+ }
399
+ const geo = polygon instanceof Feature ? polygon.getGeometry() : polygon;
400
+ if (!(geo instanceof Geometry) && ['MultiPolygon', 'Polygon'].indexOf(polygon.getType()) < 0) {
401
+ return;
402
+ }
403
+ const feature = polygon instanceof Feature ? polygon : new Feature(polygon);
404
+ const style = new Style({
405
+ fill: new Fill({
406
+ color: 'black'
407
+ })
408
+ });
409
+
410
+ const clipLayer = new VectorLayer({
411
+ source: new VectorSource({
412
+ features: [feature],
413
+ wrapX: false
414
+ })
415
+ });
416
+
417
+ const clipRender = function (e) {
418
+ const vectorContext = getVectorContext(e);
419
+ e.context.globalCompositeOperation = 'destination-in';
420
+ clipLayer.getSource().forEachFeature(function (feature) {
421
+ vectorContext.drawFeature(feature, style);
422
+ e.context.globalCompositeOperation = 'source-over';
423
+ });
424
+ };
425
+ const todoLayers = Array.isArray(layers) ? layers : [layers];
426
+ unsetMask(todoLayers);
427
+ todoLayers.forEach((layer) => {
428
+ layer.classNameBak_ = layer.className_;
429
+ layer.className_ = `ol_mask_layer_${layer.ol_uid}`;
430
+ layer.clipRender = clipRender;
431
+ layer.extentBak_ = layer.getExtent();
432
+ layer.setExtent(clipLayer.getSource().getExtent());
433
+ layer.on('postrender', clipRender);
434
+ layer.changed();
435
+ });
436
+ },
437
+ /**
438
+ * @function Util.unsetMask
439
+ * @description 取消图层掩膜。
440
+ * @version 10.1.0
441
+ * @param {ol.layer.Layer|Array.<ol.layer.Layer>} layers 图层
442
+ */
443
+ unsetMask,
444
+ getZoomByResolution(scale, scales) {
445
+ return getZoomByResolution(scale, scales);
446
+ },
447
+ scalesToResolutions(scales, bounds, dpi, unit, mapobj, level) {
448
+ return scalesToResolutions(scales, bounds, dpi, unit, mapobj, level);
449
+ },
450
+ getDpi,
451
+ getProjection(prjCoordSys, extent) {
452
+ let projection = get(`EPSG:${prjCoordSys.epsgCode}`);
453
+ if (prjCoordSys.type == 'PCS_NON_EARTH') {
454
+ projection = new Projection({
455
+ extent,
456
+ units: 'm',
457
+ code: '0'
458
+ });
459
+ }
460
+ if (!projection) {
461
+ console.error(`The projection of EPSG:${prjCoordSys.epsgCode} is missing, please register the projection of EPSG:${prjCoordSys.epsgCode} first, refer to the documentation: https://iclient.supermap.io/web/introduction/leafletDevelop.html#multiProjection`);
462
+ }
463
+ return projection;
464
+ }
465
+ }
466
+
467
+ function isString(str) {
468
+ return typeof str === 'string' && str.constructor === String;
469
+ }
470
+ function isArray(obj) {
471
+ return Object.prototype.toString.call(obj) === '[object Array]';
472
+ }
473
+ function unsetMask(layers) {
474
+ const todoLayers = Array.isArray(layers) ? layers : [layers];
475
+ for (let index = 0; index < todoLayers.length; index++) {
476
+ const layer = todoLayers[index];
477
+ if (!layer.clipRender) {
478
+ continue;
479
+ }
480
+ layer.un('postrender', layer.clipRender);
481
+ layer.className_ = layer.classNameBak_;
482
+ layer.setExtent(layer.extentBak);
483
+ delete layer.classNameBak_;
484
+ delete layer.clipRender;
485
+ delete layer.extentBak_;
486
+ layer.changed();
487
+ }
488
+ }
489
+
490
+ function isMatchAdministrativeName(featureName, fieldName) {
491
+ if (isString(fieldName)) {
492
+ let shortName = featureName.substr(0, 2);
493
+ // 张家口市和张家界市 特殊处理
494
+ if (shortName === '张家') {
495
+ shortName = featureName.substr(0, 3);
496
+ }
497
+ return !!fieldName.match(new RegExp(shortName));
498
+ }
499
+ return false;
500
+ }
package/core/index.js ADDED
@@ -0,0 +1,6 @@
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 {StyleUtils} from './StyleUtils';
5
+ export {Util} from './Util';
6
+ export {MapExtend} from './MapExtend';