【问题标题】:Viewing vector overlay in an OpenLayers Map在 OpenLayers 地图中查看矢量叠加
【发布时间】:2014-08-30 04:21:50
【问题描述】:

我是使用 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());

【问题讨论】:

  • 图层的投影是否与地图相同?
  • 所有图层都在同一个投影中。当格式从新的 OpenLayers.Layer.Vector 更改为新的 OpenLayers.Layer.WMS 时,它们可以显示在地图上。但是,这只会使它们成为基础地图层

标签: javascript openlayers


【解决方案1】:

您正在尝试通过 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]);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 2017-04-12
    • 1970-01-01
    相关资源
    最近更新 更多