@mapgis/webclient-mapboxgl-plugin 10.3.3 → 17.0.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 (87) hide show
  1. package/README.md +51 -124
  2. package/dist/es5/webclient-common.min.js +90 -0
  3. package/dist/es5/webclient-mapboxgl-plugin.min.js +1 -0
  4. package/dist/webclient-mapboxgl-plugin-es6.min.js +1 -0
  5. package/documention/EchartsLayer.html +379 -0
  6. package/documention/MapViewMapboxgl.html +3587 -0
  7. package/documention/Popup.html +1523 -0
  8. package/documention/Screenshot.html +1089 -0
  9. package/documention/SketchEditorMapboxgl.html +3383 -0
  10. package/documention/document_ArcGISVectorTileLayerView.js.html +265 -0
  11. package/documention/document_EchartsLayerView.js.html +246 -0
  12. package/documention/document_GraphicsLayerView.js.html +314 -0
  13. package/documention/document_IGSFeatureLayerView.js.html +218 -0
  14. package/documention/document_IGSMapImageLayerView.js.html +240 -0
  15. package/documention/document_IGSTileLayerView.js.html +236 -0
  16. package/documention/document_IGSVectorTileLayerView.js.html +264 -0
  17. package/documention/document_MapVLayerView.js.html +247 -0
  18. package/documention/document_WMSLayerView.js.html +240 -0
  19. package/documention/document_WMTSLayerView.js.html +234 -0
  20. package/documention/document_WebTileLayerView.js.html +240 -0
  21. package/documention/document_support_FeatureRenderView.js.html +682 -0
  22. package/documention/document_support_MapboxglGraphicsLayer.js.html +1184 -0
  23. package/documention/document_support_SourceMetaData.js.html +223 -0
  24. package/documention/document_support_Utils.js.html +624 -0
  25. package/documention/document_support_mapbox_mapboxCustomUtil.js.html +322 -0
  26. package/documention/global.html +252 -0
  27. package/documention/index.html +251 -0
  28. package/documention/module-%E5%AE%A2%E6%88%B7%E7%AB%AF%E5%8F%AF%E8%A7%86%E5%8C%96.MapvLayer.html +445 -0
  29. package/documention/scripts/app.min.js +1 -0
  30. package/documention/scripts/linenumber.js +26 -0
  31. package/documention/scripts/search.js +45 -0
  32. package/documention/scripts/sideBar.js +11 -0
  33. package/documention/sketchEditor_SketchEditorMapboxgl.js.html +875 -0
  34. package/documention/styles/anchor.png +0 -0
  35. package/documention/styles/app.min.css +1 -0
  36. package/documention/styles/c.png +0 -0
  37. package/documention/styles/iframe.css +29 -0
  38. package/documention/styles/m.png +0 -0
  39. package/documention/styles/prettify-jsdoc.css +111 -0
  40. package/documention/styles/prettify-tomorrow.css +132 -0
  41. package/documention/styles/reset.css +44 -0
  42. package/documention/styles/up-arrow.png +0 -0
  43. package/documention/tutorial-1./345/277/253/351/200/237/345/205/245/351/227/250.html +165 -0
  44. package/documention/util_ConvertRendererToStyleLayerUtil.js.html +844 -0
  45. package/documention/util_MapboxglFeatureRender.js.html +225 -0
  46. package/documention/util_MapboxglPlugin.js.html +284 -0
  47. package/documention/view_MapViewMapboxgl.js.html +1882 -0
  48. package/documention/view_utils_ArcGISVectorTileLayerUtil.js.html +382 -0
  49. package/documention/view_utils_EchartsLayerUtil.js.html +194 -0
  50. package/documention/view_utils_IGSMapImageUtil.js.html +373 -0
  51. package/documention/view_utils_IGSTileLayerUtil.js.html +285 -0
  52. package/documention/view_utils_IGSVectorTileLayerUtil.js.html +379 -0
  53. package/documention/view_utils_MapVLayerUtil.js.html +197 -0
  54. package/documention/view_utils_Popup.js.html +525 -0
  55. package/documention/view_utils_Screenshot.js.html +320 -0
  56. package/documention/view_utils_WMSLayerUtil.js.html +337 -0
  57. package/documention/view_utils_WMTSLayerUtil.js.html +331 -0
  58. package/documention/view_utils_WebTileLayerUtil.js.html +284 -0
  59. package/documention/view_utils_echarts_EchartsLayerPlugin.js.html +419 -0
  60. package/documention/view_utils_mapV_MapVLayerPlugin.js.html +527 -0
  61. package/documention/view_utils_mapV_MapvBaseLayer.js.html +477 -0
  62. package/documention/view_utils_support_rasterLayerUtil.js.html +244 -0
  63. package/documention/view_utils_support_vectorLayerUtil.js.html +503 -0
  64. package/package.json +20 -20
  65. package/core/Base.js +0 -7
  66. package/core/index.js +0 -5
  67. package/index.js +0 -6
  68. package/overlay/D3Layer.js +0 -108
  69. package/overlay/EchartsLayer.js +0 -242
  70. package/overlay/ElsCubeLayer.js +0 -125
  71. package/overlay/MapvLayer.js +0 -298
  72. package/overlay/StreamLayer.js +0 -86
  73. package/overlay/TimeSpaceCubeLayer.js +0 -135
  74. package/overlay/dthree/mapbox-d3.css +0 -9
  75. package/overlay/echarts/MapCoordSys.js +0 -105
  76. package/overlay/echarts/MapModel.js +0 -0
  77. package/overlay/echarts/MapView.js +0 -0
  78. package/overlay/echarts/index.js +0 -4
  79. package/overlay/index.js +0 -31
  80. package/overlay/mapv/MapvBaseLayer.js +0 -299
  81. package/overlay/mapv/index.js +0 -5
  82. package/overlay/stream/GeojsonStreamLayer.js +0 -135
  83. package/overlay/stream/MapvStreamLayer.js +0 -79
  84. package/overlay/stream/index.js +0 -3
  85. package/overlay/stream/popup.css +0 -31
  86. package/service/index.js +0 -1
  87. package/service/socket/SocketService.js +0 -90
