@antv/l7-layers 2.10.2 → 2.10.3

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 (128) hide show
  1. package/es/Geometry/index.js +8 -8
  2. package/es/Geometry/models/billboard.js +9 -9
  3. package/es/Geometry/models/plane.js +10 -10
  4. package/es/Geometry/models/sprite.js +10 -10
  5. package/es/canvas/index.js +8 -8
  6. package/es/canvas/models/canvas.js +9 -9
  7. package/es/citybuliding/building.js +8 -8
  8. package/es/citybuliding/models/build.js +7 -7
  9. package/es/core/BaseLayer.js +37 -46
  10. package/es/core/BaseModel.js +8 -8
  11. package/es/core/LayerPickService.js +4 -4
  12. package/es/core/shape/Path.js +1 -1
  13. package/es/core/shape/extrude.js +1 -1
  14. package/es/core/triangulation.js +2 -2
  15. package/es/earth/index.js +8 -8
  16. package/es/earth/models/atmosphere.js +6 -6
  17. package/es/earth/models/base.js +8 -8
  18. package/es/earth/models/bloomsphere.js +6 -6
  19. package/es/earth/utils.js +1 -1
  20. package/es/heatmap/index.js +8 -8
  21. package/es/heatmap/models/grid.js +6 -6
  22. package/es/heatmap/models/grid3d.js +6 -6
  23. package/es/heatmap/models/heatmap.js +8 -8
  24. package/es/heatmap/models/hexagon.js +6 -6
  25. package/es/image/index.js +8 -8
  26. package/es/image/models/dataImage.js +6 -6
  27. package/es/image/models/image.js +6 -6
  28. package/es/image/models/tileDataImage.js +6 -6
  29. package/es/line/index.js +9 -9
  30. package/es/line/models/arc.js +8 -8
  31. package/es/line/models/arc_3d.js +8 -8
  32. package/es/line/models/earthArc_3d.js +8 -8
  33. package/es/line/models/great_circle.js +8 -8
  34. package/es/line/models/half.js +6 -6
  35. package/es/line/models/line.js +8 -8
  36. package/es/line/models/linearline.js +8 -8
  37. package/es/line/models/simpleLine.js +6 -6
  38. package/es/line/models/simpleTileLine.js +6 -6
  39. package/es/line/models/tile.js +6 -6
  40. package/es/line/models/wall.js +8 -8
  41. package/es/mask/index.js +8 -8
  42. package/es/mask/models/fill.js +6 -6
  43. package/es/plugins/DataMappingPlugin.d.ts +0 -2
  44. package/es/plugins/DataMappingPlugin.js +24 -97
  45. package/es/plugins/DataSourcePlugin.js +27 -19
  46. package/es/plugins/FeatureScalePlugin.d.ts +0 -1
  47. package/es/plugins/FeatureScalePlugin.js +7 -23
  48. package/es/plugins/LayerAnimateStylePlugin.js +3 -3
  49. package/es/plugins/LayerModelPlugin.js +4 -7
  50. package/es/plugins/LayerStylePlugin.js +2 -2
  51. package/es/plugins/LightingPlugin.js +4 -4
  52. package/es/plugins/MultiPassRendererPlugin.js +2 -2
  53. package/es/plugins/PixelPickingPlugin.js +2 -2
  54. package/es/plugins/RegisterStyleAttributePlugin.js +2 -2
  55. package/es/plugins/ShaderUniformPlugin.js +6 -6
  56. package/es/plugins/UpdateModelPlugin.js +5 -2
  57. package/es/plugins/UpdateStyleAttributePlugin.js +3 -7
  58. package/es/point/index.js +8 -8
  59. package/es/point/models/earthExtrude.js +8 -8
  60. package/es/point/models/earthFill.js +8 -8
  61. package/es/point/models/extrude.js +8 -8
  62. package/es/point/models/fill.js +9 -9
  63. package/es/point/models/fillmage.js +9 -9
  64. package/es/point/models/image.js +8 -8
  65. package/es/point/models/normal.js +7 -7
  66. package/es/point/models/radar.js +9 -9
  67. package/es/point/models/simplePoint.js +7 -7
  68. package/es/point/models/text.js +45 -29
  69. package/es/point/models/tile.js +6 -6
  70. package/es/point/models/tileText.js +9 -9
  71. package/es/point/shape/extrude.js +1 -1
  72. package/es/polygon/index.js +8 -8
  73. package/es/polygon/models/extrude.js +7 -7
  74. package/es/polygon/models/fill.js +6 -6
  75. package/es/polygon/models/ocean.js +7 -7
  76. package/es/polygon/models/tile.js +6 -6
  77. package/es/polygon/models/water.js +7 -7
  78. package/es/raster/index.js +8 -8
  79. package/es/raster/models/raster.js +6 -6
  80. package/es/raster/models/rasterRgb.js +8 -8
  81. package/es/raster/models/rasterTile.js +6 -6
  82. package/es/raster/raster.js +10 -10
  83. package/es/tile/interaction/getRasterData.js +1 -1
  84. package/es/tile/interaction/utils.js +1 -1
  85. package/es/tile/manager/base.js +5 -5
  86. package/es/tile/service/TileLayerService.js +5 -5
  87. package/es/tile/service/TilePickService.d.ts +3 -3
  88. package/es/tile/service/TilePickService.js +31 -7
  89. package/es/tile/service/TileSourceService.d.ts +7 -0
  90. package/es/tile/service/TileSourceService.js +39 -0
  91. package/es/tile/style/utils.js +1 -1
  92. package/es/tile/tileFactory/DebugTile.js +6 -6
  93. package/es/tile/tileFactory/ImageTile.js +7 -7
  94. package/es/tile/tileFactory/MaskTile.js +8 -8
  95. package/es/tile/tileFactory/RasterRGBTile.js +7 -7
  96. package/es/tile/tileFactory/RasterTile.js +7 -7
  97. package/es/tile/tileFactory/Tile.d.ts +11 -0
  98. package/es/tile/tileFactory/Tile.js +68 -5
  99. package/es/tile/tileFactory/VectorTile.d.ts +1 -1
  100. package/es/tile/tileFactory/VectorTile.js +8 -14
  101. package/es/tile/tileFactory/layers/RasterDataLayer.js +8 -8
  102. package/es/tile/tileFactory/layers/TileDebugLayer.js +8 -8
  103. package/es/tile/tileLayer/BaseLayer.js +4 -4
  104. package/es/utils/blend.js +1 -1
  105. package/es/utils/collision-index.js +4 -4
  106. package/es/utils/extrude_polyline.js +5 -5
  107. package/es/utils/grid-index.js +3 -3
  108. package/es/utils/multiPassRender.js +1 -1
  109. package/es/utils/polylineNormal.js +1 -1
  110. package/es/utils/simpleLine.js +3 -3
  111. package/es/wind/index.js +8 -8
  112. package/es/wind/models/wind.js +11 -8
  113. package/es/wind/models/windRender.js +3 -3
  114. package/lib/core/BaseLayer.js +24 -33
  115. package/lib/plugins/DataMappingPlugin.js +16 -87
  116. package/lib/plugins/DataSourcePlugin.js +24 -16
  117. package/lib/plugins/FeatureScalePlugin.js +2 -18
  118. package/lib/plugins/LayerModelPlugin.js +1 -4
  119. package/lib/plugins/UpdateModelPlugin.js +3 -0
  120. package/lib/plugins/UpdateStyleAttributePlugin.js +1 -5
  121. package/lib/point/models/text.js +36 -20
  122. package/lib/tile/service/TilePickService.js +29 -3
  123. package/lib/tile/service/TileSourceService.js +59 -0
  124. package/lib/tile/tileFactory/MaskTile.js +1 -1
  125. package/lib/tile/tileFactory/Tile.js +64 -0
  126. package/lib/tile/tileFactory/VectorTile.js +1 -7
  127. package/lib/wind/models/wind.js +3 -0
  128. package/package.json +6 -6
