(layerInfo, features, iconSizeExpression, iconRotateExpression, addToMap = true, filter)
| 1550 | } |
| 1551 | |
| 1552 | async _createGraphicLayer(layerInfo, features, iconSizeExpression, iconRotateExpression, addToMap = true, filter) { |
| 1553 | return new Promise((resolve) => { |
| 1554 | const { layerID, minzoom, maxzoom, style } = layerInfo; |
| 1555 | |
| 1556 | const source = { |
| 1557 | type: 'geojson', |
| 1558 | data: { |
| 1559 | type: 'FeatureCollection', |
| 1560 | features: features |
| 1561 | } |
| 1562 | }; |
| 1563 | if (!this.map.getSource(layerID)) { |
| 1564 | this.map.addSource(layerID, source); |
| 1565 | } else { |
| 1566 | this.map.getSource(layerID).setData(source.data); |
| 1567 | } |
| 1568 | const iconID = `imageIcon-${layerID}`; |
| 1569 | if (style.type === 'IMAGE_POINT') { |
| 1570 | const imageInfo = style.imageInfo; |
| 1571 | this.map.loadImage(imageInfo.url, (error, image) => { |
| 1572 | if (error) { |
| 1573 | console.error(error); |
| 1574 | return; |
| 1575 | } |
| 1576 | const iconSize = Number.parseFloat((style.radius / image.width).toFixed(2)) * 2; |
| 1577 | !this.map.hasImage(iconID) && this.map.addImage(iconID, image); |
| 1578 | const layerOptions = { |
| 1579 | id: layerID, |
| 1580 | type: 'symbol', |
| 1581 | source: layerID, |
| 1582 | layout: { |
| 1583 | 'icon-image': iconID, |
| 1584 | 'icon-anchor': 'bottom-right', |
| 1585 | 'icon-size': iconSizeExpression || iconSize, |
| 1586 | 'icon-allow-overlap': true, |
| 1587 | visibility: layerInfo.visible, |
| 1588 | 'icon-offset': [style.offsetX * image.width || 0, style.offsetY * image.height || 0], |
| 1589 | 'icon-rotate': iconRotateExpression || ((layerInfo.style.rotation || 0) * 180) / Math.PI |
| 1590 | }, |
| 1591 | minzoom: minzoom || 0, |
| 1592 | maxzoom: maxzoom || this.map.getMaxZoom() + 1 |
| 1593 | }; |
| 1594 | if (filter) { |
| 1595 | layerOptions.filter = filter; |
| 1596 | } |
| 1597 | this._addLayer(layerOptions); |
| 1598 | if (addToMap) { |
| 1599 | this._addLayerSucceeded({ layerInfo, features }); |
| 1600 | } |
| 1601 | resolve(); |
| 1602 | }); |
| 1603 | } else if (style.type === 'SVG_POINT') { |
| 1604 | const svgUrl = style.url; |
| 1605 | if (!this._svgDiv) { |
| 1606 | this._svgDiv = document.createElement('div'); |
| 1607 | document.body.appendChild(this._svgDiv); |
| 1608 | } |
| 1609 | this.getCanvasFromSVG(svgUrl, this._svgDiv, (canvas) => { |
no test coverage detected