@@ -0,0 +1,1184 @@
1
+
2
+
3
+ <!DOCTYPE html>
4
+ <html lang="en">
5
+
6
+ <head>
7
+
8
+ <meta charset="utf-8">
9
+ <meta name="viewport" content="width=device-width, initial-scale=1">
10
+ <title>Client for JavaScript document/support/MapboxglGraphicsLayer.js</title>
11
+ <!--[if lt IE 9]>
12
+ <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
13
+ <![endif]-->
14
+ <link type="text/css" rel="stylesheet" href="styles/app.min.css">
15
+ <link type="text/css" rel="stylesheet" href="styles/iframe.css">
16
+ <link type="text/css" rel="stylesheet" href="">
17
+
18
+
19
+ </head>
20
+
21
+
22
+
23
+ <body class="layout small-header">
24
+ <div id="stickyNavbarOverlay"></div>
25
+
26
+
27
+ <div class="top-nav">
28
+ <div class="inner">
29
+ <a id="hamburger" role="button" class="navbar-burger" aria-label="menu" aria-expanded="false">
30
+ <span aria-hidden="true"></span>
31
+ <span aria-hidden="true"></span>
32
+ <span aria-hidden="true"></span>
33
+ </a>
34
+ <div class="logo">
35
+
36
+ <h1> MapGIS Client for JavaScript API</h1>
37
+
38
+
39
+ </div>
40
+ <div class="menu">
41
+
42
+ <div class="navigation">
43
+
44
+
45
+ <a
46
+ class="link user-link "
47
+ href="/static/modules/common/api/common-mapgis/index.html"
48
+ >
49
+ Common
50
+ </a>
51
+
52
+ <a
53
+ class="link user-link "
54
+ href="/static/modules/cesium/api/cesium-mapgis/index.html"
55
+ >
56
+ Cesium
57
+ </a>
58
+
59
+ <a
60
+ class="link user-link "
61
+ href="/static/modules/mapboxgl/api/mapboxgl-mapgis/index.html"
62
+ >
63
+ MapboxGL
64
+ </a>
65
+
66
+ <a
67
+ class="link user-link "
68
+ href="/static/modules/leaflet/api/leaflet-mapgis/index.html"
69
+ >
70
+ Leaflet
71
+ </a>
72
+
73
+ <a
74
+ class="link user-link "
75
+ href="/static/modules/openlayers/api/openLayers-mapgis/index.html"
76
+ >
77
+ OpenLayers
78
+ </a>
79
+
80
+
81
+
82
+ </div>
83
+ </div>
84
+ </div>
85
+ </div>
86
+
87
+ <div id="main">
88
+ <div
89
+ class="sidebar "
90
+ id="sidebarNav"
91
+ >
92
+ <div>
93
+ <span class="mapgis-api-document-span"><a href="index.html">API文档</a></span>
94
+ </div>
95
+
96
+ <div class="search-wrapper">
97
+ <input id="search" type="text" placeholder="搜索文档..." class="input">
98
+ </div>
99
+
100
+ <nav>
101
+
102
+ <div class="category"><div style="font-weight: bold;vertical-align: middle;padding: 0.4rem 0;" class="mapgis-menu-span"><img style="width: 20px;margin-right: 6px;vertical-align: middle;" src="./styles/m.png" alt="">undefined</div><ul class="mapgis-sidebar-menus"><li><img style="width: 20px;margin-right: 6px;vertical-align: middle;" src="./styles/c.png" alt=""><a href="Popup.html">Popup</a><span style="display: none;"><p>二维场景信息弹窗(leaflet引擎)
103
+ 参考示例:
104
+ <a href='#MapView'>[初始化二维场景视图]</a>
105
+ [ES6引入方式]:<br/>
106
+ import { Popup } from '@mapgis/webclient-leaflet-plugin' <br/>
107
+ 自定义样式说明:<br/>
108
+ zondy-popup__content 弹窗容器样式<br/>
109
+ zondy-popup__tip 弹窗对话框箭头样式<br/>
110
+ zondy-popup__header 弹窗头部样式<br/>
111
+ zondy-popup__content 弹窗主体样式<br/>
112
+ zondy-popup__footer 弹窗底部样式<br/></p></span></li></ul><div style="font-weight: bold;vertical-align: middle;padding: 0.4rem 0;" class="mapgis-menu-span"><img style="width: 20px;margin-right: 6px;vertical-align: middle;" src="./styles/m.png" alt="">undefined</div><ul class="mapgis-sidebar-menus"><li><img style="width: 20px;margin-right: 6px;vertical-align: middle;" src="./styles/c.png" alt=""><a href="Screenshot.html">Screenshot</a><span style="display: none;"><p>打印工具</p></span></li></ul><div style="font-weight: bold;vertical-align: middle;padding: 0.4rem 0;" class="mapgis-menu-span"><img style="width: 20px;margin-right: 6px;vertical-align: middle;" src="./styles/m.png" alt="">草图编辑模块</div><ul class="mapgis-sidebar-menus"><li><img style="width: 20px;margin-right: 6px;vertical-align: middle;" src="./styles/c.png" alt=""><a href="SketchEditorMapboxgl.html">SketchEditorMapboxgl</a><span style="display: none;"><p>二维场景草图编辑类<br/>
113
+ <br>[ES5引入方式]:<br/>
114
+ const { SketchEditorMapboxgl } = Zondy <br/>
115
+ [ES6引入方式]:<br/>
116
+ import { SketchEditorMapboxgl } from &quot;@mapgis/webclient-leaflet-plugin&quot; <br/></p></span></li></ul></div>
117
+
118
+ </nav>
119
+ </div>
120
+ <div class="core" id="main-content-wrapper">
121
+ <div class="content">
122
+ <header id="page-title" class="page-title">
123
+ <span class="page-title-main">类名</span>
124
+ <span class="page-title-sub">document/support/MapboxglGraphicsLayer.js</span>
125
+ </header>
126
+
127
+
128
+
129
+
130
+
131
+ <section>
132
+ <article>
133
+ <pre class="prettyprint source linenums"><code>import {
134
+ defaultValue,
135
+ getGUID,
136
+ Log,
137
+ Feature,
138
+ GeometryType,
139
+ SimpleMarkerSymbol,
140
+ SimpleLineSymbol,
141
+ SimpleFillSymbol,
142
+ TextSymbol,
143
+ SymbolType,
144
+ PictureMarkerSymbol
145
+ } from '@mapgis/webclient-common'
146
+ import MapboxglPlugin from '../../util/MapboxglPlugin'
147
+ import SourceMetaData from './SourceMetaData'
148
+
149
+ class MapboxglGraphicsLayer {
150
+ constructor(options) {
151
+ options = defaultValue(options, {})
152
+ this.id = options.id || getGUID()
153
+ this._opacity = options.opacity || 1
154
+ this._visible = options.visible || true
155
+ // 缓存ids
156
+ this.renderTypes = ['fill', 'line', 'circle', 'text', 'icon']
157
+ // source and layers
158
+ this._sourceMetaDatas = {}
159
+ this.renderTypes.forEach((v) => {
160
+ const metaData = {}
161
+ metaData['sourceId'] = `${this.id}_${v}`
162
+ metaData['featureCollection'] = []
163
+ metaData[`layerId`] = `${this.id}_${v}_layer`
164
+ metaData[`renderType`] = v
165
+ this._sourceMetaDatas[v] = new SourceMetaData(metaData)
166
+ })
167
+ }
168
+
169
+ /**
170
+ * @description: 添加到地图容器中
171
+ * @param {*} map
172
+ * @return {*}
173
+ */
174
+ onAdd(map) {
175
+ if (!map) return
176
+ this._map = map
177
+ const self = this
178
+
179
+ function init() {
180
+ self.renderTypes.forEach((type) => {
181
+ const metaData = self._sourceMetaDatas[type]
182
+ map.addSource(metaData.sourceId, {
183
+ type: 'geojson',
184
+ data: {
185
+ type: 'FeatureCollection',
186
+ features: []
187
+ }
188
+ })
189
+ if (type === 'text' || type === 'icon') {
190
+ type = 'symbol'
191
+ }
192
+ // 初始化图层
193
+ map.addLayer({
194
+ id: metaData.layerId,
195
+ source: metaData.sourceId,
196
+ type
197
+ })
198
+ })
199
+ }
200
+
201
+ return new Promise((resolve) => {
202
+ // 判断map的load状态
203
+ // 加载完毕直接添加
204
+ let mapLoadedInterval
205
+ const setup = () => {
206
+ init()
207
+ resolve(this)
208
+ if (mapLoadedInterval) {
209
+ clearInterval(mapLoadedInterval)
210
+ }
211
+ }
212
+ if (map.loaded()) {
213
+ setup()
214
+ } else {
215
+ map.once('load', setup)
216
+ mapLoadedInterval = setInterval(() => {
217
+ if (map.loaded()) setup()
218
+ }, 16)
219
+ }
220
+ })
221
+ }
222
+
223
+ /**
224
+ * @description: 从地图容器中移除
225
+ * @param {*} map
226
+ * @return {*}
227
+ */
228
+ onRemove(map) {
229
+ if (!map) return
230
+ this.renderTypes.forEach((type) => {
231
+ const metaData = this._sourceMetaDatas[type]
232
+ // 删除图层
233
+ map.removeLayer(metaData.layerId)
234
+ // 删除source
235
+ map.removeSource(metaData.sourceId)
236
+ })
237
+ }
238
+
239
+ /**
240
+ * @description: 获取style layer IDs
241
+ * @return {Array} id数组
242
+ */
243
+ getStyleLayerIds() {
244
+ const layerIds = []
245
+ this.renderTypes.forEach((type) => {
246
+ const metaData = this._sourceMetaDatas[type]
247
+ layerIds.push(metaData.layerId)
248
+ })
249
+ return layerIds
250
+ }
251
+
252
+ /**
253
+ * @description: 添加graphic或graphics
254
+ * @param {Array&lt;Feature>|Feature} graphic
255
+ * @return {*}
256
+ */
257
+ add(graphic) {
258
+ // 添加到容器内
259
+ if (Array.isArray(graphic)) {
260
+ graphic.forEach((v) => {
261
+ this._updateGraphicToCollection(v)
262
+ })
263
+ } else {
264
+ this._updateGraphicToCollection(graphic)
265
+ }
266
+ // 更新source资源
267
+ this._refreshSourceAndLayers()
268
+ }
269
+
270
+ /**
271
+ * @description: 移除graphics
272
+ * @param {*} graphics
273
+ * @return {*}
274
+ */
275
+ _removeGraphicsToCollection(graphics) {
276
+ // 移除缓存
277
+ const sourceMetaDatas = Object.values(this._sourceMetaDatas)
278
+ for (let i = 0; i &lt; sourceMetaDatas.length; i++) {
279
+ const sourceMetaData = sourceMetaDatas[i]
280
+ const { featureCollection } = sourceMetaData
281
+ // 删除的下标
282
+ const indexs = []
283
+ for (let j = 0; j &lt; featureCollection.length; j++) {
284
+ const feature = featureCollection[j]
285
+ if (graphics.indexOf(feature) > -1) {
286
+ indexs.push(j)
287
+ }
288
+ }
289
+ if (indexs.length > 0) {
290
+ // 过滤不删除的数据
291
+ sourceMetaData.featureCollection = featureCollection.filter(
292
+ (v, i) => indexs.indexOf(i) === -1
293
+ )
294
+ sourceMetaData.setSourceDirty(true)
295
+ }
296
+ }
297
+ }
298
+
299
+ /**
300
+ * @description: 更新graphic
301
+ * @param {Array&lt;Feature>|Feature} graphic
302
+ * @return {*}
303
+ */
304
+ update(graphic, updateDetails) {
305
+ if (!graphic) return
306
+ const graphics = Array.isArray(graphic) ? graphic : [graphic]
307
+ // 设置styleLayer dirty
308
+ for (let i = 0; i &lt; graphics.length; i++) {
309
+ const graphic = graphics[i]
310
+ const updateDetail = updateDetails[i] || {}
311
+ // 将graphic进行分组
312
+ const sourceMetaData = this._updateGraphicToCollection(graphic)
313
+ if (sourceMetaData) {
314
+ // 处理几何更新
315
+ if (updateDetail.geometryUpdated) {
316
+ sourceMetaData.setSourceDirty(true)
317
+ }
318
+ // 处理样式更新
319
+ if (updateDetail.symbolUpdated) {
320
+ sourceMetaData.setStyleLayerDirty(true)
321
+ }
322
+ }
323
+ }
324
+ this._refreshSourceAndLayers()
325
+ }
326
+
327
+ _updateGraphicToCollection(graphic) {
328
+ let sourceMetaData
329
+ if (!graphic) return
330
+ if (!(graphic instanceof Feature)) return
331
+ if (!graphic.geometry) {
332
+ Log.error('几何不存在')
333
+ return
334
+ }
335
+
336
+ const geometry = graphic.geometry
337
+ switch (geometry.type) {
338
+ case GeometryType.multiPoint:
339
+ case GeometryType.point: {
340
+ sourceMetaData = this._dividePointGraphic(graphic)
341
+ break
342
+ }
343
+ case GeometryType.multiLineString:
344
+ case GeometryType.lineString: {
345
+ sourceMetaData = this._dividePolylineGraphic(graphic)
346
+ break
347
+ }
348
+ case GeometryType.extent:
349
+ case GeometryType.circle:
350
+ case GeometryType.multiPolygon:
351
+ case GeometryType.polygon: {
352
+ sourceMetaData = this._dividePolygonGraphic(graphic)
353
+ break
354
+ }
355
+ default: {
356
+ break
357
+ }
358
+ }
359
+ return sourceMetaData
360
+ }
361
+
362
+ /**
363
+ * @description: 移除graphic
364
+ * @param {*} graphic
365
+ * @return {*}
366
+ */
367
+ remove(graphic) {
368
+ if (!graphic) return
369
+ if (Array.isArray(graphic)) {
370
+ this._removeGraphicsToCollection(graphic)
371
+ } else {
372
+ this._removeGraphicsToCollection([graphic])
373
+ }
374
+ // 更新source资源
375
+ this._refreshSourceAndLayers()
376
+ }
377
+
378
+ /**
379
+ * @description: 移除全部
380
+ * @return {*}
381
+ */
382
+ removeAll() {
383
+ const sourceMetaDatas = Object.values(this._sourceMetaDatas)
384
+ for (let i = 0; i &lt; sourceMetaDatas.length; i++) {
385
+ const sourceMetaData = sourceMetaDatas[i]
386
+ sourceMetaData.featureCollection = []
387
+ sourceMetaData.setDirty(true)
388
+ }
389
+ // 更新source资源
390
+ this._refreshSourceAndLayers()
391
+ }
392
+
393
+ /**
394
+ * @description: 刷新source数据和图层数据
395
+ * @return {Boolean} 是否进行刷新
396
+ */
397
+ _refreshSourceAndLayers() {
398
+ // 是否更新完source
399
+ const keys = Object.keys(this._sourceMetaDatas)
400
+ // 无须更新
401
+ if (!keys.some((v) => this._sourceMetaDatas[v].getDirty())) {
402
+ return false
403
+ }
404
+ // 如果未添加到source地图容器内,无法渲染
405
+ if (!this._map) return false
406
+ const map = this._map
407
+
408
+ // 更新source
409
+ keys.forEach((key) => {
410
+ const sourceMetaData = this._sourceMetaDatas[key]
411
+ // 更新style layer
412
+ if (sourceMetaData.getStyleLayerDirty()) {
413
+ this._setSourceMetaDataStyle(sourceMetaData)
414
+ // 更新渲染样式逻辑
415
+ sourceMetaData.setStyleLayerDirty(false)
416
+ }
417
+ // 更新source
418
+ if (sourceMetaData.getSourceDirty()) {
419
+ const { sourceId, featureCollection } = sourceMetaData
420
+ const geojsonSource = map.getSource(sourceId)
421
+ geojsonSource.setData({
422
+ type: 'FeatureCollection',
423
+ features: featureCollection.map(function (v) {
424
+ const geojson = MapboxglPlugin.convertToGeoJSON(v)
425
+ return geojson
426
+ })
427
+ })
428
+ sourceMetaData.setSourceDirty(false)
429
+ }
430
+ })
431
+ // 触发更新
432
+ map._update(true)
433
+
434
+ return true
435
+ }
436
+
437
+ /**
438
+ * @description: 设置sourceMetaData style
439
+ * @param {*} sourceMetaData
440
+ * @return {*}
441
+ */
442
+ _setSourceMetaDataStyle(sourceMetaData) {
443
+ const style = {}
444
+ const paint = {}
445
+ const layout = {}
446
+ const { renderType } = sourceMetaData
447
+ switch (renderType) {
448
+ case 'circle': {
449
+ // as SMS
450
+ this._setCircleStyle(sourceMetaData, paint, layout)
451
+ break
452
+ }
453
+ case 'line': {
454
+ // as SLS
455
+ this._setLineStyle(sourceMetaData, paint, layout)
456
+ break
457
+ }
458
+ case 'fill': {
459
+ // as SFS
460
+ this._setFillStyle(sourceMetaData, paint, layout)
461
+ break
462
+ }
463
+ case 'text': {
464
+ // as TS
465
+ this._setTextStyle(sourceMetaData, paint, layout)
466
+ break
467
+ }
468
+ case 'icon': {
469
+ // as PMS
470
+ this._setIconStyle(sourceMetaData, paint, layout)
471
+ break
472
+ }
473
+ default: {
474
+ break
475
+ }
476
+ }
477
+
478
+ style.paint = paint
479
+ style.layout = layout
480
+
481
+ return style
482
+ }
483
+
484
+ /**
485
+ * @description: 设置styleLayer样式
486
+ * @param {*} sourceMetaData
487
+ * @param {*} paint
488
+ * @param {*} layout
489
+ * @return {*}
490
+ */
491
+ _setCircleStyle(sourceMetaData, paint, layout) {
492
+ if (!this._map) return
493
+ const map = this._map
494
+ const style = map.style
495
+ const { layerId, featureCollection } = sourceMetaData
496
+ const opacity = this._opacity
497
+ const visible = this._visible
498
+ const paintCaches = {
499
+ 'circle-color': {
500
+ values: [],
501
+ def: '#000000'
502
+ },
503
+ 'circle-opacity': {
504
+ values: [],
505
+ def: 1
506
+ },
507
+ 'circle-stroke-color': {
508
+ values: [],
509
+ def: '#000000'
510
+ },
511
+ 'circle-stroke-opacity': {
512
+ values: [],
513
+ def: 1
514
+ },
515
+ 'circle-stroke-width': {
516
+ values: [],
517
+ def: 0
518
+ },
519
+ 'circle-radius': {
520
+ values: [],
521
+ def: 5
522
+ }
523
+ }
524
+
525
+ const layoutCaches = {}
526
+ featureCollection.forEach((feature) => {
527
+ // 此处symbol必须为SMS
528
+ const { id } = feature
529
+ let symbol = feature.symbol
530
+ if (!(symbol instanceof SimpleMarkerSymbol)) {
531
+ Log.info(`不支持类型为${symbol.type}的符号!`)
532
+ symbol = new SimpleMarkerSymbol()
533
+ }
534
+ // color
535
+ const color = MapboxglPlugin.applyVisibleAndOpacityToColor(
536
+ symbol.color,
537
+ visible,
538
+ opacity
539
+ )
540
+
541
+ paintCaches['circle-color'].values.push(id, color.toCssRGBString())
542
+ paintCaches['circle-opacity'].values.push(id, color.alpha)
543
+ // stroke color
544
+ const strokeColor = MapboxglPlugin.applyVisibleAndOpacityToColor(
545
+ symbol.outline.color,
546
+ visible,
547
+ opacity
548
+ )
549
+ paintCaches['circle-stroke-color'].values.push(
550
+ id,
551
+ strokeColor.toCssRGBString()
552
+ )
553
+ paintCaches['circle-stroke-opacity'].values.push(id, strokeColor.alpha)
554
+ paintCaches['circle-stroke-width'].values.push(id, symbol.outline.width)
555
+ // size
556
+ paintCaches['circle-radius'].values.push(id, symbol.size / 2)
557
+ })
558
+ // 设置样式
559
+ this._setLayoutAndPaintCaches(
560
+ layerId,
561
+ paintCaches,
562
+ layoutCaches,
563
+ paint,
564
+ layout,
565
+ style
566
+ )
567
+ }
568
+
569
+ /**
570
+ * @description: 设置styleLayer样式
571
+ * @param {*} sourceMetaData
572
+ * @param {*} paint
573
+ * @param {*} layout
574
+ * @return {*}
575
+ */
576
+ _setLineStyle(sourceMetaData, paint, layout) {
577
+ if (!this._map) return
578
+ const map = this._map
579
+ const style = map.style
580
+ const { layerId, featureCollection } = sourceMetaData
581
+ const opacity = this._opacity
582
+ const visible = this._visible
583
+ const paintCaches = {
584
+ 'line-color': {
585
+ values: [],
586
+ def: '#000000'
587
+ },
588
+ 'line-width': {
589
+ values: [],
590
+ def: 1
591
+ },
592
+ 'line-opacity': {
593
+ values: [],
594
+ def: 1
595
+ }
596
+ }
597
+
598
+ const layoutCaches = {
599
+ 'line-join': {
600
+ values: [],
601
+ def: 'round'
602
+ }
603
+ }
604
+ // 不支持line-dasharray line-miter-limit line-cap
605
+ featureCollection.forEach((feature) => {
606
+ // 此处symbol必须为SMS
607
+ const { id } = feature
608
+ let symbol = feature.symbol
609
+ if (!(symbol instanceof SimpleLineSymbol)) {
610
+ Log.info(`不支持类型为${symbol.type}的符号!`)
611
+ symbol = new SimpleLineSymbol()
612
+ }
613
+
614
+ // paint
615
+ const color = MapboxglPlugin.applyVisibleAndOpacityToColor(
616
+ symbol.color,
617
+ visible,
618
+ opacity
619
+ )
620
+
621
+ paintCaches['line-color'].values.push(id, color.toCssRGBString())
622
+ paintCaches['line-opacity'].values.push(id, color.alpha)
623
+ paintCaches['line-width'].values.push(id, symbol.width)
624
+ // layout
625
+ layoutCaches['line-join'].values.push(id, symbol.join)
626
+ })
627
+
628
+ // 设置样式
629
+ this._setLayoutAndPaintCaches(
630
+ layerId,
631
+ paintCaches,
632
+ layoutCaches,
633
+ paint,
634
+ layout,
635
+ style
636
+ )
637
+ }
638
+
639
+ /**
640
+ * @description: 设置styleLayer样式
641
+ * @param {*} sourceMetaData
642
+ * @param {*} paint
643
+ * @param {*} layout
644
+ * @return {*}
645
+ */
646
+ _setFillStyle(sourceMetaData, paint, layout) {
647
+ if (!this._map) return
648
+ const map = this._map
649
+ const style = map.style
650
+ const { layerId, featureCollection } = sourceMetaData
651
+ const opacity = this._opacity
652
+ const visible = this._visible
653
+ const paintCaches = {
654
+ 'fill-color': {
655
+ values: [],
656
+ def: '#ffffff'
657
+ },
658
+ 'fill-opacity': {
659
+ values: [],
660
+ def: 0.25
661
+ },
662
+ 'fill-outline-color': {
663
+ values: [],
664
+ def: '#000000'
665
+ }
666
+ }
667
+
668
+ const layoutCaches = {}
669
+
670
+ featureCollection.forEach((feature) => {
671
+ // 此处symbol必须为SMS
672
+ const { id } = feature
673
+ let symbol = feature.symbol
674
+ if (!(symbol instanceof SimpleFillSymbol)) {
675
+ Log.info(`不支持类型为${symbol.type}的符号!`)
676
+ symbol = new SimpleFillSymbol()
677
+ }
678
+
679
+ // paint
680
+ const color = MapboxglPlugin.applyVisibleAndOpacityToColor(
681
+ symbol.color,
682
+ visible,
683
+ opacity
684
+ )
685
+ const outlineColor = MapboxglPlugin.applyVisibleAndOpacityToColor(
686
+ symbol.outline.color,
687
+ visible,
688
+ opacity
689
+ )
690
+ paintCaches['fill-color'].values.push(id, color.toCssRGBString())
691
+ paintCaches['fill-opacity'].values.push(id, color.alpha)
692
+ paintCaches['fill-outline-color'].values.push(
693
+ id,
694
+ outlineColor.toCssRGBAString()
695
+ )
696
+ // layout
697
+ })
698
+
699
+ // 设置样式
700
+ this._setLayoutAndPaintCaches(
701
+ layerId,
702
+ paintCaches,
703
+ layoutCaches,
704
+ paint,
705
+ layout,
706
+ style
707
+ )
708
+ }
709
+
710
+ /**
711
+ * @description: 设置styleLayer样式
712
+ * @param {*} sourceMetaData
713
+ * @param {*} paint
714
+ * @param {*} layout
715
+ * @return {*}
716
+ */
717
+ _setTextStyle(sourceMetaData, paint, layout) {
718
+ if (!this._map) return
719
+ const map = this._map
720
+ const style = map.style
721
+ const { layerId, featureCollection } = sourceMetaData
722
+ const opacity = this._opacity
723
+ const visible = this._visible
724
+
725
+ const paintCaches = {
726
+ 'text-color': {
727
+ values: [],
728
+ def: '#000000'
729
+ },
730
+ 'text-opacity': {
731
+ values: [],
732
+ def: 1
733
+ },
734
+ 'text-halo-color': {
735
+ values: [],
736
+ def: '#000000'
737
+ },
738
+ 'text-halo-width': {
739
+ values: [],
740
+ def: 0
741
+ }
742
+ }
743
+
744
+ const layoutCaches = {
745
+ 'text-field': {
746
+ values: [],
747
+ def: ''
748
+ },
749
+ 'text-size': {
750
+ values: [],
751
+ def: 12
752
+ },
753
+ 'text-justify': {
754
+ values: [],
755
+ def: 'center'
756
+ },
757
+ 'text-letter-spacing': {
758
+ values: [],
759
+ def: 0
760
+ },
761
+ 'text-rotate': {
762
+ values: [],
763
+ def: 0
764
+ }
765
+ }
766
+
767
+ featureCollection.forEach((feature) => {
768
+ // 此处symbol必须为SMS
769
+ const { id } = feature
770
+ let symbol = feature.symbol
771
+ if (!(symbol instanceof TextSymbol)) {
772
+ Log.info(`不支持类型为${symbol.type}的符号!`)
773
+ symbol = new TextSymbol()
774
+ }
775
+ // ----------------- paint -----------------------------
776
+ const color = MapboxglPlugin.applyVisibleAndOpacityToColor(
777
+ symbol.color,
778
+ visible,
779
+ opacity
780
+ )
781
+ const haloColor = MapboxglPlugin.applyVisibleAndOpacityToColor(
782
+ symbol.haloColor,
783
+ visible,
784
+ opacity
785
+ )
786
+ paintCaches['text-color'].values.push(id, color.toCssRGBString())
787
+ paintCaches['text-opacity'].values.push(id, color.alpha)
788
+ paintCaches['text-halo-color'].values.push(
789
+ id,
790
+ haloColor.toCssRGBAString()
791
+ )
792
+ paintCaches['text-halo-width'].values.push(id, symbol.haloSize)
793
+ // ----------------- layout -----------------------------
794
+ // 设置默认文字field
795
+ layoutCaches['text-field'].values.push(id, symbol.text)
796
+ // 开启注记避让
797
+ layoutCaches['text-allow-overlap'] = false
798
+ layoutCaches['text-font'] = [
799
+ 'Open Sans Regular',
800
+ 'Arial Unicode MS Regular'
801
+ ]
802
+ layoutCaches['text-size'].values.push(id, symbol.font.size)
803
+ layoutCaches['text-justify'].values.push(id, symbol.horizontalAlignment)
804
+ layoutCaches['text-letter-spacing'].values.push(
805
+ id,
806
+ symbol.kerning ? 0.1 : 0
807
+ )
808
+ layoutCaches['text-rotate'].values.push(
809
+ id,
810
+ symbol.rotated &amp;&amp; symbol.angle !== 0 ? symbol.angle : 0
811
+ )
812
+ })
813
+
814
+ // 设置样式
815
+ this._setLayoutAndPaintCaches(
816
+ layerId,
817
+ paintCaches,
818
+ layoutCaches,
819
+ paint,
820
+ layout,
821
+ style,
822
+ ['text-allow-overlap', 'text-font']
823
+ )
824
+ }
825
+
826
+ /**
827
+ * @description: 设置styleLayer样式
828
+ * @param {*} sourceMetaData
829
+ * @param {*} paint
830
+ * @param {*} layout
831
+ * @return {*}
832
+ */
833
+ _setIconStyle(sourceMetaData, paint, layout) {
834
+ if (!this._map) return
835
+ const map = this._map
836
+ const style = map.style
837
+ const { layerId, featureCollection } = sourceMetaData
838
+ const opacity = this._opacity
839
+ const visible = this._visible
840
+
841
+ const paintCaches = {
842
+ 'icon-color': {
843
+ values: [],
844
+ def: '#000000'
845
+ },
846
+ 'icon-opacity': {
847
+ values: [],
848
+ def: 1
849
+ }
850
+ }
851
+
852
+ const layoutCaches = {
853
+ 'icon-size': {
854
+ values: [],
855
+ def: 20
856
+ },
857
+ 'icon-rotate': {
858
+ values: [],
859
+ def: 0
860
+ },
861
+ 'icon-image': {
862
+ values: [],
863
+ def: 'marker-15'
864
+ }
865
+ }
866
+
867
+ featureCollection.forEach((feature) => {
868
+ // 此处symbol必须为PMS
869
+ const { id } = feature
870
+ let symbol = feature.symbol
871
+ if (!(symbol instanceof PictureMarkerSymbol)) {
872
+ Log.info(`不支持类型为${symbol.type}的符号!`)
873
+ symbol = new PictureMarkerSymbol()
874
+ }
875
+ // ----------------- paint -----------------------------
876
+ const color = MapboxglPlugin.applyVisibleAndOpacityToColor(
877
+ symbol.color,
878
+ visible,
879
+ opacity
880
+ )
881
+ paintCaches['icon-color'].values.push(id, color.toCssRGBString())
882
+ paintCaches['icon-opacity'].values.push(id, color.alpha)
883
+ // ----------------- layout -----------------------------
884
+ layoutCaches['icon-allow-overlap'] = false
885
+ layoutCaches['icon-size'].values.push(
886
+ id,
887
+ Math.max(symbol.width, symbol.height) / 20
888
+ )
889
+ layoutCaches['icon-rotate'].values.push(id, symbol.angle)
890
+ layoutCaches['icon-image'].values.push(id, 'marker-15')
891
+ })
892
+
893
+ // 设置样式
894
+ this._setLayoutAndPaintCaches(
895
+ layerId,
896
+ paintCaches,
897
+ layoutCaches,
898
+ paint,
899
+ layout,
900
+ style,
901
+ ['icon-allow-overlap']
902
+ )
903
+ }
904
+
905
+ /**
906
+ * @description: 设置布局和绘制样式
907
+ * @param {*} layerId 图层id
908
+ * @param {*} paintCaches
909
+ * @param {*} layoutCaches
910
+ * @param {*} paint
911
+ * @param {*} layout
912
+ * @param {*} style
913
+ * @return {*}
914
+ */
915
+ _setLayoutAndPaintCaches(
916
+ layerId,
917
+ paintCaches,
918
+ layoutCaches,
919
+ paint,
920
+ layout,
921
+ style,
922
+ filterKeys
923
+ ) {
924
+ if (!filterKeys) {
925
+ filterKeys = []
926
+ }
927
+ // 绘制属性样式
928
+ for (const item in paintCaches) {
929
+ if (filterKeys.findIndex((v) => v === item) > -1) {
930
+ paint[item] = paintCaches[item]
931
+ style.setPaintProperty(layerId, item, paintCaches[item])
932
+ } else if (paintCaches[item].values.length > 0) {
933
+ // 为空时,设置默认值
934
+ let express = []
935
+ express.push('match')
936
+ express.push(['get', 'id'])
937
+ express = express.concat(paintCaches[item].values)
938
+ express.push(paintCaches[item].def)
939
+ paint[item] = express
940
+ style.setPaintProperty(layerId, item, express)
941
+ } else {
942
+ paint[item] = paintCaches[item].def
943
+ style.setPaintProperty(layerId, item, paintCaches[item].def)
944
+ }
945
+ }
946
+
947
+ // 布局属性样式
948
+ for (const item in layoutCaches) {
949
+ if (filterKeys.findIndex((v) => v === item) > -1) {
950
+ layout[item] = layoutCaches[item]
951
+ style.setLayoutProperty(layerId, item, layoutCaches[item])
952
+ } else if (layoutCaches[item].values.length > 0) {
953
+ let express = []
954
+ express.push('match')
955
+ express.push(['get', 'id'])
956
+ express = express.concat(layoutCaches[item].values)
957
+ express.push(layoutCaches[item].def)
958
+ layout[item] = express
959
+ style.setLayoutProperty(layerId, item, express)
960
+ } else {
961
+ layout[item] = layoutCaches[item].def
962
+ style.setLayoutProperty(layerId, item, layoutCaches[item].def)
963
+ }
964
+ }
965
+ }
966
+
967
+ /**
968
+ * @description: 将点类型graphic按符号分组
969
+ * @param {*} graphic
970
+ * @return {SourceMetaData}
971
+ */
972
+ _dividePointGraphic(graphic) {
973
+ const { symbol } = graphic
974
+ let hasMetaData = false
975
+ let sourceMetaData = this._sourceMetaDatas['circle']
976
+ switch (symbol.type) {
977
+ case SymbolType.simpleMarker: {
978
+ // 清空其他图层的graphic
979
+ hasMetaData = this._replaceSourceLayer(graphic, 'circle')
980
+ sourceMetaData = this._sourceMetaDatas['circle']
981
+ break
982
+ }
983
+ case SymbolType.text: {
984
+ hasMetaData = this._replaceSourceLayer(graphic, 'text')
985
+ sourceMetaData = this._sourceMetaDatas['text']
986
+ break
987
+ }
988
+ case SymbolType.pictureMarker: {
989
+ hasMetaData = this._replaceSourceLayer(graphic, 'icon')
990
+ sourceMetaData = this._sourceMetaDatas['icon']
991
+ break
992
+ }
993
+ default: {
994
+ break
995
+ }
996
+ }
997
+ // 寻找是否已经有要素缓存
998
+ // 新增
999
+ if (!hasMetaData) {
1000
+ const { featureCollection } = sourceMetaData
1001
+ featureCollection.push(graphic)
1002
+ // 全部更新
1003
+ sourceMetaData.setDirty(true)
1004
+ }
1005
+ return sourceMetaData
1006
+ }
1007
+
1008
+ /**
1009
+ * @description: 替换graphic的SoureCache
1010
+ * @param {*} graphic
1011
+ * @param {*} layerType
1012
+ * @return {Boolean} 是否添加
1013
+ */
1014
+ _replaceSourceLayer(graphic, layerType) {
1015
+ const clearTypes = this.renderTypes
1016
+ const sourceMetaData = this._hasGraphicInCollection(clearTypes, graphic)
1017
+ if (sourceMetaData) {
1018
+ if (sourceMetaData.renderType === layerType) {
1019
+ return true
1020
+ } else {
1021
+ this._removeGraphicsToCollection([graphic])
1022
+ }
1023
+ }
1024
+ return false
1025
+ }
1026
+
1027
+ /**
1028
+ * @description: 将线类型graphic按符号分组
1029
+ * @param {*} graphic
1030
+ * @return {*}
1031
+ */
1032
+ _dividePolylineGraphic(graphic) {
1033
+ const metaDataCache = this._hasGraphicInCollection(['line'], graphic)
1034
+ const sourceMetaData = this._sourceMetaDatas['line']
1035
+ if (!metaDataCache) {
1036
+ const { featureCollection } = sourceMetaData
1037
+ featureCollection.push(graphic)
1038
+ sourceMetaData.setDirty(true)
1039
+ }
1040
+ return sourceMetaData
1041
+ }
1042
+
1043
+ /**
1044
+ * @description: 将区类型graphic按符号分组
1045
+ * @param {*} graphic
1046
+ * @return {*}
1047
+ */
1048
+ _dividePolygonGraphic(graphic) {
1049
+ let hasMetaData = false
1050
+ const { symbol } = graphic
1051
+ let sourceMetaData = this._sourceMetaDatas['fill']
1052
+ switch (symbol.type) {
1053
+ case SymbolType.simpleMarker: {
1054
+ // 清空其他图层的graphic
1055
+ hasMetaData = this._replaceSourceLayer(graphic, 'circle')
1056
+ sourceMetaData = this._sourceMetaDatas['circle']
1057
+ break
1058
+ }
1059
+ case SymbolType.text: {
1060
+ hasMetaData = this._replaceSourceLayer(graphic, 'text')
1061
+ sourceMetaData = this._sourceMetaDatas['text']
1062
+ break
1063
+ }
1064
+ case SymbolType.pictureMarker: {
1065
+ hasMetaData = this._replaceSourceLayer(graphic, 'icon')
1066
+ sourceMetaData = this._sourceMetaDatas['icon']
1067
+ break
1068
+ }
1069
+ case SymbolType.pictureFill:
1070
+ case SymbolType.simpleFill: {
1071
+ hasMetaData = this._replaceSourceLayer(graphic, 'fill')
1072
+ sourceMetaData = this._sourceMetaDatas['fill']
1073
+ break
1074
+ }
1075
+ default: {
1076
+ break
1077
+ }
1078
+ }
1079
+
1080
+ if (!hasMetaData) {
1081
+ const { featureCollection } = sourceMetaData
1082
+ featureCollection.push(graphic)
1083
+ sourceMetaData.setDirty(true)
1084
+ }
1085
+ return sourceMetaData
1086
+ }
1087
+
1088
+ /**
1089
+ * @description: 判断graphic是否在某类型或类型组中的featureCollection中
1090
+ * @param {Array&lt;String>} renderType
1091
+ * @param {*} graphic
1092
+ * @return {SourceMetaData}
1093
+ */
1094
+ _hasGraphicInCollection(renderType, graphic) {
1095
+ const renderTypes = Array.isArray(renderType) ? renderType : [renderType]
1096
+ let metaData
1097
+ for (let i = 0; i &lt; renderTypes.length; i++) {
1098
+ const sourceMetaData = this._sourceMetaDatas[renderTypes[i]]
1099
+ if (!sourceMetaData) {
1100
+ break
1101
+ }
1102
+ const { featureCollection } = sourceMetaData
1103
+ if (featureCollection.indexOf(graphic) > -1) {
1104
+ metaData = sourceMetaData
1105
+ break
1106
+ }
1107
+ }
1108
+ return metaData
1109
+ }
1110
+
1111
+ set opacity(opacity) {
1112
+ this._opacity = opacity
1113
+ this._updatePaintAndLayoutStyles()
1114
+ }
1115
+
1116
+ get opacity() {
1117
+ return this._opacity
1118
+ }
1119
+
1120
+ set visible(visible) {
1121
+ this._visible = visible
1122
+ this._updatePaintAndLayoutStyles()
1123
+ }
1124
+
1125
+ get visible() {
1126
+ return this._visible
1127
+ }
1128
+
1129
+ /**
1130
+ * @description: 更新样式
1131
+ * @return {*}
1132
+ */
1133
+ _updatePaintAndLayoutStyles() {
1134
+ const sourceMetaDatas = Object.values(this._sourceMetaDatas)
1135
+ for (let i = 0; i &lt; sourceMetaDatas.length; i++) {
1136
+ const sourceMetaData = sourceMetaDatas[i]
1137
+ sourceMetaData.setStyleLayerDirty(true)
1138
+ }
1139
+ this._refreshSourceAndLayers()
1140
+ }
1141
+ }
1142
+
1143
+ export default MapboxglGraphicsLayer
1144
+ </code></pre>
1145
+ </article>
1146
+ </section>
1147
+
1148
+
1149
+
1150
+
1151
+ </div>
1152
+
1153
+ <footer class="footer">
1154
+ <div class="content has-text-centered">
1155
+ <p>文档生成<a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.11</a></p>
1156
+ <p class="sidebar-created-by">
1157
+ <a href="http://www.smaryun.com" target="_blank">司马云</a> <span>© 2023 云生态圈</span>
1158
+ <a href="http://192.168.82.89:8086/#/index" target="_blank">MapGIS Client for JavaScript</a>
1159
+ </p>
1160
+ </div>
1161
+ </footer>
1162
+
1163
+ </div>
1164
+ <div id="side-nav" class="side-nav">
1165
+ <div style="margin-bottom: 10px;">
1166
+ <img style="vertical-align: middle;margin-right: 10px;width: 30px;" src="./styles/anchor.png"/><a href="#page-title">构造函数</a>
1167
+ </div>
1168
+ <div style="margin-bottom: 10px;">
1169
+ <img style="vertical-align: middle;margin-right: 10px;width: 30px;" src="./styles/anchor.png"/><a href="#member">成员变量</a>
1170
+ </div>
1171
+ <div style="margin-bottom: 10px;">
1172
+ <img style="vertical-align: middle;margin-right: 10px;width: 30px;" src="./styles/anchor.png"/><a href="#function">方法</a>
1173
+ </div>
1174
+ <div>
1175
+ <img style="vertical-align: middle;margin-right: 10px;width: 30px;" src="./styles/anchor.png"/><a href="#event">事件</a>
1176
+ </div>
1177
+ </div>
1178
+ </div>
1179
+ <script src="scripts/linenumber.js"> </script>
1180
+
1181
+ <script src="scripts/search.js"> </script>
1182
+
1183
+ </body>
1184
+ </html>