5 function createMap(divName, centre, zoom) {
6 OpenLayers.Util.onImageLoadError = function() {
7 this.src = OpenLayers.Util.getImagesLocation() + "404.png";
10 map = new OpenLayers.Map(divName,
11 { maxExtent: new OpenLayers.Bounds(-20037508,-20037508,20037508,20037508),
13 maxResolution: 156543,
15 projection: "EPSG:41001" });
17 var mapnik = new OpenLayers.Layer.TMS("Mapnik",
18 "http://tile.openstreetmap.org/",
19 { type: 'png', getURL: getTileURL, displayOutsideMaxExtent: true });
22 var osmarender = new OpenLayers.Layer.TMS("Osmarender",
23 "http://dev.openstreetmap.org/~ojw/Tiles/tile.php/",
24 { type: 'png', getURL: getTileURL, displayOutsideMaxExtent: true });
25 map.addLayer(osmarender);
27 map.addControl(new OpenLayers.Control.LayerSwitcher());
28 map.setCenter(centre, zoom);
33 function getTileURL(bounds) {
34 var res = this.map.getResolution();
35 var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
36 var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
37 var z = this.map.getZoom();
38 var limit = Math.pow(2, z);
40 if (y < 0 || y >= limit)
46 x = ((x % limit) + limit) % limit;
48 return this.url + z + "/" + x + "/" + y + "." + this.type;
52 function addMarkerToMap(position, icon, description) {
53 if (markers == null) {
54 markers = new OpenLayers.Layer.Markers("markers");
55 map.addLayer(markers);
58 var marker = new OpenLayers.Marker(position, icon);
60 markers.addMarker(marker);
63 marker.events.register("click", marker, function() { openMapPopup(marker, description) });
69 function openMapPopup(marker, description) {
70 // var box = document.createElement("div");
71 // box.innerHTML = description;
72 // box.style.display = 'none';
73 // box.style.width = "200px";
74 // document.body.appendChild(box);
78 popup = new OpenLayers.Popup.AnchoredBubble("popup", marker.lonlat,
79 new OpenLayers.Size(200, 50),
80 "<p>" + description + "</p>",
82 popup.setBackgroundColor("#E3FFC5");
88 function closeMapPopup() {
90 map.removePopup(popup);
95 function removeMarkerFromMap(marker){
96 markers.removeMarker(marker);
99 function mercatorToLonLat(merc) {
100 var lon = (merc.lon / 20037508.34) * 180;
101 var lat = (merc.lat / 20037508.34) * 180;
102 var PI = 3.14159265358979323846;
104 lat = 180/PI * (2 * Math.atan(Math.exp(lat * PI / 180)) - PI / 2);
106 return new OpenLayers.LonLat(lon, lat);
109 function lonLatToMercator(ll) {
110 var lon = ll.lon * 20037508.34 / 180;
111 var lat = Math.log(Math.tan((90 + ll.lat) * PI / 360)) / (PI / 180);
113 lat = lat * 20037508.34 / 180;
115 return new OpenLayers.LonLat(lon, lat);
118 function scaleToZoom(scale) {
119 return Math.log(360.0/(scale * 512.0)) / Math.log(2.0);