<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 & draw the map:<br><br>var map, layer, layer0, layer1, layer2;<br><br>OpenLayers.Layer.TMS.prototype.getURL = function ( bounds )<br>{<br>
bounds=this.adjustBounds(bounds);<br> var res=this.map.getResolution();<br> var x=Math.round((bounds.left-this.tileOrigin.lon)/(res*this.tileSize.w));<br> var y=Math.round((bounds.bottom-this.tileOrigin.lat)/(res*this.tileSize.h));<br> var z=this.map.getZoom();<br> var path='slice.php?layer='+this.layer+'&x='+x+'&y='+y+'&z='+z;<br> var url=this.url;<br> if(url instanceof Array)<br> url=this.selectUrl(path,url);<br> return url+path;<br>};<br><br>function init()<br>{<br> map = new OpenLayers.Map('map', {units:'m'});<br><br> layer = new OpenLayers.Layer.TMS("3 Zoom Levels", "http://local.server/", {layer: -1, resolutions: [1,2,10],<br> maxExtent: new
OpenLayers.Bounds(0, 0, Math.ceil($x*10/256)*256, Math.ceil($y*10/256)*256),<br> tileSize: new OpenLayers.Size(256,256), buffer:0});<br><br> /* for testing ><br><br> layer0 = new OpenLayers.Layer.TMS("Zoom 0 Like", "http://local.server/", {layer: 0, resolutions: [1],<br> maxExtent: new OpenLayers.Bounds(0, 0, Math.ceil(x*1/256)*256, Math.ceil(y*1/256)*256),<br> tileSize: new OpenLayers.Size(256,256), buffer:0});<br><br> layer1 = new OpenLayers.Layer.TMS("Zoom 1 like", "http://local.server/", {layer: 1, resolutions: [1],<br> maxExtent: new OpenLayers.Bounds(0, 0, Math.ceil(x*5/256)*256, Math.ceil(y*5/256)*256),<br> tileSize: new OpenLayers.Size(256,256), buffer:0});<br><br> layer2 = new OpenLayers.Layer.TMS("Zoom 2 like", "http://local.server/", {layer:
2, resolutions: [1],<br> maxExtent: new OpenLayers.Bounds(0, 0, Math.ceil(x*10/256)*256, Math.ceil(y*10/256)*256),<br> tileSize: new OpenLayers.Size(256,256), buffer:0});<br><br> */ < for testing<br><br> map.addLayer(layer);<br> <br> map.addControl(new OpenLayers.Control.LayerSwitcher());<br> 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+'&x='+x+'&y='+y+'&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>