Fix sprite offset for pixel ratio !== 1

This commit is contained in:
Andreas Hocevar
2021-08-30 21:53:46 +02:00
parent 706955dfd9
commit df493725c6
5 changed files with 44 additions and 2 deletions

View File

@@ -249,8 +249,8 @@ class CanvasImageBuilder extends CanvasBuilder {
this.image_ = image;
this.height_ = size[1];
this.opacity_ = imageStyle.getOpacity();
this.originX_ = origin[0];
this.originY_ = origin[1];
this.originX_ = origin[0] * this.imagePixelRatio_;
this.originY_ = origin[1] * this.imagePixelRatio_;
this.rotateWithView_ = imageStyle.getRotateWithView();
this.rotation_ = imageStyle.getRotation();
this.scale_ = imageStyle.getScaleArray();

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@@ -0,0 +1,37 @@
import Feature from '../../../../src/ol/Feature.js';
import Map from '../../../../src/ol/Map.js';
import Point from '../../../../src/ol/geom/Point.js';
import View from '../../../../src/ol/View.js';
import {Icon, Style} from '../../../../src/ol/style.js';
import {Vector as VectorLayer} from '../../../../src/ol/layer.js';
import {Vector as VectorSource} from '../../../../src/ol/source.js';
const center = [0, 0];
new Map({
pixelRatio: 2,
layers: [
new VectorLayer({
style: function () {
return new Style({
image: new Icon({
src: '/data/sprites/gis_symbols.png',
color: [255, 0, 0, 1],
offset: [32, 0],
size: [32, 32],
}),
});
},
source: new VectorSource({
features: [new Feature(new Point(center))],
}),
}),
],
target: 'map',
view: new View({
center: center,
zoom: 2,
}),
});
render();

Binary file not shown.

After

Width:  |  Height:  |  Size: 904 B

View File

@@ -42,6 +42,11 @@ export default {
],
},
resolve: {
fallback: {
fs: false,
http: false,
https: false,
},
alias: {
// ol-mapbox-style imports ol/style/Style etc
ol: path.join(baseDir, '..', '..', 'src', 'ol'),