<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><br>Hi,<br><br>I want to use OpenLayers Api for displaying a custom map of objects (like a grid over the entire map, so over all map tiles), taking the functionality of zooming and panning; I'll need three custom zoom levels, using 256x256 px tile size, with the full map size of:<br><br>zoom level 0: SIZE<br>zoom level 1: SIZE * 5<br>zoom level 2: SIZE * 10<br><br>The SIZE is actually dynamic over time, so I'll cache the slices for a fixed amount of time.<br><br>Now, the grid like objects I want to draw on each slice will have 1px, 5px and respectively 10px (both on width and height), corresponding to each of the zoom levels.<br><br>Now, I have the following JavaScript code to initialize &amp; draw the map:<br><br>var map, layer, layer0, layer1, layer2;<br><br>OpenLayers.Layer.TMS.prototype.getURL = function ( bounds )<br>{<br>&nbsp;&nbsp;&nbsp;
 bounds=this.adjustBounds(bounds);<br>&nbsp;&nbsp;&nbsp; var res=this.map.getResolution();<br>&nbsp;&nbsp;&nbsp; var x=Math.round((bounds.left-this.tileOrigin.lon)/(res*this.tileSize.w));<br>&nbsp;&nbsp;&nbsp; var y=Math.round((bounds.bottom-this.tileOrigin.lat)/(res*this.tileSize.h));<br>&nbsp;&nbsp;&nbsp; var z=this.map.getZoom();<br>&nbsp;&nbsp;&nbsp; var path='slice.php?layer='+this.layer+'&amp;x='+x+'&amp;y='+y+'&amp;z='+z;<br>&nbsp;&nbsp;&nbsp; var url=this.url;<br>&nbsp;&nbsp;&nbsp; if(url instanceof Array)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; url=this.selectUrl(path,url);<br>&nbsp;&nbsp;&nbsp; return url+path;<br>};<br><br>function init()<br>{<br>&nbsp;&nbsp;&nbsp; map = new OpenLayers.Map('map', {units:'m'});<br><br>&nbsp;&nbsp;&nbsp; layer = new OpenLayers.Layer.TMS("3 Zoom Levels", "http://local.server/", {layer: -1,&nbsp;&nbsp;&nbsp; resolutions: [1,2,10],<br>&nbsp;&nbsp;&nbsp; maxExtent: new
 OpenLayers.Bounds(0, 0, Math.ceil($x*10/256)*256, Math.ceil($y*10/256)*256),<br>&nbsp;&nbsp;&nbsp; tileSize: new OpenLayers.Size(256,256), buffer:0});<br><br>&nbsp;&nbsp;&nbsp; /* for testing &gt;<br><br>&nbsp;&nbsp;&nbsp; layer0 = new OpenLayers.Layer.TMS("Zoom 0 Like", "http://local.server/", {layer: 0,&nbsp;&nbsp;&nbsp; resolutions: [1],<br>&nbsp;&nbsp;&nbsp; maxExtent: new OpenLayers.Bounds(0, 0, Math.ceil(x*1/256)*256, Math.ceil(y*1/256)*256),<br>&nbsp;&nbsp;&nbsp; tileSize: new OpenLayers.Size(256,256), buffer:0});<br><br>&nbsp;&nbsp;&nbsp; layer1 = new OpenLayers.Layer.TMS("Zoom 1 like", "http://local.server/", {layer: 1,&nbsp;&nbsp;&nbsp; resolutions: [1],<br>&nbsp;&nbsp;&nbsp; maxExtent: new OpenLayers.Bounds(0, 0, Math.ceil(x*5/256)*256, Math.ceil(y*5/256)*256),<br>&nbsp;&nbsp;&nbsp; tileSize: new OpenLayers.Size(256,256), buffer:0});<br><br>&nbsp;&nbsp;&nbsp; layer2 = new OpenLayers.Layer.TMS("Zoom 2 like", "http://local.server/", {layer:
 2,&nbsp;&nbsp;&nbsp; resolutions: [1],<br>&nbsp;&nbsp;&nbsp; maxExtent: new OpenLayers.Bounds(0, 0, Math.ceil(x*10/256)*256, Math.ceil(y*10/256)*256),<br>&nbsp;&nbsp;&nbsp; tileSize: new OpenLayers.Size(256,256), buffer:0});<br><br>&nbsp;&nbsp;&nbsp; */ &lt; for testing<br><br>&nbsp;&nbsp;&nbsp; map.addLayer(layer);<br>&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; map.addControl(new OpenLayers.Control.LayerSwitcher());<br>&nbsp;&nbsp;&nbsp; map.zoomToMaxExtent();<br>}<br><br>init();<br><br>With the [Math.ceil(x*5/256)*256] and [Math.ceil(y*5/256)*256)] (for example) I get the exact number of slices I need for a zoom level (here for the zoom level #1 as I multiply with #5)<br><br>x and y are the maximum number of grid objects on the entire map (horizontal and vertical)<br><br>so for level 0, when each object have 1px (on the slice) we'll have:<br>Math.ceil(x*1/256)*256, Math.ceil(y*1/256)*256) as the maxExtent<br><br>for zoom level 2:<br>Math.ceil(x*10/256)*256,
 Math.ceil(y*10/256)*256) as the maxExtent<br><br>Now, the problem I have is that I don't know why the map it's not ok (some offsets for the zoom level 0, it is not centered..) and also the x (slice number on x) going into the request on the server <br>(path='slice.php?layer='+this.layer+'&amp;x='+x+'&amp;y='+y+'&amp;z='+z;)<br>differs between the zoom levels with 1 (one).<br><br>If I run the code from [for testing] with each layer corresponding to a zoom level, I get the right map, with all slices correctly shown on the map (including centered for zoom level 0).<br><br>If I got it right, "resolutions" (on the map) must be set so that it represents how much of the map units are on one pixel.<br><br>I have 10 map units / pixel for zoom level 0 (object grid on slice at 1 pixel), 2 map units / pixel for zoom level 1 (object grid on slice at 5 pixels) and 1 map unit / pixel for zoom level 2 (object grid on slice at 10 pixels).<br><br>But this seem to be not
 ok, where I'm mistaken?<br><br>Dragos.<br><br><br></td></tr></table><br>