Openlayers 删除重新投影静态图像层的画布平滑
需要重投影的静态图像层不允许禁用图像平滑 下面是我正在使用的图层:Openlayers 删除重新投影静态图像层的画布平滑,openlayers,Openlayers,需要重投影的静态图像层不允许禁用图像平滑 下面是我正在使用的图层: var layer = new ol.layer.Image({ source: new ol.source.ImageStatic({ url: "grid.png", imageExtent: [-130, 20, -55, 50], projection: 'EPSG:4326' }) }); 放大时,像素边缘模糊(锯齿),需要清晰 以下是无效的,因为预渲染
var layer = new ol.layer.Image({
source: new ol.source.ImageStatic({
url: "grid.png",
imageExtent: [-130, 20, -55, 50],
projection: 'EPSG:4326'
})
});
放大时,像素边缘模糊(锯齿),需要清晰
以下是无效的,因为预渲染挂钩位于创建画布的ol/reproj.js中的投影工作之后:
layer.on('prerender', function(evt) {
evt.context.imageSmoothingEnabled = false;
});
这是我在此期间使用的黑客:
diff --git a/src/ol/reproj.js b/src/ol/reproj.js
index 7593c6b..5e0d090 100644
--- a/src/ol/reproj.js
+++ b/src/ol/reproj.js
@@ -103,6 +103,11 @@ export function render(width, height, pixelRatio,
context.scale(pixelRatio, pixelRatio);
+ context.imageSmoothingEnabled = false;
+ context.webkitImageSmoothingEnabled = false;
+ context.mozImageSmoothingEnabled = false;
+ context.msImageSmoothingEnabled = false;
+
const sourceDataExtent = createEmpty();
sources.forEach(function(src, i, arr) {
extend(sourceDataExtent, src.extent);
我错过什么了吗?有没有一种方法可以在不重建openlayers的情况下执行此操作?基于
您可以对所有二维画布上下文禁用平滑
// store a reference to original vector
HTMLCanvasElement.prototype.__oldGetContext = HTMLCanvasElement.prototype.getContext;
// patch
HTMLCanvasElement.prototype.getContext = function(type, options) {
var context = this.__oldGetContext(type, options); // call original vector
if (type === "2d") {
context.imageSmoothingEnabled = false;
context.webkitImageSmoothingEnabled = false;
context.mozImageSmoothingEnabled = false;
context.msImageSmoothingEnabled = false;
}
return context;
}