@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
@@ -0,0 +1,125 @@
1
+ /* Copyright© 2000 - 2024 SuperMap Software Co.Ltd. All rights reserved.
2
+ * This program are made available under the terms of the Apache License, Version 2.0
3
+ * which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
4
+ /**
5
+ * @constant pointStyle
6
+ * @description 点属性名的对应表。
7
+ * @private
8
+ */
9
+ export var pointStyle = {
10
+ pointFile: "",
11
+
12
+ /*expand*/
13
+ pointRadius: 3,
14
+ pointHaloRadius: 1,
15
+ pointHaloColor: "#c33",
16
+ offsetX: 0,
17
+ offsetY: 0,
18
+ fillStyle: "#fc0",
19
+
20
+ globalAlpha: 1,
21
+ globalCompositeOperation: "source-over",
22
+ imageSmoothingEnabled: true
23
+ };
24
+
25
+ /**
26
+ * @constant lineStyle
27
+ * @description 线属性名的对应表。
28
+ * @private
29
+ */
30
+ export var lineStyle = {
31
+ strokeStyle: "rgba(0,0,0,0)",
32
+ lineWidth: 1,
33
+ lineCap: "butt",
34
+ lineJoin: "round",
35
+ miterLimit: 10,
36
+ lineDashOffset: 0,
37
+ /*expand*/
38
+ lineDasharray: [],
39
+ strokeOpacity: 1,
40
+ offset: 0,
41
+
42
+ globalAlpha: 1,
43
+ globalCompositeOperation: "source-over",
44
+ imageSmoothingEnabled: true
45
+ };
46
+
47
+ /**
48
+ * @constant polygonStyle
49
+ * @description 面属性名的对应表。
50
+ * @private
51
+ */
52
+ export var polygonStyle = {
53
+ /*包含LINE的部分*/
54
+ strokeStyle: "rgba(0,0,0,0)",
55
+ lineWidth: 1,
56
+ lineCap: "butt",
57
+ lineJoin: "round",
58
+ miterLimit: 10,
59
+ lineDashOffset: 0,
60
+ /*expand*/
61
+ lineOpacity: 1,
62
+ fillOpacity: 1,
63
+ lineDasharray: [],
64
+
65
+ fillStyle: "rgba(0,0,0,0)",
66
+ polygonOpacity: 1,
67
+
68
+ /*expand*/
69
+ offsetX: 0,
70
+ offsetY: 0,
71
+
72
+ globalAlpha: 1,
73
+ globalCompositeOperation: "source-over",
74
+ imageSmoothingEnabled: true
75
+ };
76
+
77
+ /**
78
+ * @constant DeafultCanvasStyle
79
+ * @description 默认画布属性名的对应表。
80
+ * @private
81
+ */
82
+ export var DeafultCanvasStyle = {
83
+ /**
84
+ * @constant DeafultCanvasStyle.prototype.TEXT
85
+ * @description 默认文本样式。
86
+ */
87
+ "TEXT": {
88
+ font: "10px sans-serif",
89
+ textAlign: "middle",
90
+ textBaseline: "center",
91
+ direction: "ltr",
92
+ /*expand*/
93
+ bold: false,
94
+ haloRadius: 0,
95
+ backColor: "rgba(255,255,255,1)",
96
+ foreColor: "rgba(0,0,0,1)",
97
+ // foreColor: "rgba(0,0,0,0)",
98
+ offsetX: 0,
99
+ offsetY: 0,
100
+ textHeight: 0,
101
+
102
+ globalAlpha: 1,
103
+ globalCompositeOperation: "source-over",
104
+ imageSmoothingEnabled: true
105
+ },
106
+ "POINT": pointStyle,
107
+ "MULTIPOINT": pointStyle,
108
+ "LINE": lineStyle,
109
+ "LINESTRING": lineStyle,
110
+ "MULTILINESTRING": lineStyle,
111
+ "REGION": polygonStyle,
112
+ "POLYGON": polygonStyle,
113
+ "MULTIPOLYGON": polygonStyle,
114
+ "SHADOW": {
115
+ shadowBlur: 0,
116
+ shadowColor: "rgba(0,0,0,0)",
117
+ shadowOffsetX: 0,
118
+ shadowOffsetY: 0
119
+ },
120
+ "GLOBAL": {
121
+ globalAlpha: 1,
122
+ globalCompositeOperation: "source-over",
123
+ imageSmoothingEnabled: true
124
+ }
125
+ };
@@ -0,0 +1,377 @@
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 { FetchRequest } from '@supermapgis/iclient-common/util/FetchRequest';
5
+ import { SecurityManager } from '@supermapgis/iclient-common/security/SecurityManager';
6
+ import { Util as CommonUtil} from '@supermapgis/iclient-common/commontypes/Util';
7
+ import { olExtends } from './olExtends';
8
+ import remove from 'lodash.remove';
9
+ import Observable from 'ol/Observable';
10
+ import Style from 'ol/style/Style';
11
+ import CircleStyle from 'ol/style/Circle';
12
+ import FillStyle from 'ol/style/Fill';
13
+ import StrokeStyle from 'ol/style/Stroke';
14
+ import Text from 'ol/style/Text';
15
+ /**
16
+ * @class MapboxStyles
17
+ * @classdesc Mapbox 矢量瓦片风格。
18
+ * <div style="padding: 20px;border: 1px solid #eee;border-left-width: 5px;border-radius: 3px;border-left-color: #ce4844;">
19
+ * <p style="color: #ce4844">Notice</p>
20
+ * <p style="font-size: 13px">该功能依赖 <a href='https://github.com/boundlessgeo/ol-mapbox-style'>ol-mapbox-style</a> 插件,请确认引入该插件。</p>
21
+ * <a src="https://iclient.supermap.io/web/libs/openlayers/plugins/ol-mapbox-style/2.11.2-5/olms.js">https://iclient.supermap.io/web/libs/openlayers/plugins/ol-mapbox-style/2.11.2-5/olms.js</a>
22
+ * </div>
23
+ * @modulecategory Overlay
24
+ * @category Visualization VectorTile
25
+ * @param {Object} options - 参数。
26
+ * @param {(string|undefined)} [options.url] - SuperMap iServer 地图服务地址,例如'http://localhost:8090/iserver/services/map-mvt-test/rest/maps/test',与 options.style 互斥,优先级低于 options.style。
27
+ * @param {(Object|string|undefined)} [options.style] - Mapbox Style JSON 对象或获取 Mapbox Style JSON 对象的 URL。与 options.url 互斥,优先级高于 options.url。
28
+ * @param {Array.<number>} [options.resolutions] - 地图分辨率数组,用于映射 zoom 值。通常情況与地图的 {@link ol.View} 的分辨率一致。</br>
29
+ * 默认值为:[78271.51696402048,39135.75848201024, 19567.87924100512,9783.93962050256,4891.96981025128,2445.98490512564, 1222.99245256282,611.49622628141,305.748113140705,152.8740565703525, 76.43702828517625,38.21851414258813,19.109257071294063,9.554628535647032, 4.777314267823516,2.388657133911758,1.194328566955879,0.5971642834779395, 0.29858214173896974,0.14929107086948487,0.07464553543474244]。
30
+ * @param {(string|Array.<string>|undefined)} [options.source] - Mapbox Style 'source'的 key 值或者 'layer' 的 ID 数组。
31
+ * 当配置 'source' 的 key 值时,source 为该值的 layer 会被加载;
32
+ * 当配置为 'layer' 的 ID 数组时,指定的 layer 会被加载,注意被指定的 layer 需要有相同的 source。
33
+ * 当不配置时,默认为 Mapbox Style JSON 的 `sources` 对象中的第一个。
34
+ * @param {ol.Map} [options.map] - Openlayers 地图对象,仅用于面填充样式,若没有面填充样式可不填。
35
+ * @param {ol.StyleFunction} [options.selectedStyle] -选中样式 Function。
36
+ * @param {boolean} [options.withCredentials] - 请求是否携带 cookie。
37
+ * @example
38
+ * var mbStyle = new MapboxStyles({
39
+ url: url,
40
+ source: 'California',
41
+ resolutions: [78271.51696402048,39135.75848201024, 19567.87924100512,9783.93962050256,4891.96981025128,2445.98490512564]
42
+ })
43
+ mbStyle.on('styleLoaded', function () {
44
+ var vectorLayer = new ol.layer.VectorTile({
45
+ //设置避让参数
46
+ declutter: true,
47
+ source: new ol.source.VectorTileSuperMapRest({
48
+ url: url,
49
+ format: new ol.format.MVT({
50
+ featureClass: ol.Feature
51
+ }),
52
+ tileType: 'ScaleXY'
53
+ }),
54
+ style: mbStyle.featureStyleFuntion
55
+ });
56
+ map.addLayer(vectorLayer);
57
+ })
58
+ * @usage
59
+ */
60
+ export class MapboxStyles extends Observable {
61
+ constructor(options) {
62
+ super();
63
+ options = options || {};
64
+ this.spriteRegEx = /^(.*)(\?.*)$/;
65
+ this.defaultFont = ['DIN Offc Pro Medium', 'Arial Unicode MS Regular'];
66
+ this.map = options.map;
67
+ this.source = options.source;
68
+ this.styleTarget =
69
+ options.style ||
70
+ CommonUtil.urlAppend(
71
+ CommonUtil.urlPathAppend(options.url, 'tileFeature/vectorstyles'),
72
+ 'type=MapBox_GL&styleonly=true'
73
+ );
74
+ this.resolutions = options.resolutions;
75
+ this.withCredentials = options.withCredentials;
76
+ this.selectedObjects = [];
77
+ this.selectedStyle =
78
+ options.selectedStyle ||
79
+ function() {
80
+ return new Style({
81
+ fill: new FillStyle({
82
+ color: 'rgba(255, 0, 0, 1)'
83
+ }),
84
+ stroke: new StrokeStyle({
85
+ color: 'rgba(255, 0, 0, 1)',
86
+ width: 10
87
+ }),
88
+ text: new Text({
89
+ font: 'normal 400 11.19px "Microsoft YaHei"',
90
+ placement: 'point',
91
+ fill: new FillStyle({
92
+ color: 'blue'
93
+ })
94
+ }),
95
+ image: new CircleStyle({
96
+ radius: 5,
97
+ fill: new FillStyle({
98
+ color: 'blue'
99
+ })
100
+ })
101
+ });
102
+ };
103
+ this.layersBySourceLayer = {};
104
+ olExtends(this.map);
105
+ this._loadStyle(this.styleTarget);
106
+ }
107
+ /**
108
+ * @function MapboxStyles.prototype.getStyleFunction
109
+ * @description 获取 ol.StyleFunction。
110
+ * @returns {ol.StyleFunction} 返回 ol.StyleFunction。
111
+ */
112
+ getStyleFunction() {
113
+ return this.featureStyleFuntion;
114
+ }
115
+ /**
116
+ * @function MapboxStyles.prototype.getStylesBySourceLayer
117
+ * @description 根据图层名称获取样式。
118
+ * @param {string} sourceLayer - 数据图层名称。
119
+ */
120
+ getStylesBySourceLayer(sourceLayer) {
121
+ if (this.layersBySourceLayer[sourceLayer]) {
122
+ return this.layersBySourceLayer[sourceLayer];
123
+ }
124
+ const layers = [];
125
+ for (let index = 0; index < this._mbStyle.layers.length; index++) {
126
+ const layer = this._mbStyle.layers[index];
127
+ if (layer['source-layer'] !== sourceLayer) {
128
+ continue;
129
+ }
130
+ layers.push(layer);
131
+ }
132
+ this.layersBySourceLayer[sourceLayer] = layers;
133
+ return layers;
134
+ }
135
+ /**
136
+ * @function MapboxStyles.prototype.setSelectedId
137
+ * @description 设置选中要素,该要素将会用 `selectedStyle` 样式绘制。调用该方法后需要调用 {@link ol.layer.VectorTile} 的 `changed`,才能生效。
138
+ * @param {number} selectedId - 要素 ID。
139
+ * @param {string} sourceLayer - 要素所在图层名称。
140
+ */
141
+ setSelectedId(selectedId, sourceLayer) {
142
+ this.selectedObjects = [];
143
+ this.selectedObjects.push({
144
+ id: selectedId,
145
+ sourceLayer: sourceLayer
146
+ });
147
+ }
148
+ /**
149
+ * @typedef {Object} MapboxStyles.selectedObject
150
+ * @description 要选择的要素对象。
151
+ * @property {number} selectedId - 要素 ID。
152
+ * @property {string} sourceLayer - 要素所在图层名称。
153
+ */
154
+
155
+ /**
156
+ * @function MapboxStyles.prototype.setSelectedObjects
157
+ * @version 10.0.0
158
+ * @description 设置选中要素或要素数组,该要素将会用 `selectedStyle` 样式绘制。调用该方法后需要调用 {@link ol.layer.VectorTile} 的 `changed`,才能生效。
159
+ * @param {MapboxStyles.selectedObject|Array.<MapboxStyles.selectedObject>} addSelectedObjects - 选择的要素或要素数组。
160
+ */
161
+ setSelectedObjects(selectedObjects) {
162
+ if (!Array.isArray(selectedObjects)) {
163
+ selectedObjects = [selectedObjects];
164
+ }
165
+ this.selectedObjects = [];
166
+ this.selectedObjects = selectedObjects;
167
+ }
168
+ /**
169
+ * @function MapboxStyles.prototype.addSelectedObjects
170
+ * @version 10.0.0
171
+ * @description 增加选中的要素或要素数组,该要素将会用 `selectedStyle` 样式绘制。调用该方法后需要调用 {@link ol.layer.VectorTile} 的 `changed` ,才能生效。
172
+ * @param {MapboxStyles.selectedObject|Array.<MapboxStyles.selectedObject>} addSelectedObjects - 选择的要素或要素数组。
173
+ */
174
+ addSelectedObjects(selectedObjects) {
175
+ if (!Array.isArray(selectedObjects)) {
176
+ selectedObjects = [selectedObjects];
177
+ }
178
+ this.selectedObjects.push(...selectedObjects);
179
+ }
180
+ /**
181
+ * @function MapboxStyles.prototype.removeSelectedObjects
182
+ * @version 10.0.0
183
+ * @description 清空选中状态。调用该方法后需要调用 {@link ol.layer.VectorTile} 的 `changed` ,才能生效。
184
+ */
185
+ removeSelectedObjects(selectedObjects) {
186
+ if (!Array.isArray(selectedObjects)) {
187
+ selectedObjects = [selectedObjects];
188
+ }
189
+ selectedObjects.forEach(element => {
190
+ remove(this.selectedObjects, obj => {
191
+ return element.id === obj.id && element.sourceLayer === obj.sourceLayer;
192
+ });
193
+ });
194
+ }
195
+ /**
196
+ * @function MapboxStyles.prototype.clearSelectedObjects
197
+ * @version 10.0.0
198
+ * @description 清空选中状态。调用该方法后需要调用 {@link ol.layer.VectorTile} 的 `changed`,才能生效。
199
+ */
200
+ clearSelectedObjects() {
201
+ this.selectedObjects = [];
202
+ }
203
+ /**
204
+ * @function MapboxStyles.prototype.updateStyles
205
+ * @description 更新图层样式。
206
+ * @param {Object} layerStyles - 图层样式或图层样式数组。
207
+ */
208
+ updateStyles(layerStyles) {
209
+ if (Object.prototype.toString.call(layerStyles) !== '[object Array]') {
210
+ layerStyles = [layerStyles];
211
+ }
212
+ const layerObj = {};
213
+ layerStyles.forEach(layerStyle => {
214
+ layerObj[layerStyle.id] = layerStyle;
215
+ });
216
+ let count = 0;
217
+ for (const key in this._mbStyle.layers) {
218
+ const oldLayerStyle = this._mbStyle.layers[key];
219
+ if (count >= layerStyles.length) {
220
+ break;
221
+ }
222
+ if (!layerObj[oldLayerStyle.id]) {
223
+ continue;
224
+ }
225
+ const newLayerStyle = JSON.parse(JSON.stringify(layerObj[oldLayerStyle.id]));
226
+ if (newLayerStyle.paint) {
227
+ newLayerStyle.paint = Object.assign({}, oldLayerStyle.paint, newLayerStyle.paint);
228
+ }
229
+ if (newLayerStyle.layout) {
230
+ newLayerStyle.layout = Object.assign({}, oldLayerStyle.layout, newLayerStyle.layout);
231
+ }
232
+ Object.assign(oldLayerStyle, newLayerStyle);
233
+ count++;
234
+ }
235
+ this._createStyleFunction();
236
+ }
237
+ /**
238
+ * @function MapboxStyles.prototype.setStyle
239
+ * @version 9.1.1
240
+ * @description 设置 Mapbox style 对象。
241
+ * @param {Object} style - Mapbox style 对象。
242
+ */
243
+ setStyle(style) {
244
+ this.layersBySourceLayer = {};
245
+ this._loadStyle(style);
246
+ }
247
+ _loadStyle(style) {
248
+ if (Object.prototype.toString.call(style) == '[object Object]') {
249
+ this._mbStyle = style;
250
+ setTimeout(() => {
251
+ this._resolve();
252
+ }, 0);
253
+ } else {
254
+ var url = SecurityManager.appendCredential(style);
255
+ FetchRequest.get(url, null, { withCredentials: this.withCredentials })
256
+ .then(response => response.json())
257
+ .then(mbStyle => {
258
+ this._mbStyle = mbStyle;
259
+ this._resolve();
260
+ });
261
+ }
262
+ }
263
+ _resolve() {
264
+ if (!this.source) {
265
+ this.source = Object.keys(this._mbStyle.sources)[0];
266
+ }
267
+ if (this._mbStyle.sprite) {
268
+ const spriteScale = window.devicePixelRatio >= 1.5 ? 0.5 : 1;
269
+ const sizeFactor = spriteScale == 0.5 ? '@2x' : '';
270
+ //兼容一下iServer 等iServer修改
271
+ this._mbStyle.sprite = this._mbStyle.sprite.replace('@2x', '');
272
+ const spriteUrl = this._toSpriteUrl(this._mbStyle.sprite, this.path, sizeFactor + '.json');
273
+ FetchRequest.get(SecurityManager.appendCredential(spriteUrl), null, {
274
+ withCredentials: this.withCredentials
275
+ })
276
+ .then(response => response.json())
277
+ .then(spritesJson => {
278
+ this._spriteData = spritesJson;
279
+ this._spriteImageUrl = SecurityManager.appendCredential(
280
+ this._toSpriteUrl(this._mbStyle.sprite, this.path, sizeFactor + '.png')
281
+ );
282
+ this._spriteImage = null;
283
+ const img = new Image();
284
+ img.crossOrigin = this.withCredentials ? 'use-credentials' : 'anonymous';
285
+ img.onload = () => {
286
+ this._spriteImage = img;
287
+ this._initStyleFunction();
288
+ };
289
+ img.onerror = () => {
290
+ this._spriteImage = null;
291
+ this._initStyleFunction();
292
+ };
293
+ img.src = this._spriteImageUrl;
294
+ })
295
+ .catch( err => {
296
+ console.log(err);
297
+ this._spriteImage = null;
298
+ this._initStyleFunction();
299
+ });
300
+ } else {
301
+ this._initStyleFunction();
302
+ }
303
+ }
304
+ _initStyleFunction() {
305
+ if (!this.resolutions && this._mbStyle.metadata && this._mbStyle.metadata.indexbounds) {
306
+ const indexbounds = this._mbStyle.metadata.indexbounds;
307
+ var max = Math.max(indexbounds[2] - indexbounds[0], indexbounds[3] - indexbounds[1]);
308
+ const defaultResolutions = [];
309
+ for (let index = 0; index < 30; index++) {
310
+ defaultResolutions.push(max / 512 / Math.pow(2, index));
311
+ }
312
+ this.resolutions = defaultResolutions;
313
+ }
314
+ this._createStyleFunction();
315
+ /**
316
+ * @event MapboxStyles#styleloaded
317
+ * @description 样式加载成功后触发。
318
+ */
319
+ this.dispatchEvent('styleloaded');
320
+ }
321
+ _createStyleFunction() {
322
+ if (this.map) {
323
+ window.olms.applyBackground(this.map, this._mbStyle);
324
+ }
325
+ this.featureStyleFuntion = this._getStyleFunction();
326
+ }
327
+ _getStyleFunction() {
328
+ this.fun = window.olms.stylefunction(
329
+ { setStyle: function() {}, set: function() {}, changed: function() {} },
330
+ this._mbStyle,
331
+ this.source,
332
+ this.resolutions,
333
+ this._spriteData,
334
+ '',
335
+ this._spriteImage
336
+ );
337
+ return (feature, resolution) => {
338
+ const style = this.fun(feature, resolution);
339
+ if (
340
+ this.selectedObjects.length > 0 &&
341
+ this.selectedObjects.find(element => {
342
+ return element.id === feature.getId() && element.sourceLayer === feature.get('layer');
343
+ })
344
+ ) {
345
+ const styleIndex = style && style[0] ? style[0].getZIndex() : 99999;
346
+ let selectStyles = this.selectedStyle(feature, resolution);
347
+ if (!Array.isArray(selectStyles)) {
348
+ selectStyles = [selectStyles];
349
+ }
350
+ for (let index = 0; index < selectStyles.length; index++) {
351
+ const selectStyle = selectStyles[index];
352
+ if (feature.getGeometry().getType() === 'Point' && style[0].getText() && selectStyle.getText()) {
353
+ selectStyle.setFill(null);
354
+ selectStyle.setStroke(null);
355
+ selectStyle.setImage();
356
+ selectStyle.getText().setText(style[0].getText().getText());
357
+ }
358
+ selectStyle.setZIndex(styleIndex);
359
+ }
360
+ return selectStyles;
361
+ }
362
+ return style;
363
+ };
364
+ }
365
+ _withPath(url, path) {
366
+ if (path && url.indexOf('http') != 0) {
367
+ url = path + url;
368
+ }
369
+ return url;
370
+ }
371
+
372
+ _toSpriteUrl(url, path, extension) {
373
+ url = this._withPath(url, path);
374
+ const parts = url.match(this.spriteRegEx);
375
+ return parts ? parts[1] + extension + (parts.length > 2 ? parts[2] : '') : url + extension;
376
+ }
377
+ }