2

我是使用 HTML 创建地图的新手,我一直在尝试将两个矢量图层(地点、点)添加到基本地图(道路)中,但是我看不到地图上的矢量图层。图层应显示为基本地图的矢量叠加层。图层在那里,因为它们在图层切换器中显示,但没有显示在屏幕上。我认为问题与调用向量层的方式有关。什么是要显示矢量图层的解决方案。谢谢

var map = new OpenLayers.Map("map-id");

    var roads= new OpenLayers.Layer.WMS(
    "roads",
    "http://localhost:8080/geoserver/wms",
    {layers: "roads"});

var points= new OpenLayers.Layer.Vector(
    "points",
    "http://localhost:8080/geoserver/wms",
    {layers: "points"});

var places= new OpenLayers.Layer.Vector(
    "places",
    "http://localhost:8080/geoserver/wms",
    {layers: "places"});

map.addLayer(roads);
map.addLayer(points);
map.addLayer(places);
map.addControl(new OpenLayers.Control.LayerSwitcher());
4

1 回答 1

2

您正在尝试通过 WMS 协议显示您的矢量数据。为此,您应该使用 OpenLayers.Layer.WMS 实例而不是 OpenLayers.Layer.Vector。要将 WMS 图层显示为叠加层,请使用 isBaseLayer 选项:

map = new OpenLayers.Map('map'); 
var places = new OpenLayers.Layer.WMS('places',
  "http://localhost:8080/geoserver/wms",
  {layers: "places", transparent: true},
  {isBaseLayer: false, opacity: 1, singleTile: true, visibility: true}
);
map.addLayers([places]);
于 2012-04-16T04:42:52.660 回答