我是使用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());
答案 0 :(得分: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]);