OpenLayers自定义样式在Safari浏览器中的渲染问题
自定义渲染函数在iOS Safari中存在几何图形渲染异常问题
- 使用OpenLayers v7.2.2版本,通过自定义渲染函数渲染几何图形和文本时,在iPhone 13 Mini(iOS 16.1.1)的Safari浏览器中仅能看到文本,几何图形需放大到极近才能显示。
- 该代码在Windows系统的其他浏览器中运行正常,使用常规Style对象(
style: new Style({fill: new Fill...}))也可正常渲染几何图形。
相关代码:
const interactionLayer = new ol.layer.VectorImage({ source: featureSource, zIndex: Number.MAX_SAFE_INTEGER, style: (feature, resolution) => { return new ol.style.Style({ renderer: (pxGeometry, state) => { const polygon = new ol.geom.Polygon(pxGeometry); const olContext = ol.render.toContext(state.context); olContext.setFillStrokeStyle( new ol.style.Fill({ color: "rgba(255,255,0, 1)", }), new ol.style.Stroke({ color: "#000", }), ); olContext.drawGeometry(polygon); }, }); }, });
iPhone缩放截图:


补充:不使用drawGeometry,直接操作Canvas上下文可正常运行,代码如下:
ctx.beginPath(); ctx.moveTo(pxGeometry[0][0][0], pxGeometry[0][0][1]); for (let i = 1; i < pxGeometry[0].length; i++) { ctx.lineTo(pxGeometry[0][i][0], pxGeometry[0][i][1]); } ctx.closePath(); ctx.fill();
内容的提问来源于stack exchange,提问作者BR75
相关产品推荐
相关产品推荐

