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