如何将地理服务器图层添加到 openlayers?

Posted

技术标签:

【中文标题】如何将地理服务器图层添加到 openlayers?【英文标题】:How to add a geoserver layer to openlayers? 【发布时间】:2014-12-09 10:21:10 【问题描述】:

我正在尝试在 openlayers 上添加一个带有 2 个点的地理服务器层。但我只得到没有点的地图。这是我尝试的:

     <html>
     <head>
       <title>OpenLayers Example</title>
       <script src="http://openlayers.org/api/OpenLayers.js"></script>
     </head>
     <body>
       <div style="width:100%; height:100%" id="map"></div>
       <script defer="defer" type="text/javascript">
         var map = new OpenLayers.Map('map');


        var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
          "http://vmap0.tiles.osgeo.org/wms/vmap0", layers: 'basic' );


         var cabin= new OpenLayers.Layer.WMS(
                "Cabins",
                "http://localhost:8080/geoserver/wms",
                layers: "cite::obj_geom",
                    transparent: false,
                    TILED: false,
                    styles: "point"
                ,
        isBaseLayer: false,
            displayInLayerSwitcher: true,
            format: "image/png",
            visibility: false,
            displayOutsideMaxExtent: false,
            projection: new OpenLayers.Projection("EPSG:900913")

        
      );    

    map.addLayers([wms,cabin]);
    map.zoomToMaxExtent();

  </script>

  </body>
  </html>

我做错了什么?我以为是投影,但我将其更改为 EPSG:900913,与 openlayers 地图投影相同。

【问题讨论】:

【参考方案1】:

重新安装 geoserver 后一切正常。代码正确!

【讨论】:

以上是关于如何将地理服务器图层添加到 openlayers?的主要内容,如果未能解决你的问题,请参考以下文章

地理服务器中的图层未显示在 OpenLayers 中

SQL Server 中的图层未加载到地理服务器中

需要 Openlayers 指南来满足我的要求

如何向地理服务器上托管的 o​​penlayers 地图添加功能?

从地理服务器将 wmts 图层添加到 mapbox gl

OpenLayers创建一个新的Vector图层并添加覆盖物,并监听图层事件