(self)
return s
Template for openlayers.html implementing overlay of available Spherical Mercator layers.

        It returns filled string. Expected variables:
        title, bingkey, north, south, east, west, minzoom, maxzoom, tilesize, tileformat, publishurl
Template for openlayers.html implementing overlay of available Spherical Mercator layers.
Template for openlayers . html implementing overlay of available Spherical Mercator layers .
def generate_openlayers(self):
        """
        Template for openlayers.html implementing overlay of available Spherical Mercator layers.

        It returns filled string. Expected variables:
        title, bingkey, north, south, east, west, minzoom, maxzoom, tilesize, tileformat, publishurl
        """

        args = {}
        args['title'] = self.options.title
        args['bingkey'] = self.options.bingkey
        (args['south'], args['west'], args['north'], args['east']) = \
            self.swne
        args['minzoom'] = self.tminz
        args['maxzoom'] = self.tmaxz
        args['tilesize'] = self.tilesize
        args['tileformat'] = self.tileext
        args['publishurl'] = self.options.url
        args['copyright'] = self.options.copyright
        if self.options.tmscompatible:
            args['tmsoffset'] = '-1'
        else:
            args['tmsoffset'] = ''
        if self.options.profile == 'raster':
            args['rasterzoomlevels'] = self.tmaxz + 1
            args['rastermaxresolution'] = 2 ** self.nativezoom \
                * self.out_gt[1]

        s = \
            """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml"
          <head>
            <title>%(title)s</title>
            <meta http-equiv='imagetoolbar' content='no'/>
            <style type="text/css"> v\:* {behavior:url(#default#VML);}
                html, body { overflow: hidden; padding: 0; height: 100%%; width: 100%%; font-family: 'Lucida Grande',Geneva,Arial,Verdana,sans-serif; }
                body { margin: 10px; background: #fff; }
                h1 { margin: 0; padding: 6px; border:0; font-size: 20pt; }
                #header { height: 43px; padding: 0; background-color: #eee; border: 1px solid #888; }
                #subheader { height: 12px; text-align: right; font-size: 10px; color: #555;}
                #map { height: 95%%; border: 1px solid #888; }
            .olImageLoadError { display: none; }
            .olControlLayerSwitcher .layersDiv { border-radius: 10px 0 0 10px; }
            </style>""" \
            % args

        if self.options.profile == 'mercator':
            s += \
                """
            <script src='http://maps.google.com/maps/api/js?sensor=false&v=3.7'></script>""" \
                % args

        s += \
            """
            <script src="http://www.openlayers.org/api/2.12/OpenLayers.js"></script>
            <script>
                var map;
                var mapBounds = new OpenLayers.Bounds( %(west)s, %(south)s, %(east)s, %(north)s);
                var mapMinZoom = %(minzoom)s;
                var mapMaxZoom = %(maxzoom)s;
              var emptyTileURL = "http://www.maptiler.org/img/none.png";
                OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;

                function init(){""" \
            % args

        if self.options.profile == 'mercator':
            s += \
                """
                var options = {
                      div: "map",
                    controls: [],
                      projection: "EPSG:900913",
                    displayProjection: new OpenLayers.Projection("EPSG:4326"),
                      numZoomLevels: 20
                    };
                  map = new OpenLayers.Map(options);

                  // Create Google Mercator layers
                var gmap = new OpenLayers.Layer.Google("Google Streets",
                  {
                      type: google.maps.MapTypeId.ROADMAP,
                      sphericalMercator: true
                  });
                var gsat = new OpenLayers.Layer.Google("Google Satellite",
                  {
                      type: google.maps.MapTypeId.SATELLITE,
                      sphericalMercator: true
                  });
                var ghyb = new OpenLayers.Layer.Google("Google Hybrid",
                  {
                      type: google.maps.MapTypeId.HYBRID,
                      sphericalMercator: true
                  });
                var gter = new OpenLayers.Layer.Google("Google Terrain",
                  {
                      type: google.maps.MapTypeId.TERRAIN,
                      sphericalMercator: true
                  });

                  // Create Bing layers
                  var broad = new OpenLayers.Layer.Bing({
                      name: "Bing Roads",
                      key: "%(bingkey)s",
                      type: "Road",
                      sphericalMercator: true
                  });
                  var baer = new OpenLayers.Layer.Bing({
                      name: "Bing Aerial",
                      key: "%(bingkey)s",
                      type: "Aerial",
                      sphericalMercator: true
                  });
                  var bhyb = new OpenLayers.Layer.Bing({
                      name: "Bing Hybrid",
                      key: "%(bingkey)s",
                      type: "AerialWithLabels",
                      sphericalMercator: true
                  });

                  // Create OSM layer
                  var osm = new OpenLayers.Layer.OSM("OpenStreetMap");

                // create TMS Overlay layer
                var tmsoverlay = new OpenLayers.Layer.TMS( "TMS Overlay", "",
                  {
                      serviceVersion: '.',
                      layername: '.',
                      alpha: true,
                      type: '%(tileformat)s',
                      isBaseLayer: false,
                      getURL: getURL
                    });
                  if (OpenLayers.Util.alphaHack() == false) {
                      tmsoverlay.setOpacity(0.7);
                  }

                  map.addLayers([gmap, gsat, ghyb, gter,
                                 broad, baer, bhyb,
                                 osm, tmsoverlay]);

                var switcherControl = new OpenLayers.Control.LayerSwitcher();
                map.addControl(switcherControl);
                switcherControl.maximizeControl();

                map.zoomToExtent( mapBounds.transform(map.displayProjection, map.projection ) );
            """ \
                % args
        elif self.options.profile == 'geodetic':

            s += \
                """
                var options = {
                      div: "map",
                    controls: [],
                      projection: "EPSG:4326"
                    };
                  map = new OpenLayers.Map(options);

                  var wms = new OpenLayers.Layer.WMS("VMap0",
                      "http://tilecache.osgeo.org/wms-c/Basic.py?",
                      {
                          layers: 'basic',
                          format: 'image/png'
                      }
                  );
                var tmsoverlay = new OpenLayers.Layer.TMS( "TMS Overlay", "",
                    {
                      serviceVersion: '.',
                      layername: '.',
                      alpha: true,
                      type: '%(tileformat)s',
                      isBaseLayer: false,
                      getURL: getURL
                    });
                  if (OpenLayers.Util.alphaHack() == false) {
                      tmsoverlay.setOpacity(0.7);
                  }

                  map.addLayers([wms,tmsoverlay]);

                var switcherControl = new OpenLayers.Control.LayerSwitcher();
                map.addControl(switcherControl);
                switcherControl.maximizeControl();

                map.zoomToExtent( mapBounds );
           """ \
                % args
        elif self.options.profile == 'raster':

            s += \
                """
                var options = {
                      div: "map",
                    controls: [],
                    maxExtent: new OpenLayers.Bounds(  %(west)s, %(south)s, %(east)s, %(north)s ),
                    maxResolution: %(rastermaxresolution)f,
                    numZoomLevels: %(rasterzoomlevels)d
                    };
                  map = new OpenLayers.Map(options);

                var layer = new OpenLayers.Layer.TMS( "TMS Layer","",
                  {
                      serviceVersion: '.',
                      layername: '.',
                      alpha: true,
                      type: '%(tileformat)s',
                      getURL: getURL
                    });

                map.addLayer(layer);
                map.zoomToExtent( mapBounds );
        """ \
                % args

        s += \
            """
                  map.addControls([new OpenLayers.Control.PanZoomBar(),
                                   new OpenLayers.Control.Navigation(),
                                   new OpenLayers.Control.MousePosition(),
                                   new OpenLayers.Control.ArgParser(),
                                   new OpenLayers.Control.Attribution()]);
            }
            """ \
            % args

        if self.options.profile == 'mercator':
            s += \
                """
              function getURL(bounds) {
                  bounds = this.adjustBounds(bounds);
                  var res = this.getServerResolution();
                  var x = Math.round((bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w));
                  var y = Math.round((bounds.bottom - this.tileOrigin.lat) / (res * this.tileSize.h));
                  var z = this.getServerZoom();
                  if (this.map.baseLayer.CLASS_NAME === 'OpenLayers.Layer.Bing') {
                      z+=1;
                }
                  var path = this.serviceVersion + "/" + this.layername + "/" + z + "/" + x + "/" + y + "." + this.type;
                  var url = this.url;
                  if (OpenLayers.Util.isArray(url)) {
                      url = this.selectUrl(path, url);
            }
                  if (mapBounds.intersectsBounds(bounds) && (z >= mapMinZoom) && (z <= mapMaxZoom)) {
                      return url + path;
                } else {
                      return emptyTileURL;
                }
            }
            """ \
                % args
        elif self.options.profile == 'geodetic':

            s += \
                """
              function getURL(bounds) {
                bounds = this.adjustBounds(bounds);
                  var res = this.getServerResolution();
                var x = Math.round((bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w));
                var y = Math.round((bounds.bottom - this.tileOrigin.lat) / (res * this.tileSize.h));
                  var z = this.getServerZoom()%(tmsoffset)s;
                var path = this.serviceVersion + "/" + this.layername + "/" + z + "/" + x + "/" + y + "." + this.type;
                var url = this.url;
                  if (OpenLayers.Util.isArray(url)) {
                      url = this.selectUrl(path, url);
                  }
                  if (mapBounds.intersectsBounds(bounds) && (z >= mapMinZoom) && (z <= mapMaxZoom)) {
                      return url + path;
                } else {
                      return emptyTileURL;
                }
            }
            """ \
                % args
        elif self.options.profile == 'raster':

            s += \
                """
              function getURL(bounds) {
                  bounds = this.adjustBounds(bounds);
                  var res = this.getServerResolution();
                  var x = Math.round((bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w));
                  var y = Math.round((bounds.bottom - this.tileOrigin.lat) / (res * this.tileSize.h));
                  var z = this.getServerZoom();
                  var path = this.serviceVersion + "/" + this.layername + "/" + z + "/" + x + "/" + y + "." + this.type;
                  var url = this.url;
                  if (OpenLayers.Util.isArray(url)) {
                      url = this.selectUrl(path, url);
                  }
                  if (mapBounds.intersectsBounds(bounds) && (z >= mapMinZoom) && (z <= mapMaxZoom)) {
                      return url + path;
                } else {
                      return emptyTileURL;
                }
            }
            """ \
                % args

        s += \
            """
           function getWindowHeight() {
                if (self.innerHeight) return self.innerHeight;
                if (document.documentElement && document.documentElement.clientHeight)
                    return document.documentElement.clientHeight;
                if (document.body) return document.body.clientHeight;
                    return 0;
            }

            function getWindowWidth() {
                if (self.innerWidth) return self.innerWidth;
                if (document.documentElement && document.documentElement.clientWidth)
                    return document.documentElement.clientWidth;
                if (document.body) return document.body.clientWidth;
                    return 0;
            }

            function resize() {
                var map = document.getElementById("map");
                var header = document.getElementById("header");
                var subheader = document.getElementById("subheader");
                map.style.height = (getWindowHeight()-80) + "px";
                map.style.width = (getWindowWidth()-20) + "px";
                header.style.width = (getWindowWidth()-20) + "px";
                subheader.style.width = (getWindowWidth()-20) + "px";
                if (map.updateSize) { map.updateSize(); };
            }

            onresize=function(){ resize(); };

            </script>
          </head>
          <body onload="init()">
            <div id="header"><h1>%(title)s</h1></div>
            <div id="subheader">Generated by <a href="http://www.maptiler.org/">MapTiler</a>/<a href="http://www.klokan.cz/projects/gdal2tiles/">GDAL2Tiles</a>, Copyright &copy; 2008 <a href="http://www.klokan.cz/">Klokan Petr Pridal</a>,  <a href="http://www.gdal.org/">GDAL</a> &amp; <a href="http://www.osgeo.org/">OSGeo</a> <a href="http://code.google.com/soc/">GSoC</a>
            <!-- PLEASE, LET THIS NOTE ABOUT AUTHOR AND PROJECT SOMEWHERE ON YOUR WEBSITE, OR AT LEAST IN THE COMMENT IN HTML. THANK YOU -->
            </div>
            <div id="map"></div>
            <script type="text/javascript" >resize()</script>
          </body>
        </html>""" \
            % args

        return s
