[OpenLayers-Users] need help with layers

M_Airola mairola at gmail.com
Thu Mar 4 09:44:33 EST 2010


Hello,
Have you tried using the gdal utility gdal2tiles?
It is a python script that will take an image, cut it into tiles at various
resolutions, store it to a directory structure and create a ready to use
HTML file?

It seems easier than trying to pass arguments via the URL to your server.  

Links to the gdal programs can be found here: http://www.gdal.org/

My OpenLayers code looks something like this (it was mostly written by the
script and output to the HTML file. I just added the path
"/Users/Matthew/Documents/IA_NLCD_Color/" when I moved the HTML file from
the directory structure where the gdal2tiles created it. :)
var IowaColor = new OpenLayers.Layer.TMS( "NLCD Color",
"/Users/Matthew/Documents/IA_NLCD_Color/",
	                {   // url: '', serviceVersion: '.', layername: '.',
                            type: 'png', getURL: overlay_getTileURL, alpha:
true,
                            isBaseLayer: false
	                });

                    if (OpenLayers.Util.alphaHack() == false) {
IowaColor.setOpacity(0.7); }
                    
	            map.addLayers([IowaColor]);

	        function overlay_getTileURL(bounds) {
	            var res = this.map.getResolution();
	            var x = Math.round((bounds.left - this.maxExtent.left) / (res *
this.tileSize.w));
	            var y = Math.round((bounds.bottom - this.tileOrigin.lat) / (res
* this.tileSize.h));
	            var z = this.map.getZoom();

                    if (mapBounds.intersectsBounds( bounds ) && z >=
mapMinZoom && z <= mapMaxZoom ) {
                   //document.write( this.url + z + "/" + x + "/" + y + "."
+ this.type);

                  // document.getElementById("DubugOutput").value = this.url
+ z + "/" + x + "/" + y + "." + this.type
                  document.getElementById("DubugOutput").value = z + "/" + x
+ "/" + y
                   return this.url + z + "/" + x + "/" + y + "." +
this.type;
                } else {
                   return "http://www.maptiler.org/img/none.png";
                }
	        }
-- 
View this message in context: http://n2.nabble.com/need-help-with-layers-tp4668267p4674645.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.



More information about the Users mailing list