I'm wondering how to display a Layer in OpenLayers 3 which I host in Geoserver. I imported the Layer from a PostGIS-DB and it is possible to display it using the geoserver preview option. The Layer uses EPSG:3857.

<html lang="en">
    <link rel="stylesheet" href="http://openlayers.org/en/v3.1.1/css/ol.css" type="text/css">
      .map {
        height: 900px;
        width: 900px;
    <script src="http://openlayers.org/en/v3.1.1/build/ol.js" type="text/javascript"></script>
      <div id="map" class="map"></div>

          var layers = [
              new ol.layer.Tile ({
                extent: [3359890.5, 5761308, 3395047, 5773695.5],
                source: new ol.source.TileWMS(/** @type {olx.source.TileWMSOptions} */ 
                    url: '',
                    params: {
                             'LAYERS': 'jueterbog:fl_spa', 
                             'TILED': true, 
                    title: 'SPA'

                new ol.layer.Tile   ({
                source: new ol.source.OSM()

          var map = new ol.Map  ({
              layers: layers,
              target: 'map',
              view: new ol.View   ({
                center: [1450000,6809000],
                zoom: 12


The Layer should be displayed in this area: 52.025151, 13.069072


You are mixing projections. You are requesting a tile in lat/lon (4326) from Geoserver, which will disappear from view when shown in an OpenLayers page that has the default projection set to 3837 (meters), see the docs.

Geoserver will automatically reproject for you and you can pass the CRS in the params that you send to the WMS, ie,

params: {'LAYERS': 'jueterbog:fl_spa', 'TILED': true, 'CRS': 3857}

and making similar adjustments for the bounding box, ie, putting it in meters. If you WMS source is from vectors, reprojecting inside Geoserver will look fine, if your source is raster, then it will probably not, but this is the cost of mixing rasters in different projections.

  • I don't get it. I tried your way but nothing happened. I think you're right with your idea of a projection problem. What is curios for me, is the fact that the layer is defined as EPSG:3857 in geoserver (both native / declared). When I connect to the WMS via QGIS it works but the layer is placed somewhere in asia.
    – dan_ke
    Feb 11 '15 at 11:15
  • What are you using for extents, extent: [30.182409891182594, 45.88105096139946, 30.498226104036974, 45.95846372713877]. This clearly has to change to 3857 also. Could you update the question with correct extents, please. Feb 11 '15 at 11:37
  • I think I found the problem: my input data is defined with an user-specified projection which seems to be a local reference system. when I overlay my shapefile with OSM-basemap in QGIS(before postgis import) then it is placed at the same wrong position like in my WMS now. So I have to check how to reproject this local system before import.
    – dan_ke
    Feb 11 '15 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.