使用OpenLayers无法显示从geoserver导入的图层

时间:2019-06-16 11:43:44

标签: javascript openlayers layer

我正在从geoserver导入深水层(坐标系32632)的层,以使用OpenLayers进行显示,但我找不到它。 这是书面代码:

var urlgeoserver="http://localhost:8082/geoserver/BV_chiba/wms"


var urlcouches="BV_chiba:deepwatertable"


var deepwatertable = new ol.layer.Tile({
    source:new ol.imageWMS({
        url: urlgeoserver,
        params:{"LAYERS": urlcouches, "TILED":"true"},

    }),
    title: "deepwatertable"
});
deepwatertable.setVisible(true);


var listcouches= [deepwatertable];
var map = new ol.map({
target: 'map',
layers:listcouches,
view: new ol.view({
center: ol.proj.transform([0, 0], 'EPSG:4326', 'EPSG:32632'),
zoom:10
})
});

1 个答案:

答案 0 :(得分:1)

没有理由不能对WMS进行切片,因为可以缓存切片,所以效率更高,但是ol.layer.Tile需要与ol.source.TileWMS一起使用。如果您不希望平铺WMS,则必须将ol.layer.Imageol.source.ImageWMS ol.Mapol.View一起使用,也需要使用大写字母。投影(除非是EPSG:3857)必须在source和view选项中指定,并且必须在proj4定义中指定(如果使用OpenLayers 5,则必须注册),并且您将需要包括proj4库<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.5.0/proj4.js"></script>

proj4.defs("EPSG:32632","+proj=utm +zone=32 +datum=WGS84 +units=m +no_defs");

ol.proj.proj4.register(proj4); // only needed if using OpenLayers 5

var urlgeoserver="http://localhost:8082/geoserver/BV_chiba/wms"


var urlcouches="BV_chiba:deepwatertable"


var deepwatertable = new ol.layer.Tile({
    source:new ol.source.TileWMS({
        url: urlgeoserver,
        params:{"LAYERS": urlcouches, "TILED":"true"},
        projection: 'EPSG:32632'
    }),
    title: "deepwatertable"
});
deepwatertable.setVisible(true);


var listcouches= [deepwatertable];
var map = new ol.Map({
  target: 'map',
  layers:listcouches,
  view: new ol.View({
    center: ol.proj.transform([0, 0], 'EPSG:4326', 'EPSG:32632'),
    zoom:10,
    projection: 'EPSG:32632'
  })
});