在使用openlayer显示geoserver tiff时遇到一些问题

问题描述 投票:0回答:1

我试图使用openlayer来显示geoserver tif,但它显示不正确。这是我的步骤: 我从本地地理服务器中选择了一个tif,例如(topp:states) 2.然后尝试使用openlayer api加载它

const tifMap = (target) => {

new Map({
    target,
    pixelRatio: 1,
    layers: [
      new TileLayer({
        source: new TileWMS({
            url: 'http://localhost:8080/geoserver/topp/wms',
            params: {'LAYERS': 'topp:states',  
                'BBOX': '-124.73142200000001,24.955967,-66.969849,49.371735', 
                'CRS': 'EPSG:4326', 
                'FORMAT': 'image/jpeg',
                'VERSION': '1.1.0'
            },
            serverType: 'geoserver'  
        })

      })
    ],
    view: new View({
      center: [741189, -3741196],
      zoom: 4
    })
  })
};

3.遗憾的是,几个相同的图像显示在div上,我不知道为什么,实际上我试图通过浏览器打开链接(openlayer试图获得),它显示正常。

openlayers geoserver
1个回答
0
投票

OpenLayers会根据源选项中的投影集和TileWMS的图块网格或ImageWMS的视口自动创建BBOX和CRS参数。可以在tilegrid(在服务器投影单元中)或在图层上(在视图投影单元中)设置最大范围。假设服务器仅支持EPSG:4326并且您希望以EPSG显示平铺输出:3857这些中的任何一个都可以工作:

  new TileLayer({
    source: new TileWMS({
        url: 'http://localhost:8080/geoserver/topp/wms',
        params: {'LAYERS': 'topp:states',  
            'FORMAT': 'image/jpeg',
            'VERSION': '1.1.0'
        },
        serverType: 'geoserver',
        projection: 'EPSG:4326' 
    }),
    extent: transformExtent([-124.73142200000001,24.955967,-66.969849,49.371735], 'EPSG:4326', 'EPSG:3857')
  })

.

  new TileLayer({
    source: new TileWMS({
        url: 'http://localhost:8080/geoserver/topp/wms',
        params: {'LAYERS': 'topp:states',  
            'FORMAT': 'image/jpeg',
            'VERSION': '1.1.0'
        },
        serverType: 'geoserver',  
        projection: 'EPSG:4326', 
        tilegrid: createXYZ({extent: [-124.73142200000001,24.955967,-66.969849,49.371735]})
    })
  })
© www.soinside.com 2019 - 2024. All rights reserved.