//
// Appelé dans le body onload()
//
function init(){

    var tileServer = "http://tilecache.quiedeville.org/";

    map = new OpenLayers.Map('map',
			     { maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
			       numZoomLevels: 19,
			       maxResolution: 156543.0399,
			       units: 'm',
			       transitionEffect: "resize",
			       projection: new OpenLayers.Projection("EPSG:900913")});
    
    var layerMapnik = new OpenLayers.Layer.TMS("Mapnik",tileServer,{transitionEffect:'resize',getURL:getOSMURL});
    
    map.addLayers([layerMapnik]);
    
    map.setCenter(new OpenLayers.LonLat(0.49,47).transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913")), 5);
        
    newl = new OpenLayers.Layer.GML( "France", "eol.xml", { units :'m', projection :"EPSG:4326" });

    newl.events.register("moveend", newl, resizePoint);

    map.addLayer(newl);

}
//
// Resize point element depends on zoom level
//
function resizePoint (evt) {

    var z = this.map.getZoom();

    var pointSize = Math.max(1, Math.min(10, z - 3)) ;

    var oRegStyleMap = new OpenLayers.StyleMap({ pointRadius: pointSize,
						 strokeColor: "blue",
						 strokeWidth: 1,
						 fillOpacity: 0.3,
						 fillColor: "#3A79BB"});

    this.addOptions({ styleMap: oRegStyleMap });
}



function getOSMURL(bounds) {
    var res = this.map.getResolution();
    var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
    var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
    var z = this.map.getZoom();
    var limit = Math.pow(2, z);
    x = ((x % limit) + limit) % limit;
    var url = this.url;
    var path = z + "/" + x + "/" + y + ".png";
    
    if (url instanceof Array)
	{
	    url = this.selectUrl(path, url);
	}
    return url + path;
}
