5 function createMap(divName) {
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 markers = new OpenLayers.Layer.Markers("markers", { visibility: false });
28 map.addLayer(markers);
30 map.addControl(new OpenLayers.Control.LayerSwitcher());
35 function getTileURL(bounds) {
36 var res = this.map.getResolution();
37 var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
38 var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
39 var z = this.map.getZoom();
40 var limit = Math.pow(2, z);
42 if (y < 0 || y >= limit)
48 x = ((x % limit) + limit) % limit;
50 return this.url + z + "/" + x + "/" + y + "." + this.type;
54 function addMarkerToMap(position, icon, description) {
55 var marker = new OpenLayers.Marker(position, icon);
57 markers.addMarker(marker);
58 markers.setVisibility(true);
61 marker.events.register("click", marker, function() { openMapPopup(marker, description) });
67 function openMapPopup(marker, description) {
68 // var box = document.createElement("div");
69 // box.innerHTML = description;
70 // box.style.display = 'none';
71 // box.style.width = "200px";
72 // document.body.appendChild(box);
76 popup = new OpenLayers.Popup.AnchoredBubble("popup", marker.lonlat,
77 new OpenLayers.Size(200, 50),
78 "<p>" + description + "</p>",
80 popup.setBackgroundColor("#E3FFC5");
86 function closeMapPopup() {
88 map.removePopup(popup);
93 function removeMarkerFromMap(marker){
94 markers.removeMarker(marker);
97 function getMapLayers() {
100 for (var i=0; i< this.map.layers.length; i++) {
101 var layer = this.map.layers[i];
103 if (layer.isBaseLayer) {
104 layers += (layer == this.map.baseLayer) ? "B" : "0";
106 layers += (layer.getVisibility()) ? "T" : "F";
113 function setMapLayers(layers) {
114 for (var i=0; i < layers.length; i++) {
115 var layer = map.layers[i];
116 var c = layers.charAt(i);
119 map.setBaseLayer(layer);
120 } else if ( (c == "T") || (c == "F") ) {
121 layer.setVisibility(c == "T");
126 function mercatorToLonLat(merc) {
127 var lon = (merc.lon / 20037508.34) * 180;
128 var lat = (merc.lat / 20037508.34) * 180;
130 lat = 180/Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180)) - Math.PI / 2);
132 return new OpenLayers.LonLat(lon, lat);
135 function lonLatToMercator(ll) {
136 var lon = ll.lon * 20037508.34 / 180;
137 var lat = Math.log(Math.tan((90 + ll.lat) * Math.PI / 360)) / (Math.PI / 180);
139 lat = lat * 20037508.34 / 180;
141 return new OpenLayers.LonLat(lon, lat);
144 function scaleToZoom(scale) {
145 return Math.log(360.0/(scale * 512.0)) / Math.log(2.0);