def generate_openlayers ( self ) : args = { } args [ 'title' ] = self . options . title args [ 'bingkey' ] = self . options . bingkey ( args [ 'south' ] , args [ 'west' ] , args [ 'north' ] , args [ 'east' ] ) = self . swne args [ 'minzoom' ] = self . tminz args [ 'maxzoom' ] = self . tmaxz args [ 'tilesize' ] = self . tilesize args [ 'tileformat' ] = self . tileext args [ 'publishurl' ] = self . options . url args [ 'copyright' ] = self . options . copyright if self . options . tmscompatible : args [ 'tmsoffset' ] = '-1' else : args [ 'tmsoffset' ] = '' if self . options . profile == 'raster' : args [ 'rasterzoomlevels' ] = self . tmaxz + 1 args [ 'rastermaxresolution' ] = 2 ** self . nativezoom * self . out_gt [ 1 ] s = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml"
          <head>
            <title>%(title)s</title>
            <meta http-equiv='imagetoolbar' content='no'/>
            <style type="text/css"> v\:* {behavior:url(#default#VML);}
                html, body { overflow: hidden; padding: 0; height: 100%%; width: 100%%; font-family: 'Lucida Grande',Geneva,Arial,Verdana,sans-serif; }
                body { margin: 10px; background: #fff; }
                h1 { margin: 0; padding: 6px; border:0; font-size: 20pt; }
                #header { height: 43px; padding: 0; background-color: #eee; border: 1px solid #888; }
                #subheader { height: 12px; text-align: right; font-size: 10px; color: #555;}
                #map { height: 95%%; border: 1px solid #888; }
            .olImageLoadError { display: none; }
            .olControlLayerSwitcher .layersDiv { border-radius: 10px 0 0 10px; }
            </style>""" % args if self . options . profile == 'mercator' : s += """
            <script src='http://maps.google.com/maps/api/js?sensor=false&v=3.7'></script>""" % args s += """
            <script src="http://www.openlayers.org/api/2.12/OpenLayers.js"></script>
            <script>
                var map;
                var mapBounds = new OpenLayers.Bounds( %(west)s, %(south)s, %(east)s, %(north)s);
                var mapMinZoom = %(minzoom)s;
                var mapMaxZoom = %(maxzoom)s;
              var emptyTileURL = "http://www.maptiler.org/img/none.png";
                OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;

                function init(){""" % args if self . options . profile == 'mercator' : s += """
                var options = {
                      div: "map",
                    controls: [],
                      projection: "EPSG:900913",
                    displayProjection: new OpenLayers.Projection("EPSG:4326"),
                      numZoomLevels: 20
                    };
                  map = new OpenLayers.Map(options);

                  // Create Google Mercator layers
                var gmap = new OpenLayers.Layer.Google("Google Streets",
                  {
                      type: google.maps.MapTypeId.ROADMAP,
                      sphericalMercator: true
                  });
                var gsat = new OpenLayers.Layer.Google("Google Satellite",
                  {
                      type: google.maps.MapTypeId.SATELLITE,
                      sphericalMercator: true
                  });
                var ghyb = new OpenLayers.Layer.Google("Google Hybrid",
                  {
                      type: google.maps.MapTypeId.HYBRID,
                      sphericalMercator: true
                  });
                var gter = new OpenLayers.Layer.Google("Google Terrain",
                  {
                      type: google.maps.MapTypeId.TERRAIN,
                      sphericalMercator: true
                  });

                  // Create Bing layers
                  var broad = new OpenLayers.Layer.Bing({
                      name: "Bing Roads",
                      key: "%(bingkey)s",
                      type: "Road",
                      sphericalMercator: true
                  });
                  var baer = new OpenLayers.Layer.Bing({
                      name: "Bing Aerial",
                      key: "%(bingkey)s",
                      type: "Aerial",
                      sphericalMercator: true
                  });
                  var bhyb = new OpenLayers.Layer.Bing({
                      name: "Bing Hybrid",
                      key: "%(bingkey)s",
                      type: "AerialWithLabels",
                      sphericalMercator: true
                  });

                  // Create OSM layer
                  var osm = new OpenLayers.Layer.OSM("OpenStreetMap");

                // create TMS Overlay layer
                var tmsoverlay = new OpenLayers.Layer.TMS( "TMS Overlay", "",
                  {
                      serviceVersion: '.',
                      layername: '.',
                      alpha: true,
                      type: '%(tileformat)s',
                      isBaseLayer: false,
                      getURL: getURL
                    });
                  if (OpenLayers.Util.alphaHack() == false) {
                      tmsoverlay.setOpacity(0.7);
                  }

                  map.addLayers([gmap, gsat, ghyb, gter,
                                 broad, baer, bhyb,
                                 osm, tmsoverlay]);

                var switcherControl = new OpenLayers.Control.LayerSwitcher();
                map.addControl(switcherControl);
                switcherControl.maximizeControl();

                map.zoomToExtent( mapBounds.transform(map.displayProjection, map.projection ) );
            """ % args elif self . options . profile == 'geodetic' : s += """
                var options = {
                      div: "map",
                    controls: [],
                      projection: "EPSG:4326"
                    };
                  map = new OpenLayers.Map(options);

                  var wms = new OpenLayers.Layer.WMS("VMap0",
                      "http://tilecache.osgeo.org/wms-c/Basic.py?",
                      {
                          layers: 'basic',
                          format: 'image/png'
                      }
                  );
                var tmsoverlay = new OpenLayers.Layer.TMS( "TMS Overlay", "",
                    {
                      serviceVersion: '.',
                      layername: '.',
                      alpha: true,
                      type: '%(tileformat)s',
                      isBaseLayer: false,
                      getURL: getURL
                    });
                  if (OpenLayers.Util.alphaHack() == false) {
                      tmsoverlay.setOpacity(0.7);
                  }

                  map.addLayers([wms,tmsoverlay]);

                var switcherControl = new OpenLayers.Control.LayerSwitcher();
                map.addControl(switcherControl);
                switcherControl.maximizeControl();

                map.zoomToExtent( mapBounds );
           """ % args elif self . options . profile == 'raster' : s += """
                var options = {
                      div: "map",
                    controls: [],
                    maxExtent: new OpenLayers.Bounds(  %(west)s, %(south)s, %(east)s, %(north)s ),
                    maxResolution: %(rastermaxresolution)f,
                    numZoomLevels: %(rasterzoomlevels)d
                    };
                  map = new OpenLayers.Map(options);

                var layer = new OpenLayers.Layer.TMS( "TMS Layer","",
                  {
                      serviceVersion: '.',
                      layername: '.',
                      alpha: true,
                      type: '%(tileformat)s',
                      getURL: getURL
                    });

                map.addLayer(layer);
                map.zoomToExtent( mapBounds );
        """ % args s += """
                  map.addControls([new OpenLayers.Control.PanZoomBar(),
                                   new OpenLayers.Control.Navigation(),
                                   new OpenLayers.Control.MousePosition(),
                                   new OpenLayers.Control.ArgParser(),
                                   new OpenLayers.Control.Attribution()]);
            }
            """ % args if self . options . profile == 'mercator' : s += """
              function getURL(bounds) {
                  bounds = this.adjustBounds(bounds);
                  var res = this.getServerResolution();
                  var x = Math.round((bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w));
                  var y = Math.round((bounds.bottom - this.tileOrigin.lat) / (res * this.tileSize.h));
                  var z = this.getServerZoom();
                  if (this.map.baseLayer.CLASS_NAME === 'OpenLayers.Layer.Bing') {
                      z+=1;
                }
                  var path = this.serviceVersion + "/" + this.layername + "/" + z + "/" + x + "/" + y + "." + this.type;
                  var url = this.url;
                  if (OpenLayers.Util.isArray(url)) {
                      url = this.selectUrl(path, url);
            }
                  if (mapBounds.intersectsBounds(bounds) && (z >= mapMinZoom) && (z <= mapMaxZoom)) {
                      return url + path;
                } else {
                      return emptyTileURL;
                }
            }
            """ % args elif self . options . profile == 'geodetic' : s += """
              function getURL(bounds) {
                bounds = this.adjustBounds(bounds);
                  var res = this.getServerResolution();
                var x = Math.round((bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w));
                var y = Math.round((bounds.bottom - this.tileOrigin.lat) / (res * this.tileSize.h));
                  var z = this.getServerZoom()%(tmsoffset)s;
                var path = this.serviceVersion + "/" + this.layername + "/" + z + "/" + x + "/" + y + "." + this.type;
                var url = this.url;
                  if (OpenLayers.Util.isArray(url)) {
                      url = this.selectUrl(path, url);
                  }
                  if (mapBounds.intersectsBounds(bounds) && (z >= mapMinZoom) && (z <= mapMaxZoom)) {
                      return url + path;
                } else {
                      return emptyTileURL;
                }
            }
            """ % args elif self . options . profile == 'raster' : s += """
              function getURL(bounds) {
                  bounds = this.adjustBounds(bounds);
                  var res = this.getServerResolution();
                  var x = Math.round((bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w));
                  var y = Math.round((bounds.bottom - this.tileOrigin.lat) / (res * this.tileSize.h));
                  var z = this.getServerZoom();
                  var path = this.serviceVersion + "/" + this.layername + "/" + z + "/" + x + "/" + y + "." + this.type;
                  var url = this.url;
                  if (OpenLayers.Util.isArray(url)) {
                      url = this.selectUrl(path, url);
                  }
                  if (mapBounds.intersectsBounds(bounds) && (z >= mapMinZoom) && (z <= mapMaxZoom)) {
                      return url + path;
                } else {
                      return emptyTileURL;
                }
            }
            """ % args s += """
           function getWindowHeight() {
                if (self.innerHeight) return self.innerHeight;
                if (document.documentElement && document.documentElement.clientHeight)
                    return document.documentElement.clientHeight;
                if (document.body) return document.body.clientHeight;
                    return 0;
            }

            function getWindowWidth() {
                if (self.innerWidth) return self.innerWidth;
                if (document.documentElement && document.documentElement.clientWidth)
                    return document.documentElement.clientWidth;
                if (document.body) return document.body.clientWidth;
                    return 0;
            }

            function resize() {
                var map = document.getElementById("map");
                var header = document.getElementById("header");
                var subheader = document.getElementById("subheader");
                map.style.height = (getWindowHeight()-80) + "px";
                map.style.width = (getWindowWidth()-20) + "px";
                header.style.width = (getWindowWidth()-20) + "px";
                subheader.style.width = (getWindowWidth()-20) + "px";
                if (map.updateSize) { map.updateSize(); };
            }

            onresize=function(){ resize(); };

            </script>
          </head>
          <body onload="init()">
            <div id="header"><h1>%(title)s</h1></div>
            <div id="subheader">Generated by <a href="http://www.maptiler.org/">MapTiler</a>/<a href="http://www.klokan.cz/projects/gdal2tiles/">GDAL2Tiles</a>, Copyright &copy; 2008 <a href="http://www.klokan.cz/">Klokan Petr Pridal</a>,  <a href="http://www.gdal.org/">GDAL</a> &amp; <a href="http://www.osgeo.org/">OSGeo</a> <a href="http://code.google.com/soc/">GSoC</a>
            <!-- PLEASE, LET THIS NOTE ABOUT AUTHOR AND PROJECT SOMEWHERE ON YOUR WEBSITE, OR AT LEAST IN THE COMMENT IN HTML. THANK YOU -->
            </div>
            <div id="map"></div>
            <script type="text/javascript" >resize()</script>
          </body>
        </html>""" % args return s