在 Skalár Wag 的帮助下,我用 3 个矩形制作了六边形,放置了边框半径并将图像放在顶部。所有内容都包含在“fa-container-surface”中,仅通过六角形管理一次事件点击。
下面是我使用的代码:
<!-- Hexa Tile Surface -->
<fa-container-surface fa-click="onClickHexagonTile(hexagon.idx)">
<!-- Hexagon Background -->
<fa-modifier fa-opacity="hexagon.opacity">
<fa-container-surface>
<fa-modifier ng-repeat="rect in rects"
fa-origin="[0.5, 0.5]"
fa-size="[csts.hexagonTileWidth, 50]"
fa-rotate-z="rect.rotateZ">
<fa-surface fa-background-color="hexagon.color"
class="hexagon-tile-rect"/>
</fa-modifier>
</fa-container-surface>
</fa-modifier>
<!-- Image -->
<fa-modifier fa-translate="[-30, -30, 0]"
fa-size="[60, 40]">
<fa-image-surface fa-image-url="{{hexagon.img}}"
fa-size="[60, 40]"
class="hexagon-tile-img"/>
</fa-modifier>
<!-- Text -->
<fa-modifier fa-translate="[-30, 10, 0]"
fa-size="[60, 20]">
<fa-surface class="hexagon-tile-text">
{{hexagon.text}}
</fa-surface>
</fa-modifier>
</fa-container-surface>
在我的控制器中:
///////////////////////////////
// Define constants
$scope.csts = {
hexagonTileHeight: 75,
hexagonTileWidth: 80,
hexagonTileMargin: 5,
};
///////////////////////////////
// Define Hexagonal definition
// Math.PI / 3 = 60°
$scope.rects = [
{idx: 0, rotateZ: 0},
{idx: 1, rotateZ: Math.PI / 3},
{idx: 2, rotateZ: -Math.PI / 3}
];
///////////////////////////////
// Define hexagonal list
$scope.hexagonList = [
{idx: 0, column: 0, line: 0, color: "#43D0FA", opacity: 1, img: './img/1.png', text:'1'},
{idx: 1, column: 1, line: 0, color: "#14AF59", opacity: 1, img: './img/2.png', text:'2'},
{idx: 2, column: 0, line: 1, color: "#E1553E", opacity: 1, img: './img/3.png', text:'3'}
];
///////////////////////////////
// Hexagon tile events
$scope.onClickHexagonTile = function($hexagonTileIdx) {
console.log('Click on hexagon tile : ' + $hexagonTileIdx);
};