2017-07-18 349 views
0

我正在從OL2升級到OL4。 OL2版本正在運行在vegkart.noOpenlayers 4地圖在指定tilegrid時很模糊

我遇到了一個問題,當tileGrid被指定時,地圖變得模糊。如果沒有tileGrid,地圖看起來很清晰,但繪製的特徵將被抵消。

Here是一個有比較的最小版本。

ol.proj.setProj4(proj4); 
proj4.defs('EPSG:25833', '+proj=utm +zone=33 +ellps=GRS80 +units=m +no_defs'); 
const EPSG25833 = new ol.proj.Projection({ 
    code: 'EPSG:25833', 
    extent: [-25e5, 35e5, 3045984, 9045984] 
}); 

var map = new ol.Map({ 
    target: 'map', 
    layers: [ 
     new ol.layer.Tile({ 
      source: new ol.source.XYZ({ 
       projection: EPSG25833, 
       url: 'https://m{1-9}-nvdbcache.geodataonline.no/arcgis/rest/services/Trafikkportalen/GeocacheTrafikkJPG/MapServer/tile/{z}/{y}/{x}', 
       maxZoom: 16, 
       minZoom: 3, 
       tileGrid: new ol.tilegrid.TileGrid({ 
        extent: [-3438648.9692659, -2500000, 9984632.9692659, 9045984], 
        resolutions: [21674.7100160867, 10837.35500804335, 5418.677504021675, 2709.3387520108377, 1354.6693760054188, 677.3346880027094, 338.6673440013547, 169.33367200067735, 84.66683600033868, 42.33341800016934, 21.16670900008467, 10.583354500042335, 5.291677250021167, 2.6458386250105836, 1.3229193125052918, 0.6614596562526459, 0.33072982812632296], 
        origin: [-2500000, 9045984] 
       }) 
      }) 
     }) 
    ], 
    view: new ol.View({ 
     projection: EPSG25833, 
     center: [600000,7225000], 
     zoom: 3 
    }) 
}); 

Here是瓷磚的概述。

我發現了一個計算分辨率的例子。

const projectionExtent = EPSG25833.getExtent(); 
const size = ol.extent.getWidth(projectionExtent)/256; 
const resolutions = new Array(17); 
const matrixIds = new Array(17); 
for (let z = 0; z < 17; ++z) { 
    // generate resolutions and matrixIds arrays for this WMTS 
    resolutions[z] = size/Math.pow(2, z); 
    matrixIds[z] = z; 
} 

當使用它時,地圖清晰但移動。 https://jsfiddle.net/computerlove/t3afh9v9/

我錯過了什麼,或者這是一個錯誤?

回答

3

與v2不同,視圖分辨率不會從v4中的基礎層獲取。如果您希望視圖使用與平鋪圖層相同的分辨率,則必須使用

new ol.View({ 
    resolutions: tileSource.getTileGrid().getResolutions() 
})