Fix icon displacement

This commit is contained in:
Andreas Hocevar
2021-04-01 12:08:32 +02:00
parent 1cb89ab991
commit 4a6db3d2f8
5 changed files with 53 additions and 18 deletions

View File

@@ -8,6 +8,7 @@ import Style from '../../../src/ol/style/Style.js';
import VectorLayer from '../../../src/ol/layer/Vector.js';
import VectorSource from '../../../src/ol/source/Vector.js';
import View from '../../../src/ol/View.js';
import {Icon} from '../../../src/ol/style.js';
const vectorSource = new VectorSource();
function createFeatures(stroke, fill, offSet = [0, 0]) {
@@ -16,7 +17,7 @@ function createFeatures(stroke, fill, offSet = [0, 0]) {
geometry: new Point([offSet[0], offSet[1]]),
});
// square with offset
feature.setStyle(
feature.setStyle([
new Style({
image: new RegularShape({
fill: fill,
@@ -26,8 +27,18 @@ function createFeatures(stroke, fill, offSet = [0, 0]) {
angle: Math.PI / 4,
displacement: [-15, 15],
}),
})
);
}),
new Style({
image: new Icon({
src: '/data/cross.svg',
size: [20, 20],
anchor: [0.5, 0.5],
anchorXUnits: 'fraction',
anchorYUnits: 'fraction',
displacement: [-15, 15],
}),
}),
]);
vectorSource.addFeature(feature);
feature = new Feature({