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://a.tile.openstreetmap.org/","http://b.tile.openstreetmap.org/","http://c.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)
44 return OpenLayers.Util.getImagesLocation() + "404.png";
48 x = ((x % limit) + limit) % limit;
51 var path = z + "/" + x + "/" + y + "." + this.type;
53 if (url instanceof Array)
55 url = this.selectUrl(path, url);
62 function getArrowIcon() {
63 var size = new OpenLayers.Size(25, 22);
64 var offset = new OpenLayers.Pixel(-30, -27);
65 var icon = new OpenLayers.Icon("/images/arrow.png", size, offset);
70 function addMarkerToMap(position, icon, description) {
71 var marker = new OpenLayers.Marker(position, icon);
73 markers.addMarker(marker);
74 markers.setVisibility(true);
77 marker.events.register("click", marker, function() { openMapPopup(marker, description) });
83 function openMapPopup(marker, description) {
86 popup = new OpenLayers.Popup.AnchoredBubble("popup", marker.lonlat,
87 sizeMapPopup(description),
88 "<p style='padding-right: 28px'>" + description + "</p>",
90 popup.setBackgroundColor("#E3FFC5");
96 function closeMapPopup() {
98 map.removePopup(popup);
103 function sizeMapPopup(text) {
104 var box = document.createElement("div");
106 box.innerHTML = text;
107 box.style.visibility = "hidden";
108 box.style.position = "absolute";
109 box.style.top = "0px";
110 box.style.left = "0px";
111 box.style.width = "200px";
112 box.style.height = "auto";
114 document.body.appendChild(box);
116 var width = box.offsetWidth;
117 var height = box.offsetHeight;
119 document.body.removeChild(box);
121 return new OpenLayers.Size(width + 30, height + 24);
124 function removeMarkerFromMap(marker){
125 markers.removeMarker(marker);
128 function getMapLayers() {
131 for (var i=0; i< this.map.layers.length; i++) {
132 var layer = this.map.layers[i];
134 if (layer.isBaseLayer) {
135 layers += (layer == this.map.baseLayer) ? "B" : "0";
137 layers += (layer.getVisibility()) ? "T" : "F";
144 function setMapLayers(layers) {
145 for (var i=0; i < layers.length; i++) {
146 var layer = map.layers[i];
147 var c = layers.charAt(i);
150 map.setBaseLayer(layer);
151 } else if ( (c == "T") || (c == "F") ) {
152 layer.setVisibility(c == "T");
157 function mercatorToLonLat(merc) {
158 var lon = (merc.lon / 20037508.34) * 180;
159 var lat = (merc.lat / 20037508.34) * 180;
161 lat = 180/Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180)) - Math.PI / 2);
163 return new OpenLayers.LonLat(lon, lat);
166 function lonLatToMercator(ll) {
167 var lon = ll.lon * 20037508.34 / 180;
168 var lat = Math.log(Math.tan((90 + ll.lat) * Math.PI / 360)) / (Math.PI / 180);
170 lat = lat * 20037508.34 / 180;
172 return new OpenLayers.LonLat(lon, lat);
175 function scaleToZoom(scale) {
176 return Math.log(360.0/(scale * 512.0)) / Math.log(2.0);