Comments (7)
@ismailsunni Your sandboxes are private, so I cannot view them. Anyway, I think this issue is the same as #15680. If so, it is fixed already in ol@dev
.
from openlayers.
I managed to access the v9.0.0 sandbox. It is not the same issue as #15680. You should use getRenderPixel
as in https://openlayers.org/en/latest/examples/layer-swipe.html to calculate your pixel positions instead of assuming the orientation of the canvas.
from openlayers.
hi @ahocevar thanks for the reply.
I have tried with ol@dev
, but it still has similar issue (although different in term of how it move). I have the sandbox for ol@dev
here.
I also have fixed the links to the sandboxes in my issue above so you can access it (there was a typo in the URL).
Some gif for illustration:
OL v9.0.0 (normal):
OL v9.1.1-dev.1715581613988 (bug):
from openlayers.
hi @mike-000
thanks, your hint seems promising. I will try tomorrow.
But, it seems there is some changes in 9.1.0 that create the regresion. Because previously I don't need to do anything more to make it work.
from openlayers.
it seems there is some changes in 9.1.0
Yes, the vector layer now shares a canvas with the tile layer, which rotates as the view rotates.
Even before that change your example could have worked without a vector layer, you could have applied the postrender processing directly to the tile layer using getRenderPixel
to calculate the pixel positions.
from openlayers.
@ismailsunni Here is the postrender code that will work with any layer in any version:
layer.on('postrender', function (event) {
const context = event.context;
const size = map.getSize();
const [width, height] = size;
const [minx, miny] = size.map((n) => n * 0.25);
const [maxx, maxy] = size.map((n) => n * 0.75);
context.save();
context.beginPath();
// Outside polygon, must be clockwise
context.moveTo(...getRenderPixel(event, [0, 0]));
context.lineTo(...getRenderPixel(event, [width, 0]));
context.lineTo(...getRenderPixel(event, [width, height]));
context.lineTo(...getRenderPixel(event, [0, height]));
// Inner polygon, must be counter-clockwise
context.moveTo(...getRenderPixel(event, [minx, miny]));
context.lineTo(...getRenderPixel(event, [minx, maxy]));
context.lineTo(...getRenderPixel(event, [maxx, maxy]));
context.lineTo(...getRenderPixel(event, [maxx, miny]));
context.closePath();
context.fillStyle = 'rgba(0, 5, 25, 0.75)';
context.fill();
context.restore();
});
See it live: https://codesandbox.io/p/sandbox/print-rectangle-ol-9-1-1-dev-forked-fm5vph
@mike-000's advice to always use getRenderPixel()
when drawing to a canvas in a postrender event is correct.
Your code worked by chance in v9.0.0, because it played well with internal implementation details by that time. This isn't a regression or a bug in OpenLayers, but apologies for the internal change that broke your code.
from openlayers.
Thanks @ahocevar and @mike-000
using getRenderPixel works!
Best regards.
from openlayers.
Related Issues (20)
- Polygon area calculation is inaccurate with large coordinate values
- Can't run/compile angular/typescript application with OL > 9.0.0 HOT 7
- Google source not allowing to pass `apiOptions` in order to opt-in for new styles
- ol.VERSION not available in umd pkg
- when dragging map, it stuck HOT 4
- Color based on Feature in WebGLPoints Layer style expression not working HOT 3
- Previously working WebGLPointsLayer styles crash in 9.2.3 HOT 4
- Style expression updates HOT 1
- Nonexistent Road is being displayed on the map with an inappropriate title HOT 3
- WebGLPointsLayer styles crash in 9.2.4 related to 'icon-scale'
- Draw lines rendered with WebGL中使用stroke-pattern-offset属性
- After interpolate is set to true, there are still curved teeth when loading cogtif HOT 1
- Bug HOT 1
- Stroke and Fill style does not declutter when used with Circle style. HOT 7
- COG Data Problem on High Resolution HOT 1
- @mike-000 你好 我按照上述方法 添加了个 额外的 baiduG 的坐标系,并且在初始化 view的时候 使用的是BD09G, 现在遇到一个问题 我们在缩放或者移动地图的时候 会出现 空白区域,且我看了network下瓦片请求没有出现404或者异常的情况。但当我们将view下使用的坐标系改成 BD09 则不会有此问题 。我观察了 BD09与BD09G的差异 就在与 global 配置。 请问出现这种情况 有合适的解决方案嘛 ?
- SourceInfo parameters are applied to converted image (not source) when using `convertToRGB` in `GeoTIFF`
- the overlay dom z-index can not be bigger than a common dom outside openlayer HOT 1
- Feature collection disordered after having drawn a specifing number of features or vertices HOT 3
- VectorImage type declaration errors HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openlayers.