(layerInfo, features, textSizeExpresion, textRotateExpresion, addToMap = true, filter)
| 1489 | } |
| 1490 | |
| 1491 | _createSymbolLayer(layerInfo, features, textSizeExpresion, textRotateExpresion, addToMap = true, filter) { |
| 1492 | // 用来请求symbol_point字体文件 |
| 1493 | const target = document.getElementById(`${this.target}`); |
| 1494 | target.classList.add('supermapol-icons-map'); |
| 1495 | const { layerID, minzoom, maxzoom, style } = layerInfo; |
| 1496 | const unicode = style.unicode; |
| 1497 | const text = String.fromCharCode(parseInt(unicode.replace(/^&#x/, ''), 16)); |
| 1498 | const textSize = |
| 1499 | textSizeExpresion || |
| 1500 | (Array.isArray(style.fontSize) ? style.fontSize : (style.fontSize && parseFloat(style.fontSize)) || 12); |
| 1501 | const rotate = Array.isArray(style.rotation) ? style.rotation : ((style.rotation || 0) * 180) / Math.PI; |
| 1502 | if (!this.map.getSource(layerID)) { |
| 1503 | this.map.addSource(layerID, { |
| 1504 | type: 'geojson', |
| 1505 | data: { |
| 1506 | type: 'FeatureCollection', |
| 1507 | features: [] |
| 1508 | } |
| 1509 | }); |
| 1510 | } |
| 1511 | const layerOptions = { |
| 1512 | id: layerID, |
| 1513 | type: 'symbol', |
| 1514 | source: layerID, |
| 1515 | paint: { |
| 1516 | 'text-color': Array.isArray(style.fillColor) |
| 1517 | ? style.fillColor |
| 1518 | : ColorsPickerUtil.getColorWithOpacity(style.fillColor, style.fillOpacity), |
| 1519 | // 'text-opacity': style.fillOpacity === 0 ? 0.1 : style.fillOpacity, |
| 1520 | 'text-halo-color': Array.isArray(style.strokeColor) |
| 1521 | ? style.strokeColor |
| 1522 | : ColorsPickerUtil.getColorWithOpacity(style.strokeColor || 'rgba(0,0,0,0)', style.strokeOpacity), |
| 1523 | 'text-halo-width': style.strokeWidth || 0 |
| 1524 | }, |
| 1525 | layout: { |
| 1526 | 'text-field': text, |
| 1527 | 'text-size': textSize, |
| 1528 | 'text-font': ['supermapol-icons'], |
| 1529 | 'text-rotate': textRotateExpresion || rotate || 0, |
| 1530 | 'text-offset': Array.isArray(style.offsetX) |
| 1531 | ? style.offsetX |
| 1532 | : [style.offsetX / 2 || 0, style.offsetY / 2 || 0], |
| 1533 | 'text-allow-overlap': true, |
| 1534 | visibility: layerInfo.visible |
| 1535 | }, |
| 1536 | minzoom: minzoom || 0, |
| 1537 | maxzoom: maxzoom || this.map.getMaxZoom() + 1 |
| 1538 | }; |
| 1539 | if (filter) { |
| 1540 | layerOptions.filter = filter; |
| 1541 | } |
| 1542 | this._addLayer(layerOptions); |
| 1543 | this.map.getSource(layerID).setData({ |
| 1544 | type: 'FeatureCollection', |
| 1545 | features: features |
| 1546 | }); |
| 1547 | if (addToMap) { |
| 1548 | this._addLayerSucceeded({ layerInfo, features }); |
no test coverage detected