I'm using latest OL 4 version. I have several features on the map (one company -> one feature). Each company has a category and each category has one color.
Style of feature
var style = new ol.style.Style({
image: new ol.style.RegularShape({
fill: new ol.style.Fill({color: color}),
stroke: new ol.style.Stroke({ color: 'black', width: 2 }),
points: 4,
radius: 10,
angle: Math.PI / 4
})
});
Color is a simple string like: "green" or "blue". This is working fine.
But there are companies with more than one category (max 2). My idea was to use a canvas pattern:
var canvas = document.createElement('canvas');
canvas.width = 10;
canvas.height = 10;
var context = canvas.getContext('2d');
context.fillStyle = "black";
context.fillRect(0, 0, 5, 5);
context.fillStyle= "white";
context.fillRect(5,0,5,5);
color = context.createPattern(canvas, "no-repeat");
And then use this color for the style of the feature:
var style = new ol.style.Style({
fill: new ol.style.Fill({colorlike: color})
});
this didn't work so I tried to use it with image fill:
var style = new ol.style.Style({
image: new ol.style.RegularShape({
fill: new ol.style.Fill({colorlike: color})
})
});
This didn't work either. color and colorlike won't work
How do I use a canvas pattern for a OL feature. I just want a rectangle with a different color each half. But I can't get it by the OL api or the examples, because they all use style on layer or image style, but not the exact way I need it...
Any ideas?
thanks in advance