4

Having successfully used the new OpenLayers.Layer.GeoWebCache to add a local tile cache created using Geowebcache, I thought I would compare against the same data as a wms from my local GeoServer.

Looking at the geowebcache.js file there is an option to specify the cache layer as a base layer, so I sent it to false and added a layer switcher to the map

Both layers add to the map however there is a significant offset. enter image description here

The cache layer is the one that is set to the right.

In the geowebcache.js there is no mention of offset needing to be set.

Any ideas on what would cause this and what I need to change?

thanks

UPDATE

As requested my openlayers code

<script src="http://openlayers.org/api/OpenLayers.js"></script>
<script src="geowebcache.js" type="text/javascript"></script>
<script type="text/javascript">
     var map;
        function init() {

            var world = new OpenLayers.Bounds(
                0, 0, 700000, 1344000
            );

            map = new OpenLayers.Map({
                div: "map",
                projection: new OpenLayers.Projection("EPSG:27700"),
                numZoomLevels: 11,
                resolutions: [896,448,224,112,56,28,14,7,4,2,1],
                maxExtent: world,
                center: new OpenLayers.LonLat(400000, 500000),
                zoom: 11
            });

            map.addControl(new OpenLayers.Control.LayerSwitcher());

            var cache = new OpenLayers.Layer.GeoWebCache({
                  url: "https://url/",
                  isBaseLayer: false,
                  name: "Cache Layer",
                  gridSetId: "zoommap",
              });

            // Add WMS layer to our map
            map.addLayer(cache);

            var bwms = new OpenLayers.Layer.WMS( "Base Map",
              "http://localhost:8080/geoserver/wms?",
              { "transparent":"false",
                isBaseLayer: true,
                "layers":"osgb:aa_base",
                "format":"image/png" },
              { "reproject":"true" }
              );

            // Add WMS layer to our map
            map.addLayer(bwms);

Here is my GWC configuration file

  `

<?xml version="1.0" encoding="utf-8"?>
    <gwcConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://geowebcache.org/schema/1.5.0 http://geowebcache.org/schema/1.5.0/geowebcache.xsd" xmlns="http://geowebcache.org/schema/1.5.0">
  <version>1.5.0</version>
  <backendTimeout>120</backendTimeout>
  <gridSets>
    <gridSet>
      <name>zoommap</name>
      <srs>
        <number>27700</number>
      </srs>
      <extent>
        <coords>
          <double>0.0</double>
          <double>0.0</double>
          <double>700000.0</double>
          <double>1344000.0</double>
        </coords>
      </extent>
      <alignTopLeft>false</alignTopLeft>
      <resolutions>
        <double>896.0</double>
        <double>448.0</double>
        <double>224.0</double>
        <double>112.0</double>
        <double>56.0</double>
        <double>28.0</double>
        <double>14.0</double>
        <double>7.0</double>
        <double>4.0</double>
        <double>2.0</double>
        <double>1.0</double>
      </resolutions>
      <metersPerUnit>1.0</metersPerUnit>
      <pixelSize>2.8E-4</pixelSize>
      <scaleNames>
        <string>zoommap:0</string>
        <string>zoommap:1</string>
        <string>zoommap:2</string>
        <string>zoommap:3</string>
        <string>zoommap:4</string>
        <string>zoommap:5</string>
        <string>zoommap:6</string>
        <string>zoommap:7</string>
        <string>zoommap:8</string>
        <string>zoommap:9</string>
        <string>zoommap:10</string>
      </scaleNames>
      <tileHeight>250</tileHeight>
      <tileWidth>250</tileWidth>
      <yCoordinateFirst>false</yCoordinateFirst>
    </gridSet>
  </gridSets>
  <layers/>
</gwcConfiguration>

The data is stored in a PostGIS database and the projection is definitely EPSG:27700.

As you can see I have defined the projection in my OpenLayers code and included the same resolutions as my geowebcache configuration resolutions.

  • Please provide your OpenLayers code and/or your GeoWebCache config. Also, what is your data projection? – Julien-Samuel Lacroix Nov 7 '13 at 19:16
  • updated with all my HTML code and geowebcache config file – tjmgis Nov 7 '13 at 19:23
1

First tentative answer:

In your GeoWebCache config...

  • try with tileHeight and tileWidth of 256 instead of 250
  • try changing the name of your grid to EPSG:27700

Next, and most important, try using the full extent of the projection and not just the region covered by your data. If I'm not mistaken, EPSG:27700 extent is:

1393.0196, 13494.9764, 671196.3657, 1230275.0454

See: http://spatialreference.org/ref/epsg/27700/

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.