openlayers6加载百度地图偏移问题解决

openlayers6加载百度地图偏移问题解决

标题功能说明

openlayers升级到6版本后,3、4、5版本加载百度地图的代码,加载的地图发生了偏移,原始代码和偏移情况如下

let baiduSource = new TileImage({
                    projection: projection,
                    tileGrid: tilegrid,
                    tileUrlFunction: function (tileCoord, pixelRatio, proj) {
                        if (!tileCoord) {
                            return '';
                        }
                        let z = tileCoord[0];
                        let x = tileCoord[1];
                        let y = tileCoord[2]; 
                        return "http://online1.map.bdimg.com/onlinelabel/?qt=tile&x=" +
                            x + "&y=" + y + "&z=" + z +
                            "&styles=pl&scaler=1&udt=20191119";
                    },
                    crossOrigin: 'anonymous'
                });

![偏移情况]( https://img-blog.csdnimg.cn/20200412180701934.jpg?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2dpc2RvZXI=,size_16,color_FFFFFF,t_70#pic_center)

解决方案

修改tileUrlFunction方法
详情:https://www.giserdqy.com/secdev/openlayers/36281/

posted @ 2020-04-12 18:20  dqygiser  阅读(1266)  评论(0)    收藏  举报