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.34,-20037508.34,20037508.34,20037508.34),
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 });
22 var osmarender = new OpenLayers.Layer.TMS("Osmarender",
23 "http://dev.openstreetmap.org/~ojw/Tiles/tile.php/",
24 { type: 'png', getURL: getTileURL });
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();
39 return this.url + z + "/" + x + "/" + y + "." + this.type;
42 function addMarkerToMap(position, icon, description) {
43 if (markers == null) {
44 markers = new OpenLayers.Layer.Markers("markers");
45 map.addLayer(markers);
48 var marker = new OpenLayers.Marker(position, icon);
50 markers.addMarker(marker);
53 marker.events.register("click", marker, function() { openMapPopup(marker, description) });
59 function openMapPopup(marker, description) {
60 // var box = document.createElement("div");
61 // box.innerHTML = description;
62 // box.style.display = 'none';
63 // box.style.width = "200px";
64 // document.body.appendChild(box);
68 popup = new OpenLayers.Popup.AnchoredBubble("popup", marker.lonlat,
69 new OpenLayers.Size(200, 50),
70 "<p>" + description + "</p>",
72 popup.setBackgroundColor("#E3FFC5");
78 function closeMapPopup() {
80 map.removePopup(popup);
85 function removeMarkerFromMap(marker){
86 markers.removeMarker(marker);
89 function mercatorToLonLat(merc) {
90 var lon = (merc.lon / 20037508.34) * 180;
91 var lat = (merc.lat / 20037508.34) * 180;
92 var PI = 3.14159265358979323846;
94 lat = 180/PI * (2 * Math.atan(Math.exp(lat * PI / 180)) - PI / 2);
96 return new OpenLayers.LonLat(lon, lat);
99 function lonLatToMercator(ll) {
100 var lon = ll.lon * 20037508.34 / 180;
101 var lat = Math.log(Math.tan((90 + ll.lat) * PI / 360)) / (PI / 180);
103 lat = lat * 20037508.34 / 180;
105 return new OpenLayers.LonLat(lon, lat);
108 function scaleToZoom(scale) {
109 return Math.log(360.0/(scale * 512.0)) / Math.log(2.0);