<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#ffffff" text="#000000">
    Hi,<br>
    I thought about optimizing the WMS Layers and the simplest thing
    would be if the extents are known(which is the most of the cases)
    just to get the tiles which are needed and for the others only one
    static file so the browser has to cache only one file with no
    opacity. It should reduce memory usage and number of request in cost
    of some calculations. So I made the Extents WMS Layer(I know not a
    good name, I'm looking for a good one) which I paste at the bottom.
    Than I thought I could save some calculations by saving a tile's
    "empty"-state in it, by a class derived from Image-class (just
    override the renderTile-funciton and add an isEmpty-attribute in the
    class), but tiles are reused so this leads to some ugly empty tiles
    in some cases(especially panning, zoom is no problem). So I want to
    share the class with interested and hope for some feedback and
    optimization suggestions. This solution is better then the normal
    WMS especially in cases where a small WMS picture lies on an bigger
    one and even better if someone has some small WMS layers in "space",
    it could be interesting for mobiles too and it is interesting if
    your caching your tiles like us so there are no empty tiles in cache
    any more there is only one image for all. It should be inferior to
    the normal one if your view is filled with the not empty WMS tiles
    because intersection is calculated every time, but I don't know if
    the calculations impact that much. <br>
    Regards<br>
    Slawomir<br>
    <br>
    OpenLayers.Layer.WMS.Extents =
    OpenLayers.Class(OpenLayers.Layer.WMS, {<br>
    <br>
    &nbsp;&nbsp;&nbsp;<b> extents:null,</b><br>
    &nbsp;&nbsp;&nbsp; <b>emptyTileImageUrl:null,</b><br>
    <br>
    &nbsp;&nbsp;&nbsp; getURL: function (bounds) {<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bounds = this.adjustBounds(bounds);<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<b> if(this.extents == null || this.emptyTileImageUrl == null
      || this.extents.intersectsBounds(bounds)) {</b><br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; var imageSize = this.getImageSize();<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; var newParams = {};<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // WMS 1.3 introduced axis order<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; var reverseAxisOrder = this.reverseAxisOrder();<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; newParams.BBOX = this.encodeBBOX ?<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bounds.toBBOX(null, reverseAxisOrder) :<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bounds.toArray(reverseAxisOrder);<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; newParams.WIDTH = imageSize.w;<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; newParams.HEIGHT = imageSize.h;<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; var requestString =
    this.getFullRequestString(newParams);<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return requestString;<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<b> } else {<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return this.emptyTileImageUrl;<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</b><br>
    &nbsp;&nbsp;&nbsp; },<br>
    &nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp; CLASS_NAME: "OpenLayers.Layer.WMS.Extents"<br>
    });<br>
  </body>
</html>