@@ -105,13 +105,6 @@ var DataMappingPlugin = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inver
105
105
  }()); // remapping before render
106
106
 
107
107
  layer.hooks.beforeRender.tap('DataMappingPlugin', function () {
108
- var _layer$getLayerConfig = layer.getLayerConfig(),
109
- usage = _layer$getLayerConfig.usage;
110
-
111
- if (usage === 'basemap') {
112
- return;
113
- }
114
-
115
108
  var source = layer.getSource();
116
109
 
117
110
  if (layer.layerModelNeedUpdate || !source || !source.inited) {
@@ -120,7 +113,12 @@ var DataMappingPlugin = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inver
120
113
 
121
114
  var attributes = styleAttributeService.getLayerStyleAttributes() || [];
122
115
  var filter = styleAttributeService.getLayerStyleAttribute('filter');
123
- var dataArray = source.data.dataArray;
116
+ var dataArray = source.data.dataArray; // TODO 数据为空的情况
117
+
118
+ if (Array.isArray(dataArray) && dataArray.length === 0) {
119
+ return;
120
+ }
121
+
124
122
  var attributesToRemapping = attributes.filter(function (attribute) {
125
123
  return attribute.needRemapping;
126
124
  } // 如果filter变化
@@ -144,10 +142,9 @@ var DataMappingPlugin = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inver
144
142
  var _encodeData = _this.mapping(layer, attributesToRemapping, filterData, layer.getEncodedData());
145
143
 
146
144
  layer.setEncodedData(_encodeData);
147
- } // 处理文本更新
145
+ } // 处理文本更新,更新文字形状
146
+ // layer.emit('remapping', null);
148
147
 
149
-
150
- layer.emit('remapping', null);
151
148
  }
152
149
  });
