更新时间:2023-02-26 20:30:17
Following @Mike's suggestions and the continuation of this problem, the problem can be solved using a function like displayed bellow, which apply the desired pattern to a VectorLayer
.
stylePatternSimplePoly(pattern:string, vectorLayer) {
let ctx = document.createElement('canvas').getContext('2d');
let vectorImage = new Image();
vectorImage.onload = () => {
console.log("Function triggered!");
let createdPattern = ctx.createPattern(vectorImage, 'repeat');
vectorLayer.setStyle(
new Style({
fill: new Fill({
color: createdPattern
})
})
);
};
vectorImage.src = 'assets/images/patterns/' + pattern;
}