153
150
  }
@@ -238,55 +235,10 @@ var DataMappingPlugin = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inver
238
235
  this.adjustData2SimpleCoordinates(mappedData);
239
236
  return mappedData;
240
237
  }
241
- }, {
242
- key: "mapLayerMapping",
243
- value: function mapLayerMapping(layer, attributes, data, predata) {
244
- var _this4 = this;
245
-
246
- var usedAttributes = attributes.filter(function (attribute) {
247
- return attribute.scale !== undefined;
248
- });
249
- var mappedData = data.map(function (record, i) {
250
- var preRecord = predata ? predata[i] : {};
251
- var encodeRecord = (0, _objectSpread2.default)({
252
- id: record._id,
253
- coordinates: record.coordinates
254
- }, preRecord);
255
- usedAttributes.forEach(function (attribute) {
256
- var _layer$shapeOption;
257
-
258
- if (attribute.name === 'shape' && // @ts-ignore
259
- ((_layer$shapeOption = layer.shapeOption) === null || _layer$shapeOption === void 0 ? void 0 : _layer$shapeOption.field) === 'simple') {
260
- encodeRecord[attribute.name] = 'simple';
261
- attribute.needRemapping = false;
262
- } else {
263
- var values = _this4.applyMapLayerAttributeMapping(attribute, record);
264
-
265
- attribute.needRemapping = false; // @ts-ignore
266
-
267
- encodeRecord[attribute.name] = Array.isArray(values) && values.length === 1 ? values[0] : values; // 增加对 layer/text/iconfont unicode 映射的解析
268
-
269
- if (attribute.name === 'shape') {
270
- encodeRecord.shape = _this4.fontService.getIconFontKey(encodeRecord[attribute.name]);
271
- }
272
- }
273
- });
274
-
275
- if (encodeRecord.size === undefined) {
276
- // in case not set size
277
- encodeRecord.size = 1;
278
- }
279
-
280
- return encodeRecord;
281
- }); // 调整数据兼容 Amap2.0
282
-
283
- this.adjustData2Amap2Coordinates(mappedData, layer);
284
- return mappedData;
285
- }
286
238
  }, {
287
239
  key: "adjustData2Amap2Coordinates",
288
240
  value: function adjustData2Amap2Coordinates(mappedData, layer) {
289
- var _this5 = this;
241
+ var _this4 = this;
290
242
 
291
243
  // 根据地图的类型判断是否需要对点位数据进行处理, 若是高德2.0则需要对坐标进行相对偏移
292
244
  if (mappedData.length > 0 && this.mapService.version === _l7Maps.Version['GAODE2.x']) {
@@ -305,7 +257,7 @@ var DataMappingPlugin = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inver
305
257
  // @ts-ignore
306
258
  // d.coordinates = this.mapService.lngLatToCoord(d.coordinates);
307
259
 
308
- d.coordinates = _this5.mapService.lngLatToCoordByLayer(d.coordinates, layerCenter);
260
+ d.coordinates = _this4.mapService.lngLatToCoordByLayer(d.coordinates, layerCenter);
309
261
  });
310
262
  } else {
311
263
  // 连续的线、面数据
@@ -319,7 +271,7 @@ var DataMappingPlugin = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inver
319
271
  // @ts-ignore
320
272
  // d.coordinates = this.mapService.lngLatToCoords(d.coordinates);
321
273
 
322
- d.coordinates = _this5.mapService.lngLatToCoordsByLayer(d.coordinates, layerCenter);
274
+ d.coordinates = _this4.mapService.lngLatToCoordsByLayer(d.coordinates, layerCenter);
323
275
  });
324
276
  }
325
277
  }
@@ -327,12 +279,12 @@ var DataMappingPlugin = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inver
327
279
  }, {
328
280
  key: "adjustData2SimpleCoordinates",
329
281
  value: function adjustData2SimpleCoordinates(mappedData) {
330
- var _this6 = this;
282
+ var _this5 = this;
331
283
 
332
284
  if (mappedData.length > 0 && this.mapService.version === _l7Maps.Version.SIMPLE) {
333
285
  mappedData.map(function (d) {
334
286
  if (!d.simpleCoordinate) {
335
- d.coordinates = _this6.unProjectCoordinates(d.coordinates);
287
+ d.coordinates = _this5.unProjectCoordinates(d.coordinates);
336
288
  d.simpleCoordinate = true;
337
289
  }
338
290
  });
@@ -341,7 +293,7 @@ var DataMappingPlugin = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inver
341
293
  }, {
342
294
  key: "unProjectCoordinates",
343
295
  value: function unProjectCoordinates(coordinates) {
344
- var _this7 = this;
296
+ var _this6 = this;
345
297
 
346
298
  if (typeof coordinates[0] === 'number') {
347
299
  return this.mapService.simpleMapCoord.unproject(coordinates);
@@ -354,7 +306,7 @@ var DataMappingPlugin = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inver
354
306
  // @ts-ignore
355
307
  var c1 = [];
356
308
  coord.map(function (co) {
357
- c1.push(_this7.mapService.simpleMapCoord.unproject(co));
309
+ c1.push(_this6.mapService.simpleMapCoord.unproject(co));
358
310
  }); // @ts-ignore
359
311
 
360
312
  coords.push(c1);
@@ -366,7 +318,7 @@ var DataMappingPlugin = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inver
366
318
  var _coords = []; // @ts-ignore
367
319
 
368
320
  coordinates.map(function (coord) {
369
- _coords.push(_this7.mapService.simpleMapCoord.unproject(coord));
321
+ _coords.push(_this6.mapService.simpleMapCoord.unproject(coord));
370
322
  }); // @ts-ignore
371
323
 
372
324
  return _coords;
@@ -396,29 +348,6 @@ var DataMappingPlugin = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inver
396
348
  var mappingResult = attribute.mapping ? attribute.mapping(params) : [];
397
349
  return mappingResult; // return attribute.mapping ? attribute.mapping(params) : [];
398
350
  }
399
- }, {
400
- key: "applyMapLayerAttributeMapping",
401
- value: function applyMapLayerAttributeMapping(attribute, record) {
402
- var _attribute$scale3;
403
-
404
- if (!attribute.scale) {
405
- return [];
406
- }
407
-
408
- var scalers = (attribute === null || attribute === void 0 ? void 0 : (_attribute$scale3 = attribute.scale) === null || _attribute$scale3 === void 0 ? void 0 : _attribute$scale3.scalers) || [];
409
- var params = [];
410
- scalers.forEach(function (_ref7) {
411
- var _attribute$scale4;
412
-
413
- var field = _ref7.field;
414
-
415
- if (record.hasOwnProperty(field) || ((_attribute$scale4 = attribute.scale) === null || _attribute$scale4 === void 0 ? void 0 : _attribute$scale4.type) === 'variable') {
416
- params.push(record[field]);
417
- }
418
- });
419
- var mappingResult = attribute.mapping ? attribute.mapping(params) : [];
420
- return mappingResult;
421
- }
422
351
  }, {
423
352
  key: "getArrowPoints",
424
353
  value: function getArrowPoints(p1, p2) {
@@ -45,35 +45,43 @@ var DataSourcePlugin = (_dec = (0, _inversify.injectable)(), _dec(_class = /*#__
45
45
  case 0:
46
46
  source = layer.getSource();
47
47
 
48
- if (source) {
48
+ if (!source) {
49
+ // Tip: 用户没有传入 source 的时候使用图层的默认数据
50
+ _ref2 = layer.sourceOption || layer.defaultSourceConfig, data = _ref2.data, options = _ref2.options;
51
+ source = new _l7Source.default(data, options);
52
+ layer.setSource(source); // await new Promise((resolve) => {
53
+ // source.on('update', (e) => {
54
+ // if (e.type === 'inited') {
55
+ // layer.initSource(source);
56
+ // }
57
+ // resolve(null);
58
+ // });
59
+ // });
60
+ }
61
+
62
+ if (!source.inited) {
49
63
  _context.next = 6;
50
64
  break;
51
65
  }
52
66
 
53
- // Tip: 用户没有传入 source 的时候使用图层的默认数据
54
- _ref2 = layer.sourceOption || layer.defaultSourceConfig, data = _ref2.data, options = _ref2.options;
55
- source = new _l7Source.default(data, options);
56
- _context.next = 6;
67
+ _this.updateClusterData(layer);
68
+
69
+ _context.next = 8;
70
+ break;
71
+
72
+ case 6:
73
+ _context.next = 8;
57
74
  return new Promise(function (resolve) {
58
75
  source.on('update', function (e) {
59
76
  if (e.type === 'inited') {
60
- layer.initSource(source);
77
+ _this.updateClusterData(layer);
61
78
  }
62
79
 
63
80
  resolve(null);
64
81
  });
65
82
  });
66
83
 
67
- case 6:
68
- if (source.inited) {
69
- _this.updateClusterData(layer);
70
- } else {
71
- source.once('update', function () {
72
- _this.updateClusterData(layer);
73
- });
74
- }
75
-
76
- case 7:
84
+ case 8:
77
85
  case "end":
78
86
  return _context.stop();
79
87
  }
@@ -54,19 +54,6 @@ var FeatureScalePlugin = (_dec = (0, _inversify.injectable)(), _dec(_class = /*#
54
54
  }
55
55
 
56
56
  (0, _createClass2.default)(FeatureScalePlugin, [{
57
- key: "getSourceData",
58
- value: function getSourceData(layer, callback) {
59
- var source = layer.getSource();
60
-
61
- if (source.inited) {
62
- callback(source.data);
63
- } else {
64
- source.once('update', function () {
65
- callback(source.data);
66
- });
67
- }
68
- }
69
- }, {
70
57
  key: "apply",
71
58
  value: function apply(layer, _ref) {
72
59
  var _this = this;
@@ -126,7 +113,7 @@ var FeatureScalePlugin = (_dec = (0, _inversify.injectable)(), _dec(_class = /*#
126
113
  break;
127
114
  }
128
115
 
129
- return _context2.abrupt("return");
116
+ return _context2.abrupt("return", true);
130
117
 
131
118
  case 7:
132
119
  _this.caculateScalesForAttributes(attributes || [], dataArray);
@@ -147,10 +134,7 @@ var FeatureScalePlugin = (_dec = (0, _inversify.injectable)(), _dec(_class = /*#
147
134
  };
148
135
  }());
149
136
  layer.hooks.beforeRender.tap('FeatureScalePlugin', function () {
150
- var _layer$getLayerConfig = layer.getLayerConfig(),
151
- usage = _layer$getLayerConfig.usage;
152
-
153
- if (layer.layerModelNeedUpdate || usage === 'basemap') {
137
+ if (layer.layerModelNeedUpdate) {
154
138
  return;
155
139
  }
156
140
 
@@ -79,9 +79,6 @@ _dec = (0, _inversify.injectable)(), _dec(_class = /*#__PURE__*/function () {
79
79
  return layer.buildModels();
80
80
 
81
81
  case 3:
82
- layer.layerModelNeedUpdate = false;
83
-
84
- case 4:
85
82
  case "end":
86
83
  return _context2.stop();
87
84
  }
@@ -145,7 +142,7 @@ _dec = (0, _inversify.injectable)(), _dec(_class = /*#__PURE__*/function () {
145
142
  }
146
143
 
147
144
  layer.tileLayer = new _BaseLayer.default(layer);
148
- return _context4.abrupt("return");
145
+ return _context4.abrupt("return", false);
149
146
 
150
147
  case 5:
151
148
  _context4.next = 7;
@@ -35,6 +35,9 @@ _dec = (0, _inversify.injectable)(), _dec(_class = /*#__PURE__*/function () {
35
35
  layer.layerModel.needUpdate();
36
36
  }
37
37
  });
38
+ layer.hooks.afterRender.tap('UpdateModelPlugin', function () {
39
+ layer.layerModelNeedUpdate = false;
40
+ });
38
41
  }
39
42
  }]);
40
43
  return UpdateModelPlugin;
@@ -38,11 +38,7 @@ _dec = (0, _inversify.injectable)(), _dec(_class = /*#__PURE__*/function () {
38
38
  });
39
39
  });
40
40
  layer.hooks.beforeRender.tap('UpdateStyleAttributePlugin', function () {
41
- var _layer$getLayerConfig = layer.getLayerConfig(),
42
- usage = _layer$getLayerConfig.usage;
43
-
44
- if (layer.layerModelNeedUpdate || layer.tileLayer || usage === 'basemap' // TODO: Chore 不走该流程 应从外部统一控制,而不是打补丁
45
- ) {
41
+ if (layer.layerModelNeedUpdate) {
46
42
  return;
47
43
  }
48
44
 
@@ -112,16 +112,15 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
112
112
  while (1) {
113
113
  switch (_context.prev = _context.next) {
114
114
  case 0:
115
- _this.initGlyph();
115
+ _this.initGlyph(); //
116
116
 
117
- _this.updateTexture();
118
117
 
119
- _this.filterGlyphs();
118
+ _this.updateTexture();
120
119
 
121
- _context.next = 5;
120
+ _context.next = 4;
122
121
  return _this.reBuildModel();
123
122
 
124
- case 5:
123
+ case 4:
125
124
  case "end":
126
125
  return _context.stop();
127
126
  }
@@ -227,7 +226,10 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
227
226
  switch (_context2.prev = _context2.next) {
228
227
  case 0:
229
228
  // 绑定事件
230
- this.bindEvent();
229
+ if (!this.layer.inited) {
230
+ this.bindEvent();
231
+ }
232
+
231
233
  this.extent = this.textExtent();
232
234
  _ref3 = this.layer.getLayerConfig(), _ref3$textAnchor = _ref3.textAnchor, textAnchor = _ref3$textAnchor === void 0 ? 'center' : _ref3$textAnchor, _ref3$textAllowOverla = _ref3.textAllowOverlap, textAllowOverlap = _ref3$textAllowOverla === void 0 ? true : _ref3$textAllowOverla;
233
235
  this.preTextStyle = {
@@ -258,15 +260,23 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
258
260
  key: "buildModels",
259
261
  value: function () {
260
262
  var _buildModels = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
261
- var _ref4, _ref4$mask, mask, _ref4$maskInside, maskInside, model;
263
+ var _ref4, _ref4$mask, mask, _ref4$maskInside, maskInside, _ref4$textAllowOverla, textAllowOverlap, model;
262
264
 
263
265
  return _regenerator.default.wrap(function _callee3$(_context3) {
264
266
  while (1) {
265
267
  switch (_context3.prev = _context3.next) {
266
268
  case 0:
267
- _ref4 = this.layer.getLayerConfig(), _ref4$mask = _ref4.mask, mask = _ref4$mask === void 0 ? false : _ref4$mask, _ref4$maskInside = _ref4.maskInside, maskInside = _ref4$maskInside === void 0 ? true : _ref4$maskInside;
268
- this.mapping();
269
- _context3.next = 4;
269
+ _ref4 = this.layer.getLayerConfig(), _ref4$mask = _ref4.mask, mask = _ref4$mask === void 0 ? false : _ref4$mask, _ref4$maskInside = _ref4.maskInside, maskInside = _ref4$maskInside === void 0 ? true : _ref4$maskInside, _ref4$textAllowOverla = _ref4.textAllowOverlap, textAllowOverlap = _ref4$textAllowOverla === void 0 ? false : _ref4$textAllowOverla; // this.mapping(); 重复调用
270
+
271
+ this.initGlyph(); //
272
+
273
+ this.updateTexture();
274
+
275
+ if (!textAllowOverlap) {
276
+ this.filterGlyphs();
277
+ }
278
+
279
+ _context3.next = 6;
270
280
  return this.layer.buildLayerModel({
271
281
  moduleName: 'pointText',
272
282
  vertexShader: textVert,
@@ -279,11 +289,11 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
279
289
  stencil: (0, _l7Utils.getMask)(mask, maskInside)
280
290
  });
281
291
 
282
- case 4:
292
+ case 6:
283
293
  model = _context3.sent;
284
294
  return _context3.abrupt("return", [model]);
285
295
 
286
- case 6:
296
+ case 8:
287
297
  case "end":
288
298
  return _context3.stop();
289
299
  }
@@ -302,15 +312,22 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
302
312
  value: function needUpdate() {
303
313
  var _ref5 = this.layer.getLayerConfig(),
304
314
  _ref5$textAllowOverla = _ref5.textAllowOverlap,
305
- textAllowOverlap = _ref5$textAllowOverla === void 0 ? false : _ref5$textAllowOverla; // textAllowOverlap 发生改变
315
+ textAllowOverlap = _ref5$textAllowOverla === void 0 ? false : _ref5$textAllowOverla;
316
+
317
+ var data = this.layer.getEncodedData();
318
+
319
+ if (data.length < 5 || textAllowOverlap) {
320
+ // 小于不做避让
321
+ return false;
322
+ } // textAllowOverlap 发生改变
306
323
 
307
324
 
308
325
  var zoom = this.mapService.getZoom();
309
326
  var extent = this.mapService.getBounds();
310
327
  var flag = (0, _l7Utils.boundsContains)(this.extent, extent); // 文本不能压盖则进行过滤
311
328
 
312
- if (!textAllowOverlap && (Math.abs(this.currentZoom - zoom) > 1 || !flag) || textAllowOverlap !== this.preTextStyle.textAllowOverlap) {
313
- // TODO this.mapping
329
+ if (Math.abs(this.currentZoom - zoom) > 1 || !flag || textAllowOverlap !== this.preTextStyle.textAllowOverlap) {
330
+ // TODO this.mapping 数据未变化,避让
314
331
  this.reBuildModel();
315
332
  return true;
316
333
  }
@@ -406,7 +423,7 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
406
423
  key: "bindEvent",
407
424
  value: function bindEvent() {
408
425
  if (!this.layer.isTileLayer) {
409
- // console.log('mapping')
426
+ // 重新绑定
410
427
  this.layer.on('remapping', this.mapping);
411
428
  }
412
429
  }
@@ -574,7 +591,7 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
574
591
 
575
592
  var centroid = feature.version === 'GAODE2.x' ? feature.originCentroid : feature.centroid;
576
593
  var size = feature.size;
577
- var fontScale = size / 24;
594
+ var fontScale = size / 16;
578
595
 
579
596
  var pixels = _this3.mapService.lngLatToContainer(centroid);
580
597
 
@@ -668,10 +685,9 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
668
685
  case 4:
669
686
  model = _context4.sent;
670
687
  // TODO 渲染流程待修改
671
- this.layer.models = [model];
672
- this.layerService.throttleRenderLayers();
688
+ this.layer.models = [model]; // this.layerService.throttleRenderLayers();
673
689
 
674
- case 7:
690
+ case 6:
675
691
  case "end":
676
692
  return _context4.stop();
677
693
  }
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.TilePickService = void 0;
9
9
 
10
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
+
10
12
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
13
 
12
14
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
@@ -15,6 +17,8 @@ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/creat
15
17
 
16
18
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
19
 
20
+ var _TileSourceService = require("./TileSourceService");
21
+
18
22
  var SELECT = 'select';
19
23
  var ACTIVE = 'active';
20
24
 
@@ -26,6 +30,7 @@ var TilePickService = /*#__PURE__*/function () {
26
30
  (0, _defineProperty2.default)(this, "tilePickID", new Map());
27
31
  this.layerService = layerService;
28
32
  this.tileLayerService = tileLayerService;
33
+ this.tileSourceService = new _TileSourceService.TileSourceService();
29
34
  }
30
35
 
31
36
  (0, _createClass2.default)(TilePickService, [{
@@ -36,8 +41,11 @@ var TilePickService = /*#__PURE__*/function () {
36
41
 
37
42
  if (tile) {
38
43
  // TODO 多图层拾取
39
- var pickLayer = tile.getLayers()[0];
40
- pickLayer.layerPickService.pickRender(target);
44
+ var pickLayer = tile.getMainLayer();
45
+
46
+ if (pickLayer) {
47
+ pickLayer.layerPickService.pickRender(target);
48
+ }
41
49
  }
42
50
  }
43
51
  }, {
@@ -128,7 +136,25 @@ var TilePickService = /*#__PURE__*/function () {
128
136
 
129
137
  }, {
130
138
  key: "getFeatureById",
131
- value: function getFeatureById() {}
139
+ value: function getFeatureById(pickedFeatureIdx) {
140
+ // 提取当前可见瓦片
141
+ var tiles = this.tileLayerService.getTiles().filter(function (tile) {
142
+ return tile.visible;
143
+ }); // 提取当前可见瓦片中匹配 ID 的 feature 列表
144
+
145
+ var features = [];
146
+ tiles.map(function (tile) {
147
+ features.push.apply(features, (0, _toConsumableArray2.default)(tile.getFeatureById(pickedFeatureIdx)));
148
+ });
149
+
150
+ if (features.length <= 0) {
151
+ return null;
152
+ } // 将 feature 列表合并后返回
153
+ // 统一返回成 polygon 的格式 点、线、面可以通用
154
+
155
+
156
+ return this.tileSourceService.getCombineFeature(features);
157
+ }
132
158
  }]);
133
159
  return TilePickService;
134
160
  }();
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports.TileSourceService = void 0;
11
+
12
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
13
+
14
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
15
+
16
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
17
+
18
+ var turf = _interopRequireWildcard(require("@turf/helpers"));
19
+
20
+ var _union = _interopRequireDefault(require("@turf/union"));
21
+
22
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
23
+
24
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
25
+
26
+ /**
27
+ * 专门处理 Tile 数据相关
28
+ */
29
+ var TileSourceService = /*#__PURE__*/function () {
30
+ function TileSourceService() {
31
+ (0, _classCallCheck2.default)(this, TileSourceService);
32
+ }
33
+
34
+ (0, _createClass2.default)(TileSourceService, [{
35
+ key: "getCombineFeature",
36
+ value: function getCombineFeature(features) {
37
+ var p = null;
38
+ var properties = features[0];
39
+ features.map(function (feature) {
40
+ var polygon = turf.polygon(feature.coordinates);
41
+
42
+ if (p === null) {
43
+ p = polygon;
44
+ } else {
45
+ p = (0, _union.default)(p, polygon);
46
+ }
47
+ });
48
+
49
+ if (properties) {
50
+ p.properties = (0, _objectSpread2.default)({}, properties);
51
+ }
52
+
53
+ return p;
54
+ }
55
+ }]);
56
+ return TileSourceService;
57
+ }();
58
+
59
+ exports.TileSourceService = TileSourceService;
@@ -91,7 +91,7 @@ var MaskTile = /*#__PURE__*/function (_Tile) {
91
91
  sourceLayer = _this$parent$getLayer.sourceLayer,
92
92
  featureId = _this$parent$getLayer.featureId;
93
93
 
94
- var features = this.sourceTile.data.layers[sourceLayer].features;
94
+ var features = this.getFeatures(sourceLayer);
95
95
  return {
96
96
  data: {
97
97
  type: 'FeatureCollection',
@@ -9,6 +9,8 @@ exports.default = void 0;
9
9
 
10
10
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
11
 
12
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
13
+
12
14
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
15
 
14
16
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
@@ -132,6 +134,68 @@ var Tile = /*#__PURE__*/function () {
132
134
  l.updateLayerConfig((0, _defineProperty2.default)({}, key, value));
133
135
  });
134
136
  }
137
+ /**
138
+ * 一个 Tile 可能有多个 layer,但是在发生拾取、点击事件的时候只有一个生效
139
+ */
140
+
141
+ }, {
142
+ key: "getMainLayer",
143
+ value: function getMainLayer() {
144
+ return this.layers[0];
145
+ }
146
+ }, {
147
+ key: "getFeatures",
148
+ value: function getFeatures(sourceLayer) {
149
+ var _this$sourceTile$data, _this$sourceTile$data2;
150
+
151
+ if (!sourceLayer || !((_this$sourceTile$data = this.sourceTile.data) !== null && _this$sourceTile$data !== void 0 && _this$sourceTile$data.layers[sourceLayer])) {
152
+ return [];
153
+ }
154
+
155
+ var vectorTile = (_this$sourceTile$data2 = this.sourceTile.data) === null || _this$sourceTile$data2 === void 0 ? void 0 : _this$sourceTile$data2.layers[sourceLayer];
156
+
157
+ if (Array.isArray(vectorTile.features)) {
158
+ // 数据不需要被解析 geojson-vt 类型
159
+ return vectorTile.features;
160
+ }
161
+
162
+ var _this$sourceTile = this.sourceTile,
163
+ x = _this$sourceTile.x,
164
+ y = _this$sourceTile.y,
165
+ z = _this$sourceTile.z;
166
+ var features = [];
167
+
168
+ for (var i = 0; i < vectorTile.length; i++) {
169
+ var vectorTileFeature = vectorTile.feature(i);
170
+ var feature = vectorTileFeature.toGeoJSON(x, y, z);
171
+ features.push((0, _objectSpread2.default)((0, _objectSpread2.default)({}, feature), {}, {
172
+ properties: (0, _objectSpread2.default)({
173
+ id: feature.id
174
+ }, feature.properties)
175
+ }));
176
+ }
177
+
178
+ return features;
179
+ }
180
+ /**
181
+ * 在一个 Tile 中可能存在一个相同 ID 的 feature
182
+ * @param id
183
+ * @returns
184
+ */
185
+
186
+ }, {
187
+ key: "getFeatureById",
188
+ value: function getFeatureById(id) {
189
+ var layer = this.getMainLayer();
190
+
191
+ if (!layer) {
192
+ return [];
193
+ }
194
+
195
+ return layer.getSource().data.dataArray.filter(function (d) {
196
+ return d._id === id;
197
+ });
198
+ }
135
199
  }, {
136
200
  key: "destroy",
137
201
  value: function destroy() {